cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
503
Views
1
Helpful
1
Replies

am trying to change loopback ip address through netconf

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()

 

 

 

 

 

1 Reply 1

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>

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io