def detail(self, req, data, resp, **kwargs): ''' :param req: :param data: re_type 关系类型 is_exists 校验是否存在一定的关联关系,做深度搜索,可与max_search_deep结合,限制搜索深度 max_search_deep 与 is_exists 配合使用,单独使用不生效,默认搜索深度3 :param resp: :param kwargs: :return: ''' uuid1 = kwargs.pop("uuid1", None) uuid2 = kwargs.pop("uuid2", None) re_type = data.pop("re_type", None) is_exists = data.pop("is_exists", None) max_search_deep = data.pop("max_search_deep", 3) HostApi().valitdae_host(uuid1) HostApi().valitdae_host(uuid2) if is_exists: return HostGraphApi().deep_match_relation(primary_key1=uuid1, primary_key2=uuid2, deep=max_search_deep) result = HostGraphApi().match_node_relation(primary_key1=uuid1, primary_key2=uuid2, re_type=re_type) return {"data": result}
def delete(self, req, data, resp, **kwargs): uuid = kwargs.pop("uuid", None) _host = HostApi().get(primiry_id=uuid) if not _host: return {} Redis.delete(uuid) self.on_ipaddress_delete(uuid) self.on_graph_delete(uuid) return HostApi().delete(primiry_id=uuid)
def update(self, req, data, resp, **kwargs): ip = kwargs.pop("ip", None) if not is_ip(ip): return {} if "host_id" in data.keys(): HostApi().valitdae_host(data["host_id"]) return IpaddressApi().update(primiry_id=ip, data=data)
def delete(self, req, data, resp, **kwargs): uuid = kwargs.pop("uuid", None) result = HostApi().delete(primiry_id=uuid) if result: Redis.delete(uuid) self.on_graph_delete(uuid) self.on_ipaddress_delete(uuid) return result
def update(self, req, data, resp, **kwargs): uuid = kwargs.pop("uuid", None) if "ipaddress" in data.keys(): raise ValueError("ipaddress 不允许更新, 默认为主机注册ip, 如需更改请重新注册") count, after_data = HostApi().update(primiry_id=uuid, data=data) if count: Redis.delete(uuid) self.on_graph_update(uuid=uuid, data=data) return count, after_data
def create(self, req, data, resp, **kwargs): if not data.get("id"): raise ValueError("主机注册缺少UUID") hostApi = HostApi() uuid = data["id"] hostRegisterData = hostApi.get(primiry_id=uuid) if hostRegisterData: raise ValueError( "UUID:%s 已注册, 注册信息 - HOSTNAME %s - IP: " % (uuid, hostRegisterData["hostname"]), hostRegisterData["ipaddress"]) # 一台主机可能拥有多个ip, 注册主机以请求IP进行注册(默认情况下, 该ip应该为默认出口ip) data["ipaddress"] = getRequestIpaddress(req) self.on_ipaddress_create(uuid, data) self.on_graph_create(uuid, data) count, cid = hostApi.insert(data) Redis.set(uuid, to_str(data=data)) return count.cid
def detail(self, req, data, resp, **kwargs): uuid = kwargs.pop("uuid", None) return HostApi().get(primiry_id=uuid)
def list(self, req, data, resp, **kwargs): return HostApi().query(filter=data, **kwargs)
def detail(self, req, data, resp, **kwargs): uuid = kwargs.pop("uuid", None) re_type = data.pop("re_type", None) HostApi().valitdae_host(uuid) result = HostGraphApi().match_node(primary_key1=uuid, re_type=re_type) return {"data": result}