cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
325
Views
5
Helpful
10
Replies
Highlighted

redeploy a service from python

Hello can you help on this please,

I'd like to re-deploy a service from my python code.

 

your help will be appreciate.

 

regards.

10 REPLIES 10
Highlighted
Cisco Employee

Re: redeploy a service from python

        with ncs.maapi.Maapi() as m:
            with ncs.maapi.Session(m, 'admin', 'system'):
                with m.start_read_trans() as t:
                    instance = ncs.maagic.get_node(t, dst_path)
                    inputs = instance.re_deploy.get_input()
                    inputs.reconcile.create()
                    self.log.debug('Redeploying instance...')
                    instance.re_deploy(inputs)
                    self.log.debug('Instance reconciled.')

This one is for re-deploy reconcile, but you can set whatever parameters you want instead.

Highlighted

Re: redeploy a service from python

Hello Dear Thanks for your reply, could you please tell me what represent 

dst_path

is it a variable that containe the service name?

 

regards. 

Highlighted

Re: redeploy a service from python

Hello I have test the code and debug, here the working code hope it will help someone else:

dst_path = SERVICE_NAME
with ncs.maapi.Maapi() as m:
            with ncs.maapi.Session(m, 'admin', 'system'):
                with m.start_read_trans() as t:
                    instance = ncs.maagic.get_node(t, dst_path)
                    inputs = instance["service_id"].re_deploy.get_input()
                    inputs.reconcile.create()
                    self.log.debug('Redeploying instance...')
                    instance["service_id"].re_deploy(inputs)
                    self.log.debug('Instance reconciled.')
Cisco Employee

Re: redeploy a service from python

Just a quick piece of extra information: It is generally not a good idea to use this kind of code from inside your create() code.
Highlighted

Re: redeploy a service from python

please what you mean? could you be most explicit.

Highlighted
Cisco Employee

Re: redeploy a service from python

Sure: You have operations such a re-deploy dry-run and commit dry-run. You want to be able to run those as dry-run, without changing the system. If you do things as part of the create code that starts a new transaction, that transaction will not have the dry-run flag on it, and the effects of that transaction is not visible in the original transaction.

For that reason creating a new transaction that changes the system from within create()-code is normally a bad idea, as is calling certain types of actions from within your existing transaction (namely, actions that in themselves create a new transaction).
Highlighted

Re: redeploy a service from python

Hello dear could you please share an example of the best practice.

regards.

Highlighted
Cisco Employee

Re: redeploy a service from python

I am not sure what you are asking for, can you please elaborate?
Highlighted

Re: redeploy a service from python

Hello, You just said that it is bad idea to use create() function since it start a new transaction.

So I'm asking according to you how could I manage service re-deploy from python.

Highlighted
Cisco Employee

Re: redeploy a service from python

Well, there are three main options I would say: Through a new action, kickers or the touch action.

But the best thing is to take a step back: Why do you want to do this redeploy and what is the situation/context where you need to do the redeploy?