예제 #1
0
    def from_xml(self, elem):  # , handle, modify_self=False, mo=None):
        """Method updates/fills the object from the xml representation
        of the external method object. """
        if elem.attrib:
            for attr_name, attr_value in elem.attrib.iteritems():
                if attr_name in self.__property_map:
                    attr = self.__property_map[attr_name]
                    method_prop_meta = self.__property_meta[attr]
                    if method_prop_meta.inp_out == "Input" or (method_prop_meta.is_complex_type):
                        continue
                    self.set_attr(attr, str(attr_value))
                elif attr_name in ExternalMethod._external_method_attrs:
                    self.set_attr(ExternalMethod._external_method_attrs[attr_name], str(attr_value))

        child_elems = elem.getchildren()
        if child_elems:
            for child_elem in child_elems:
                if not ET.iselement(child_elem):
                    continue
                child_name = child_elem.tag
                if child_name in self.__property_map:
                    child_name = self.__property_map[child_name]
                    method_prop_meta = self.__property_meta[child_name]
                    if method_prop_meta.inp_out == "Output" and (method_prop_meta.is_complex_type):
                        child_obj = ucscoreutils.get_ucs_obj(method_prop_meta.field_type, child_elem)
                        if child_obj is not None:
                            self.set_attr(child_name, child_obj)
                            # print child_method_obj.__dict__
                            child_obj.from_xml(child_elem)
예제 #2
0
def from_xml_str(xml_str):
    """
    Generates response object from the given xml string.

    Args:
        xml_str (str): xml string

    Returns:
        object (external method or managed object or generic managed object)

    Example:
        xml_str='''\n
        <lsServer dn="org-root/ls-testsp" dynamicConPolicyName="test"\n
        extIPPoolName="ext-mgmt" name="testsp" />\n
        '''\n
        root_element = extract_root_elem(xml_str)\n
    """

    root_elem = ET.fromstring(xml_str)
    if root_elem.tag == "error":
        error_code = root_elem.attrib["errorCode"]
        error_descr = root_elem.attrib["errorDescr"]
        raise ex.UcsException(error_code, error_descr)

    class_id = ucsgenutils.word_u(root_elem.tag)
    response = ucscoreutils.get_ucs_obj(class_id, root_elem)
    response.from_xml(root_elem)
    return response
예제 #3
0
파일: ucscore.py 프로젝트: kraz4glf/ucsmsdk
    def from_xml(self, elem):
        """This method creates the object from the xml representation
        of the Method object."""
        if elem.attrib:
            for attr_name, attr_value in elem.attrib.iteritems():
                self.attr_set(ucsgenutils.convert_to_python_var_name(attr_name)
                            , str(attr_value))

        child_elems = elem.getchildren()
        if child_elems:
            for child_elem in child_elems:
                if not ET.iselement(child_elem):
                    continue

                cln = ucsgenutils.word_u(child_elem.tag)
                child = ucscoreutils.get_ucs_obj(cln, child_elem)
                self._child.append(child)
                child.from_xml(child_elem)
예제 #4
0
파일: ucsmo.py 프로젝트: kraz4glf/ucsmsdk
    def from_xml(self, elem):
        """
        Method updates the object from the xml representation of the managed
        object.
        """

        if elem.attrib:
            if self.__class__.__name__ != "ManagedObject":
                for attr_name, attr_value in elem.attrib.iteritems():
                    if attr_name in self.prop_map:
                        attr_name = self.prop_map[attr_name]
                    else:
                        self.__xtra_props[attr_name] = _GenericProp(
                            attr_name,
                            attr_value,
                            False)
                    object.__setattr__(self, attr_name, attr_value)
            else:
                for attr_name, attr_value in elem.attrib.iteritems():
                    object.__setattr__(self, attr_name, attr_value)

        self.mark_clean()

        child_elems = elem.getchildren()
        if child_elems:
            for child_elem in child_elems:
                if not ET.iselement(child_elem):
                    continue

                if self.__class__.__name__ != "ManagedObject" and (
                            child_elem.tag in self.mo_meta.field_names):
                    pass

                class_id = ucsgenutils.word_u(child_elem.tag)
                child_obj = ucscoreutils.get_ucs_obj(class_id, child_elem,
                                                     self)
                self.child_add(child_obj)
                child_obj.from_xml(child_elem)