Skip to content

Commit 009faa7

Browse files
committed
adding Junos
1 parent 6d11df1 commit 009faa7

File tree

7 files changed

+81
-1
lines changed

7 files changed

+81
-1
lines changed

Python/Networking/IOS-XE/netconf-4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ncclient import manager
22
from pprint import pprint
33
import xmltodict
4-
import xml.dom.minidom
4+
55
# import logging
66
# logging.basicConfig(level=logging.DEBUG)
77

Python/Networking/Junos/getconfig.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from ncclient import manager
2+
from pprint import pprint
3+
from ncclient.xml_ import *
4+
5+
# set device configs
6+
switch = {"host": "10.10.10.150", "port": "830",
7+
"username": "root", "password": ""}
8+
9+
# make initial connection and save session as variable m
10+
with manager.connect(host=switch["host"], port=switch["port"], username=switch["username"], password=switch["password"], hostkey_verify=False, device_params={"name": "junos"}) as m:
11+
# retrieve config in XML format
12+
response = m.get_configuration(format='xml')
13+
14+
interfaces = response.xpath('configuration/interfaces/interface')
15+
16+
for interface in interfaces:
17+
int_name = interface.xpath('name')[0].text
18+
int_unit = interface.xpath('unit/name')[0].text
19+
ip = []
20+
for name in interface.xpath('unit/family/inet/address/name'):
21+
ip.append(name.text)
22+
print(f"{int_name}.{int_unit} {ip}")
23+
# print(response)

Python/Networking/Junos/junos.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from ncclient import manager
2+
from pprint import pprint
3+
import xmltodict
4+
import xml.dom.minidom
5+
switch = {"host": "10.10.10.150", "port": "830",
6+
"username": "root", "password": ""}
7+
8+
#rpc_filter = "<get-interface-information><interface-name>ge-0/0/1</interface-name><detail/></get-interface-information>"
9+
rpc_filter = "<get-interface-information><terse/></get-interface-information>"
10+
11+
with manager.connect(host=switch["host"], port=switch["port"], username=switch["username"], password=switch["password"], hostkey_verify=False, device_params={"name": "junos"}) as m:
12+
for capability in m.server_capabilities:
13+
print('*' * 50)
14+
print(capability)
15+
# get the running config on the filtered out interface
16+
print('Connected')
17+
netconf_response = m.rpc(rpc_filter)
18+
print('getting interface details')
19+
# print(netconf_response)
20+
interface_name = netconf_response.xpath('//physical-interface/name')
21+
interface_status = netconf_response.xpath(
22+
'//physical-interface/oper-status')
23+
int_admin = netconf_response.xpath('//physical-interface/admin-status')
24+
logical_name = netconf_response.xpath(
25+
'//physical-interface/logical-interface/name')
26+
local_address = netconf_response.xpath(
27+
'//physical-interface/logical-interface/address-family/interface-address/ifa-local')
28+
29+
for ph_name, status, admin, l_name in zip(interface_name, interface_status, int_admin, logical_name):
30+
ph_name = ph_name.text.split('\n')[1]
31+
status = status.text.split('\n')[1]
32+
admin = admin.text.split('\n')[1]
33+
l_name = l_name.text.split('\n')[1]
34+
35+
print(f"{ph_name} , {status} , {admin} , {l_name}")

Python/Networking/Junos/netconf.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh [email protected] -p 830 -s netconf
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<rpc>
2+
<close-session/>
3+
</rpc>
4+
5+
<rpc>
6+
<get-software-information>
7+
</get-software-information>
8+
</rpc>
9+
10+
<rpc>
11+
<get-alarm-information>
12+
</get-alarm-information>
13+
</rpc>
14+
15+
<rpc>
16+
<get-route-information>
17+
</get-route-information>
18+
</rpc>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<configuration>
2+
3+
</configuration>

src/lxml/apihelpers.pxi

Whitespace-only changes.

0 commit comments

Comments
 (0)