cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1112
Views
0
Helpful
1
Replies

Re deploy dry_run nso service instances using python

Hello,

 

I want to execute a python script that test if a service instance is out-of-sync and if this is True I want to execute re_deploy dry_run output. For this I worte the following script:

import ncs

with ncs.maapi.Maapi() as m:
  with ncs.maapi.Session(m, 'admin', 'python'):
   with m.start_read_trans() as t:
        root = ncs.maagic.get_root(t)
        for si in root.services.service:
                print(si.name)
                if si.check_sync().in_sync == False:
                        redeploy = si.re_deploy
                        inp = redeploy.get_input()
                        inp.dry_run.create()
                        result = redeploy(inp)
                        print(result.cli.local_node.data)

But when I execute this script I get the following error:

Traceback (most recent call last):
File "test.py", line 18, in <module>
result = redeploy(inp)
File "/opt/ncs/current/src/ncs/pyapi/ncs/maagic.py", line 1190, in __call__
return self.request(params)
File "/opt/ncs/current/src/ncs/pyapi/ncs/maagic.py", line 1181, in request
tv = params._tagvalues() if params else []
File "/opt/ncs/current/src/ncs/pyapi/ncs/maagic.py", line 1239, in _tagvalues
tv.extend(child._tagvalues())
File "/opt/ncs/current/src/ncs/pyapi/ncs/maagic.py", line 625, in _tagvalues
if self.exists():
File "/opt/ncs/current/src/ncs/pyapi/ncs/maagic.py", line 648, in exists
self._cache = self._backend._exists(self._path)
AttributeError: 'NoneType' object has no attribute '_exists'

 

Can someone please explain to me what I have done wrong ? and how can I correct it ?

Thanks in advance.

1 Reply 1

Alex Stevenson
Cisco Employee
Cisco Employee

 

Hello @AlaeddineJebnoun90723,

 

This is interesting because whether I run the script with Python 2 or 3, it always gives me this error:

 

Traceback (most recent call last):
  File "/Users/alexstev/Documents/dev/test.py", line 3, in <module>
    with ncs.maapi.Maapi() as m:
AttributeError: module 'ncs' has no attribute 'maapi'

 

 

I found some NSO API docs on DevNet that use maapi in a similar way as you: https://developer.cisco.com/docs/nso/api/#!ncs-maapi/module-ncs-maapi

 

Strange...

 

According to the NSO API Documentation, NSO requires Java to be installed to function, so make sure you install that. They also recommend you install the development tools. Furthermore, if you're using Mac or Linux, you must also install Ant. Instructions are on the page I linked. 

 

Unfortunately, when I run the script with Python 2 or 3, I now get an error 'No module named 'ncs' (even though I installed it) and 'AttributeError: module 'ncs' has no attribute 'maapi'', respectively. It might be a good idea to restart the computer at this point and try again.