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

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

yfherzog
Cisco Employee
Cisco Employee
        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.

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. 

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.')

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.

please what you mean? could you be most explicit.

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).

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

regards.

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

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.

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?