Ejemplo n.º 1
0
def get_attribute_type(attribute, class_name):
    ''' Returns the type of the attribute in the given class

        This is safe to use from OI callbacks
    '''

    class_desc = immom.class_description_get(class_name)

    attr_desc = [ad for ad in class_desc if ad.attrName == attribute][0]

    return attr_desc.attrValueType
Ejemplo n.º 2
0
def get_rdn_attribute_for_class(class_name):
    ''' Returns the RDN attribute for the given class

        This is safe to call from OI callbacks
    '''

    desc = immom.class_description_get(class_name)

    for attr_desc in desc:
        if attr_desc.attrFlags & saImm.saImm.SA_IMM_ATTR_RDN:
            return attr_desc.attrName

    return None
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
def create_added(oi_handle, c_ccb_id, c_class_name, c_parent, c_attr_values):
    ''' Callback for object create '''

    # Unmarshal parameters
    parent     = saImm.unmarshalSaImmValue(c_parent,
                                           eSaImmValueTypeT.SA_IMM_ATTR_SANAMET)
    class_name = c_class_name
    ccb_id     = c_ccb_id

    attributes = {}

    for attr in saAis.unmarshalNullArray(c_attr_values):
        attr_name = attr.attrName
        attr_type = attr.attrValueType
        nr_values = attr.attrValuesNumber

        attr_values = immoi.unmarshall_len_array(attr.attrValues, nr_values,
                                                 attr_type)

        if len(attr_values) > 0:
            attributes[attr_name] = attr_values
        else:
            attributes[attr_name] = None

    # Fill in any missing attributes
    description = immom.class_description_get(class_name)

    for attribute in description:

        if not attribute.attrName in attributes:
            attributes[attribute.attrName] = None

    # Create a new CCB in the cache if needed
    if not ccb_id in CCBS.keys():
        CCBS[ccb_id] = []

    # Cache the create operation
    CCBS[ccb_id].append({'type'       : 'CREATE',
                         'parent'     : parent,
                         'className'  : class_name,
                         'attributes' : attributes})

    # Tell the implementer about the operation
    obj = immoi.create_non_existing_imm_object(class_name, parent, attributes)

    return implementer_instance.on_create_added(class_name, parent, obj)