-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ktbyers/pynet
- Loading branch information
Showing
12 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[local] | ||
localhost ansible_connection=local | ||
|
||
[juniper] | ||
pynet-sf-srx ansible_ssh_host=10.10.10.227 juniper_user=pyclass juniper_passwd=password | ||
|
||
[juniper:vars] | ||
ansible_connection=local | ||
ansible_python_interpreter=~/applied_python/bin/python | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Print out Juniper Facts | ||
hosts: juniper | ||
gather_facts: false | ||
tasks: | ||
- name: Retrieve Juniper Facts | ||
junos_get_facts: host={{ ansible_ssh_host }} user={{ juniper_user }} passwd={{ juniper_passwd }} | ||
register: srx_info | ||
|
||
- name: Print SRX information | ||
debug: msg="{{ srx_info.facts }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
- name: Set hostname using conf notation | ||
hosts: juniper | ||
gather_facts: false | ||
tasks: | ||
- name: Set system hostname | ||
junos_install_config: | ||
host={{ ansible_ssh_host }} | ||
file=set_hostname.conf | ||
overwrite=false | ||
user={{ juniper_user }} | ||
passwd={{ juniper_passwd }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
- name: Set hostname using XML | ||
hosts: juniper | ||
gather_facts: false | ||
tasks: | ||
- name: Set system hostname | ||
junos_install_config: | ||
host={{ ansible_ssh_host }} | ||
file=set_hostname.xml | ||
overwrite=false | ||
user={{ juniper_user }} | ||
passwd={{ juniper_passwd }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
system { | ||
host-name pynet-test1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<configuration> | ||
<system> | ||
<host-name>pynet-jnpr-srx1</host-name> | ||
</system> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
''' | ||
Connect to Juniper device using PyEZ. Display device facts. | ||
''' | ||
|
||
from jnpr.junos import Device | ||
from getpass import getpass | ||
from pprint import pprint | ||
|
||
|
||
def main(): | ||
''' | ||
Connect to Juniper device using PyEZ. Display device facts. | ||
''' | ||
pwd = getpass() | ||
ip_addr = raw_input("Enter Juniper SRX IP: ") | ||
ip_addr = ip_addr.strip() | ||
|
||
juniper_srx = { | ||
"host": ip_addr, | ||
"user": "pyclass", | ||
"password": pwd | ||
} | ||
|
||
print "\n\nConnecting to Juniper SRX...\n" | ||
a_device = Device(**juniper_srx) | ||
a_device.open() | ||
pprint(a_device.facts) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
''' | ||
Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all | ||
of the interfaces. | ||
''' | ||
|
||
from jnpr.junos import Device | ||
from jnpr.junos.op.ethport import EthPortTable | ||
from getpass import getpass | ||
|
||
|
||
def main(): | ||
''' | ||
Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all | ||
of the interfaces. | ||
''' | ||
pwd = getpass() | ||
ip_addr = raw_input("Enter Juniper SRX IP: ") | ||
ip_addr = ip_addr.strip() | ||
|
||
juniper_srx = { | ||
"host": ip_addr, | ||
"user": "pyclass", | ||
"password": pwd | ||
} | ||
|
||
print "\n\nConnecting to Juniper SRX...\n" | ||
a_device = Device(**juniper_srx) | ||
a_device.open() | ||
|
||
eth_ports = EthPortTable(a_device) | ||
eth_ports.get() | ||
|
||
print "{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE", "IN PACKETS", "OUT PACKETS") | ||
for intf, eth_stats in eth_ports.items(): | ||
eth_stats = dict(eth_stats) | ||
oper_state = eth_stats['oper'] | ||
pkts_in = eth_stats['rx_packets'] | ||
pkts_out = eth_stats['tx_packets'] | ||
print "{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in, pkts_out) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
''' | ||
Connect to Juniper device using PyEZ. Display the routing table. | ||
''' | ||
|
||
from jnpr.junos import Device | ||
from jnpr.junos.op.routes import RouteTable | ||
from getpass import getpass | ||
|
||
|
||
def main(): | ||
''' | ||
Connect to Juniper device using PyEZ. Display the routing table. | ||
''' | ||
pwd = getpass() | ||
ip_addr = raw_input("Enter Juniper SRX IP: ") | ||
ip_addr = ip_addr.strip() | ||
|
||
juniper_srx = { | ||
"host": ip_addr, | ||
"user": "pyclass", | ||
"password": pwd | ||
} | ||
|
||
print "\n\nConnecting to Juniper SRX...\n" | ||
a_device = Device(**juniper_srx) | ||
a_device.open() | ||
|
||
routes = RouteTable(a_device) | ||
routes.get() | ||
|
||
print "\nJuniper SRX Routing Table: " | ||
for a_route, route_attr in routes.items(): | ||
print "\n" + a_route | ||
for attr_desc, attr_value in route_attr: | ||
print " {} {}".format(attr_desc, attr_value) | ||
|
||
print "\n" | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
''' | ||
Exercise using Juniper's PyEZ to make changes to device in various ways | ||
Using the PyEZ load method set the hostname on the device using set, conf, and XML formats. | ||
Display the differences between the running config and candidate config after each change. | ||
Perform at least one commit and one rollback(0) during this process. | ||
The hostname at the end of the testing should be: pynet-jnpr-srx1 | ||
''' | ||
|
||
from jnpr.junos import Device | ||
from jnpr.junos.utils.config import Config | ||
from getpass import getpass | ||
|
||
|
||
def main(): | ||
''' | ||
Exercise using Juniper's PyEZ to make changes to device in various ways | ||
''' | ||
pwd = getpass() | ||
ip_addr = raw_input("Enter Juniper SRX IP: ") | ||
ip_addr = ip_addr.strip() | ||
|
||
juniper_srx = { | ||
"host": ip_addr, | ||
"user": "pyclass", | ||
"password": pwd | ||
} | ||
|
||
print "\n\nConnecting to Juniper SRX...\n" | ||
a_device = Device(**juniper_srx) | ||
a_device.open() | ||
|
||
cfg = Config(a_device) | ||
|
||
print "Setting hostname using set notation" | ||
cfg.load("set system host-name test1", format="set", merge=True) | ||
|
||
print "Current config differences: " | ||
print cfg.diff() | ||
|
||
print "Performing rollback" | ||
cfg.rollback(0) | ||
|
||
print "\nSetting hostname using {} notation (external file)" | ||
cfg.load(path="load_hostname.conf", format="text", merge=True) | ||
|
||
print "Current config differences: " | ||
print cfg.diff() | ||
|
||
print "Performing commit" | ||
cfg.commit() | ||
|
||
print "\nSetting hostname using XML (external file)" | ||
cfg.load(path="load_hostname.xml", format="xml", merge=True) | ||
|
||
print "Current config differences: " | ||
print cfg.diff() | ||
|
||
print "Performing commit" | ||
cfg.commit() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
system { | ||
host-name test2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<configuration> | ||
<system> | ||
<host-name>pynet-jnpr-srx1</host-name> | ||
</system> | ||
</configuration> | ||
|