Beispiel #1
0
 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}
Beispiel #2
0
 def __create_cloud_node(self):
     uuid = "netmapcloud"
     _graph_data = HostGraphApi().queryone(primary_key=uuid)
     if not _graph_data:
         HostGraphApi().insert(
             data={
                 "uuid": uuid,
                 "ipaddress": "0.0.0.0",
                 "hostname": "__netmapcloud__",
                 "describe": "互联网访问"
             })
Beispiel #3
0
 def callback(self, msg):
     '''
     :param msg:
     :return:
     '''
     # TODO  识别访问src ip是否为外网地址, 若为外网地址, 则统一归属为netmapcloud
     try:
         access_data = {
             "uuid": msg.get("id"),
             "src": msg.get("src"),
             "dest": msg.get("dest"),
             "port": msg.get("port")
         }
         self.mongoClient.insert(access_data)
         ip_data = IpaddressApi().get(primiry_id=msg.get("src"))
         if ip_data:
             HostGraphApi().create_relation(
                 primary_key1=msg.get("id"),
                 primary_key2=ip_data.get("host_id"),
                 re_type="access",
                 port=msg.get("port"),
                 access="%s_%s" % (msg.get("src"), msg.get("dest")))
     except:
         logger.info(traceback.format_exc())
         logger.info("Access Drawer failed: %s" % to_str(msg))
Beispiel #4
0
 def on_graph_update(self, uuid, data):
     graph_update = {}
     if "ipaddress" in data.keys():
         graph_update["ipaddress"] = data["ipaddress"]
     if "hostname" in data.keys():
         graph_update["hostname"] = data['hostname']
     HostGraphApi().update(uuid, data=graph_update)
Beispiel #5
0
 def on_graph_create(self, uuid, data):
     graphData = {
         "uuid": uuid,
         "hostname": data.get("hostname"),
         "ipaddress": data.get("ipaddress")
     }
     return HostGraphApi().insert(graphData)
Beispiel #6
0
 def on_graph_delete(self, uuid):
     return HostGraphApi().delete(primary_key=uuid)
Beispiel #7
0
 def list(self, req, data, resp, **kwargs):
     re_type = data.pop("re_type", None)
     result = HostGraphApi().match_relation(re_type)
     return len(result), result
Beispiel #8
0
 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}
Beispiel #9
0
 def on_graph_delete(self, uuid):
     return HostGraphApi().delete(uuid)