02-02-2022 05:37 AM
Hi,
Does anybody know if it's possible to concatenate the output of one leaf with a substring in another leafref. In my specific use-case I have a device-group that makes up an area, in that 'area' device-group I have a child device-group that contains all access-switches;
leaf area-id { tailf:info "Area assignment"; mandatory true; type leafref { path "/ncs:devices/ncs:device-group/ncs:name"; } } container access-port { leaf access-sw { type leafref { path "/ncs:devices/ncs:device-group[ncs:name=concat(current()/../../area-id,'-SW')]/ncs:member"; } leaf port { type leafref { path "deref(../access-sw)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name"; } } }
Is this possible?
-J
Solved! Go to Solution.
02-02-2022 11:37 AM
leaf area-id { tailf:info "Area assignment"; mandatory false; type leafref { path "/ncs:devices/ncs:device-group/ncs:name"; } } container access-port { leaf access-sw { type leafref { path "/ncs:devices/ncs:device-group/ncs:member"; require-instance false; } must ". = concat(current()/../../area-id, '-SW')"; } leaf port { type leafref { path "/ncs:devices/ncs:device[ncs:name=current()/../access-sw]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name"; } } }
admin@ncs# show devices device-group member NAME MEMBER ----------------------------- area1 [ area1-R area1-SW ] area2 [ area2-R area2-SW ] admin@ncs# conf Entering configuration mode terminal admin@ncs(config)# myservice example area-id area Possible completions: area1 area2 admin@ncs(config)# myservice example area-id area1 admin@ncs(config-myservice-example)# access-port access-sw area1-SW admin@ncs(config-myservice-example)# port ^ % Invalid input detected at '^' marker. admin@ncs(config-myservice-example)# access-port port 0/ Possible completions: 1 Hi 2 Hi admin@ncs(config-myservice-example)# access-port port 0/1 admin@ncs(config-myservice-example)# val Validation complete
02-02-2022 07:30 AM
02-02-2022 10:31 AM - edited 02-02-2022 10:32 AM
Thanks for your reply, Viktor.
Can you provide an example on how to do that?
I tried to do this, but I the access-sw leafref returned a list of device-group names instead of the members (and the port leafref failed as well);
leaf area-id { tailf:info "Area assignment"; mandatory true; type leafref { path "/ncs:devices/ncs:device-group/ncs:name"; } } list access-port { tailf:info "Access ports to assign vlan to"; key "access-sw port"; leaf access-sw { type leafref { path "/ncs:devices/ncs:device-group/ncs:name"; } must "contains(deref(current())/../ncs:name,deref(current())/../../area-id) and contains(deref(current())/../ncs:name,'-SW')" { tailf:dependency "/ncs:devices/ncs:device-group/ncs:name"; } } leaf port { type leafref { path "/ncs:devices/ncs:device[name=current()/../access-sw]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name"; } } }
02-02-2022 11:37 AM
leaf area-id { tailf:info "Area assignment"; mandatory false; type leafref { path "/ncs:devices/ncs:device-group/ncs:name"; } } container access-port { leaf access-sw { type leafref { path "/ncs:devices/ncs:device-group/ncs:member"; require-instance false; } must ". = concat(current()/../../area-id, '-SW')"; } leaf port { type leafref { path "/ncs:devices/ncs:device[ncs:name=current()/../access-sw]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name"; } } }
admin@ncs# show devices device-group member NAME MEMBER ----------------------------- area1 [ area1-R area1-SW ] area2 [ area2-R area2-SW ] admin@ncs# conf Entering configuration mode terminal admin@ncs(config)# myservice example area-id area Possible completions: area1 area2 admin@ncs(config)# myservice example area-id area1 admin@ncs(config-myservice-example)# access-port access-sw area1-SW admin@ncs(config-myservice-example)# port ^ % Invalid input detected at '^' marker. admin@ncs(config-myservice-example)# access-port port 0/ Possible completions: 1 Hi 2 Hi admin@ncs(config-myservice-example)# access-port port 0/1 admin@ncs(config-myservice-example)# val Validation complete
02-02-2022 01:10 PM - edited 02-02-2022 01:11 PM
I could imagine that the level of details I've provided makes it a bit weird
Image that you have a "distribution-block" consisting of a range of routers and range of access switches. All access switches are grouped in a device group "AREA01-SW" and all routers in that area are in "AREA01-RTR" device-group. As a parent device group, we have "AREA01" which has the two device-groups as child device-groups.
So basically, when constructing the service I want to reference only the top-level device-group AREA01, then for the access-port element (which is actually a list, and not a container) I want the YANG model to figure out to only allow (or display in the UI) all devices in the AREA01-SW device-group.
Further down, for the access-port selection I want to allow or display the ports on the particular device selected from the AREA01-SW device-group.
I know that this goes against the idea being abstracted from the underlying hardware/vendor etc. But in this case, the major purpose is to develop a user-friendly UI in a strict environment that doesn't require very deep network configuration skills to be able to deploy a service.
02-02-2022 02:59 PM
02-02-2022 05:12 PM
Ok thanks, I think that I've found an approach then. I do have another issue about the 'port' element. Then name in the path is in the /devices/device tree, while the element-name is derived from /devices/device-group. This doesn't seem to work..
Is there a way to just use the 'device-name' element as a string in the /ncs:devices/ncs:device[ncs:name=...] ?
02-02-2022 05:16 PM
02-02-2022 10:42 PM - edited 02-03-2022 01:02 AM
Thanks a lot Viktor! It seem to be working for me now
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: