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 = saImmOmAdminOwnerInitialize(HANDLE, owner_name, saAis.eSaBoolT.SA_TRUE, owner_handle) idx = dn.rfind(",") parent_name = SaNameT(dn[idx + 1:]) object_names = [parent_name] err = saImmOmAdminOwnerSet(owner_handle, object_names, eSaImmScopeT.SA_IMM_SUBTREE) if params is None: params = [] object_dn = SaNameT(dn) retval = saAis.SaAisErrorT() err = saImmOmAdminOperationInvoke_2(owner_handle, object_dn, 0, op_id, params, retval, saAis.saAis.SA_TIME_ONE_SECOND * 10) if retval.value != eSaAisErrorT.SA_AIS_OK: print "saImmOmAdminOperationInvoke_2: %s" % \ eSaAisErrorT.whatis(retval.value) raise SafException(retval.value) error = saImmOmAdminOwnerFinalize(owner_handle)
def _fill_in_filter_header(self, filter_header): """ Fill in the given notification filter header with user-provided data """ for i, info in enumerate(self.filter_info.notification_object_list): filter_header.notificationObjects[i] = SaNameT(info) for i, info in enumerate(self.filter_info.notifying_objects_list): filter_header.notifyingObjects[i] = SaNameT(info) for i, info in enumerate(self.filter_info.ntf_class_id_list): filter_header.notificationClassIds[i] = info
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 update_rt_object(dn, attributes): ''' Updates the given object with the given attribute modifications ''' # Get the class name for the object class_name = get_class_name_for_dn(dn) # Create and marshall attribute modifications attr_mods = [] for name, values in attributes.iteritems(): 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 = 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) # Call the function saImmOiRtObjectUpdate_2(HANDLE, SaNameT(dn), attr_mods)
def delete_rt_object(dn): ''' Deletes a runtime object ''' # Marshall the parameter c_dn = SaNameT(dn) saImmOiRtObjectDelete(HANDLE, c_dn)
def _value_to_ctype_ptr(value_type, value): ''' convert a value to a ctypes value ptr ''' if value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT32T: ctypeptr = cast(pointer(SaInt32T(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAUINT32T: ctypeptr = cast(pointer(SaUint32T(long(value))), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT64T: ctypeptr = cast(pointer(SaInt64T(long(value))), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAUINT64T: ctypeptr = cast(pointer(SaUint64T(long(value))), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SATIMET: ctypeptr = cast(pointer(SaTimeT(long(value))), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SANAMET: ctypeptr = cast(pointer(SaNameT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAFLOATT: ctypeptr = cast(pointer(SaFloatT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SADOUBLET: ctypeptr = cast(pointer(SaDoubleT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SASTRINGT: ctypeptr = cast(pointer(SaStringT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAANYT: assert 0 else: assert 0 return ctypeptr
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 _value_to_ctype_ptr(value_type, value): """ Convert a value to a ctypes value ptr Args: value_type (eSaImmValueTypeT): Value type value (ptr): Value in pointer Returns: c_void_p: ctype pointer which points to value """ if value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT32T: ctypeptr = cast(pointer(SaInt32T(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAUINT32T: ctypeptr = cast(pointer(SaUint32T(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT64T: ctypeptr = cast(pointer(SaInt64T(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAUINT64T: ctypeptr = cast(pointer(SaUint64T(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SATIMET: ctypeptr = cast(pointer(SaTimeT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SANAMET: ctypeptr = cast(pointer(SaNameT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAFLOATT: ctypeptr = cast(pointer(SaFloatT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SADOUBLET: ctypeptr = cast(pointer(SaDoubleT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SASTRINGT: ctypeptr = cast(pointer(SaStringT(value)), c_void_p) elif value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAANYT: assert 0 else: assert 0 return ctypeptr
def __init__(self, root_name=None, scope=eSaImmScopeT.SA_IMM_SUBTREE, attribute_names=None, search_param=None, version=None): """ Constructor for SearchIterator class """ super(SearchIterator, self).__init__(version) self.search_handle = None if root_name is not None: self.root_name = SaNameT(root_name) else: self.root_name = None self.scope = scope self.attribute_names = [SaImmAttrNameT(attr_name) for attr_name in attribute_names] \ if attribute_names else None self.search_options = saImm.SA_IMM_SEARCH_ONE_ATTR if attribute_names is None: self.search_options |= saImm.SA_IMM_SEARCH_GET_ALL_ATTR else: self.search_options |= saImm.SA_IMM_SEARCH_GET_SOME_ATTR if search_param is None: self.search_param = SaImmSearchParametersT_2() else: self.search_param = search_param
def next(self): name = SaNameT() attributes = pointer(pointer(SaImmAttrValuesT_2())) try: immom.saImmOmSearchNext_2(self.search_handle, name, attributes) except SafException as err: if err.value == eSaAisErrorT.SA_AIS_ERR_NOT_EXIST: raise StopIteration else: raise 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(name.value, attribs)
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 _fill_in_header(self, ntf_handle, header): """ Fill in the given notification header with the provided information Args: ntf_handle (SaNtfNotificationHandleT): Notification handle header (SaNtfNotificationHeaderT): Notification header """ header.eventType.contents.value = self.ntf_info.event_type header.notificationObject[0] = \ SaNameT(self.ntf_info.notification_object) header.notifyingObject[0] = SaNameT(self.ntf_info.notifying_object) header.notificationClassId.contents.vendorId = \ self.ntf_info.ntf_class_id.vendorId header.notificationClassId.contents.majorId = \ self.ntf_info.ntf_class_id.majorId header.notificationClassId.contents.minorId = \ self.ntf_info.ntf_class_id.minorId header.eventTime.contents.value = self.ntf_info.event_time additional_text = self.ntf_info.additional_text if PY3: additional_text = self.ntf_info.additional_text.encode('utf-8') header.lengthAdditionalText = len(additional_text) ctypes.memmove(header.additionalText, additional_text, len(additional_text) + 1) if self.ntf_info.additional_info: for i, add_info in enumerate(self.ntf_info.additional_info): header.additionalInfo[i].infoId = add_info.info_id header.additionalInfo[i].infoType = add_info.info_type self._assign_ntf_value(ntf_handle, header.additionalInfo[i].infoValue, add_info.info_value, add_info.info_type)
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 delete(self, _object_name): ''' Adds a delete operation of the object with the given DN to the CCB''' if _object_name is None: raise SafException(eSaAisErrorT.SA_AIS_ERR_NOT_EXIST) object_name = SaNameT(_object_name) object_names = [object_name] immom.saImmOmAdminOwnerSet(self.owner_handle, object_names, eSaImmScopeT.SA_IMM_SUBTREE) immom.saImmOmCcbObjectDelete(self.ccb_handle, object_name)
def _generate_log_header(self): """ Fill in the header of the log record to be written with user- provided information Returns: SaLogHeaderTypeT: Log header type SaLogHeaderT: Log header structure filled with information """ if self.logger_info.stream_name == ALARM_STREAM or \ self.logger_info.stream_name == NOTIF_STREAM: header_type = eSaLogHeaderTypeT.SA_LOG_NTF_HEADER ntf_header = SaLogNtfLogHeaderT() ntf_header.notificationId = saNtf.SA_NTF_IDENTIFIER_UNUSED ntf_header.eventType = self.logger_info.event_type ntf_header.notificationObject.contents = SaNameT( self.logger_info.notification_object) ntf_header.notifyingObject.contents = SaNameT( self.logger_info.notifying_object) if self.logger_info.ntf_class_id: ntf_header.notificationClassId.contents = \ self.logger_info.ntf_class_id ntf_header.eventTime = self.logger_info.event_time log_header = SaLogHeaderT() log_header.ntfHdr = ntf_header else: header_type = eSaLogHeaderTypeT.SA_LOG_GENERIC_HEADER generic_header = SaLogGenericLogHeaderT() if self.logger_info.ntf_class_id: generic_header.notificationClassId.contents = \ self.logger_info.ntf_class_id generic_header.logSvcUsrName.contents = \ SaNameT(self.logger_info.log_service_user_name) generic_header.logSeverity = self.logger_info.log_severity log_header = SaLogHeaderT() log_header.genericHdr = generic_header return header_type, log_header
def modify_value_add(self, object_name, attr_name, values): ''' add to the CCB an ADD modification of an existing object ''' assert object_name # Make sure the values field is a list if not isinstance(values, list): values = [values] # first get class name to read class description to get value type... try: obj = 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 = 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 = immom.saImmOmAdminOwnerSet(self.owner_handle, object_names, eSaImmScopeT.SA_IMM_ONE) attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() attr_mod.modType = \ saImm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_ADD attr_mod.modAttr = SaImmAttrValuesT_2() attr_mod.modAttr.attrName = attr_name attr_mod.modAttr.attrValueType = value_type attr_mod.modAttr.attrValuesNumber = len(values) attr_mod.modAttr.attrValues = marshal_c_array(value_type, values) attr_mods.append(attr_mod) err = immom.saImmOmCcbObjectModify_2(self.ccb_handle, object_names[0], attr_mods)
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 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 __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)
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 create_rt_object(class_name, parent_name, obj): ''' Creates a 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 obj.attrs.iteritems(): if values == 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 len(values) == 0: c_attr.attrValues = None else: c_attr.attrValues = marshal_c_array(c_attr_type, values) c_attr_values.append(c_attr) # Call the function saImmOiRtObjectCreate_2(HANDLE, c_class_name, c_parent_name, c_attr_values)
def get(object_name, attr_name_list=None, class_name=None): ''' obtain values of some attributes of the specified object ''' # Always request the SaImmAttrClassName attribute if needed if attr_name_list and \ not class_name and \ not 'SaImmAttrClassName' in attr_name_list and \ not attr_name_list == ['SA_IMM_SEARCH_GET_CONFIG_ATTR']: attr_name_list.append('SaImmAttrClassName') attrib_names = [SaImmAttrNameT(a) for a in attr_name_list]\ if attr_name_list else None attributes = pointer(pointer(SaImmAttrValuesT_2())) try: err = saImmOmAccessorGet_2(ACCESSOR_HANDLE, SaNameT(object_name), attrib_names, attributes) except SafException as err: if err.value == eSaAisErrorT.SA_AIS_ERR_NOT_EXIST: return None else: raise 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 ] ] if not 'SaImmAttrClassName' in attribs and class_name: attribs['SaImmAttrClassName'] = class_name return ImmObject(object_name, attribs)
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] immom.saImmOmAdminOwnerSet(self.owner_handle, object_names, eSaImmScopeT.SA_IMM_SUBTREE) 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) immom.saImmOmCcbObjectCreate_2(self.ccb_handle, obj.class_name, parent_name, attr_values)
def __init__(self, root_name=None, scope=eSaImmScopeT.SA_IMM_SUBTREE, attribute_names=None, _search_param=None): self.search_handle = saImmOm.SaImmSearchHandleT() if root_name is not None: self.root_name = SaNameT(root_name) else: self.root_name = None self.scope = scope self.attribute_names = \ [SaImmAttrNameT(n) for n in attribute_names] \ if attribute_names else None search_options = saImm.SA_IMM_SEARCH_ONE_ATTR if attribute_names is None: search_options |= saImm.SA_IMM_SEARCH_GET_ALL_ATTR else: search_options |= saImm.SA_IMM_SEARCH_GET_SOME_ATTR if _search_param is None: search_param = SaImmSearchParametersT_2() else: search_param = _search_param try: immom.saImmOmSearchInitialize_2(immom.HANDLE, self.root_name, self.scope, search_options, search_param, self.attribute_names, self.search_handle) except SafException as err: if err.value == eSaAisErrorT.SA_AIS_ERR_NOT_EXIST: self.search_handle = None raise err else: raise err
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
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
def _modify(self, object_name, attr_name, values, mod_type): """ Modify an existing object Args: object_name (str): Object name attr_name (str): Attribute name values (list): List of attribute values mod_type (eSaImmAttrModificationTypeT): Modification type Return: SaAisErrorT: Return code of the corresponding IMM API call(s) """ if object_name is None: rc = eSaAisErrorT.SA_AIS_ERR_INVALID_PARAM else: if not self.accessor: self.accessor = ImmOmAccessor(self.init_version) self.accessor.init() # Get the attribute value type by reading the object's class # description rc, obj = self.accessor.get(object_name) if rc == eSaAisErrorT.SA_AIS_OK: class_name = obj.SaImmAttrClassName _, attr_def_list = self.get_class_description(class_name) value_type = None for attr_def in attr_def_list: if str(attr_def.attrName) == attr_name: value_type = attr_def.attrValueType break if value_type: rc = self.admin_owner.set_owner(object_name, eSaImmScopeT.SA_IMM_ONE) if rc == eSaAisErrorT.SA_AIS_OK: # Make sure the values field is a list if not isinstance(values, list): values = [values] attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() attr_mod.modType = mod_type attr_mod.modAttr = SaImmAttrValuesT_2() attr_mod.modAttr.attrName = SaImmAttrNameT(attr_name) attr_mod.modAttr.attrValueType = value_type attr_mod.modAttr.attrValuesNumber = len(values) attr_mod.modAttr.attrValues = marshal_c_array( value_type, values) attr_mods.append(attr_mod) object_name = SaNameT(object_name) rc = agent.saImmOmCcbObjectModify_2(self.ccb_handle, object_name, attr_mods) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saImmOmCcbObjectModify_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