Exemple #1
0
def _compare(from_mo, to_mo, diff):
    """ Internal method to support compare_imc_managedobject functionality. """

    if from_mo.class_id != to_mo.class_id:
        return _CompareStatus.TYPES_DIFFERENT

    for prop in CoreUtils.get_property_list(str(from_mo.class_id)):
        prop_meta = CoreUtils.is_property_in_meta_ignore_case(from_mo.class_id, prop)
        if prop_meta != None:
            if prop_meta.access == MoPropertyMeta.INTERNAL or prop_meta.access == MoPropertyMeta.READ_ONLY or prop in to_mo.exclude_prop_list:
            #if (prop in to_mo._excludePropList):
                continue
            if to_mo.__dict__.has_key(prop) and from_mo.get_attr(prop) != to_mo.get_attr(prop):
                diff.append(prop)

    if len(diff) > 0:
        return _CompareStatus.PROPS_DIFFERENT

    return _CompareStatus.EQUAL
Exemple #2
0
def _compare(from_mo, to_mo, diff):
    """ Internal method to support compare_imc_managedobject functionality. """

    if from_mo.class_id != to_mo.class_id:
        return _CompareStatus.TYPES_DIFFERENT

    for prop in CoreUtils.get_property_list(str(from_mo.class_id)):
        prop_meta = CoreUtils.is_property_in_meta_ignore_case(
            from_mo.class_id, prop)
        if prop_meta != None:
            if prop_meta.access == MoPropertyMeta.INTERNAL or prop_meta.access == MoPropertyMeta.READ_ONLY or prop in to_mo.exclude_prop_list:
                #if (prop in to_mo._excludePropList):
                continue
            if to_mo.__dict__.has_key(
                    prop) and from_mo.get_attr(prop) != to_mo.get_attr(prop):
                diff.append(prop)

    if len(diff) > 0:
        return _CompareStatus.PROPS_DIFFERENT

    return _CompareStatus.EQUAL
Exemple #3
0
    def add_imc_managedobject(self,
                              in_mo=None,
                              class_id=None,
                              params=None,
                              dump_xml=None):
        """
        Adds a Managed Object to IMC.

        - in_mo, if provided, it acts as a parent for the present operation.
          It should be None unless a username wants to define a parent scope.
          It can be a single MO or a list containing multiple managed objects.
        - class_id of the managed object/s to be added.
        - params contains semicolon (;) separated list of key/value pairs(key=value),
          that are used as filters for selecting specific managed objects.
          The key should be a valid property of the managed object to be added.
        """

        unknown_mo = False
        if class_id == None or class_id == "":
            raise ImcValidationException(
                '[Error]: add_imc_managedobject [Description]: class_id is Null'
            )

        meta_class_id = CoreUtils.find_class_id_in_mo_meta_ignore_case(
            class_id)
        if meta_class_id != None:
            class_id = meta_class_id
            mo_meta = CoreUtils.get_mo_property_meta(class_id, "Meta")
        else:
            unknown_mo = True

        config_map = ConfigMap()
        rn = None
        dn = None
        #mo_meta = CoreUtils.get_mo_property_meta(class_id, "Meta")
        if params != None:
            keys = params.keys()
        else:
            keys = []

        if not unknown_mo:
            rn = mo_meta.rn
            for prop in CoreUtils.get_property_list(class_id):
                prop_meta = CoreUtils.get_mo_property_meta(class_id, prop)
                if prop_meta.access != MoPropertyMeta.NAMING:
                    continue
                naming_prop_found = False
                for key in keys:
                    if key.lower() == prop.lower():
                        rn = re.sub(r'\[%s\]' % prop, '%s' % params[key], rn)
                        naming_prop_found = True
                        break

                if naming_prop_found == False:
                    ImcUtils.write_imc_warning(
                        "[Warning]: add_imc_managedobject [Description]:Expected NAMING Property %s for ClassId %s not found"
                        % (prop, class_id))
                    rn = re.sub(r'\[%s\]' % prop, '%s' % "", rn)

        obj = ManagedObject(class_id)

        for prop in keys:
            if not unknown_mo:
                prop_mo_meta = CoreUtils.is_property_in_meta_ignore_case(
                    class_id, prop)
                if prop_mo_meta != None:
                    if prop.lower() == "rn" or prop.lower() == "dn":
                        pass
                    elif prop_mo_meta.access == MoPropertyMeta.READ_ONLY:
                        ImcUtils.write_imc_warning(
                            "[Warning]: AddManagedObject [Description]:Attempt to add non-writeable property %s in Class %s"
                            % (prop, class_id))

                    if prop.lower() == "rn":
                        if in_mo == None or not isinstance(
                                in_mo, list) or len(in_mo) == 0:
                            ImcUtils.write_imc_warning(
                                "[Warning]: AddManagedObject [Description]:Ignoring Rn since no parent provided"
                            )
                        if rn != params[prop]:
                            ImcUtils.write_imc_warning(
                                "[Warning]: AddManagedObject [Description]:Rn Mismatch. Provided %s Computed %s. Ignoring Computed Rn"
                                % (params[prop], rn))
                            rn = params[
                                prop]  #bug fix. if Rn and Name are both provided by username then Rn will get preference.

                    if prop.lower() == "dn":
                        dn = params[prop]

                    obj.set_attr(prop_mo_meta.name, str(params[prop]))
                else:
                    #Known MO - Unknown Property
                    obj.set_attr(ImcUtils.word_l(prop), str(params[prop]))
            else:
                #Unknown MO
                if prop.lower() == "dn":
                    dn = params[prop]

                if prop.lower() == "rn":
                    rn = params[prop]
                if rn == None:
                    rn = ""

                obj.set_attr(ImcUtils.word_l(prop), str(params[prop]))

        obj.set_attr("Status", Status().CREATED)

        if dn != None and dn != "":
            obj.set_attr("Dn", dn)
            pair = Pair()
            #pair.set_attr("Key", obj.dn)
            pair.set_attr("Key", obj.get_attr("Dn"))
            pair.add_child(obj)
            config_map.add_child(pair)
        elif in_mo != None and isinstance(in_mo, list) and len(in_mo) > 0:
            for mo in in_mo:
                pdn = mo.get_attr("Dn")
                if pdn != None:
                    obj.set_attr("Dn", pdn + '/' + rn)
                    pair = Pair()
                    #pair.set_attr("Key", obj.dn)
                    pair.set_attr("Key", obj.get_attr("Dn"))
                    pair.add_child(obj.clone())
                    config_map.add_child(pair)

        if config_map.get_child_count() == 0:
            ImcUtils.write_imc_warning(
                '[Warning]: AddManagedObject [Description]: Nothing to Add')
            return None

        output_molist = []
        for pair in config_map.child:
            in_config = ConfigConfig()
            for mo in pair.child:
                in_config.add_child(mo)
            ccm = self.config_conf_mo(dn=pair.Key,
                                      in_config=in_config,
                                      in_hierarchical=YesOrNo.FALSE,
                                      dump_xml=dump_xml)
            if ccm.error_code == 0:
                molist = []
                for child in ccm.OutConfig.child:
                    if isinstance(child, Pair) == True:
                        for mo in child.child:
                            molist.append(mo)
                    elif isinstance(child, ManagedObject) == True:
                        molist.append(child)
                output_molist.extend(molist)
            else:
                raise ImcException(ccm.error_code, ccm.error_descr)

        return output_molist
Exemple #4
0
    def add_imc_managedobject(self, in_mo=None, class_id=None, params=None, dump_xml=None):
        """
        Adds a Managed Object to IMC.

        - in_mo, if provided, it acts as a parent for the present operation.
          It should be None unless a username wants to define a parent scope.
          It can be a single MO or a list containing multiple managed objects.
        - class_id of the managed object/s to be added.
        - params contains semicolon (;) separated list of key/value pairs(key=value),
          that are used as filters for selecting specific managed objects.
          The key should be a valid property of the managed object to be added.
        """

        unknown_mo = False
        if class_id == None or class_id == "":
            raise ImcValidationException('[Error]: add_imc_managedobject [Description]: class_id is Null')

        meta_class_id = CoreUtils.find_class_id_in_mo_meta_ignore_case(class_id)
        if meta_class_id != None:
            class_id = meta_class_id
            mo_meta = CoreUtils.get_mo_property_meta(class_id, "Meta")
        else:
            unknown_mo = True

        config_map = ConfigMap()
        rn = None
        dn = None
        #mo_meta = CoreUtils.get_mo_property_meta(class_id, "Meta")
        if params != None:
            keys = params.keys()
        else:
            keys = []

        if not unknown_mo:
            rn = mo_meta.rn
            for prop in CoreUtils.get_property_list(class_id):
                prop_meta = CoreUtils.get_mo_property_meta(class_id, prop)
                if prop_meta.access != MoPropertyMeta.NAMING:
                    continue
                naming_prop_found = False
                for key in keys:
                    if key.lower() == prop.lower():
                        rn = re.sub(r'\[%s\]' % prop, '%s' % params[key], rn)
                        naming_prop_found = True
                        break

                if naming_prop_found == False:
                    ImcUtils.write_imc_warning("[Warning]: add_imc_managedobject [Description]:Expected NAMING Property %s for ClassId %s not found" %(prop, class_id))
                    rn = re.sub(r'\[%s\]' % prop, '%s' % "", rn)

        obj = ManagedObject(class_id)

        for prop in keys:
            if not unknown_mo:
                prop_mo_meta = CoreUtils.is_property_in_meta_ignore_case(class_id, prop)
                if prop_mo_meta != None:
                    if prop.lower() == "rn" or prop.lower() == "dn":
                        pass
                    elif prop_mo_meta.access == MoPropertyMeta.READ_ONLY:
                        ImcUtils.write_imc_warning("[Warning]: AddManagedObject [Description]:Attempt to add non-writeable property %s in Class %s" %(prop, class_id))

                    if prop.lower() == "rn":
                        if in_mo == None or not isinstance(in_mo, list) or len(in_mo) == 0:
                            ImcUtils.write_imc_warning("[Warning]: AddManagedObject [Description]:Ignoring Rn since no parent provided")
                        if rn != params[prop]:
                            ImcUtils.write_imc_warning("[Warning]: AddManagedObject [Description]:Rn Mismatch. Provided %s Computed %s. Ignoring Computed Rn" %(params[prop], rn))
                            rn = params[prop]#bug fix. if Rn and Name are both provided by username then Rn will get preference.

                    if prop.lower() == "dn":
                        dn = params[prop]

                    obj.set_attr(prop_mo_meta.name, str(params[prop]))
                else:
                    #Known MO - Unknown Property
                    obj.set_attr(ImcUtils.word_l(prop), str(params[prop]))
            else:
                #Unknown MO
                if prop.lower() == "dn":
                    dn = params[prop]

                if prop.lower() == "rn":
                    rn = params[prop]
                if rn == None:
                    rn = ""

                obj.set_attr(ImcUtils.word_l(prop), str(params[prop]))

        obj.set_attr("Status", Status().CREATED)

        if dn != None and dn != "":
            obj.set_attr("Dn", dn)
            pair = Pair()
            #pair.set_attr("Key", obj.dn)
            pair.set_attr("Key", obj.get_attr("Dn"))
            pair.add_child(obj)
            config_map.add_child(pair)
        elif in_mo != None and isinstance(in_mo, list) and len(in_mo) > 0:
            for mo in in_mo:
                pdn = mo.get_attr("Dn")
                if pdn != None:
                    obj.set_attr("Dn", pdn + '/' +rn)
                    pair = Pair()
                    #pair.set_attr("Key", obj.dn)
                    pair.set_attr("Key", obj.get_attr("Dn"))
                    pair.add_child(obj.clone())
                    config_map.add_child(pair)

        if config_map.get_child_count() == 0:
            ImcUtils.write_imc_warning('[Warning]: AddManagedObject [Description]: Nothing to Add')
            return None

        output_molist = []
        for pair in config_map.child:
            in_config = ConfigConfig()
            for mo in pair.child:
                in_config.add_child(mo)
            ccm = self.config_conf_mo(dn=pair.Key, in_config=in_config, in_hierarchical=YesOrNo.FALSE, dump_xml=dump_xml)
            if ccm.error_code == 0:
                molist = []
                for child in ccm.OutConfig.child:
                    if isinstance(child, Pair) == True:
                        for mo in child.child:
                            molist.append(mo)
                    elif isinstance(child, ManagedObject) == True:
                        molist.append(child)
                output_molist.extend(molist)
            else:
                raise ImcException(ccm.error_code, ccm.error_descr)

        return output_molist