-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Expert
committed
Jan 12, 2023
1 parent
12120f1
commit b65a909
Showing
5 changed files
with
399 additions
and
1 deletion.
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,45 @@ | ||
from ncclient import manager | ||
import xmltodict | ||
from rich.table import Table | ||
from rich.console import Console | ||
from pathlib import Path | ||
import os | ||
|
||
USERNAME = "expert" | ||
PASSWORD = "1234QWer!" | ||
NETCONF_PORT = 830 | ||
|
||
DEVICES = { | ||
"dev-c8kv-1": "192.168.100.11", | ||
"dev-c8kv-2": "192.168.100.12", | ||
"dev-c8kv-3": "192.168.100.13", | ||
} | ||
|
||
|
||
def main(): | ||
# open connect to netconf device | ||
for device,ip in DEVICES.items(): | ||
m = manager.connect( | ||
host=ip, | ||
port=NETCONF_PORT, | ||
username=USERNAME, | ||
password=PASSWORD, | ||
hostkey_verify=False, | ||
look_for_keys=False, | ||
allow_agent=False, | ||
) | ||
|
||
print(f"Configuring {device}") | ||
config = Path(__file__).parent / "configs" / f"{device}.xml" | ||
configure_ospf(m, config.read_text()) | ||
m.close_session() | ||
|
||
def configure_ospf(m, config): | ||
netconf_reply = m.edit_config(config, target="running") | ||
if netconf_reply.ok and netconf_reply.error == None: | ||
return | ||
else: | ||
print(netconf_reply.xml) | ||
|
||
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
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,113 @@ | ||
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> | ||
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> | ||
<router> | ||
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> | ||
<ospf> | ||
<process-id> | ||
<id>1</id> | ||
<network> | ||
<ip>10.10.12.0</ip> | ||
<wildcard>255.255.255.0</wildcard> | ||
<area>0</area> | ||
</network> | ||
<network> | ||
<ip>10.10.23.0</ip> | ||
<wildcard>255.255.255.0</wildcard> | ||
<area>0</area> | ||
</network> | ||
<network> | ||
<ip>10.2.0.0</ip> | ||
<wildcard>255.255.255.0</wildcard> | ||
<area>0</area> | ||
</network> | ||
<router-id>2.2.2.2</router-id> | ||
</process-id> | ||
</ospf> | ||
</router-ospf> | ||
</router> | ||
<interface> | ||
<GigabitEthernet> | ||
<name>1</name> | ||
<switchport> | ||
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch"> | ||
<native> | ||
<vlan-config> | ||
<tag>true</tag> | ||
</vlan-config> | ||
</native> | ||
</trunk> | ||
</switchport> | ||
<ip> | ||
<address> | ||
<primary> | ||
<address>10.0.12.2</address> | ||
<mask>255.255.255.0</mask> | ||
</primary> | ||
</address> | ||
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> | ||
<ospf> | ||
<process-id> | ||
<id>1</id> | ||
<area> | ||
<area-id>0</area-id> | ||
</area> | ||
</process-id> | ||
</ospf> | ||
</router-ospf> | ||
</ip> | ||
</GigabitEthernet> | ||
<GigabitEthernet> | ||
<name>2</name> | ||
<switchport> | ||
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch"> | ||
<native> | ||
<vlan-config> | ||
<tag>true</tag> | ||
</vlan-config> | ||
</native> | ||
</trunk> | ||
</switchport> | ||
<ip> | ||
<address> | ||
<primary> | ||
<address>10.0.23.2</address> | ||
<mask>255.255.255.0</mask> | ||
</primary> | ||
</address> | ||
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> | ||
<ospf> | ||
<process-id> | ||
<id>1</id> | ||
<area> | ||
<area-id>0</area-id> | ||
</area> | ||
</process-id> | ||
</ospf> | ||
</router-ospf> | ||
</ip> | ||
</GigabitEthernet> | ||
</interface> | ||
</native> | ||
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> | ||
<interface> | ||
<name>GigabitEthernet1</name> | ||
<enabled>true</enabled> | ||
</interface> | ||
<interface> | ||
<name>GigabitEthernet2</name> | ||
<enabled>true</enabled> | ||
</interface> | ||
<interface> | ||
<name>Loopback1</name> | ||
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type> | ||
<enabled>true</enabled> | ||
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"> | ||
<address> | ||
<ip>10.2.0.1</ip> | ||
<netmask>255.255.255.0</netmask> | ||
</address> | ||
</ipv4> | ||
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/> | ||
</interface> | ||
</interfaces> | ||
</config> |
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,113 @@ | ||
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> | ||
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> | ||
<router> | ||
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> | ||
<ospf> | ||
<process-id> | ||
<id>1</id> | ||
<network> | ||
<ip>10.10.13.0</ip> | ||
<wildcard>255.255.255.0</wildcard> | ||
<area>0</area> | ||
</network> | ||
<network> | ||
<ip>10.10.23.0</ip> | ||
<wildcard>255.255.255.0</wildcard> | ||
<area>0</area> | ||
</network> | ||
<network> | ||
<ip>10.3.0.0</ip> | ||
<wildcard>255.255.255.0</wildcard> | ||
<area>0</area> | ||
</network> | ||
<router-id>3.3.3.3</router-id> | ||
</process-id> | ||
</ospf> | ||
</router-ospf> | ||
</router> | ||
<interface> | ||
<GigabitEthernet> | ||
<name>2</name> | ||
<switchport> | ||
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch"> | ||
<native> | ||
<vlan-config> | ||
<tag>true</tag> | ||
</vlan-config> | ||
</native> | ||
</trunk> | ||
</switchport> | ||
<ip> | ||
<address> | ||
<primary> | ||
<address>10.0.23.3</address> | ||
<mask>255.255.255.0</mask> | ||
</primary> | ||
</address> | ||
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> | ||
<ospf> | ||
<process-id> | ||
<id>1</id> | ||
<area> | ||
<area-id>0</area-id> | ||
</area> | ||
</process-id> | ||
</ospf> | ||
</router-ospf> | ||
</ip> | ||
</GigabitEthernet> | ||
<GigabitEthernet> | ||
<name>3</name> | ||
<switchport> | ||
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch"> | ||
<native> | ||
<vlan-config> | ||
<tag>true</tag> | ||
</vlan-config> | ||
</native> | ||
</trunk> | ||
</switchport> | ||
<ip> | ||
<address> | ||
<primary> | ||
<address>10.0.13.3</address> | ||
<mask>255.255.255.0</mask> | ||
</primary> | ||
</address> | ||
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> | ||
<ospf> | ||
<process-id> | ||
<id>1</id> | ||
<area> | ||
<area-id>0</area-id> | ||
</area> | ||
</process-id> | ||
</ospf> | ||
</router-ospf> | ||
</ip> | ||
</GigabitEthernet> | ||
</interface> | ||
</native> | ||
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> | ||
<interface> | ||
<name>GigabitEthernet2</name> | ||
<enabled>true</enabled> | ||
</interface> | ||
<interface> | ||
<name>GigabitEthernet3</name> | ||
<enabled>true</enabled> | ||
</interface> | ||
<interface> | ||
<name>Loopback1</name> | ||
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type> | ||
<enabled>true</enabled> | ||
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"> | ||
<address> | ||
<ip>10.3.0.1</ip> | ||
<netmask>255.255.255.0</netmask> | ||
</address> | ||
</ipv4> | ||
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/> | ||
</interface> | ||
</interfaces> | ||
</config> |
Oops, something went wrong.