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 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 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)