mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-02-14 20:22:13 +00:00
Errors managment
This commit is contained in:
parent
bd0ccfe48a
commit
aab75535e1
1 changed files with 64 additions and 21 deletions
|
@ -109,6 +109,19 @@ class MongoDB:
|
|||
raise("MongoDB authentification error on {0}:{1} ({2})".format(self.server, self.port, e))
|
||||
|
||||
|
||||
def generalmongosearch(self, collection, id):
|
||||
try:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(self.db[collection].find({"_id": id})))
|
||||
}
|
||||
except BaseException as e:
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"value": "{0} {1}".format("Invalid request", e)
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
""" CLUSTER """
|
||||
def get_clusters_conf(self, cluster=None):
|
||||
|
@ -211,19 +224,33 @@ class MongoDB:
|
|||
def get_node(self, date, cluster, node, grata=0):
|
||||
try:
|
||||
if not cluster:
|
||||
return json.loads(
|
||||
dumps(self.db[self.collection_nodes].find(
|
||||
{'$and': [{'date': date, 'grata': str(grata)}]})))
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(
|
||||
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(
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": 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, 'grata': str(grata)}]})))
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(
|
||||
dumps(self.db[self.collection_nodes].find_one(
|
||||
{'$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))
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||
}
|
||||
return result
|
||||
|
||||
""" INSTANCE MANAGEMENT"""
|
||||
def insert_instance(self, data):
|
||||
|
@ -236,23 +263,39 @@ class MongoDB:
|
|||
def get_instance(self, date, cluster, node, vmid):
|
||||
try:
|
||||
if not cluster:
|
||||
return json.loads(dumps(
|
||||
self.db[self.collection_instance].find({"date": int(date)})))
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": 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}]})))
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": 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}]})))
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": 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)}]})))
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": 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))
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||
}
|
||||
return result
|
||||
|
||||
"""
|
||||
def update_instance(self, data, vmid, node=None, cluster=None):
|
||||
|
|
Loading…
Reference in a new issue