cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
685
Views
0
Helpful
3
Replies

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

Roland_S
Level 1
Level 1

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

1 Accepted Solution

Accepted Solutions

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

View solution in original post

3 Replies 3

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

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

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