cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2032
Views
2
Helpful
23
Replies

Example for id-allocation using Templates

gmathewk
Cisco Employee
Cisco Employee

Hi Team,

I had some questions about id-allocation using resource-manager package. I wanted to establish the following scenario. I have some interface tunnel configs for IOS device. I want to use id-allocation for assigning the interface number when this template is assigned to a device. Is there a way in the XML template I can request for an allocation and get back the value assigned and use it ?

Do you have any example where you have used allocation ?

Regards

Georgy

23 Replies 23

vleijon
Cisco Employee
Cisco Employee

Hi Georgy,


Unfortunately, you will have to write a little bit of code to use the id-allocator. You can of course keep your template and apply the template from your code.

--Viktor

I think i can request for an allocation using Netconf operation. And in the device template can i use the xpath and retrieve the ID allocated for that request ?

adam.allen
Level 1
Level 1

Doesn't the resource-manager package follow the reactive-fast-map pattern, in which case it wouldn't be possible to do in templates alone.

Adam

Hi Adam, it does use RFM. Which was why my instinctive answer was no. But, now that I was challenged on it I am thinking it can actually be done in this simple case. I'll try to whip up an example!

-Viktor

That would be interesting to see - I was looking at allocating ID's for IP SLA probes - but decided against adding RFM to the service just to get an ID.

vleijon
Cisco Employee
Cisco Employee

First of all - this is not recommended practice! Writing a few lines of code really isn't that bad.

That being said: I made it work!

I setup a simple ncs with the id-allocator, resource-manager packages, and the router ned from the examples directory. Then I did

ncs-make-package --service-skeleton template templ

and compiled the model for templ.

I modified the template a lot, see https://gist.github.com/vleijon/d2dcdffd70bfab7dcaddbdd47196505dfor full template, and created a pool named pool1 (hardcoded name):

set resource-pools id-pool pool1 range start 1 end 100

I can then create services:

admin@ncs% set tmpl demo device ex1

[ok][2018-07-14 11:35:50]

[edit]

admin@ncs% commit dry-run

cli {

    local-node {

        data +tmpl demo {

             +    device [ ex1 ];

             +}

              resource-pools {

                  id-pool pool1 {

             +        allocation demo {

             +            allocating-service /tmpl[name='demo'];

             +        }

                  }

              }

    }

}

[ok][2018-07-14 11:35:52]

[edit]

admin@ncs% commit

Commit complete.

[ok][2018-07-14 11:36:00]

[edit]

admin@ncs% exit

[ok][2018-07-14 11:36:01]

admin@ncs> request tmpl demo get-modifications

cli {

    local-node {

        data  devices {

                   device ex1 {

                       config {

                           r:sys {

                               interfaces {

              +                    interface eth5 {

              +                        description "Interface 5";

              +                    }

                               }

                           }

                       }

                   }

               }

               resource-pools {

                   id-pool pool1 {

              +        allocation demo {

              +            allocating-service /tmpl[name='demo'];

              +        }

                   }

               }

             

    }

}

[ok][2018-07-14 11:36:12]

And this is sort of the desired behaviour, it waits for allocation before applying the template.

Hi Viktor,

Thanks for the example. I tried this with NSO 4.6.1.3 version. But doesnt seem to work for me. I am using a cisco-ios netsim device, and i dont see the {$val} being used.

Thanks for your help in advance.

Regards

Georgy

I'd not thought about the new template features, for me I think I'd prefer a little bit of code instead of baking the complexity into the template.

Adam

Georgy: I modified it for ios in the obvious ways (using config trees from the ios ned instead of the router ned),

https://gist.github.com/vleijon/8aba33485ab353ceb24203bd5fab410a and it seems to work fine for me on 4.6.1.

Adam: I agree with you. It is neat that it works, but in most cases I would pick the code route.

gmathewk
Cisco Employee
Cisco Employee

Thanks Viktor. Which version of resource-manager package are you using ?

Regards

Georgy

I was using the versions from the NSO distribution, they don't have any nice version numbers, but are just called example:

admin@ncs> show packages package resource-manager-example

packages package resource-manager-example

package-version 0.0.0.0

description     "Resource manager package"

ncs-min-version [ 3.0 ]

directory       ./state/packages-in-use/1/resource-manager

oper-status up

gmathewk
Cisco Employee
Cisco Employee

I have NCS - 4.6.1.3 and resource-manager - 3.3.0

admin@ncs% commit dry-run | debug template

Fetching literal "pool1" (from file "tmpl-template.xml", line 8)

Operation 'merge' on existing node: /resource-pools/idalloc:id-pool[name='pool1'] (from file "tmpl-template.xml", line 8)

Evaluating "./name" (from file "tmpl-template.xml", line 10)

Context node: /tmpl[name='vishal']

Result:

For /tmpl[name='vishal'], it evaluates to "vishal"

Operation 'merge' on non-existing node: /resource-pools/idalloc:id-pool[name='pool1']/allocation[id='vishal'] (from file "tmpl-template.xml", line 10)

Operation 'merge' on non-existing node: /resource-pools/idalloc:id-pool[name='pool1']/allocation[id='vishal']/username (from file "tmpl-template.xml", line 11)

Evaluating "./name" (from file "tmpl-template.xml", line 11)

Context node: /tmpl[name='vishal']

Result:

For /tmpl[name='vishal'], it evaluates to "vishal"

Setting /resource-pools/idalloc:id-pool[name='pool1']/allocation[id='vishal']/username to "vishal"

Operation 'merge' on non-existing node: /resource-pools/idalloc:id-pool[name='pool1']/allocation[id='vishal']/allocating-service (from file "tmpl-template.xml", line 12)

Fetching literal "/tmpl:tmpl[tmpl:name='" (from file "tmpl-template.xml", line 12)

Evaluating "./name" (from file "tmpl-template.xml", line 12)

Context node: /tmpl[name='vishal']

Result:

For /tmpl[name='vishal'], it evaluates to "vishal"

Fetching literal "']" (from file "tmpl-template.xml", line 12)

Setting /resource-pools/idalloc:id-pool[name='pool1']/allocation[id='vishal']/allocating-service to "/tmpl:tmpl[tmpl:name='vishal']"

Processing instruction 'set-root-node': changing XPath root node to the datastore root node (from file "tmpl-template.xml", line 23)

Processing instruction 'set': evaluating expression for variable myref (from file "tmpl-template.xml", line 24)

Evaluating "concat('/tmpl:tmpl{',./name,'}')" (from file "tmpl-template.xml", line 24)

Context node: /tmpl[name='vishal']

Result: "/tmpl:tmpl{vishal}"

Processing instruction 'set': evaluating expression for variable val (from file "tmpl-template.xml", line 25)

Evaluating "/id-allocator/pool[name='pool1']/allocation[owner=$myref]" (from file "tmpl-template.xml", line 25)

Context node: /tmpl[name='vishal']

Result: empty node

Processing instruction 'if': evaluating the condition (from file "tmpl-template.xml", line 27)

Evaluating conditional expression "boolean($val)" (from file "tmpl-template.xml", line 27)

Context node: /tmpl[name='vishal']

Result: false - skipping siblings

Processing instruction 'if': skipping (from file "tmpl-template.xml", line 27)

cli {

    local-node {

        data +tmpl vishal {

             +    device [ md1 ];

             +}

              resource-pools {

                  id-pool pool1 {

             +        allocation vishal {

             +            username vishal;

             +            allocating-service /tmpl[name='vishal'];

             +        }

                  }

              }

    }

}

gmathewk
Cisco Employee
Cisco Employee

Also the config template you used the key 'owner'

<?set val = {/id-allocator/pool[name='pool1']/allocation[owner=$myref]}?>

But i dont see that in the xpath.

admin@ncs> show resource-pools | display xpath

/resource-pools/idalloc:id-pool[name='pool1']/allocation[id='cc']/response/id 102

/resource-pools/idalloc:id-pool[name='pool1']/allocation[id='demo']/response/id 100

/resource-pools/idalloc:id-pool[name='pool1']/allocation[id='denis']/response/id 103

/resource-pools/idalloc:id-pool[name='pool1']/allocation[id='gmk']/response/id 10

vleijon
Cisco Employee
Cisco Employee

First of all, you are looking at the wrong place, try

show id-allocator | display xpath

Second of all, in commit dry-run, you shouldn't expect to see a value for val, because the id-allocator hasn't had a chance to allocate it yet.