cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1281
Views
5
Helpful
2
Replies

Error when i use when statement in yang

RehabRezek73161
Level 1
Level 1

i'm trying to make condition in NSO service that when i chose the device name to check it ned type ( ios or iosxr ) and depending on the output to will create the right container 

here is the part of yang that i used :

 

leaf device {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}


container SR_inputs {

container iosxr {


when " /ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='cisco-iosxr-cli-7.19-id:cisco-iosxr-cli-7.19'"

{

tailf:dependency "/ncs:devices/ncs:device/ncs:device-type/ncs:cli/ncs:ned-id";
}


}



}

 

the compile doesn't give me errors only warning : "warning: The when expression refers to the current node, will probably not work as intended. "

but it doesn't give me the correct output ( no container created after i choose the device ) 

 

 

any help please ? 

 

 

2 Replies 2

rogaglia
Cisco Employee
Cisco Employee

Containers are not "created on demand", the when statement condition is satisfied. The idea of a when statement is to validate when the container should exist. If you want to force the user API call to include the container, you should use the "mandatory true" statement.

 

RFC6020:

7.19.5. The when Statement

   The "when" statement makes its parent data definition statement
   conditional.  The node defined by the parent data definition
   statement is only valid when the condition specified by the "when"
   statement is satisfied.    

 

Thanks @rogaglia  for your reply 

I think i asked a wrong question. 

what i'm searching for exactly  is validate when the container should exist. 

as i have 2 containers  iosxe and iosxr and depending on ned type of device i choose i want to have one to appear 

as shown below:

leaf device {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}


container SR_inputs {

container iosxr {


when " /ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='cisco-iosxr-cli-7.19-id:cisco-iosxr-cli-7.19'"

{

tailf:dependency "/ncs:devices/ncs:device/ncs:device-type/ncs:cli/ncs:ned-id";
}


}

container iosxe {
when " /ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='cisco-ios-cli-6.90-id:cisco-ios-cli-6.90'"
{
tailf:dependency "/ncs:devices/ncs:device/ncs:device-type/ncs:cli/ncs:ned-id";
}
} }

 do when can validate xpath ? because as I found when i search that when always validate value not xpath. 

 

thanks