Exemplo n.º 1
0
Arquivo: ci.py Projeto: shuke163/cmdb
    def delete(cr_id):
        cr = CIRelation.get_by_id(cr_id) or abort(404, "CIRelation <{0}> is not existed".format(cr_id))
        cr.soft_delete()

        his_manager = CIRelationHistoryManager()
        his_manager.add(cr, operate_type=OperateType.DELETE)

        return cr_id
Exemplo n.º 2
0
Arquivo: ci.py Projeto: zzszmyf/cmdb
    def add(cls,
            first_ci_id,
            second_ci_id,
            more=None,
            relation_type_id=None,
            many_to_one=False):

        first_ci = CIManager.confirm_ci_existed(first_ci_id)
        second_ci = CIManager.confirm_ci_existed(second_ci_id)

        existed = CIRelation.get_by(first_ci_id=first_ci_id,
                                    second_ci_id=second_ci_id,
                                    to_dict=False,
                                    first=True)
        if existed is not None:
            if existed.relation_type_id != relation_type_id and relation_type_id is not None:
                existed.update(relation_type_id=relation_type_id)

                CIRelationHistoryManager().add(existed, OperateType.UPDATE)
        else:
            if relation_type_id is None:
                type_relation = CITypeRelation.get_by(
                    parent_id=first_ci.type_id,
                    child_id=second_ci.type_id,
                    first=True,
                    to_dict=False)
                relation_type_id = type_relation and type_relation.relation_type_id
                relation_type_id or abort(
                    404, "Relation {0} <-> {1} is not found".format(
                        first_ci.ci_type.name, second_ci.ci_type.name))

            if many_to_one:
                for item in CIRelation.get_by(
                        second_ci_id=second_ci_id,
                        relation_type_id=relation_type_id,
                        to_dict=False):
                    item.soft_delete()
                    his_manager = CIRelationHistoryManager()
                    his_manager.add(item, operate_type=OperateType.DELETE)

                    ci_relation_delete.apply_async(args=(item.first_ci_id,
                                                         item.second_ci_id),
                                                   queue=CMDB_QUEUE)

            existed = CIRelation.create(first_ci_id=first_ci_id,
                                        second_ci_id=second_ci_id,
                                        relation_type_id=relation_type_id)

            CIRelationHistoryManager().add(existed, OperateType.ADD)

            ci_relation_cache.apply_async(args=(first_ci_id, second_ci_id),
                                          queue=CMDB_QUEUE)

        if more is not None:
            existed.upadte(more=more)

        return existed.id
Exemplo n.º 3
0
    def delete(cr_id):
        cr = CIRelation.get_by_id(cr_id) or abort(404, "CIRelation <{0}> is not existed".format(cr_id))
        cr.delete()

        his_manager = CIRelationHistoryManager()
        his_manager.add(cr, operate_type=OperateType.DELETE)

        ci_relation_delete.apply_async(args=(cr.first_ci_id, cr.second_ci_id), queue=CMDB_QUEUE)

        return cr_id