Skip to content

Commit

Permalink
Merge pull request CiscoUcs#37 from ragupta-git/ignore_validation_for…
Browse files Browse the repository at this point in the history
…_xml_response

Ignore propert validation for the MO created from ucsm xml response
  • Loading branch information
vvb committed May 20, 2016
2 parents 8b6746f + e5cd162 commit 270c830
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
2 changes: 2 additions & 0 deletions tests/common/test_unknown_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_001_knownmo_unknownprop():
name="ra11"
type="instance"
usrLbl="b"
rn = "ls-ra11"
unknownProps="unknown"/>'''

obj = xc.from_xml_str(xml_str)
Expand All @@ -40,6 +41,7 @@ def test_002_knownmo_unknownprop():
name="ra11"
type="instance"
usrLbl="b"
rn = "ls-ra11"
unknownProps="unknown"/>'''

obj = xc.from_xml_str(xml_str)
Expand Down
10 changes: 3 additions & 7 deletions ucsmsdk/ucscoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def get_ucs_obj(class_id, elem, mo_obj=None):
mo_class_params = inspect.getargspec(mo_class.__init__)[0][2:]
mo_class_param_dict = {}
for param in mo_class_params:
mo_param = mo_class.prop_meta[param].xml_attribute
if mo_param not in elem.attrib:
mo_class_param_dict[param] = ""
continue
mo_class_param_dict[param] = elem.attrib[mo_param]
mo_class_param_dict[param] = None

p_dn = ""
if "dn" in elem.attrib:
Expand All @@ -70,9 +66,9 @@ def get_ucs_obj(class_id, elem, mo_obj=None):
p_dn = mo_obj.dn

if 'topRoot' in mo_class.mo_meta.parents:
mo_obj = mo_class(**mo_class_param_dict)
mo_obj = mo_class(from_xml_response=True, **mo_class_param_dict)
else:
mo_obj = mo_class(parent_mo_or_dn=p_dn, **mo_class_param_dict)
mo_obj = mo_class(parent_mo_or_dn=p_dn, from_xml_response=True, **mo_class_param_dict)
return mo_obj
elif class_id in OTHER_TYPE_CLASS_ID:
module_ = load_module(class_id)
Expand Down
33 changes: 20 additions & 13 deletions ucsmsdk/ucsmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,26 @@ class ManagedObject(UcsBase):
__internal_prop = frozenset(
["_dirty_mask", "_class_id", "_child", "_handle", ''])

def __init__(self, class_id, parent_mo_or_dn=None, **kwargs):
def __init__(self, class_id, parent_mo_or_dn=None, from_xml_response=False, **kwargs):
self.__parent_mo = None
self.__status = None
self.__parent_dn = None
self.__xtra_props = {}
self.__xtra_props_dirty_mask = 0x1

self._rn_set()
self._dn_set(parent_mo_or_dn)
if parent_mo_or_dn:
if isinstance(parent_mo_or_dn, ManagedObject):
self.__parent_mo = parent_mo_or_dn
self.__parent_dn = self.__parent_mo.dn
elif isinstance(parent_mo_or_dn, str):
self.__parent_dn = parent_mo_or_dn
else:
raise ValueError('parent mo or dn must be specified')

if not from_xml_response:
self._rn_set()
self._dn_set()

xml_attribute = self.mo_meta.xml_attribute

UcsBase.__init__(self, ucsgenutils.word_u(xml_attribute))
Expand Down Expand Up @@ -96,20 +107,12 @@ def _rn_set(self):
else:
self.rn = ""

def _dn_set(self, pmo_or_dn):

def _dn_set(self):
"""
Internal method to set dn
"""

if pmo_or_dn:
if isinstance(pmo_or_dn, ManagedObject):
self.__parent_mo = pmo_or_dn
self.__parent_dn = self.__parent_mo.dn
elif isinstance(pmo_or_dn, str):
self.__parent_dn = pmo_or_dn
else:
raise ValueError('parent mo or dn must be specified')

if "prop_meta" in dir(self) and "dn" in self.prop_meta:
if self.__parent_dn:
self.dn = self.__parent_dn + '/' + self.rn
Expand Down Expand Up @@ -342,6 +345,10 @@ def from_xml(self, elem, handle=None):
for attr_name, attr_value in ucsgenutils.iteritems(elem.attrib):
object.__setattr__(self, attr_name, attr_value)

if hasattr(self, 'rn') and not hasattr(self, 'dn'):
self._dn_set()
elif not hasattr(self, 'rn') and hasattr(self, 'dn'):
self.__set_prop("rn", os.path.basename(self.dn), forced=True)
self.mark_clean()

child_elems = elem.getchildren()
Expand Down

0 comments on commit 270c830

Please sign in to comment.