Grouping in yang

Hi,

I have a grouping similar to the one below with several other attributes.

grouping common-attrib {
    leaf defaultLeaseTime { 
      description "Default lease time in seconds"; 
      type uint32 {
        range "1..31104000";
      }
      default 3600;
      units "seconds";
    }
}

Now this grouping is used in multiple places as below.

container server {
  container global-client-attributes {
    **uses common-attrib;**
  }

  list subnet {
    leaf subnet-with-prefix-length {
       type inet:ipv4-prefix;
    }
    container client-attributes {
      **uses common-attrib;**
    }
  }
}

Here I want the default value(3600s) of defaultLeaseTime leaf within the grouping to be applied only at the global level(server/global-client-attributes). Value for the same leaf inside the subnet list should be coming from user configuration only(no default value has to be set).

Is there a way to achieve this by still using the grouping?

You can use the refine statement to add default values to leafs. Specify the grouping as before without default value:

grouping common-attrib {
    leaf defaultLeaseTime { 
      description "Default lease time in seconds"; 
      type uint32 {
        range "1..31104000";
      }
      units "seconds";
    }
}

and then add default using refine sub statement:

container server {
  container global-client-attributes {
    uses common-attrib {
      refine defaultLeaseTime {
        default 3600; // Add default at the global level
      }
   }
}

list subnet {
  leaf subnet-with-prefix-length {
    type inet:ipv4-prefix;
  }
  container client-attributes {
    uses common-attrib;
    // No refine here
  }
}

See section 7.13.2 in RFC 7950 - The YANG 1.1 Data Modeling Language to learn more about refine.

If my Yang Parser cant handle ‘Refine’ statement what are the consequences?

You then likely want to educate yourself on what you are missing out on by reading up on the “refine” statement in the YANG 1.1 RFC 7950
https://tools.ietf.org/html/rfc7950#section-7.13.2