Esempio n. 1
0
    def add(cls, **kwargs):
        unique_key = kwargs.pop("unique_key", None)
        unique_key = AttributeCache.get(unique_key) or abort(
            404, "Unique key is not defined")

        kwargs["alias"] = kwargs["name"] if not kwargs.get(
            "alias") else kwargs["alias"]

        cls._validate_unique(name=kwargs['name'])
        cls._validate_unique(alias=kwargs['alias'])

        kwargs["unique_id"] = unique_key.id
        ci_type = CIType.create(**kwargs)

        CITypeAttributeManager.add(ci_type.id, [unique_key.id],
                                   is_required=True)

        CITypeCache.clean(ci_type.name)

        if current_app.config.get("USE_ACL"):
            from api.lib.perm.acl.acl import ACLManager
            from api.lib.cmdb.const import ResourceTypeEnum, RoleEnum, PermEnum
            ACLManager().add_resource(ci_type.name, ResourceTypeEnum.CI)
            ACLManager().grant_resource_to_role(ci_type.name,
                                                RoleEnum.CMDB_READ_ALL,
                                                ResourceTypeEnum.CI,
                                                permissions=[PermEnum.READ])

        return ci_type.id
Esempio n. 2
0
def init_ci_types(num=1):
    attrs = init_attributes(num)

    ci_types = []
    for i in range(num):
        ci_type = CIType.create(name=uuid.uuid4().hex[:8],
                                alias=uuid.uuid4().hex[:8],
                                unique_id=attrs[i].id)
        CITypeAttribute.create(
            type_id=ci_type.id,
            attr_id=attrs[i].id,
        )
        ci_types.append(ci_type)

    return ci_types
Esempio n. 3
0
    def add(cls, **kwargs):
        unique_key = kwargs.pop("unique_key", None)
        unique_key = AttributeCache.get(unique_key) or abort(
            404, "Unique key is not defined")

        CIType.get_by(name=kwargs['name']) and abort(
            404, "CIType <{0}> is already existed".format(kwargs.get("name")))

        kwargs["alias"] = kwargs["name"] if not kwargs.get(
            "alias") else kwargs["alias"]

        kwargs["unique_id"] = unique_key.id
        ci_type = CIType.create(**kwargs)

        CITypeAttributeManager.add(ci_type.id, [unique_key.id],
                                   is_required=True)

        CITypeCache.clean(ci_type.name)

        return ci_type.id