07-13-2018 08:00 AM - edited 03-01-2019 04:12 AM
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
07-17-2018 07:27 AM
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'];
+ }
}
}
}
}
07-17-2018 07:31 AM
After you have done that commit, and have the allocation there, try doing a re-deploy | debug template.
07-17-2018 07:41 AM
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.
07-17-2018 07:44 AM
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']
07-17-2018 08:08 AM
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.
07-17-2018 08:35 AM
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 ?
07-17-2018 08:51 AM
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.
07-18-2018 05:14 AM
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
07-24-2018 03:02 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide