def delete(cls, type_id, attr_ids=None): """ delete attributes from CIType :param type_id: :param attr_ids: list :return: """ from api.tasks.cmdb import ci_cache cls._check(type_id, attr_ids) for attr_id in attr_ids: existed = CITypeAttribute.get_by(type_id=type_id, attr_id=attr_id, first=True, to_dict=False) if existed is not None: existed.soft_delete() for ci in CI.get_by(type_id=type_id, to_dict=False): AttributeValueManager.delete_attr_value(attr_id, ci.id) ci_cache.apply_async([ci.id], queue=CMDB_QUEUE) CITypeAttributeCache.clean(type_id, attr_id) CITypeAttributesCache.clean(type_id)
def delete(cls, type_id, attr_ids=None): """ delete attributes from CIType :param type_id: :param attr_ids: list :return: """ cls._check(type_id, attr_ids) for attr_id in attr_ids: existed = CITypeAttribute.get_by(type_id=type_id, attr_id=attr_id, first=True, to_dict=False) if existed is not None: existed.soft_delete() CITypeAttributeCache.clean(type_id)
def update(cls, type_id, attributes): """ update attributes to CIType :param type_id: :param attributes: list :return: """ cls._check(type_id, [i.get('attr_id') for i in attributes]) for attr in attributes: existed = CITypeAttribute.get_by(type_id=type_id, attr_id=attr.get("attr_id"), first=True, to_dict=False) if existed is None: continue existed.update(**attr) CITypeAttributeCache.clean(type_id)
def add(cls, type_id, attr_ids=None, **kwargs): """ add attributes to CIType :param type_id: :param attr_ids: list :param kwargs: :return: """ cls._check(type_id, attr_ids) for attr_id in attr_ids: existed = CITypeAttribute.get_by(type_id=type_id, attr_id=attr_id, first=True, to_dict=False) if existed is not None: continue current_app.logger.debug(attr_id) CITypeAttribute.create(type_id=type_id, attr_id=attr_id, **kwargs) CITypeAttributeCache.clean(type_id)