Skip to content

Instantly share code, notes, and snippets.

View jeremyschulman's full-sized avatar

Jeremy Schulman jeremyschulman

View GitHub Profile
@jeremyschulman
jeremyschulman / demo_ipaddress.py
Created October 2, 2015 14:52
Demo subnetting IP pool using python ipaddress library
from ipaddress import IPv4Network
# mock link data
g_links = [
{'local': dict(name='leaf-1', ifname='swp1'),
'remote': dict(name='rtr-1', ifname='eth1/1')},
{'local': dict(name='leaf-1', ifname='swp2'),
'remote': dict(name='rtr-2', ifname='eth2/1')},
@jeremyschulman
jeremyschulman / eth_nei_table.yml(for junos)
Last active August 29, 2015 14:06
Ethernet Link Checker (multi-vendor/using Schprokits Table output)
# for hosts wtih _os = 'junos'
---
eth_nei_table:
rpc: get-lldp-neighbors-information
item: lldp-neighbor-information
key: lldp-local-interface
view: eth_nei_record
eth_nei_record:
fields:
>>> dev
Device(srx210)
# import the filesystem library and bind it to the device (dev)
>>> from jnpr.junos.utils.fs import *
>>> fs = FS(dev)
# use the 'cat' function to dump the content of the file
>>> print fs.cat('/var/log/dcd')
@jeremyschulman
jeremyschulman / admin_ifd_byidx.py
Last active November 6, 2020 16:57
Python script to admin up/down a Junos interface using the SNMP ifTable index value. Requires the "ncclient" module found at www.github.com/Juniper/ncclient
# Copyright (c) 1999-2011, Juniper Networks Inc.
# All rights reserved.
# Author: Jeremy Schulman
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
@jeremyschulman
jeremyschulman / change_interface_admin.py
Created September 25, 2013 13:40
python example to change Junos port admin state
import sys
from ncclient import manager as ncclient
from ncclient.operations.rpc import RPCError
from lxml import etree
### ---------------------------------------------------------------------------
### unix invocation:
### $ python change_interface_admin.py <hostname> <portname> [up|down]
###
@jeremyschulman
jeremyschulman / dnsmasq.conf
Created June 27, 2013 21:59
Sample dnsmasq.conf file that uses option-82 circuit-id to assign fixed IP address
#domain-needed
bogus-priv
expand-hosts
addn-hosts=/var/lib/dnsmasq/hosts
# interfaces ...
interface=eth1
# DCHP configs ...
require 'net/netconf/jnpr'
require 'junos-ez/stdlib'
require 'junos-ez/srx'
login = { :target => 'vsrx', :username => 'jeremy', :password => 'jeremy1', }
### open a NETCONF session to the SRX device
ndev = Netconf::SSH.new( login )
@jeremyschulman
jeremyschulman / trace-route-ldp.rb
Last active December 11, 2015 05:08
A simple example tracking down a routing path through a BGP/MPLS/LDP Junos network.
require 'highline/import'
require 'net/netconf/jnpr'
target = ARGV[0] || begin
puts "You must specify a starting target device"
exit 1
end
dst_route = ARGV[1] || begin
puts "You need to specify a destination route"
@jeremyschulman
jeremyschulman / junos-walk-lldp.rb
Last active December 11, 2015 04:39
Simple demonstration of "walking LLDP" in a Junos network to create a connection map
require 'highline/import'
require 'net/netconf/jnpr'
start_at = ARGV[0] || begin
puts "You need to specify a starting target ip/host"
exit 1
end
my_username = ENV["USER"]
puts "login: #{my_username}"