Esempio n. 1
0
    def delete(ci_id):
        ci = CI.get_by_id(ci_id) or abort(
            404, "CI <{0}> is not found".format(ci_id))

        attrs = CITypeAttribute.get_by(type_id=ci.type_id, to_dict=False)
        attr_names = set(
            [AttributeCache.get(attr.attr_id).name for attr in attrs])
        for attr_name in attr_names:
            value_table = TableMap(attr_name=attr_name).table
            for item in value_table.get_by(ci_id=ci_id, to_dict=False):
                item.delete()

        for item in CIRelation.get_by(first_ci_id=ci_id, to_dict=False):
            item.delete()

        for item in CIRelation.get_by(second_ci_id=ci_id, to_dict=False):
            item.delete()

        ci.delete()  # TODO: soft delete

        AttributeHistoryManger.add(ci_id,
                                   [(None, OperateType.DELETE, None, None)])

        ci_delete.apply_async([ci.id], queue=CMDB_QUEUE)

        return ci_id
Esempio n. 2
0
 def _write_change(ci_id, attr_id, operate_type, old, new):
     AttributeHistoryManger.add(ci_id, [(attr_id, operate_type, old, new)])