mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
API update for mongoDB query
This commit is contained in:
parent
c6584dec25
commit
bd0ccfe48a
3 changed files with 42 additions and 18 deletions
|
@ -10,7 +10,6 @@
|
|||
from core.modules.mod_proxmox import *
|
||||
from core.modules.mod_database import *
|
||||
from core.modules.mod_analyst import *
|
||||
from core.modules.mod_crawler import *
|
||||
from core.modules.mod_access import *
|
||||
from core.libs.hcrypt import *
|
||||
from netaddr import iter_iprange
|
||||
|
@ -65,11 +64,10 @@ class Core:
|
|||
# GENERAL FUNCTIONS #
|
||||
#######################
|
||||
"""
|
||||
|
||||
def is_json(myjson):
|
||||
def is_json(selmyjson):
|
||||
try:
|
||||
json_object = json.loads(myjson)
|
||||
except ValueError, e:
|
||||
json.loads(myjson)
|
||||
except ValueError as e:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -79,7 +77,7 @@ class Core:
|
|||
else:
|
||||
return json_decode({"value": "Bad request"})
|
||||
|
||||
def generalquerycacheinfra(self, dest, date, cluster, node, vmid):
|
||||
def generalquerycacheinfra(self, dest, date, cluster=None, node=None, vmid=None):
|
||||
if dest == "instances":
|
||||
return self.mongo.get_instance(date, cluster, node, vmid)
|
||||
elif dest == "nodes":
|
||||
|
|
|
@ -208,20 +208,23 @@ class MongoDB:
|
|||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
def get_node(self, date, cluster, node, grata=None):
|
||||
def get_node(self, date, cluster, node, grata=0):
|
||||
try:
|
||||
if grata:
|
||||
if not cluster:
|
||||
return json.loads(
|
||||
dumps(self.db[self.collection_nodes].find_one(
|
||||
{'$and': [{'date': date, 'cluster': cluster, 'node': node, 'grata': 1}]})))
|
||||
dumps(self.db[self.collection_nodes].find(
|
||||
{'$and': [{'date': date, 'grata': str(grata)}]})))
|
||||
elif not node:
|
||||
return json.loads(
|
||||
dumps(self.db[self.collection_nodes].find(
|
||||
{'$and': [{'date': date, 'cluster': cluster, 'grata': str(grata)}]})))
|
||||
else:
|
||||
return json.loads(
|
||||
dumps(self.db[self.collection_nodes].find_one(
|
||||
{'$and': [{'date': date, 'cluster': cluster, 'node': node}]})))
|
||||
{'$and': [{'date': date, 'cluster': cluster, 'node': node, 'grata': str(grata)}]})))
|
||||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
|
||||
""" INSTANCE MANAGEMENT"""
|
||||
def insert_instance(self, data):
|
||||
try:
|
||||
|
@ -232,9 +235,22 @@ class MongoDB:
|
|||
# Revoir la multiplicite des instances/nodes
|
||||
def get_instance(self, date, cluster, node, vmid):
|
||||
try:
|
||||
return json.loads(dumps(
|
||||
if not cluster:
|
||||
return json.loads(dumps(
|
||||
self.db[self.collection_instance].find({"date": int(date)})))
|
||||
elif not node:
|
||||
return json.loads(dumps(
|
||||
self.db[self.collection_instance].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
||||
elif not vmid:
|
||||
return json.loads(dumps(
|
||||
self.db[self.collection_instance].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
|
||||
else:
|
||||
return json.loads(dumps(
|
||||
self.db[self.collection_instance].find_one(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})))
|
||||
|
||||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
|
|
|
@ -91,15 +91,25 @@ if __name__ == "__main__":
|
|||
|
||||
# CACHE DATA (MONGO)
|
||||
# date/cluster/node/vmid
|
||||
'/api/v1/static/(instances|nodes|clusters)/([0-9]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9]+)', 'QueryCache_Infra',
|
||||
'/api/v1/static/(instances)/([0-9]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9]+)', 'QueryCache_Infra',
|
||||
'/api/v1/static/(instances)/([0-9]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/', 'QueryCache_Infra',
|
||||
'/api/v1/static/(instances)/([0-9]+)/([0-9a-zA-Z]+)/', 'QueryCache_Infra',
|
||||
'/api/v1/static/(instances)/([0-9]+)/', 'QueryCache_Infra',
|
||||
|
||||
# date/cluster/node
|
||||
# '/api/v1/static/nodes/([0-9]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)', 'Static_Nodes',
|
||||
'/api/v1/static/(nodes)/([0-9]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)', 'QueryCache_Infra',
|
||||
'/api/v1/static/(nodes)/([0-9]+)/([0-9a-zA-Z]+)/', 'QueryCache_Infra',
|
||||
'/api/v1/static/(nodes)/([0-9]+)/', 'QueryCache_Infra',
|
||||
|
||||
# cluster
|
||||
# '/api/v1/static/clusters/([0-9]+)/([0-9a-zA-Z]+)', 'Static_Clusters',
|
||||
'/api/v1/static/(clusters)/([0-9]+)/(?:[0-9a-zA-Z]+)', 'QueryCache_Infra',
|
||||
'/api/v1/static/(clusters)/([0-9]+)/', 'QueryCache_Infra',
|
||||
|
||||
# date
|
||||
'/api/v1/static/dates', 'QueryCache_Dates',
|
||||
'/api/v1/static/dates/', 'QueryCache_Dates',
|
||||
|
||||
# mongoid
|
||||
'/api/v1/static/id/[a-z0-9]+', 'General_Search',
|
||||
'/api/v1/static/(instances|nodes|clusters)/id/[a-z0-9]+', 'General_Search',
|
||||
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue