04-15-2019 01:23 AM
Hello all,
I am trying to add NETCONF device to NSO through python API as follows:
import ncs;
with ncs.maapi.single_write_trans('admin', 'python', groups=['ncsadmin']) as t:
root = ncs.maagic.get_root(t)
root.devices.device.create('test')
root.devices.device['test'].address = '127.0.0.1'
root.devices.device['test'].port = 22
root.devices.device['test'].device_type.cli.create()
root.devices.device['test'].device_type.cli.ned_id = 'netconf'
root.devices.device['test'].device_type.cli.protocol = 'ssh'
root.devices.device['test'].authgroup = 'authtest'
root.devices.device['test'].state.admin_state = 'unlocked'
But I receive the following error:
root.devices.device['test'].device_type.cli.ned_id = 'netconf'
File "src/ncs/pyapi/ncs/maagic.py", line 471, in __setattr__
child.set_value(value)
File "src/ncs/pyapi/ncs/maagic.py", line 939, in set_value
value = _python_to_yang(value, self._cs_node)
File "src/ncs/pyapi/ncs/maagic.py", line 1927, in _python_to_yang
return _tm.Value.str2val(str(value), cs_node)
_ncs.error.Error: item has a bad/wrong type (5): Invalid string for type
what is the problem of my code?
Thanks,
Regards,
Solved! Go to Solution.
04-15-2019 09:55 AM
This python code will add a netconf device to the device tree:
In [15]: with ncs.maapi.Maapi() as m:
...: with ncs.maapi.Session(m, 'admin', 'python'):
...: with m.start_write_trans() as t:
...: root = ncs.maagic.get_root(t)
...: newdev = root.devices.device.create('test-dev')
...: newdev.address = '127.0.0.1'
...: newdev.port = 830
...: newdev.authgroup = 'default'
...: dev_type = newdev.device_type.netconf.create()
...: dev_type.ned_id = 'netconf'
...: print (dev_type)
...: newdev.state.admin_state = 'southbound-locked'
...: t.apply()
...:
netconf
admin@ncs% show devices device test-dev
address 127.0.0.1;
port 830;
authgroup default;
device-type {
netconf {
ned-id netconf;
}
}
state {
admin-state southbound-locked;
}
04-15-2019 01:49 AM
root.devices.device['test'].device_type.cli.ned_id = 'netconf'
root.devices.device['test'].device_type.cli.protocol = 'ssh'
protocol will = netconf or ssh
ned_id should be cisco-ios or nx or xr etc etc
04-15-2019 02:32 AM
Still it does not work. My goal is to add a netconf device do you think my syntax is OK:
root.devices.device['test'].device_type.cli.ned_id = ...
device_type.cli does not indicate I am adding a cli device?
Thanks,
04-15-2019 03:07 AM
what is the actual device ?
and do you have a NED for it
eg if i wanted to add an IOS router i would use the cisco-ios NED that ned can communicate with the device in several ways eg SSH or Netconf
04-15-2019 03:40 AM
04-15-2019 04:24 AM
So, as I understood the cli does not indicate I am adding a cli device it can be used to add a netconf device ad well. Am I right?
04-15-2019 04:40 AM
04-15-2019 04:53 AM - edited 04-15-2019 04:55 AM
Thanks for the reply. I set the netconf.ned_id to 'netconf' and I removed the netconf.protocol. Still I have the following ERR:
File "src/ncs/pyapi/ncs/maapi.py", line 1005, in apply
self.maapi.apply_trans_flags(self.th, keep_open, flags)
File "src/ncs/pyapi/ncs/maapi.py", line 254, in proxy
return real(self2.msock, *args, **kwargs)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
File "/usr/lib/python2.7/socket.py", line 174, in _dummy
raise error(EBADF, 'Bad file descriptor')
socket.error: [Errno 9] Bad file descriptor
04-15-2019 05:02 AM
04-15-2019 04:21 AM
I have a host with NETCONF server. I created already a NED for it in the NSO.
04-15-2019 09:55 AM
This python code will add a netconf device to the device tree:
In [15]: with ncs.maapi.Maapi() as m:
...: with ncs.maapi.Session(m, 'admin', 'python'):
...: with m.start_write_trans() as t:
...: root = ncs.maagic.get_root(t)
...: newdev = root.devices.device.create('test-dev')
...: newdev.address = '127.0.0.1'
...: newdev.port = 830
...: newdev.authgroup = 'default'
...: dev_type = newdev.device_type.netconf.create()
...: dev_type.ned_id = 'netconf'
...: print (dev_type)
...: newdev.state.admin_state = 'southbound-locked'
...: t.apply()
...:
netconf
admin@ncs% show devices device test-dev
address 127.0.0.1;
port 830;
authgroup default;
device-type {
netconf {
ned-id netconf;
}
}
state {
admin-state southbound-locked;
}
04-16-2019 03:09 AM
Thanks. It worked for me!
10-11-2023 06:56 AM
I have multiple neds with me and I need to add a device with multiple
cisco-nx-cli-3.0
snmp
netconf
how do i do that
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