cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
629
Views
5
Helpful
1
Replies

How to write must statement to test if a device belongs to a given device group

Hello,

Can someone please point me to how to write must statement in the Yang model to test if a device belongs to a given device group ?

1 Accepted Solution

Accepted Solutions

vleijon
Cisco Employee
Cisco Employee

I made a quick example that I am going to attach, but basically the must expression can look like this (this also answers your previous question about two device groups):

    leaf-list device {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
      must "/ncs:devices/ncs:device-group[ncs:name='g1']/ncs:device-name[. = current()]"
        + "or /ncs:devices/ncs:device-group[ncs:name='g2']/ncs:device-name[. = current()]";
    }

I have devices r0 to r3, but I get this interaction in the CLI, which is better than I was expecting (note that I do not get r2 in the tab expansion):

admin@ncs(config)# show full-configuration devices device-group
devices device-group g1
 device-name [ r0 r1 ]
!
devices device-group g2
 device-name [ r1 r3 ]
!
admin@ncs(config)# multiref m1 device
Possible completions:
  [  r0  r1  r3

 

View solution in original post

1 Reply 1

vleijon
Cisco Employee
Cisco Employee

I made a quick example that I am going to attach, but basically the must expression can look like this (this also answers your previous question about two device groups):

    leaf-list device {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
      must "/ncs:devices/ncs:device-group[ncs:name='g1']/ncs:device-name[. = current()]"
        + "or /ncs:devices/ncs:device-group[ncs:name='g2']/ncs:device-name[. = current()]";
    }

I have devices r0 to r3, but I get this interaction in the CLI, which is better than I was expecting (note that I do not get r2 in the tab expansion):

admin@ncs(config)# show full-configuration devices device-group
devices device-group g1
 device-name [ r0 r1 ]
!
devices device-group g2
 device-name [ r1 r3 ]
!
admin@ncs(config)# multiref m1 device
Possible completions:
  [  r0  r1  r3