Skip to content

Commit

Permalink
Resolved enhancement #918
Browse files Browse the repository at this point in the history
  • Loading branch information
ygorelik authored and Abhi Keshav committed May 15, 2019
1 parent e133c3d commit 7c21ac4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* RPC execution stuck when NETCONF server closes session unexpectedly ([#914](https://github.com/CiscoDevNet/ydk-gen/issues/914))
* YDK attempting to send Commit command when 'writable-running' in capabilities ([#915](https://github.com/CiscoDevNet/ydk-gen/issues/915))
* Max value of range is set to None when not specified in the Yang model ([#916](https://github.com/CiscoDevNet/ydk-gen/issues/916))
* YDK MetaInfo should have a field for mandatory leaf ([#918](https://github.com/CiscoDevNet/ydk-gen/issues/918))

##### Note
The solution for GitHub issue ([#891](https://github.com/CiscoDevNet/ydk-gen/issues/891)) changed model API. However all model bundles generated with YDK-Gen version 0.7.3 and later are still compatible with core YDK components.
Expand Down
5 changes: 3 additions & 2 deletions sdk/cpp/core/tests/models/ydktest-sanity@2015-11-17.yang
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,9 @@ module ydktest-sanity {
}

leaf mtu {
type int32;
type int32 {
range "10..8000";
}
mandatory true;
}
}
Expand Down Expand Up @@ -793,7 +795,6 @@ module ydktest-sanity {
uses inner-pres;

container runner-2 {

presence "Runner-2 is presence controlled";
leaf some-leaf {
type string;
Expand Down
1 change: 1 addition & 0 deletions sdk/python/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Installation documentation for YDK-Py needs an update ([#906](https://github.com/CiscoDevNet/ydk-gen/issues/906))
* README file for YDK-Py repo is not rendering correctly ([#907](https://github.com/CiscoDevNet/ydk-gen/issues/907))
* Max value of range is set to None when not specified in the Yang model ([#916](https://github.com/CiscoDevNet/ydk-gen/issues/916))
* YDK MetaInfo should have a field for mandatory leaf ([#918](https://github.com/CiscoDevNet/ydk-gen/issues/918))

##### Note
The solution for GitHub issue ([#891](https://github.com/CiscoDevNet/ydk-gen/issues/891)) changed model API. However all model bundles generated with YDK-Gen version 0.7.3 and later are still compatible with core YDK components.
Expand Down
6 changes: 6 additions & 0 deletions sdk/python/core/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def test_enum_union_meta(self):
self.assertTrue(len(peer_type_meta_enum_dict) > 0)
print("\nEnum dictionary:\n %s" % peer_type_meta_enum_dict)

def test_mandatory_leaf(self):
mand = Runner.Mtus.Mtu()
mand.owner = 'test'
mand.mtu = 1500
mand_meta = mand._meta_info()
self.assertTrue(mand_meta.member('mtu').is_mandatory)

if __name__ == '__main__':
import sys
Expand Down
12 changes: 11 additions & 1 deletion sdk/python/core/ydk/_core/_dm_meta_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def __init__(self, name, mtype, ptype, ytype,
pmodule_name, clazz_name,
prange, pattern, doc,
presentation_name, module_name, is_key,
members=None, max_elements=None, min_elements=None, default_value=None, is_config=True, is_presence=False):
members=None, max_elements=None, min_elements=None, default_value=None,
is_config=True, is_presence=False, is_mandatory=False):
self._name = name
self._mtype = mtype
self._ptype = ptype
Expand All @@ -55,6 +56,7 @@ def __init__(self, name, mtype, ptype, ytype,
self._default_value = default_value
self._is_config = is_config
self._is_presence = is_presence
self._is_mandatory = is_mandatory

@property
def members(self):
Expand Down Expand Up @@ -108,6 +110,14 @@ def min_elements(self):
def default_value(self):
return self._default_value

@property
def is_mandatory(self):
return self._is_mandatory

@property
def is_presence(self):
return self._is_presence

def union_list(self):
_list = []
if self._mtype == REFERENCE_UNION:
Expand Down
2 changes: 2 additions & 0 deletions ydkgen/printer/python/class_meta_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def print_meta_class_member(self, meta_info_data, ctx):
ctx.str(", is_config=False")
if meta_info_data.is_presence:
ctx.str(", is_presence=True")
if meta_info_data.mandatory:
ctx.str(", is_mandatory=True")
ctx.str('),\n')

ctx.lvl_dec()

0 comments on commit 7c21ac4

Please sign in to comment.