02-15-2018 12:45 PM - edited 03-01-2019 04:06 AM
I am trying to create a multi-stage service model where certain selections provide the user with different choices and/or different templates. For example, assume the following YANG:
leaf device-size {
type enumeration {
enum small;
enum medium;
enum large;
}
leaf vnf-device-type {
type enumeration {
enum 1-arm;
enum 2-arm;
enum 3-arm;
}
Would it be possible to "dynamically" create a device template such that a user could select small / 1-arm and get one device configuration, but then select large / 2-arm and get another template? Or, do I need a seperate template for every permutation? I am assuming that some of this can be done in Python with variables, but I wasn't sure if NSO had any built in features to handle this kind of model natively.
Solved! Go to Solution.
02-16-2018 07:58 AM
So, if I am understanding this correctly, the following lines dictate when a certain section of the XML is actually "applicable"?
<config-template xmlns="http://tail-f.com/ns/config/1.0"
servicepoint="template-svc">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>{/device}</name>
<config>
<fooo>
...
</fooo>
<bar when="{/device-size='medium' && /vnf-device-type='1-arm'}">
....
</bar>
<baz when="{/vnf-device-type='2-arm'}">
....
</baz>
</config>
</device>
</devices>
</config-template>
Let me give this a test - this seems super handy! Thanks.
02-15-2018 02:27 PM
Maybe a simple template service:
list template-svc {
key name;
uses ncs:service-data;
ncs:servicepoint "template-svc";
leaf name {
type string;
}
leaf device {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}
leaf device-size {
type enumeration {
enum small;
enum medium;
enum large;
}
leaf vnf-device-type {
type enumeration {
enum 1-arm;
enum 2-arm;
enum 3-arm;
}
}
}
}
<config-template xmlns="http://tail-f.com/ns/config/1.0"
servicepoint="template-svc">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>{/device}</name>
<config>
<fooo>
...
</fooo>
<bar when="{/device-size='medium' && /vnf-device-type='1-arm'}">
....
</bar>
<baz when="{/vnf-device-type='2-arm'}">
....
</baz>
</config>
</device>
</devices>
</config-template>
02-16-2018 07:58 AM
So, if I am understanding this correctly, the following lines dictate when a certain section of the XML is actually "applicable"?
<config-template xmlns="http://tail-f.com/ns/config/1.0"
servicepoint="template-svc">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>{/device}</name>
<config>
<fooo>
...
</fooo>
<bar when="{/device-size='medium' && /vnf-device-type='1-arm'}">
....
</bar>
<baz when="{/vnf-device-type='2-arm'}">
....
</baz>
</config>
</device>
</devices>
</config-template>
Let me give this a test - this seems super handy! Thanks.
02-16-2018 08:22 AM
Yes, exactly like that. Between the {} you can put XPATH 1.0 expressions that are evaluated. The XML tags where the expressions evaluating to "false" are skipped.
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