Esempio n. 1
0
    def get_record_detail(record_id):
        from api.lib.cmdb.ci import CIManager

        record = OperationRecord.get_by_id(record_id) or abort(
            404, "Record <{0}> is not found".format(record_id))

        username = UserCache.get(record.uid).nickname or UserCache.get(
            record.uid).username
        timestamp = record.created_at.strftime("%Y-%m-%d %H:%M:%S")
        attr_history = AttributeHistory.get_By(record_id=record_id,
                                               to_dict=False)
        rel_history = CIRelationHistory.get_by(record_id=record_id,
                                               to_dict=False)

        attr_dict, rel_dict = dict(), {"add": [], "delete": []}
        for attr_h in attr_history:
            attr_dict[AttributeCache.get(attr_h.attr_id).alias] = dict(
                old=attr_h.old,
                new=attr_h.new,
                operate_type=attr_h.operate_type)

        for rel_h in rel_history:
            first = CIManager.get_ci_by_id(rel_h.first_ci_id)
            second = CIManager.get_ci_by_id(rel_h.second_ci_id)
            rel_dict[rel_h.operate_type].append(
                (first, RelationTypeCache.get(rel_h.relation_type_id).name,
                 second))

        return username, timestamp, attr_dict, rel_dict
Esempio n. 2
0
    def add(rel_obj, operate_type=OperateType.ADD):
        record = OperationRecord.create(uid=g.user.uid)

        CIRelationHistory.create(relation_id=rel_obj.id,
                                 record_id=record.id,
                                 operate_type=operate_type,
                                 first_ci_id=rel_obj.first_ci_id,
                                 second_ci_id=rel_obj.second_ci_id,
                                 relation_type_id=rel_obj.relation_type_id)
Esempio n. 3
0
    def add(ci_id, history_list):
        record = OperationRecord.create(uid=g.user.uid)

        for attr_id, operate_type, old, new in history_list or []:
            AttributeHistory.create(attr_id=attr_id,
                                    operate_type=operate_type,
                                    old=json.dumps(old) if isinstance(old, (dict, list)) else old,
                                    new=json.dumps(new) if isinstance(new, (dict, list)) else new,
                                    ci_id=ci_id,
                                    record_id=record.id)
Esempio n. 4
0
    def add(ci_id, history_list):
        record = OperationRecord.create(uid=g.user.uid)

        for attr_id, operate_type, old, new in history_list or []:
            AttributeHistory.create(attr_id=attr_id,
                                    operate_type=operate_type,
                                    old=old,
                                    new=new,
                                    ci_id=ci_id,
                                    record_id=record.id)