cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1365
Views
5
Helpful
2
Replies

How do i rename the device name in nso through python maapi

azhasale
Cisco Employee
Cisco Employee

From nso cli i can rename device name to some new name

rename devices device old_name new_name

commit no-networking

i am trying this but getting error:

with ncs.maapi.Maapi() as m:
with ncs.maapi.Session(m, 'azhar', 'system'):
with m.start_write_trans() as t:
root = ncs.maagic.get_root(t)
old_device = root.devices.device['MADSIM11']
m.move(t.th, ['new_device'], old_device._path)
t.apply(True, maapi.COMMIT_NCS_NO_NETWORKING)

 

this is the error i am getting:

Traceback (most recent call last):
File "/home/azhar/Documents/scripts/rename_nso_devices.py", line 173, in <module>
m.move(t.th, [new_device], old_device._path)
File "/opt/ncs/current/src/ncs/pyapi/ncs/maapi.py", line 272, in proxy
return real(self2.msock, *args, **kwargs)
TypeError: tokey[0] must be a _ncs.Value instance
[Finished in 0.1s with exit code 1]

 

Can someone please help here.

 

Thanks

1 Accepted Solution

Accepted Solutions

sspehar
Level 1
Level 1

Hi,

from _ncs.maapi docs tokey argument is a list of confdValues.

So try creating the Value object first and use that when calling move method. E.g

 
...
_new_device = _ncs.Value('new_device', _ncs.C_BUF)
m.move(t.th, [_new_device], old_device._path)

t.apply(True, maapi.COMMIT_NCS_NO_NETWORKING)

Hope it helps,

Simon

View solution in original post

2 Replies 2

sspehar
Level 1
Level 1

Hi,

from _ncs.maapi docs tokey argument is a list of confdValues.

So try creating the Value object first and use that when calling move method. E.g

 
...
_new_device = _ncs.Value('new_device', _ncs.C_BUF)
m.move(t.th, [_new_device], old_device._path)

t.apply(True, maapi.COMMIT_NCS_NO_NETWORKING)

Hope it helps,

Simon

Hi Simon,

 

Thank you, it works fine.