Skip to content

Instantly share code, notes, and snippets.

@vleijon
Created July 14, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vleijon/d2dcdffd70bfab7dcaddbdd47196505d to your computer and use it in GitHub Desktop.
Save vleijon/d2dcdffd70bfab7dcaddbdd47196505d to your computer and use it in GitHub Desktop.
<config-template xmlns="http://tail-f.com/ns/config/1.0"
servicepoint="tmpl">
<resource-pools xmlns="http://cisco.com/yang/nso/resource-allocator">
<!-- This part does the allocation, the pool name is fixed, but the allocation is set to the current name
of the service -->
<id-pool>
<name>pool1</name>
<allocation>
<id>{./name}</id>
<allocating-service xmlns:tmpl="http://com/example/tmpl">/tmpl:tmpl[tmpl:name='{./name}']</allocating-service>
</allocation>
</id-pool>
</resource-pools>
<!-- We want to do our change only if the allocation is ready -->
<devices xmlns="http://tail-f.com/ns/ncs">
<!-- This is a little bit of a hack to find our allocation, if it exists.
We should really look at /ralloc:resource-pools/ralloc:id-pool[ralloc:name='pool1']/allocation[id='t1']/response, but I couldn't make that work the way I wanted. -->
<?set-root-node {/}?>
<?set myref = {concat('/tmpl:tmpl\{',./name,'\}')}?>
<?set val = {/id-allocator/pool[name='pool1']/allocation[owner=$myref]}?>
<!-- Then we make a conditional based on if the value is there yet or not -->
<?if {$val}?>
<device>
<name>{./device}</name>
<config>
<sys xmlns="http://example.com/router">
<interfaces>
<interface>
<name>eth{$val}</name>
<description>Interface {$val}</description>
</interface>
</interfaces>
</sys>
</config>
</device>
<?end?>
</devices>
</config-template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment