06-03-2023 11:24 AM
hello this script is for testing only , i want to change the loop back of cisco ios xr (https://devnetsandbox.cisco.com/RM/Diagram/Index/e83cfd31-ade3-4e15-91d6-3118b867a0dd?diagramType=Topology)
i dont want to use the cisco-ios-xe-native schema , i want to learn how to change things through the output of get_config(source="running") but am always getting error not sure why , i hope you could help me to understand this
the initial ip is .54 am changing to .55 from the script
from ncclient import manager
import xml.dom.minidom
def check():
x = input('please type y/n')
while x not in ["n","y"]:
x = input('retype y/n')
if x in ["n","y"]:
return x
def connection(user,pwd,url):
return manager.connect(host=url,username=user,password=pwd,port=830,device_params={'name':'iosxr'}, hostkey_verify=False )
def main():
m = connection("admin","C1sco12345","sandbox-iosxr-1.cisco.com")
x = m.get_config(source='running')
#print(xml.dom.minidom.parseString(m.xml))
#print(xml.dom.minidom.parseString(x.xml).toprettyxml())
filterx='''
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Loopback18</name>
</interface>
</interfaces>
</filter>
'''
config_edit ='''
<config>
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Loopback18</name>
<config>
<name>Loopback18</name>
<type xmlns:idx="urn:ietf:params:xml:ns:yang:iana-if-type">idx:softwareLoopback</type>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<addresses>
<address>
<ip>191.168.10.55</ip>
<config>
<ip>191.168.10.55</ip>
<prefix-length>32</prefix-length>
</config>
</address>
</addresses>
</ipv4>
</subinterface>
</subinterfaces>
</interface>
</interfaces>
</config>
'''
y = m.get_config(source='running' , filter=filterx )
print(y.xml)
z = m.edit_config(target='running' , config=config_edit, default_operation="merge")
print(z.xml)
y = m.get_config(source='running' , filter=filterx )
print(y.xml)
if __name__ == "__main__":
main()
06-05-2023 01:05 AM
You cannot use cisco-ios-xe-native schema on an XR device. I would try with
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
<interface-configurations>
<interface-configuration>
<active>act</active>
<interface-name>Loopback18</interface-name>
<ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
<addresses>
<primary>
<address>191.168.10.55</address>
<netmask>255.255.255.255</netmask>
</primary>
</addresses>
</ipv4-network>
</interface-configuration>
</interface-configurations>
</interfaces>
</config>
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide