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-13-2018 09:04 AM
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
07-13-2018 10:21 AM
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 ?
07-13-2018 12:06 PM
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
07-13-2018 12:32 PM
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
07-13-2018 01:17 PM
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.
07-14-2018 02:40 AM
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.
07-16-2018 11:20 AM
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
07-16-2018 12:33 PM
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
07-17-2018 12:08 AM
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.
07-17-2018 06:28 AM
Thanks Viktor. Which version of resource-manager package are you using ?
Regards
Georgy
07-17-2018 06:50 AM
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
07-17-2018 07:15 AM
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'];
+ }
}
}
}
}
07-17-2018 07:20 AM
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
07-17-2018 07:22 AM
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.
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