06-10-2020 11:05 AM
Hello,
I can get the value of description on device interface using python maapi as below, but I couldnot get the value of ip address:
import ncs
import ncs.maagic as maagic
import ncs.maapi as maapi
with ncs.maapi.single_read_trans('admin', 'system', db=ncs.OPERATIONAL) as m:
root = ncs.maagic.get_root(m)
print(root.devices.device['mydevice'].config.ios__interface.GigabitEthernet[1].description)
my_interface_desc
print(root.devices.device['mydevice'].config.ios__interface.GigabitEthernet[1].ip.address)
the value returned is the word address not the ip address itself.
device: cisco IOS XE
NSO: 4.7.5
Solved! Go to Solution.
06-10-2020 11:44 AM
Right, you need to look at how the interface address is modeled:
This is what I see on 5.3.2.1 with IOS ned v 6.46:
admin@ncs% show devices device ios-0 config interface GigabitEthernet 0/0 | display xml
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>ios-0</name>
<config>
<interface xmlns="urn:ios">
<GigabitEthernet>
<name>0/0</name>
<description>Test interface</description>
<ip>
<address>
<primary>
<address>10.0.1.0</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
</GigabitEthernet>
</interface>
</config>
</device>
</devices>
</config>
So you'll need to add in 'ip.address.primary.address' to get address:
In [12]: with ncs.maapi.Maapi() as m:
...: with ncs.maapi.Session(m, 'admin', 'system'):
...: with m.start_write_trans() as t:
...: root = ncs.maagic.get_root(t)
...: dev = root.ncs__devices.device['ios-0']
...: devname = dev.name
...: print (devname)
...: desc = root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].description
...: print (desc)
...: addr = desc = root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].ip.address.primary.address
...: print (addr)
...: mask = desc = root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].ip.address.primary.mask
...: print (mask)
...:
ios-0
Test interface
10.0.1.0
255.255.255.0
06-10-2020 11:44 AM
Right, you need to look at how the interface address is modeled:
This is what I see on 5.3.2.1 with IOS ned v 6.46:
admin@ncs% show devices device ios-0 config interface GigabitEthernet 0/0 | display xml
<config xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>ios-0</name>
<config>
<interface xmlns="urn:ios">
<GigabitEthernet>
<name>0/0</name>
<description>Test interface</description>
<ip>
<address>
<primary>
<address>10.0.1.0</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
</GigabitEthernet>
</interface>
</config>
</device>
</devices>
</config>
So you'll need to add in 'ip.address.primary.address' to get address:
In [12]: with ncs.maapi.Maapi() as m:
...: with ncs.maapi.Session(m, 'admin', 'system'):
...: with m.start_write_trans() as t:
...: root = ncs.maagic.get_root(t)
...: dev = root.ncs__devices.device['ios-0']
...: devname = dev.name
...: print (devname)
...: desc = root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].description
...: print (desc)
...: addr = desc = root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].ip.address.primary.address
...: print (addr)
...: mask = desc = root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].ip.address.primary.mask
...: print (mask)
...:
ios-0
Test interface
10.0.1.0
255.255.255.0
06-10-2020 12:05 PM
06-10-2020 12:23 PM
06-10-2020 02:28 PM - edited 06-11-2020 03:56 AM
Many thanks for your quick response, last question, instead of getting a single value, can I get the output of whole configuration below the interface (e.g. description, ip address, ...) using python, something like:
root.ncs__devices.device['ios-0'].config.ios__interface.GigabitEthernet['0/0'].?
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