Пример #1
0
    def create(cls, **attrs):
        '''Create an object of this class'''
        if cls.rdn_attr not in attrs:
            raise TypeError("All %s objects must have a %s field" %
                            (cls, cls.rdn_attr))
        if hasattr(cls, "default_objectclass"):
            if 'objectClass' not in attrs:
                attrs['objectClass'] = list(cls.default_objectclass)
        modlist = []
        backlinks = []
        for key in attrs:
            val = attrs[key]
            attribute = Attribute.get_attribute(key)
            if attribute.is_multival():
                if attribute.is_backlink_attr():
                    backlinks.append(key)
                else:
                    for v in val:
                        modlist.append((attribute.get_ldap_name(),
                                        attribute.py_to_ldap(v)))
            else:
                modlist.append((attribute.get_ldap_name(),
                                attribute.py_to_ldap(val)))

        dn = tuple_to_dn(((cls.rdn_attr, attrs[cls.rdn_attr]),) +
                         cls.cls_dn_tuple)
        linfo("Creating %s of type %s" % (dn, cls.__name__))
        lc.add(dn, modlist)
        assert(LDAPClass.get_class_by_dn(dn) is cls)

        ret_obj = cls(obj_dn=dn)

        for key in backlinks:
            for obj in attrs[key]:
                getattr(ret_obj, key).add(obj)

        return ret_obj
Пример #2
0
    def create(cls, **attrs):
        '''Create an object of this class'''
        if cls.rdn_attr not in attrs:
            raise TypeError("All %s objects must have a %s field" %
                            (cls, cls.rdn_attr))
        if hasattr(cls, "default_objectclass"):
            if 'objectClass' not in attrs:
                attrs['objectClass'] = list(cls.default_objectclass)
        modlist = []
        backlinks = []
        for key in attrs:
            val = attrs[key]
            attribute = Attribute.get_attribute(key)
            if attribute.is_multival():
                if attribute.is_backlink_attr():
                    backlinks.append(key)
                else:
                    for v in val:
                        modlist.append((attribute.get_ldap_name(),
                                        attribute.py_to_ldap(v)))
            else:
                modlist.append(
                    (attribute.get_ldap_name(), attribute.py_to_ldap(val)))

        dn = tuple_to_dn(((cls.rdn_attr, attrs[cls.rdn_attr]), ) +
                         cls.cls_dn_tuple)
        linfo("Creating %s of type %s" % (dn, cls.__name__))
        lc.add(dn, modlist)
        assert (LDAPClass.get_class_by_dn(dn) is cls)

        ret_obj = cls(obj_dn=dn)

        for key in backlinks:
            for obj in attrs[key]:
                getattr(ret_obj, key).add(obj)

        return ret_obj
Пример #3
0
 def destroy(self):
     '''Delete this object from LDAP'''
     linfo("Destroying %s of type %s" % (self.get_dn(), type(self)))
     lc.delete(self.get_dn())
Пример #4
0
 def destroy(self):
     '''Delete this object from LDAP'''
     linfo("Destroying %s of type %s" % (self.get_dn(), type(self)))
     lc.delete(self.get_dn())