10-09-2019 12:38 PM
In ncs_cli, I can do the following:
admin@ncs(config)# copy devices device ios0 ios-copy1
admin@ncs(config)# no devices device ios-copy1 config
admin@ncs(config)# commit no-networking
Commit complete.
I want to do the same thing from Python, so I have come up with this:
maapi.copy_tree(trans.th, '/devices/device{ios0}', '/devices/device{ios0-copy2}')
del root.devices.device['ios0-copy2'].config
trans.apply(flags=maapi.COMMIT_NCS_NO_NETWORKING)
Unfortunately, it errors on line 2. I see the following when I attempt this from ipython-superuser:
---------------------------------------------------------------------------
Error Traceback (most recent call last)
<ipython-input-2-253dba028a5a> in <module>
----> 1 del root.devices.device['ios0-copy2'].config
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maagic.py in __delattr__(self, name)
483 child = children[name]
484 if hasattr(child, 'delete'):
--> 485 child.delete()
486 return
487 else:
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maagic.py in delete(self)
742 "To delete a list item, use del list[key]")
743 if self._backend:
--> 744 self._backend._delete(self._path)
745 self._set_attr('_populated', False)
746 if '_children' in self.__dict__:
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maagic.py in _delete(self, path)
128
129 def _delete(self, path):
--> 130 self.delete(path)
131
132 def _num_instances(self, path):
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maapi.py in proxy(self2, *args, **kwargs)
941 else:
942 real = getattr(_tm.maapi, name)
--> 943 return real(self2.maapi.msock, self2.th, *args, **kwargs)
944 setattr(Transaction, name, proxy)
945 return getattr(self, name)
Error: item does not exist (1):
Am I doing something wrong? Could this be a bug?
Thanks,
-Allen
10-09-2019 12:44 PM
10-09-2019 01:24 PM
Hi Viktor,
I just tried the .delete() as you suggested and it results in essentially the same error:
In [3]: root.devices.device['ios0-copy2'].config.delete()
---------------------------------------------------------------------------
Error Traceback (most recent call last)
<ipython-input-3-61453441d7f2> in <module>
----> 1 root.devices.device['ios0-copy2'].config.delete()
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maagic.py in delete(self)
742 "To delete a list item, use del list[key]")
743 if self._backend:
--> 744 self._backend._delete(self._path)
745 self._set_attr('_populated', False)
746 if '_children' in self.__dict__:
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maagic.py in _delete(self, path)
128
129 def _delete(self, path):
--> 130 self.delete(path)
131
132 def _num_instances(self, path):
/Users/achen/Documents/sandbox/nso/4.7/src/ncs/pyapi/ncs/maapi.py in proxy(self2, *args, **kwargs)
941 else:
942 real = getattr(_tm.maapi, name)
--> 943 return real(self2.maapi.msock, self2.th, *args, **kwargs)
944 setattr(Transaction, name, proxy)
945 return getattr(self, name)
Error: item does not exist (1):
I will also note that both `del` and `.delete()` of the device config work if I use them on a committed device (or device copy).
-Allen
10-09-2019 04:25 PM
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