cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1220
Views
0
Helpful
3
Replies

Unable to delete device configuration from a copied device in Python

allenc
Level 1
Level 1

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

3 Replies 3

vleijon
Cisco Employee
Cisco Employee
Config is a container, so you cannot use the del built-in, you can use the delete() method, you probably want to do root.devices.device['ios0-copy2'].config.delete(), though I have not checked this.

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

 

That is what I get for guessing too quickly! That does look surprising to me, might be worth raising a ticket with post-sales.
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: