cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
308
Views
8
Helpful
0
Replies
snovello
Cisco Employee

Shared templates anti-pattern, simple stacked service explanation

Overview

In NSO the templates are in a flat namespace, and they can be referred to from any service. So it is possible to create a single template, say to set an interface description, and reuse it across services.

This note explains why this pattern is often not a good idea, and describes how stacked services can be a better solution.

Shared templates in practice

The interface between a template and the yang service model that is using it is in one of two forms, either through xpath expressions like

{/endpoint/name}

or $ variables like {$NETMASK} which are filled in by code - python or java

If you use xpath there is a tight linkage between template and yang model. All the services using a template would have to be guaranteed to have a particular structure which the template was dependent on. To do that you would typically define a grouping which they all import. This creates a tight coupling across all those services using the template, and also means the models cannot abstract what is in the template.

If you use $ variables, then whatever the template is, you must have code to fill in those variables, so often you will just be moving simple xpath expressions into your code. This will make your services less readable and add maintenace costs.

Stacked services

Normally we think of FASTMAP mapping from service models to device models directly, but it of can also map from service models to simpler service models. So if we have a shared template we can have  a simple service model to represent the variables that occur in that template. Typically we need no code just the template and a yang file.

Any service wanting to use that simple model simply creates instances of that simple model within its own templates.

For example:

say we have a simple model to set interface descriptions

list if-desc {

key "device interface";

leaf device { .... }

leaf interface { .... }

leaf description { ... }

}

If another service needs to set a description, then somewhere in it's templates we have for example:

<if-desc>

  <device>{/a-end/device}</device>

  <interface{interface}</interface>

  <description>{../circuit-id} A End</description>

<if-desc>

0 REPLIES 0