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

Apply Templates to cisco-ios devices

houlee
Cisco Employee
Cisco Employee

I have a service callback applying several templates in a row to a cisco-ios device. The pseudo code is like this:

 

tvars = ncs.template.Variables()
template = ncs.template.Template(service)
...
template.apply('template_1', tvars)
template.apply('template_2', tvars)
template.apply('template_3', tvars)

Suppose 'template_1' is a big one and it takes a while to actually apply it to the device. When running the service, the applying of 'template_2' wasn't blocked by the applying of 'template_1'. The service code just went through the template.apply() one by one without waiting for the previous one to be completed.

 

Is there any way to let the template.apply() block the service code until it finishes applying the template to the device? such as setting the flag in template.apply()? or some settings of the device?

 

Thanks.

1 Reply 1

yfherzog
Cisco Employee
Cisco Employee

Your service callback is running as part of a transaction.

The service callbacks gather all changes that you want to make to the data model, and only when all those callbacks return, all changes are sent to the devices using the NEDs.

 

For that reason, if you want templates to be applied one by one to your devices, they need to be part of different transactions, which means, a different run of the callback.

 

In most cases though, the NED is in charge of pushing the changes to the device in such sequence that all configs can be pushed as part of the same transaction (and it shouldn't matter in which order you actually applied the templates).

 

If you still need the different templates to be pushed one by one, you can add a new leaf to your service, e.g. 'service-phase', and change your callback pseudo code to be something like this:

 

 

tvars = ncs.template.Variables()
template = ncs.template.Template(service)
...
if phase 1:
template.apply('template_1', tvars)
if phase 2:
template.apply('template_1', tvars)
template.apply('template_2', tvars)
template.apply('template_3', tvars)
if phase 3:
template.apply('template_1', tvars)
template.apply('template_2', tvars)
template.apply('template_3', tvars)

 

 

There are also mechanisms to move between the phases in an automated way, but before you go there, convince yourself that this is indeed what you're after.

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:

Recognize Your Peers