mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 05:34:48 +08:00
facet query fix
This commit is contained in:
@@ -8,4 +8,4 @@ from ci_relation import cirelation
|
||||
from ci import ci
|
||||
from history import history
|
||||
from account import account
|
||||
# from special import special
|
||||
from special import special
|
@@ -102,15 +102,21 @@ def delete_attribute(attr_id=None):
|
||||
|
||||
|
||||
@attribute.route("/citype/<int:type_id>", methods=["GET"])
|
||||
def get_attributes_by_type(type_id=None):
|
||||
@attribute.route("/citype/<string:type_name>", methods=["GET"])
|
||||
def get_attributes_by_type(type_id=None, type_name=None):
|
||||
manager = CITypeAttributeManager()
|
||||
from models.attribute import CIAttributeCache
|
||||
from models.ci_type import CITypeCache
|
||||
from models.ci_type import CITypeAttributeCache
|
||||
|
||||
t = CITypeCache.get(type_id)
|
||||
if not t:
|
||||
return abort(400, "CIType {0} is not existed".format(type_id))
|
||||
t = CITypeCache.get(type_name)
|
||||
if not t:
|
||||
return abort(400, "CIType {0} is not existed".format(type_id))
|
||||
type_id = t.type_id
|
||||
uniq_id = t.uniq_id
|
||||
CITypeAttributeCache.clean(type_id)
|
||||
unique = CIAttributeCache.get(uniq_id).attr_name
|
||||
return jsonify(attributes=manager.get_attributes_by_type_id(type_id),
|
||||
type_id=type_id, uniq_id=uniq_id, unique=unique)
|
||||
|
29
core/ci.py
29
core/ci.py
@@ -16,6 +16,7 @@ from flask import abort
|
||||
|
||||
from lib.auth import auth_with_key
|
||||
from lib.ci import CIManager
|
||||
from lib.ci import HostNumStatis
|
||||
from lib.search import Search
|
||||
from lib.search import SearchError
|
||||
from lib.utils import get_page
|
||||
@@ -156,6 +157,14 @@ def update_ci():
|
||||
return jsonify(ci_id=ci_id)
|
||||
|
||||
|
||||
@ci.route("/<int:ci_id>/unique", methods=["PUT"])
|
||||
@auth_with_key
|
||||
def update_ci_unique(ci_id):
|
||||
m = CIManager()
|
||||
m.update_unique_value(ci_id, request.values)
|
||||
return jsonify(ci_id=ci_id)
|
||||
|
||||
|
||||
@ci.route("/<int:ci_id>", methods=["DELETE"])
|
||||
@auth_with_key
|
||||
def delete_ci(ci_id=None):
|
||||
@@ -186,4 +195,22 @@ def get_heartbeat():
|
||||
numfound, result = CIManager().get_heartbeat(page,
|
||||
ci_type,
|
||||
agent_status=agent_status)
|
||||
return jsonify(numfound=numfound, result=result)
|
||||
return jsonify(numfound=numfound, result=result)
|
||||
|
||||
|
||||
######################### just for frontend ###################################
|
||||
|
||||
@ci.route("/hosts/nums", methods=["GET"])
|
||||
def get_hosts_nums():
|
||||
ci_type = request.args.get("ci_type", "").strip()
|
||||
ci_ids = request.args.get("ci_ids", "").strip()
|
||||
ci_id_list = ci_ids.split(",")
|
||||
ci_id_list = map(str, filter(lambda x: x != "", ci_id_list))
|
||||
res = {}
|
||||
if ci_type == "bu":
|
||||
res = HostNumStatis().get_hosts_by_bu(ci_id_list)
|
||||
elif ci_type == "product":
|
||||
res = HostNumStatis().get_hosts_by_product(ci_id_list)
|
||||
elif ci_type == "project":
|
||||
res = HostNumStatis().get_hosts_by_project(ci_id_list)
|
||||
return jsonify(hosts=res)
|
@@ -86,4 +86,4 @@ def enable(type_id=None):
|
||||
enable = request.values.get("enable", True)
|
||||
manager = CITypeManager()
|
||||
manager.set_enabled(type_id, enabled=enable)
|
||||
return jsonify(type_id=type_id)
|
||||
return jsonify(type_id=type_id)
|
||||
|
Reference in New Issue
Block a user