cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2609
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

gmathewk
Cisco Employee
Cisco Employee

I see the allocation happening. But get-modifications does not show anything

admin@ncs> request tmpl vishal get-modifications

cli {

    local-node {

        data  resource-pools {

                   id-pool pool1 {

              +        allocation vishal {

              +            username vishal;

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

              +        }

                   }

               }

    }

}

After you have done that commit, and have the allocation there, try doing a re-deploy | debug template.

gmathewk
Cisco Employee
Cisco Employee

admin@ncs> show resource-pools

NAME   ID  ERROR  ID

----------------------

pool1  g1  -      1

       g2  -      2

[ok][2018-07-17 10:38:33]

admin@ncs> show id-allocator

NAME   START  END  START  END  START  END  ID

-----------------------------------------------

pool1  -      -                3      10   1

                                           2

admin@ncs% request tmpl g2 re-deploy | 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='g2']

Result:

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

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

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

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

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

Result:

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

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

Operation 'merge' on non-existing node: /resource-pools/idalloc:id-pool[name='pool1']/allocation[id='g2']/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='g2']

Result:

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

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

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

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='g2']

Result: "/tmpl:tmpl{g2}"

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='g2']

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='g2']

Result: false - skipping siblings

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

[ok][2018-07-17 10:41:40]

[edit]

admin@ncs%

System message at 2018-07-17 10:41:40...

Commit performed by admin via console using cli.

gmathewk
Cisco Employee
Cisco Employee

I was checking the xpath.

admin@ncs> show id-allocator | display xpath

/id-allocator/pool[name='pool1']/available[start='3'][end='10']

/id-allocator/pool[name='pool1']/allocation[id='1']

/id-allocator/pool[name='pool1']/allocation[id='2']

Yeah. That is a difference in your id-allocator. It doesn't seem to contain the owner in the allocation pool.

It might be possible to make it work using the resource-pool path instead, using a query like the one in the comment in the template. But, I am not entirely sure how.

I would recommend just breaking the allocation out into python code.

gmathewk
Cisco Employee
Cisco Employee

Why is the resource manager package in the distribution different from the official version ? Are there plans to add this owner tag in the official one too ?

vleijon
Cisco Employee
Cisco Employee

Generally, both the NEDs and the other packages distributed with NSO are old, and for testing only. This is done because they have to work with the examples, and it is easier to do that if they are not upgraded as often as the official ones.


The reason I used that tag was because of a problem with xpath processing in NSO (I think it is namespace related, but I didn't bother breaking it down further). I am guessing that making it work with a more official resource-manager would be fairly straight-forward.

gmathewk
Cisco Employee
Cisco Employee

Hi Viktor,

For some reason i am not able to make it work with the new resource manager package. Will you be able to help ?

Regards

Georgy

Hi Georgy,

 

I double checked last week and unfortunately I had missed a few details of how id-allocations work. So, no, it will not be possible to make it work using only templates, you will have to write those five lines of python. 

 

Best Regards,

  Viktor