cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
154
Views
0
Helpful
3
Replies
Highlighted
Beginner

re-use templates with java mapping from given service context in NSO?

From documentation, I found how to do service-device mappings using java with a @ServiceCallback method. It works by instantiating templates from the service context like so:

 

@ServiceCallback(...)
public Properties create(ServiceContext context, ...) {
  ...
// instantiate the template   Template template = new Template(context, "template-name"); // where a file called template-name.xml must exist in the service package directory structure (context)   // then populate the template with variables
... }

Now, is it possible (from this service context) to grab a template from another directory?

 

The idea is to be able to grab templates from a common directory to re-use in multiple services in NSO without duplicating templates in each service.

 

Thanks

Roland

Everyone's tags (4)
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Re: re-use templates with java mapping from given service context in NSO?

Templates are not scoped, so you can use templates from any package. You cannot grab them from an arbitrary directory but you can make a package that basically contains only templates.
3 REPLIES 3
Cisco Employee

Re: re-use templates with java mapping from given service context in NSO?

Templates are not scoped, so you can use templates from any package. You cannot grab them from an arbitrary directory but you can make a package that basically contains only templates.
Beginner

Re: re-use templates with java mapping from given service context in NSO?

Thanks for your answer but maybe I have not written my problem clearly.

I don't want to work with a package only made of templates. What I want is to work with @ServiceCallback functions in java and populate my template instances there. It seems so far that you can only do this if the template (the actual xml file) is present in this particular package (or service as I called it initially)

I would like to be able to do something like the following from a @ServiceCallback function:
Template myTemplate = new Template(thisServiceContext, "/path/to/some/common/folder/that/all/my/packages/may/have/access/to") // grab a template out of the scope of this package if you will

otherwise if a piece of configuration happens in 2 packages, I need to duplicate the template.xml for that piece of configuration in multiple packages

Thanks
Cisco Employee

Re: re-use templates with java mapping from given service context in NSO?

I am sorry if I was unclear, that was exactly what I was trying to say: all templates are in scope from all packages.

So if you have a template template.xml in package A then in package B you can write template myTemplate = new Template(thisServiceContext, “template”) without problems. You cannot give a path, but if the template exists in the system you can access it from all services.