Example #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
Example #2
0
 def get(self, record_id):
     username, timestamp, attr_dict, rel_dict = AttributeHistoryManger.get_record_detail(
         record_id)
     return self.jsonify(username=username,
                         timestamp=timestamp,
                         attr_history=attr_dict,
                         rel_history=rel_dict)
Example #3
0
    def get(self):
        page = get_page(request.values.get("page", 1))
        page_size = get_page_size(request.values.get("page_size"))
        _start = request.values.get("start")
        _end = request.values.get("end")
        username = request.values.get("username", "")
        start, end = None, None
        if _start:
            try:
                start = datetime.datetime.strptime(_start, '%Y-%m-%d %H:%M:%S')
            except ValueError:
                abort(400, 'incorrect start date time')
        if _end:
            try:
                end = datetime.datetime.strptime(_end, '%Y-%m-%d %H:%M:%S')
            except ValueError:
                abort(400, 'incorrect end date time')

        numfound, total, res = AttributeHistoryManger.get_records(
            start, end, username, page, page_size)

        return self.jsonify(numfound=numfound,
                            records=res,
                            page=page,
                            total=total,
                            start=_start,
                            end=_end,
                            username=username)
Example #4
0
 def _write_change(ci_id, attr_id, operate_type, old, new):
     AttributeHistoryManger.add(ci_id, [(attr_id, operate_type, old, new)])
Example #5
0
 def get(self, ci_id):
     result = AttributeHistoryManger.get_by_ci_id(ci_id)
     return self.jsonify(result)