ConfD User Community

Make container as optional

Hi ,

Is it possible to make container “SwitchPort” as optional (even with one of the members of the container as mandatory) so that commit is allowed even without configuring mandatory element “location” below yang schema.

please suggest if any options available.

module test-switch {
yang-version 1.1;
namespace “urn:test-switch”;
prefix “Switch”;

container SwitchPort {  //optional 
    leaf name { //optional
        type string;   
    }
    leaf location { //mandatory
        type string;   
        mandatory "true";
    }
}

}

Thanks,
Raja

Make it a presence container:
More details in the RFC.

container SwitchPort { //optional
presence “Enables switch port configuration”;
leaf name { //optional
type string;
}
leaf location { //mandatory
type string;
mandatory “true”;
}
}

Also double check the container name “SwitchPort” => check “Identifier Naming Conventions” in https://datatracker.ietf.org/doc/rfc8407/?include_text=1

thanks Nabil, it works