Exemple #1
0
    def create(self, obj, _parent_name=None):
        ''' add to the CCB the object 'obj' '''
        if _parent_name is not None:
            parent_name = SaNameT(_parent_name)
            object_names = [parent_name]
            err = saImmOm.saImmOmAdminOwnerSet(self.owner_handle, object_names,
                eSaImmScopeT.SA_IMM_SUBTREE)
            if err != eSaAisErrorT.SA_AIS_OK:
                msg = "saImmOmAdminOwnerSet: %s - obj:%s" % \
                    (_parent_name, eSaAisErrorT.whatis(err))
                raise SafException(err, msg)
        else:
            parent_name = None

        attr_values = []
        for attr_name, type_values in obj.attrs.iteritems():
            values = type_values[1]
            attr = SaImmAttrValuesT_2()
            attr.attrName = attr_name
            attr.attrValueType = type_values[0]
            attr.attrValuesNumber = len(values)
            attr.attrValues = marshal_c_array(attr.attrValueType, values)
            attr_values.append(attr)

        err = saImmOm.saImmOmCcbObjectCreate_2(self.ccb_handle,
                                               obj.class_name,
                                               parent_name,
                                               attr_values)
        if err != eSaAisErrorT.SA_AIS_OK:
            msg = "saImmOmCcbObjectCreate_2: %s, parent:%s, class:%s" % (
                eSaAisErrorT.whatis(err), _parent_name, obj.class_name)
            raise SafException(err, msg)
Exemple #2
0
    def modify_value_delete(self, object_name, attr_name, value):
        ''' add to the CCB an DELETE modification of an existing object '''

        assert object_name

        # first get class name to read class description to get value type...
        try:
            obj = pyosaf.utils.immom.get(object_name)
        except SafException as err:
            print "failed: %s" % err
            return

        object_names = [SaNameT(object_name)]
        class_name = obj.SaImmAttrClassName
        value_type = None
        attr_def_list = pyosaf.utils.immom.class_description_get(class_name)
        for attr_def in attr_def_list:
            if attr_def.attrName == attr_name:
                value_type = attr_def.attrValueType
                break

        if value_type is None:
            # means attribute name is invalid
            raise SafException(eSaAisErrorT.SA_AIS_ERR_NOT_EXIST,
                "attribute '%s' does not exist" % attr_name)

        err = saImmOm.saImmOmAdminOwnerSet(self.owner_handle, object_names,
            eSaImmScopeT.SA_IMM_ONE)
        if err != eSaAisErrorT.SA_AIS_OK:
            raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \
                (object_name, eSaAisErrorT.whatis(err)))

        attr_mods = []
        attr_mod = saImmOm.SaImmAttrModificationT_2()
        attr_mod.modType = \
            saImmOm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_DELETE
        attr_mod.modAttr = SaImmAttrValuesT_2()
        attr_mod.modAttr.attrName = attr_name
        attr_mod.modAttr.attrValueType = value_type
        attr_mod.modAttr.attrValuesNumber = 1

        values = []
        values.append(value)
        try:
            ptr2ctype = _value_to_ctype_ptr(value_type, value)
        except ValueError:
            raise SafException(eSaAisErrorT.SA_AIS_ERR_INVALID_PARAM,
                "value '%s' has wrong type" % value)

        attr_mod.modAttr.attrValues = pointer(ptr2ctype)
        attr_mods.append(attr_mod)

        err = saImmOm.saImmOmCcbObjectModify_2(self.ccb_handle,
            object_names[0], attr_mods)
        if err != eSaAisErrorT.SA_AIS_OK:
            print "saImmOmCcbObjectModify_2: %s, %s" % (eSaAisErrorT.whatis(err), object_name)
            raise SafException(err)
Exemple #3
0
    def delete(self, _object_name):
        if _object_name is None:
            raise SafException(eSaAisErrorT.SA_AIS_ERR_NOT_EXIST)

        object_name = SaNameT(_object_name)
        object_names = [object_name]

        err = saImmOm.saImmOmAdminOwnerSet(self.owner_handle, object_names,
            eSaImmScopeT.SA_IMM_SUBTREE)
        if err != eSaAisErrorT.SA_AIS_OK:
            raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \
                (_object_name, eSaAisErrorT.whatis(err)))

        err = saImmOm.saImmOmCcbObjectDelete(self.ccb_handle, object_name)
        if err != eSaAisErrorT.SA_AIS_OK:
            raise SafException(err, "saImmOmCcbObjectDelete: %s - %s" % \
                (_object_name, eSaAisErrorT.whatis(err)))
Exemple #4
0
def raise_saf_exception(function, error):
    ''' Raises an exception for a given SAF function, based on
        the given error code 
    '''

    error_string = "%s: %s" % (function.__name__, eSaAisErrorT.whatis(error))

    raise SafException(error, error_string)
Exemple #5
0
    def __del__(self):
        one_sec_sleeps = 0
        error = saImmOm.saImmOmAdminOwnerFinalize(self.owner_handle)
        while error == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN:
            if one_sec_sleeps == TRYAGAIN_CNT:
                break
            time.sleep(1)
            one_sec_sleeps += 1
            error = saImmOm.saImmOmAdminOwnerFinalize(self.owner_handle)

        if error != eSaAisErrorT.SA_AIS_OK:
            print "saImmOmAdminOwnerFinalize: %s" % eSaAisErrorT.whatis(error)
            raise SafException(error)
def _initialize():
    ''' saImmOmInitialize with TRYAGAIN handling '''
    version = SaVersionT('A', 2, 1)
    one_sec_sleeps = 0
    err = saImmOm.saImmOmInitialize(HANDLE, None, version)
    while err == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN:
        if one_sec_sleeps == TRYAGAIN_CNT:
            break
        time.sleep(1)
        one_sec_sleeps += 1
        err = saImmOm.saImmOmInitialize(HANDLE, None, version)

    if err != eSaAisErrorT.SA_AIS_OK:
        raise SafException(err,
                           "saImmOmInitialize: %s" % eSaAisErrorT.whatis(err))

    # TODO TRYAGAIN handling? Is it needed?
    err = saImmOm.saImmOmAccessorInitialize(HANDLE, ACCESSOR_HANDLE)
    if err != eSaAisErrorT.SA_AIS_OK:
        raise SafException(err,
                           "saImmOmAccessorInitialize: %s" %
                           eSaAisErrorT.whatis(err))
Exemple #7
0
    def dispatch(self, flags):
        """ Invoke IMM callbacks for queued events

        Args:
            flags (eSaDispatchFlagsT): Flags specifying dispatch mode

        Returns:
            SaAisErrorT: Return code of the saImmOmDispatch() API call
        """
        rc = saImmOmDispatch(self.handle, flags)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOmDispatch FAILED - %s" % eSaAisErrorT.whatis(rc))

        return rc
Exemple #8
0
    def create_runtime_object(self, class_name, parent_name, runtime_obj):
        """ Create a runtime object

        Args:
            class_name (str): Class name
            parent_name (str): Parent name
            runtime_obj (ImmObject): Runtime object to create

        Returns:
            SaAisErrorT: Return code of OI create runtime object
        """
        # Marshall parameters
        c_class_name = SaImmClassNameT(class_name)
        if parent_name:
            c_parent_name = SaNameT(parent_name)
        else:
            c_parent_name = None

        c_attr_values = []

        for name, (c_attr_type, values) in runtime_obj.attrs.items():
            if values is None:
                values = []
            elif values == [None]:
                values = []

            # Make sure all values are in lists
            if not isinstance(values, list):
                values = [values]

            # Create the values struct
            c_attr = SaImmAttrValuesT_2()
            c_attr.attrName = SaImmAttrNameT(name)
            c_attr.attrValueType = c_attr_type
            c_attr.attrValuesNumber = len(values)

            if not values:
                c_attr.attrValues = None
            else:
                c_attr.attrValues = marshal_c_array(c_attr_type, values)

            c_attr_values.append(c_attr)

        rc = saImmOiRtObjectCreate_2(self.handle, c_class_name,
                                     c_parent_name, c_attr_values)

        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOiRtObjectCreate_2 FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
Exemple #9
0
    def close_stream(self):
        """ Close the log stream associated with the handle

        Returns:
            SaAisErrorT: Return code of the corresponding LOG API call(s)
        """
        rc = log.saLogStreamClose(self.stream_handle)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saLogStreamClose FAILED - %s" % eSaAisErrorT.whatis(rc))
        if rc == eSaAisErrorT.SA_AIS_OK or \
                rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            self.stream_handle = None

        return rc
Exemple #10
0
    def __init__(self):
        self.owner_handle = saImmOm.SaImmAdminOwnerHandleT()

        owner_name = saImmOm.SaImmAdminOwnerNameT("DummyName")
        one_sec_sleeps = 0
        err = saImmOm.saImmOmAdminOwnerInitialize(pyosaf.utils.immom.HANDLE, owner_name,
                saAis.eSaBoolT.SA_TRUE, self.owner_handle)
        while err == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN:
            if one_sec_sleeps == TRYAGAIN_CNT:
                break
            time.sleep(1)
            one_sec_sleeps += 1
            err = saImmOm.saImmOmAdminOwnerInitialize(pyosaf.utils.immom.HANDLE, owner_name,
                saAis.eSaBoolT.SA_TRUE, self.owner_handle)

        if err != eSaAisErrorT.SA_AIS_OK:
            print "saImmOmAdminOwnerInitialize: %s" % eSaAisErrorT.whatis(err)
            raise SafException(err)

        self.ccb_handle = saImmOm.SaImmCcbHandleT()

        ccb_flags = saImmOm.SaImmCcbFlagsT(
            saImm.saImm.SA_IMM_CCB_REGISTERED_OI)
        one_sec_sleeps = 0
        err = saImmOm.saImmOmCcbInitialize(self.owner_handle, ccb_flags,
                                           self.ccb_handle)
        while err == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN:
            if one_sec_sleeps == TRYAGAIN_CNT:
                break
            time.sleep(1)
            one_sec_sleeps += 1
            err = saImmOm.saImmOmCcbInitialize(self.owner_handle, ccb_flags,
                                               self.ccb_handle)

        if err != eSaAisErrorT.SA_AIS_OK:
            print "saImmOmCcbInitialize: %s" % eSaAisErrorT.whatis(err)
            raise SafException(err)
Exemple #11
0
    def invoke_admin_operation(self, dn, op_id, params=None):
        """ Invoke admin op for dn

        Args:
            dn (str): Object dn
            op_id (str): Operation id
            params (list): List of parameters

        Returns:
            SaAisErrorT: Return code of the corresponding IMM API call(s)
        """
        _owner = OmAdminOwner(self.handle)
        rc = _owner.init()
        if rc == eSaAisErrorT.SA_AIS_OK:
            index = dn.rfind(",")
            object_rdn = dn[index + 1:]
            rc = _owner.set_owner(object_rdn)

        if rc == eSaAisErrorT.SA_AIS_OK:
            owner_handle = _owner.get_handle()
            if params is None:
                params = []

            object_dn = SaNameT(dn)
            operation_rc = SaAisErrorT()

            rc = saImmOmAdminOperationInvoke_2(owner_handle, object_dn, 0,
                                               op_id, params, operation_rc,
                                               saAis.SA_TIME_ONE_SECOND * 10)
            if rc != eSaAisErrorT.SA_AIS_OK:
                log_err("saImmOmAdminOperationInvoke_2 FAILED - %s" %
                        eSaAisErrorT.whatis(rc))
            elif operation_rc.value != eSaAisErrorT.SA_AIS_OK:
                log_err("Administrative operation(%s) on %s FAILED - %s" %
                        (op_id, object_dn, eSaAisErrorT.whatis(operation_rc)))

        return rc
Exemple #12
0
    def _generate_alarm_filter(self):
        """ Allocate memory for the alarm notification filter and fill in the
        corresponding user-provided data

        Returns:
            SaAisErrorT: Return code of the
                saNtfAlarmNotificationFilterAllocate() API call
        """
        notification_filter = saNtf.SaNtfAlarmNotificationFilterT()

        rc = ntf.saNtfAlarmNotificationFilterAllocate(
            self.handle, notification_filter,
            len(self.filter_info.alarm_evt_list),
            len(self.filter_info.notification_object_list),
            len(self.filter_info.notifying_objects_list),
            len(self.filter_info.ntf_class_id_list),
            len(self.filter_info.probable_cause_list),
            len(self.filter_info.perceived_severity_list),
            len(self.filter_info.trend_list))
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saNtfAlarmNotificationFilterAllocate FAILED, "
                    "rc = %s" % eSaAisErrorT.whatis(rc))
        else:
            self.filter_handles.alarmFilterHandle = \
                notification_filter.notificationFilterHandle

            self._fill_in_filter_header(
                notification_filter.notificationFilterHeader)

            # Fill in the eventTypes array with user-provided data
            for i, evt in enumerate(self.filter_info.alarm_evt_list):
                notification_filter.notificationFilterHeader.eventTypes[i] = \
                    evt

            # Fill in the probableCauses array with user-provided data
            for i, probable_cause in \
                    enumerate(self.filter_info.probable_cause_list):
                notification_filter.probableCauses[i] = probable_cause

            # Fill in the perceivedSeverities array with user-provided data
            for i, perceived_severity in \
                    enumerate(self.filter_info.perceived_severity_list):
                notification_filter.perceivedSeverities[i] = perceived_severity

            # Fill in the trends array with user-provided data
            for i, trend in enumerate(self.filter_info.trend_list):
                notification_filter.trends[i] = trend

        return rc
Exemple #13
0
    def report_admin_operation_result(self, invocation_id, result):
        """ Report the result of an administrative operation

        Args:
            invocation_id (SaInvocationT): Invocation id
            result (SaAisErrorT): Result of admin operation

        Returns:
            SaAisErrorT: Return code of OI admin operation
        """
        rc = saImmOiAdminOperationResult(self.handle, invocation_id, result)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOiAdminOperationResult FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
Exemple #14
0
    def _register_implementer(self, oi_name):
        """ Register as an implementer

        Args:
            oi_name (str): Implementer name

        Returns:
            SaAisErrorT: Return code of implementer set
        """
        implementer_name = SaImmOiImplementerNameT(oi_name)
        rc = saImmOiImplementerSet(self.handle, implementer_name)

        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOiClassImplementerSet FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
Exemple #15
0
    def _re_init(self):
        """ Internal function to re-initialize the CLM agent in case of getting
        BAD_HANDLE during an operation

        Returns:
            SaAisErrorT: Return code of the corresponding CLM API call(s)
        """
        self.finalize()
        self.handle = saClm.SaClmHandleT()
        self.version = deepcopy(self.init_version)
        rc = saClmInitialize_4(self.handle, self.callbacks, self.version)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saClmInitialize_4 FAILED - %s" % eSaAisErrorT.whatis(rc))
        else:
            rc = self._fetch_sel_obj()

        return rc
Exemple #16
0
    def _re_init(self):
        """ Internal function to re-initialize the NTF agent and fetch a new
        selection object in case of getting BAD_HANDLE during an operation

        Returns:
            SaAisErrorT: Return code of the corresponding NTF API call(s)
        """
        self.finalize()
        self.version = deepcopy(self.init_version)
        self.handle = saNtf.SaNtfHandleT()
        rc = ntf.saNtfInitialize(self.handle, self.callbacks, self.version)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saNtfInitialize FAILED - %s" % (eSaAisErrorT.whatis(rc)))
        else:
            rc = self._fetch_sel_obj()

        return rc
Exemple #17
0
    def delete_runtime_object(self, dn):
        """ Delete a runtime object

        Args:
            dn (str): Runtime object dn

        Returns:
            SaAisErrorT: Return code of OI delete runtime object
        """
        # Marshall the parameter
        c_dn = SaNameT(dn)
        rc = saImmOiRtObjectDelete(self.handle, c_dn)

        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOiRtObjectDelete FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
Exemple #18
0
    def init(self):
        """ Initialize the accessor handle

        Returns:
            SaAisErrorT: Return code of the saImmOmAccessorInitialize() call
        """
        self.finalize()
        rc = self.initialize()
        if rc == eSaAisErrorT.SA_AIS_OK:
            self.accessor_handle = saImmOm.SaImmAccessorHandleT()
            # Initialize ImmOmAccessor Handle
            rc = agent.saImmOmAccessorInitialize(self.handle,
                                                 self.accessor_handle)
            if rc != eSaAisErrorT.SA_AIS_OK:
                log_err("saImmOmAccessorInitialize FAILED - %s" %
                        eSaAisErrorT.whatis(rc))
        return rc
Exemple #19
0
    def create(self, obj, parent_name=None):
        """ Create the CCB object

        Args:
            obj (ImmObject): Imm object
            parent_name (str): Parent name

        Return:
            SaAisErrorT: Return code of the corresponding IMM API calls
        """
        rc = eSaAisErrorT.SA_AIS_OK
        if parent_name is not None:
            rc = self.admin_owner.set_owner(parent_name)
            parent_name = SaNameT(parent_name)

        if rc == eSaAisErrorT.SA_AIS_OK:
            attr_values = []
            for attr_name, type_values in obj.attrs.items():
                values = type_values[1]
                attr = SaImmAttrValuesT_2()
                attr.attrName = attr_name
                attr.attrValueType = type_values[0]

                attr.attrValuesNumber = len(values)
                attr.attrValues = marshal_c_array(attr.attrValueType, values)
                attr_values.append(attr)

            rc = agent.saImmOmCcbObjectCreate_2(self.ccb_handle,
                                                obj.class_name,
                                                parent_name,
                                                attr_values)
            if rc != eSaAisErrorT.SA_AIS_OK:
                log_err("saImmOmCcbObjectCreate_2 FAILED - %s" %
                        eSaAisErrorT.whatis(rc))

        if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            init_rc = self.init()
            # If the re-initialization of agent handle succeeds, we still need
            # to return BAD_HANDLE to the users, so that they would re-try the
            # failed operation. Otherwise, the true error code is returned
            # to the user to decide further actions.
            if init_rc != eSaAisErrorT.SA_AIS_OK:
                rc = init_rc

        return rc
Exemple #20
0
    def finalize(self):
        """ Finalize the NTF agent handle

        Returns:
            SaAisErrorT: Return code of the saNtfFinalize() API call
        """
        rc = eSaAisErrorT.SA_AIS_OK
        if self.handle:
            rc = saNtfFinalize(self.handle)
            if rc != eSaAisErrorT.SA_AIS_OK:
                log_err("saNtfFinalize FAILED - %s" % eSaAisErrorT.whatis(rc))
            if rc == eSaAisErrorT.SA_AIS_OK \
                    or rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
                # If the Finalize() call returned BAD_HANDLE, the handle should
                # already become stale and invalid, so we reset it anyway
                self.handle = None

        return rc
Exemple #21
0
    def track_stop(self):
        """ Stop cluster membership tracking

        Returns:
            SaAisErrorT: Return code of the saClmClusterTrackStop() API call
        """
        rc = saClmClusterTrackStop(self.handle)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saClmClusterTrackStop FAILED - %s" %
                    eSaAisErrorT.whatis(rc))

        if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            init_rc = self._re_init()
            if init_rc != eSaAisErrorT.SA_AIS_OK:
                rc = init_rc
        # No need to retry in case of BAD_HANDLE since the tracking should
        # have already been stopped when the agent disconnected
        return rc
Exemple #22
0
    def set_class_implementer(self, class_name):
        """ Add the given class_name to the list of classes this implementer
        implements

        Args:
            class_name (str): Class name

        Returns:
            SaAisErrorT: Return code of class implementer set
        """
        c_class_name = SaImmClassNameT(class_name)
        rc = saImmOiClassImplementerSet(self.handle, c_class_name)
        if rc == eSaAisErrorT.SA_AIS_OK:
            self.implemented_names.append(class_name)
        else:
            log_err("saImmOiClassImplementerSet FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
Exemple #23
0
    def _get_ptr_value(ntf_handle, value):
        """ Get the correct string value from the given 'value' field in the
        received notification

        Args:
            ntf_handle (SaNtfNotificationHandleT): A handle to the internal
                notification structure
            value (SaNtfValueT): A 'value' field in the notification structure

        Returns:
            SaStringT: The value in string format
        """
        data_ptr = SaVoidPtr()
        data_size = SaUint16T()
        rc = ntf.saNtfPtrValGet(ntf_handle, value, data_ptr, data_size)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_warn("saNtfPtrValGet FAILED - %s" % (eSaAisErrorT.whatis(rc)))
        return ctypes.cast(data_ptr, SaStringT).value
Exemple #24
0
    def set_error_string(self, ccb_id, error_string):
        """ Set the error string
        This can only be called from within OI callbacks of a real implementer.

        Args:
            ccb_id (SaImmOiCcbIdT): CCB id
            error_string (str): Error string

        Returns:
            SaAisErrorT: Return code of OI CCB set error string
        """
        c_error_string = SaStringT(error_string)
        rc = saImmOiCcbSetErrorString(self.handle, ccb_id, c_error_string)

        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOiCcbSetErrorString FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
Exemple #25
0
 def __next__(self):
     obj_name = SaNameT()
     attributes = pointer(pointer(SaImmAttrValuesT_2()))
     rc = agent.saImmOmSearchNext_2(self.search_handle, obj_name,
                                    attributes)
     if rc != eSaAisErrorT.SA_AIS_OK:
         if rc != eSaAisErrorT.SA_AIS_ERR_NOT_EXIST:
             log_err("saImmOmSearchNext_2 FAILED - %s" %
                     eSaAisErrorT.whatis(rc))
         raise StopIteration
     attrs = {}
     attr_list = unmarshalNullArray(attributes)
     for attr in attr_list:
         attr_range = list(range(attr.attrValuesNumber))
         attrs[attr.attrName] = [attr.attrValueType,
                                 [unmarshalSaImmValue(attr.attrValues[val],
                                                      attr.attrValueType)
                                  for val in attr_range]]
     return ImmObject(str(obj_name), attrs)
Exemple #26
0
    def get_class_description(self, class_name):
        """ Get class description as a Python list

        Args:
            class_name (str): Class name

        Returns:
            SaAisErrorT: Return code of the corresponding IMM API call(s)
            list: List of class attributes
        """

        # Perform a deep copy
        def attr_def_copy(attr_def):
            """ Deep copy attributes """
            attr_def_cpy = saImm.SaImmAttrDefinitionT_2()
            attr_def_cpy.attrName = SaImmAttrNameT(
                deepcopy(str(attr_def.attrName)))
            attr_def_cpy.attrValueType = attr_def.attrValueType
            attr_def_cpy.attrFlags = attr_def.attrFlags

            return attr_def_cpy

        class_attrs = []
        attr_defs = pointer(pointer(saImm.SaImmAttrDefinitionT_2()))
        category = saImm.SaImmClassCategoryT()
        c_class_name = class_name if isinstance(
            class_name, SaStringT) else SaImmClassNameT(class_name)
        rc = saImmOmClassDescriptionGet_2(self.handle, c_class_name, category,
                                          attr_defs)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOmClassDescriptionGet_2 FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        else:
            _class_attrs = unmarshalNullArray(attr_defs)

            # Make copy of attr_defs list
            class_attrs = [attr_def_copy(item) for item in _class_attrs]

            # Free the original memory
            saImmOmClassDescriptionMemoryFree_2(self.handle,
                                                attr_defs.contents)

        return rc, class_attrs
Exemple #27
0
    def init(self):
        """ Initialize the IMM OM search iterator

        Returns:
            SaAisErrorT: Return code of the IMM OM APIs
        """
        # Cleanup previous resources if any
        self.finalize()
        rc = self.initialize()

        self.search_handle = saImmOm.SaImmSearchHandleT()
        if rc == eSaAisErrorT.SA_AIS_OK:
            rc = agent.saImmOmSearchInitialize_2(
                self.handle, self.root_name, self.scope, self.search_options,
                self.search_param, self.attribute_names, self.search_handle)
            if rc != eSaAisErrorT.SA_AIS_OK:
                log_err("saImmOmSearchInitialize_2 FAILED - %s" %
                        eSaAisErrorT.whatis(rc))
                self.search_handle = None
        return rc
Exemple #28
0
    def get_class_category(self, class_name):
        """ Return the category of the given class

        Args:
            class_name (str): Class name

        Returns:
            SaImmClassCategoryT: Class category
        """
        c_attr_defs = pointer(pointer(saImmOm.SaImmAttrDefinitionT_2()))
        c_category = saImmOm.SaImmClassCategoryT()
        c_class_name = saImmOm.SaImmClassNameT(class_name)

        rc = saImmOmClassDescriptionGet_2(self.handle, c_class_name,
                                          c_category, c_attr_defs)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOmClassDescriptionGet_2 FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
            return ""
        return c_category.value
Exemple #29
0
    def apply(self):
        """ Apply the CCB

        Return:
            SaAisErrorT: Return code of the APIs
        """
        rc = agent.saImmOmCcbApply(self.ccb_handle)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOmCcbApply FAILED - %s" % eSaAisErrorT.whatis(rc))

        if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            init_rc = self.init()
            # If the re-initialization of agent handle succeeds, we still
            # need to return BAD_HANDLE to the users, so that they would
            # re-try the failed operation. Otherwise, the true error code
            # is returned to the user to decide further actions.
            if init_rc != eSaAisErrorT.SA_AIS_OK:
                rc = init_rc

        return rc
Exemple #30
0
    def update_runtime_object(self, dn, attributes):
        """ Update the specified object with the requested attribute
        modifications

        Args:
            dn (str): Object dn
            attributes (dict): Dictionary of attribute modifications

        Returns:
            SaAisErrorT: Return code of OI update runtime object
        """
        # Get the class name for the object
        class_name = self.get_class_name_for_dn(dn)

        # Create and marshall attribute modifications
        attr_mods = []

        for name, values in attributes.items():
            if values is None:
                print("WARNING: Received no values for %s in %s" % (name, dn))
                continue
            if not isinstance(values, list):
                values = [values]

            attr_type = self.get_attribute_type(name, class_name)
            c_attr_mod = SaImmAttrModificationT_2()
            c_attr_mod.modType = \
                eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_REPLACE
            c_attr_mod.modAttr = SaImmAttrValuesT_2()
            c_attr_mod.modAttr.attrName = SaImmAttrNameT(name)
            c_attr_mod.modAttr.attrValueType = attr_type
            c_attr_mod.modAttr.attrValuesNumber = len(values)
            c_attr_mod.modAttr.attrValues = marshal_c_array(attr_type, values)
            attr_mods.append(c_attr_mod)

        rc = saImmOiRtObjectUpdate_2(self.handle, SaNameT(dn), attr_mods)

        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saImmOiRtObjectUpdate_2 FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
        return rc
def get(object_name, attr_name_list=None):
    ''' obtain values of some attributes of the specified object '''

    attrib_names = [SaImmAttrNameT(a) for a in attr_name_list]\
        if attr_name_list else None

    attributes = pointer(pointer(SaImmAttrValuesT_2()))

    one_sec_sleeps = 0
    err = saImmOm.saImmOmAccessorGet_2(ACCESSOR_HANDLE,
                                       SaNameT(object_name),
                                       attrib_names, attributes)
    while err == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN:
        if one_sec_sleeps == TRYAGAIN_CNT:
            break
        time.sleep(1)
        one_sec_sleeps += 1
        err = saImmOm.saImmOmAccessorGet_2(ACCESSOR_HANDLE,
                                           SaNameT(object_name),
                                           attrib_names, attributes)

    if err == eSaAisErrorT.SA_AIS_ERR_NOT_EXIST:
        return None

    if err != eSaAisErrorT.SA_AIS_OK:
        raise SafException(err,
                           "saImmOmInitialize: %s" % eSaAisErrorT.whatis(err))

    attribs = {}
    attr_list = unmarshalNullArray(attributes)
    for attr in attr_list:
        attr_range = range(attr.attrValuesNumber)
        attribs[attr.attrName] = [
            attr.attrValueType,
            [unmarshalSaImmValue(
                attr.attrValues[val],
                attr.attrValueType) for val in attr_range]
            ]

    return ImmObject(object_name, attribs)
Exemple #32
0
    def _generate_object_create_delete_filter(self):
        """ Allocate memory for the object-create/delete notification filter
        and fill in the corresponding user-provided data

        Returns:
            SaAisErrorT: Return code of the
                saNtfObjectCreateDeleteNotificationFilterAllocate() API call
        """
        notification_filter = \
            saNtf.SaNtfObjectCreateDeleteNotificationFilterT()

        rc = ntf.saNtfObjectCreateDeleteNotificationFilterAllocate(
            self.handle, notification_filter,
            len(self.filter_info.obj_create_del_evt_list),
            len(self.filter_info.notification_object_list),
            len(self.filter_info.notifying_objects_list),
            len(self.filter_info.ntf_class_id_list),
            len(self.filter_info.source_indicator_list))
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saNtfObjectCreateDeleteNotificationFilterAllocate"
                    " FAILED, rc = %s" % eSaAisErrorT.whatis(rc))
        else:
            self.filter_handles.objectCreateDeleteFilterHandle = \
                notification_filter.notificationFilterHandle

            self._fill_in_filter_header(
                notification_filter.notificationFilterHeader)

            # Fill in the eventTypes array with user-provided data
            for i, evt in enumerate(self.filter_info.obj_create_del_evt_list):
                notification_filter.notificationFilterHeader.eventTypes[i] = \
                    evt

            # Fill in the sourceIndicators array with user-provided data
            for i, source_indicator in \
                    enumerate(self.filter_info.source_indicator_list):
                notification_filter.sourceIndicators[i] = source_indicator

        return rc
Exemple #33
0
    def release_owner(self, obj_name, scope=eSaImmScopeT.SA_IMM_SUBTREE):
        """ Release the admin owner for the set of objects identified by the
        scope and obj_name parameters

        Args:
            obj_name (str): Object name
            scope (SaImmScopeT): Scope of the admin owner release operation

        Return:
            SaAisErrorT: Return code of the saImmOmAdminOwnerRelease() API call
        """
        if not obj_name:
            rc = eSaAisErrorT.SA_AIS_ERR_NOT_EXIST
        else:
            obj_name = SaNameT(obj_name)
            obj_name = [obj_name]

            rc = saImmOmAdminOwnerRelease(self.owner_handle, obj_name, scope)
            if rc != eSaAisErrorT.SA_AIS_OK:
                log_err("saImmOmAdminOwnerRelease FAILED - %s" %
                        eSaAisErrorT.whatis(rc))

        return rc
Exemple #34
0
    def get_node_info(self, node_id, time_out):
        """ Get information of a specific cluster member node.

        Args:
            node_id (SaClmNodeIdT): Node id
            time_out (SaTimeT): Time-out (in nanosecond) for
                saClmClusterNodeGet_4 operation

        Returns:
            SaAisErrorT: Return code of the saClmClusterNodeGet_4() API call.
            ClusterNode: Node info or None if node with `node id` is not found.
        """
        clm_cluster_node = saClm.SaClmClusterNodeT_4()

        rc = saClmClusterNodeGet_4(self.handle, node_id, time_out,
                                   clm_cluster_node)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saClmClusterNodeGet() FAILED - %s" %
                    eSaAisErrorT.whatis(rc))
            return rc, None

        cluster_node = self.create_cluster_node_instance(clm_cluster_node)
        return rc, cluster_node
Exemple #35
0
    def get_members(self):
        """ Obtain information of each CLM cluster member node

        Returns:
            SaAisErrorT: Return code of the corresponding CLM API call(s)
            list(ClusterNode): The list of ClusterNode structures containing
                information of each CLM member node
        """
        cluster_nodes = []

        notification_buffer = saClm.SaClmClusterNotificationBufferT_4()

        rc = saClmClusterTrack_4(self.handle, saAis.SA_TRACK_CURRENT,
                                 notification_buffer)
        if rc == eSaAisErrorT.SA_AIS_OK:
            for i in range(notification_buffer.numberOfItems):
                notification = notification_buffer.notification[i]
                clm_cluster_node = notification.clusterNode

                cluster_node = \
                    self.create_cluster_node_instance(clm_cluster_node)

                cluster_nodes.append(cluster_node)
        else:
            log_err("saClmClusterTrack_4 FAILED - %s" %
                    eSaAisErrorT.whatis(rc))

        if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            init_rc = self._re_init()
            # If the re-initialization of agent handle succeeds, we still need
            # to return BAD_HANDLE to the function decorator, so that it would
            # re-try the failed operation. Otherwise, the true error code is
            # returned to the user to decide further actions.
            if init_rc != eSaAisErrorT.SA_AIS_OK:
                rc = init_rc

        return rc, cluster_nodes
Exemple #36
0
    def response(self, invocation, result):
        """ Respond to CLM the result of execution of the requested callback

        Args:
            invocation (SaInvocationT): Invocation id associated with the
                callback
            result (SaAisErrorT): Result of callback execution

        Returns:
            SaAisErrorT: Return code of the saClmResponse_4() API call
        """
        rc = saClmResponse_4(self.handle, invocation, result)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saClmResponse_4 FAILED - %s" % eSaAisErrorT.whatis(rc))

        if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            init_rc = self._re_init()
            if init_rc != eSaAisErrorT.SA_AIS_OK:
                rc = init_rc
            # No need to retry in case of BAD_HANDLE since the corresponding
            # callback response will no longer be valid with the new
            # re-initialized handle

        return rc
Exemple #37
0
    def track_start(self, flags):
        """ Start cluster membership tracking with the specified track flags

        Args:
            flags (SaUint8T): Type of cluster membership tracking

        Returns:
            SaAisErrorT: Return code of the corresponding CLM API call(s)
        """
        rc = saClmClusterTrack_4(self.handle, flags, None)
        if rc != eSaAisErrorT.SA_AIS_OK:
            log_err("saClmClusterTrack_4 FAILED - %s" %
                    eSaAisErrorT.whatis(rc))

        if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE:
            init_rc = self._re_init()
            # If the re-initialization of agent handle succeeds, we still need
            # to return BAD_HANDLE to the function decorator, so that it would
            # re-try the failed operation. Otherwise, the true error code is
            # returned to the user to decide further actions.
            if init_rc != eSaAisErrorT.SA_AIS_OK:
                rc = init_rc

        return rc
Exemple #38
0
    def init(self, owner_name=""):
        """ Initialize the IMM OM interface needed for CCB operations

        Args:
            owner_name (str): Name of the admin owner

        Return:
            SaAisErrorT: Return code of the corresponding IMM API calls
        """
        rc = super(Ccb, self).init()
        if rc == eSaAisErrorT.SA_AIS_OK:
            self.admin_owner = agent.OmAdminOwner(self.handle, owner_name)
            rc = self.admin_owner.init()

            if rc == eSaAisErrorT.SA_AIS_OK:
                _owner_handle = self.admin_owner.get_handle()
                self.ccb_handle = saImmOm.SaImmCcbHandleT()

                rc = agent.saImmOmCcbInitialize(_owner_handle, self.ccb_flags,
                                                self.ccb_handle)
                if rc != eSaAisErrorT.SA_AIS_OK:
                    log_err("saImmOmCcbInitialize FAILED - %s" %
                            eSaAisErrorT.whatis(rc))
        return rc
Exemple #39
0
 def __str__(self):
     return eSaAisErrorT.whatis(self.value)
def admin_op_invoke(dn, op_id, params=None):
    ''' invokes admin op for dn '''
    owner_handle = saImmOm.SaImmAdminOwnerHandleT()
    owner_name = saImmOm.SaImmAdminOwnerNameT(os.getlogin())
    err = saImmOm.saImmOmAdminOwnerInitialize(HANDLE,
                                              owner_name,
                                              saAis.eSaBoolT.SA_TRUE,
                                              owner_handle)

    if err != eSaAisErrorT.SA_AIS_OK:
        print "saImmOmAdminOwnerInitialize: %s" % eSaAisErrorT.whatis(err)
        raise SafException(err)

    idx = dn.rfind(",")
    parent_name = SaNameT(dn[idx+1:])
    object_names = [parent_name]
    err = saImmOm.saImmOmAdminOwnerSet(owner_handle, object_names,
                                       eSaImmScopeT.SA_IMM_SUBTREE)
    if err != eSaAisErrorT.SA_AIS_OK:
        print "saImmOmAdminOwnerInitialize: %s" % eSaAisErrorT.whatis(err)
        raise SafException(err)

    if params is None:
        params = []

    object_dn = SaNameT(dn)
    retval = saAis.SaAisErrorT()

    err = saImmOm.saImmOmAdminOperationInvoke_2(
        owner_handle,
        object_dn,
        0,
        op_id,
        params,
        retval,
        saAis.saAis.SA_TIME_ONE_SECOND * 10)

    if err != eSaAisErrorT.SA_AIS_OK:
        print "saImmOmAdminOperationInvoke_2: %s" % eSaAisErrorT.whatis(err)
        raise SafException(err)

    one_sec_sleeps = 0
    while retval.value == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN:
        if one_sec_sleeps == TRYAGAIN_CNT:
            break
        time.sleep(0.1)
        one_sec_sleeps += 1
        err = saImmOm.saImmOmAdminOperationInvoke_2(
            owner_handle,
            object_dn,
            0,
            op_id,
            params,
            retval,
            saAis.saAis.SA_TIME_ONE_SECOND * 10)

    if err != eSaAisErrorT.SA_AIS_OK:
        print "saImmOmAdminOperationInvoke_2: %s" % eSaAisErrorT.whatis(err)
        raise SafException(err)

    if retval.value != eSaAisErrorT.SA_AIS_OK:
        print "saImmOmAdminOperationInvoke_2: %s" % \
            eSaAisErrorT.whatis(retval.value)
        raise SafException(retval.value)

    error = saImmOm.saImmOmAdminOwnerFinalize(owner_handle)
    if error != eSaAisErrorT.SA_AIS_OK:
        print "saImmOmAdminOwnerFinalize: %s" % eSaAisErrorT.whatis(error)
        raise SafException(error)