def initialize(self, ntf_notif_func=None, ntf_notif_discarded_func=None): """ Initialize the NTF agent library Args: ntf_notif_func (callback): Callback function for subscribed notifications ntf_notif_discarded_func (callback): Callback function for discarded notifications Returns: SaAisErrorT: Return code of the saNtfInitialize() API call """ self.callbacks = None # Set up callbacks if any if ntf_notif_func is not None or ntf_notif_discarded_func is not None: self.ntf_notif_function = ntf_notif_func self.ntf_notif_discarded_function = ntf_notif_discarded_func self.callbacks = saNtf.SaNtfCallbacksT() self.callbacks.saNtfNotificationCallback = \ saNtf.SaNtfNotificationCallbackT(self._ntf_notif_callback) self.callbacks.saNtfNotificationDiscardedCallback = \ saNtf.SaNtfNotificationDiscardedCallbackT( self._ntf_notif_discarded_callback) self.handle = saNtf.SaNtfHandleT() self.version = deepcopy(self.init_version) rc = saNtfInitialize(self.handle, self.callbacks, self.version) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfInitialize FAILED - %s" % eSaAisErrorT.whatis(rc)) return rc
def open_stream(self): """ Open the log stream specified by the user Returns: SaAisErrorT: Return code of the corresponding LOG API call(s) """ rc = eSaAisErrorT.SA_AIS_OK if self.stream_handle is not None: self.close_stream() if self.log_handle is None: rc = self.init() self.stream_handle = SaLogStreamHandleT() if rc == eSaAisErrorT.SA_AIS_OK: stream_name = SaNameT(self.logger_info.stream_name) create_attrs, open_flag = self._generate_log_stream_open_config() rc = log.saLogStreamOpen_2(self.log_handle, stream_name, create_attrs, open_flag, saAis.SA_TIME_ONE_SECOND, self.stream_handle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saLogStreamOpen_2 FAILED - %s" % eSaAisErrorT.whatis(rc)) if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: self.log_handle = None return rc
def delete(self, object_name): """ Add a delete operation of the object with the given DN to the CCB Args: object_name (str): Object name Return: SaAisErrorT: Return code of the corresponding IMM API calls """ if object_name is None: return eSaAisErrorT.SA_AIS_ERR_NOT_EXIST rc = self.admin_owner.set_owner(object_name) if rc == eSaAisErrorT.SA_AIS_OK: obj_name = SaNameT(object_name) rc = agent.saImmOmCcbObjectDelete(self.ccb_handle, obj_name) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saImmOmCcbObjectDelete 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
def initialize(self, track_func=None, node_get_func=None): """ Initialize the CLM agent library Args: track_func (callback): Cluster track callback function node_get_func (callback): Cluster node get function Returns: SaAisErrorT: Return code of the saClmInitialize_4() API call """ self.track_function = track_func self.node_get_function = node_get_func self.callbacks = saClm.SaClmCallbacksT_4() self.callbacks.saClmClusterTrackCallback = \ saClm.SaClmClusterTrackCallbackT_4(self._track_callback) self.callbacks.saClmClusterNodeGetCallback = \ saClm.SaClmClusterNodeGetCallbackT_4( self._node_get_callback) 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)) return rc
def send_state_change_notification(self): """ Send an SaNtfStateChangeNotificationT notification Returns: SaAisErrorT: Return code of the corresponding NTF API call(s) """ # Create the notification notification = saNtf.SaNtfStateChangeNotificationT() rc = ntf.saNtfStateChangeNotificationAllocate( self.handle, notification, 0, len(self.ntf_info.additional_text) + 1, len(self.ntf_info.additional_info), len(self.ntf_info.state_changes), saNtf.saNtf.SA_NTF_ALLOC_SYSTEM_LIMIT) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfStateChangeNotificationAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: # Fill in the header self._fill_in_header(notification.notificationHandle, notification.notificationHeader) # Fill in the notification notification.sourceIndicator.contents.value = \ self.ntf_info.source_indicator for i, state_change in enumerate(self.ntf_info.state_changes): ptr = notification.changedStates[i] ptr.stateId = state_change.state_id ptr.newState = state_change.new_state if state_change.old_state_present: ptr.oldStatePresent = eSaBoolT.SA_TRUE ptr.oldState = state_change.old_state else: ptr.oldStatePresent = eSaBoolT.SA_FALSE # Send the notification rc = ntf.saNtfNotificationSend(notification.notificationHandle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfNotificationSend FAILED, rc = %s" % eSaAisErrorT.whatis(rc)) # Free the notification ntf.saNtfNotificationFree(notification.notificationHandle) 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 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
def get(self, object_name, attr_name_list=None, class_name=None): """ Obtain values of some attributes of the given object Args: object_name (str): Object name attr_name_list (list): List of attributes class_name (str): Class name Returns: SaAisErrorT: Return code of the corresponding IMM API call(s) ImmObject: Imm object """ imm_obj = None # Always request the SaImmAttrClassName attribute if needed if attr_name_list and not class_name \ and 'SaImmAttrClassName' not in attr_name_list \ and not attr_name_list == \ ['SA_IMM_SEARCH_GET_CONFIG_ATTR']: attr_name_list.append('SaImmAttrClassName') attr_names = [SaImmAttrNameT(attr) for attr in attr_name_list] \ if attr_name_list else None attributes = pointer(pointer(SaImmAttrValuesT_2())) rc = agent.saImmOmAccessorGet_2(self.accessor_handle, SaNameT(object_name), attr_names, attributes) if rc == eSaAisErrorT.SA_AIS_OK: 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 ] ] if 'SaImmAttrClassName' not in attrs and class_name: attrs['SaImmAttrClassName'] = class_name imm_obj = ImmObject(dn=object_name, attributes=attrs) 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: log_err("saImmOmAccessorGet_2 FAILED - %s" % eSaAisErrorT.whatis(rc)) rc = init_rc return rc, imm_obj
def send_object_create_delete_notification(self): """ Send an SaNtfObjectCreateDeleteNotificationT notification Returns: SaAisErrorT: Return code of the corresponding NTF API call(s) """ # Create the notification notification = saNtf.SaNtfObjectCreateDeleteNotificationT() rc = ntf.saNtfObjectCreateDeleteNotificationAllocate( self.handle, notification, 0, len(self.ntf_info.additional_text) + 1, len(self.ntf_info.additional_info), len(self.ntf_info.object_attributes), saNtf.saNtf.SA_NTF_ALLOC_SYSTEM_LIMIT) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfObjectCreateDeleteNotificationAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: # Fill in the header self._fill_in_header(notification.notificationHandle, notification.notificationHeader) # Fill in the notification notification.sourceIndicator.contents.value = \ self.ntf_info.source_indicator for i, attribute in enumerate(self.ntf_info.object_attributes): ptr = notification.objectAttributes[i] ptr.attributeId = attribute.attribute_id ptr.attributeType = attribute.attribute_type self._assign_ntf_value(notification.notificationHandle, ptr.attributeValue, attribute.attribute_value, attribute.attribute_type) # Send the notification rc = ntf.saNtfNotificationSend(notification.notificationHandle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfNotificationSend FAILED, rc = %s" % eSaAisErrorT.whatis(rc)) # Free the notification ntf.saNtfNotificationFree(notification.notificationHandle) 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 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
def __next__(self): """ Return the next element of the class iterator """ notification = saNtf.SaNtfNotificationsT() rc = ntf.saNtfNotificationReadNext(self.read_handle, self.search_direction, notification) if rc != eSaAisErrorT.SA_AIS_OK: if rc != eSaAisErrorT.SA_AIS_ERR_NOT_EXIST: log_err("saNtfNotificationReadNext FAILED - %s" % eSaAisErrorT.whatis(rc)) raise StopIteration return self._parse_notification(notification)
def _finalize(self): """ Finalize the log handle The log stream associated with the handle will be closed as a result. """ if self.log_handle is not None: rc = log.saLogFinalize(self.log_handle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saLogFinalize FAILED - %s" % eSaAisErrorT.whatis(rc)) if rc == eSaAisErrorT.SA_AIS_OK or \ rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: self.log_handle = None self.stream_handle = None
def _fetch_sel_obj(self): """ Obtain a selection object (OS file descriptor) Returns: SaAisErrorT: Return code of the saImmOiSelectionObjectGet() API """ rc = saImmOiSelectionObjectGet(self.handle, self.selection_object) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saImmOiSelectionObjectGet FAILED - %s" % eSaAisErrorT.whatis(rc)) return rc
def _generate_state_change_filter(self): """ Allocate memory for the state change notification filter and fill in the corresponding user-provided data Returns: SaAisErrorT: Return code of the saNtfStateChangeNotificationFilterAllocate() API call """ notification_filter = saNtf.SaNtfStateChangeNotificationFilterT() rc = ntf.saNtfStateChangeNotificationFilterAllocate( self.handle, notification_filter, len(self.filter_info.state_change_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), len(self.filter_info.changed_state_list)) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfStateChangeNotificationFilterAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: self.filter_handles.stateChangeFilterHandle = \ 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.state_change_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 # Fill in the changedStates array with user-provided data for i, state_change in \ enumerate(self.filter_info.changed_state_list): notification_filter.changedStates[i].stateId = \ state_change.state_id notification_filter.changedStates[i].newState = \ state_change.new_state notification_filter.changedStates[i].oldStatePresent = \ state_change.old_state_present if notification_filter.changedStates[i].oldStatePresent: notification_filter.changedStates[i].oldState = \ state_change.old_state return rc
def init(self): """ Initialize the IMM admin owner interface Return: SaAisErrorT: Return code of the saImmOmAdminOwnerInitialize() call """ self.owner_handle = saImmOm.SaImmAdminOwnerHandleT() rc = saImmOmAdminOwnerInitialize(self.imm_handle, self.owner_name, eSaBoolT.SA_TRUE, self.owner_handle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saImmOmAdminOwnerInitialize FAILED - %s" % eSaAisErrorT.whatis(rc)) return rc
def initialize(self): """ Initialize the IMM OM library Returns: SaAisErrorT: Return code of the saImmOmInitialize() API call """ self.handle = saImmOm.SaImmHandleT() self.version = deepcopy(self.init_version) rc = saImmOmInitialize(self.handle, None, self.version) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saImmOmInitialize FAILED - %s" % eSaAisErrorT.whatis(rc)) return rc
def dispatch(self, flags=eSaDispatchFlagsT.SA_DISPATCH_ALL): """ Dispatch all queued callbacks Args: flags (eSaDispatchFlagsT): Flags specifying dispatch mode Returns: SaAisErrorT: Return code of OI dispatch """ rc = saImmOiDispatch(self.handle, flags) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saImmOiDispatch FAILED - %s" % eSaAisErrorT.whatis(rc)) return rc
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
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
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
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
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
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
def log(self, message): """ Write a message (log record) to a log stream Args: message (str): Message to write to the log stream Returns: SaAisErrorT: Return code of the corresponding LOG API call(s) """ header_type, log_header = self._generate_log_header() self.record.logTimeStamp = saAis.SA_TIME_UNKNOWN self.record.logHdrType = header_type self.record.logHeader = log_header log_buffer = ctypes.pointer(SaLogBufferT(message)) self.record.logBuffer = log_buffer rc = log.saLogWriteLogAsync(self.stream_handle, self._get_invocation(), saLog.SA_LOG_RECORD_WRITE_ACK, self.record) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saLogWriteLogAsync FAILED - %s" % eSaAisErrorT.whatis(rc)) else: fds = [self.sel_obj.value] io_evt = select(fds, [], [], 10) if self.sel_obj.value in io_evt[0]: rc = log.saLogDispatch(self.log_handle, eSaDispatchFlagsT.SA_DISPATCH_ALL) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saLogDispatch FAILED - %s" % eSaAisErrorT.whatis(rc)) else: self.log_write_error = eSaAisErrorT.SA_AIS_ERR_TIMEOUT if rc == eSaAisErrorT.SA_AIS_OK and self.log_write_error == \ eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: rc = eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE 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 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
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
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
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
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
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
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
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
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
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