Originele netconf "script": Usertoevoegen_netconf.txt
Verbeterde script: user_toevoegen.py
This commit is contained in:
parent
3f8cadbb60
commit
5152f17c41
|
@ -0,0 +1,111 @@
|
|||
#Onderstaande commando uitvoeren op alle routers onder config-t
|
||||
Netconf-yang
|
||||
|
||||
#Onderstaande installeren op CentOS8
|
||||
yum install python3-pip
|
||||
python3 -m pip install ncclient
|
||||
|
||||
touch netconfr3.py
|
||||
nano netconfr3.py
|
||||
|
||||
#Onderstaande is het script om een user toevoegen op ISP!
|
||||
from ncclient import manager
|
||||
import xml.dom.minidom
|
||||
|
||||
m = manager.connect(
|
||||
host="ISP",
|
||||
port=830,
|
||||
username="cisco",
|
||||
password="cisco",
|
||||
hostkey_verify=False
|
||||
)
|
||||
|
||||
netconf_user = """
|
||||
<config>
|
||||
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
|
||||
<username>
|
||||
<name>HU</name>
|
||||
<privilege>15</privilege>
|
||||
<password>
|
||||
<encryption>0</encryption>
|
||||
<password>cisco1234</password>
|
||||
</password>
|
||||
</username>
|
||||
</native>
|
||||
</config>
|
||||
netconf_reply = m.edit_config(target="running", config=netconf_user)
|
||||
|
||||
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
|
||||
|
||||
touch netconfedgerouter.py
|
||||
nano netconfedgerouter.py
|
||||
|
||||
#Onderstaande is het script om een user toevoegen op Edgerouter!
|
||||
m = manager.connect(
|
||||
host="EdgeRouter",
|
||||
port=830,
|
||||
username="cisco",
|
||||
password="cisco",
|
||||
hostkey_verify=False
|
||||
)
|
||||
|
||||
netconf_user = """
|
||||
<config>
|
||||
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
|
||||
<username>
|
||||
<name>HU</name>
|
||||
<privilege>15</privilege>
|
||||
<password>
|
||||
<encryption>0</encryption>
|
||||
<password>cisco1234</password>
|
||||
</password>
|
||||
</username>
|
||||
</native>
|
||||
</config>
|
||||
netconf_reply = m.edit_config(target="running", config=netconf_user)
|
||||
|
||||
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
|
||||
|
||||
touch netconfisp.py
|
||||
nano netconfisp.py
|
||||
|
||||
#Onderstaande is het script om een user toevoegen op R3!
|
||||
|
||||
#User toevoegen ISP
|
||||
from ncclient import manager
|
||||
import xml.dom.minidom
|
||||
|
||||
m = manager.connect(
|
||||
host="R3",
|
||||
port=830,
|
||||
username="cisco",
|
||||
password="cisco",
|
||||
hostkey_verify=False
|
||||
)
|
||||
|
||||
netconf_user = """
|
||||
<config>
|
||||
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
|
||||
<username>
|
||||
<name>HU</name>
|
||||
<privilege>15</privilege>
|
||||
<password>
|
||||
<encryption>0</encryption>
|
||||
<password>cisco1234</password>
|
||||
</password>
|
||||
</username>
|
||||
</native>
|
||||
</config>
|
||||
netconf_reply = m.edit_config(target="running", config=netconf_user)
|
||||
|
||||
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# Originele uitvoering: Robbin, netheid: Taha
|
||||
from ncclient import manager # python3 -m pip install ncclient
|
||||
import xml.dom.minidom
|
||||
|
||||
routers = {'ISP':'10.5.5.2', 'EdgeRouter':'10.5.5.3', 'R3':'10.5.5.4'}
|
||||
|
||||
for router in routers:
|
||||
print(f"{'*'*6} working on: {router} {'*'*6}")
|
||||
m = manager.connect(
|
||||
host=routers[router],
|
||||
port=830,
|
||||
username="cisco",
|
||||
password="cisco",
|
||||
hostkey_verify=False
|
||||
)
|
||||
|
||||
netconf_user = """
|
||||
<config>
|
||||
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
|
||||
<username>
|
||||
<name>HU</name>
|
||||
<privilege>15</privilege>
|
||||
<password>
|
||||
<encryption>0</encryption>
|
||||
<password>cisco1234</password>
|
||||
</password>
|
||||
</username>
|
||||
</native>
|
||||
</config>
|
||||
"""
|
||||
netconf_reply = m.edit_config(target="running", config=netconf_user)
|
||||
|
||||
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
|
Reference in New Issue