mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
MongoIndex
This commit is contained in:
parent
22479eeded
commit
199a72b4e4
2 changed files with 73 additions and 16 deletions
|
@ -17,6 +17,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import pymongo
|
||||||
|
|
||||||
def RunAnalyse(generalconf, logger):
|
def RunAnalyse(generalconf, logger):
|
||||||
play = Analyse(generalconf, logger)
|
play = Analyse(generalconf, logger)
|
||||||
|
@ -56,6 +57,9 @@ class Core:
|
||||||
if self.mongo.client and self.redis_msg.connect() and self.redis_cache.connect():
|
if self.mongo.client and self.redis_msg.connect() and self.redis_cache.connect():
|
||||||
self.mongo.db = self.mongo.client.db
|
self.mongo.db = self.mongo.client.db
|
||||||
|
|
||||||
|
""" Create indexes"""
|
||||||
|
self.setupindexes()
|
||||||
|
|
||||||
""" Others """
|
""" Others """
|
||||||
# value
|
# value
|
||||||
self.concurrencydeploy = generalconf["deploy"]["concurrencydeploy"]
|
self.concurrencydeploy = generalconf["deploy"]["concurrencydeploy"]
|
||||||
|
@ -528,6 +532,30 @@ class Core:
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def setupindexes(self):
|
||||||
|
self.mongo.set_indexes("disks",
|
||||||
|
[('date', pymongo.ASCENDING), ("cluster", pymongo.ASCENDING),
|
||||||
|
("node", pymongo.ASCENDING), ("vmid", pymongo.ASCENDING)])
|
||||||
|
self.mongo.set_indexes("storages",
|
||||||
|
[('date', pymongo.ASCENDING), ("cluster", pymongo.ASCENDING), ("node", pymongo.ASCENDING)])
|
||||||
|
self.mongo.set_indexes("instances",
|
||||||
|
[('date', pymongo.ASCENDING), ("cluster", pymongo.ASCENDING),
|
||||||
|
("node", pymongo.ASCENDING), ("vmid", pymongo.ASCENDING)])
|
||||||
|
self.mongo.set_indexes("nodes",
|
||||||
|
[('date', pymongo.ASCENDING), ("cluster", pymongo.ASCENDING), ("node", pymongo.ASCENDING)])
|
||||||
|
self.mongo.set_indexes("clusters",
|
||||||
|
[('date', pymongo.ASCENDING), ("cluster", pymongo.ASCENDING)])
|
||||||
|
self.mongo.set_indexes("cluster_conf", [('name', pymongo.ASCENDING)])
|
||||||
|
|
||||||
|
indexes_result = {
|
||||||
|
"value": "{0}".format("All indexes created"),
|
||||||
|
"result": "OK",
|
||||||
|
"type": "HYPERPROXMOX"
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexes_result
|
||||||
|
|
||||||
"""
|
"""
|
||||||
#######################
|
#######################
|
||||||
# STORAGES MANAGEMENT #
|
# STORAGES MANAGEMENT #
|
||||||
|
|
|
@ -75,6 +75,8 @@ class MongoDB:
|
||||||
collection = self.collection_instances
|
collection = self.collection_instances
|
||||||
elif col == "nodes":
|
elif col == "nodes":
|
||||||
collection = self.collection_nodes
|
collection = self.collection_nodes
|
||||||
|
elif col == "clusters_conf":
|
||||||
|
collection = self.collection_clusters_conf
|
||||||
elif col == "disks":
|
elif col == "disks":
|
||||||
collection = self.collection_disks
|
collection = self.collection_disks
|
||||||
elif col == "storages":
|
elif col == "storages":
|
||||||
|
@ -145,14 +147,14 @@ class MongoDB:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(
|
"value": json.loads(
|
||||||
dumps(self.db[self.collection_clusters].find({'date': int(date)})))
|
dumps(self.db[self.collection_clusters].find({'date': int(date)}).hint(self.collection_clusters)))
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(
|
"value": json.loads(
|
||||||
dumps(self.db[self.collection_clusters].find(
|
dumps(self.db[self.collection_clusters].find(
|
||||||
{'$and': [{'date': int(date), 'cluster': cluster}]})))
|
{'$and': [{'date': int(date), 'cluster': cluster}]}).hint(self.collection_clusters)))
|
||||||
}
|
}
|
||||||
|
|
||||||
except BaseException as serr:
|
except BaseException as serr:
|
||||||
|
@ -299,7 +301,7 @@ class MongoDB:
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(
|
"value": json.loads(
|
||||||
dumps(self.db[self.collection_nodes].find(
|
dumps(self.db[self.collection_nodes].find(
|
||||||
{'date': int(date)})))
|
{'date': int(date)}).hint(self.collection_nodes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
elif not node:
|
elif not node:
|
||||||
|
@ -307,14 +309,16 @@ class MongoDB:
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(
|
"value": json.loads(
|
||||||
dumps(self.db[self.collection_nodes].find(
|
dumps(self.db[self.collection_nodes].find(
|
||||||
{'$and': [{'date': int(date), 'cluster': cluster}]})))
|
{'$and': [{'date': int(date), 'cluster': cluster}]})
|
||||||
|
.hint(self.collection_nodes)))
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(
|
"value": json.loads(
|
||||||
dumps(self.db[self.collection_nodes].find(
|
dumps(self.db[self.collection_nodes].find(
|
||||||
{'$and': [{'date': int(date), 'cluster': cluster, 'node': node}]})))
|
{'$and': [{'date': int(date), 'cluster': cluster, 'node': node}]})
|
||||||
|
.hint(self.collection_nodes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
except BaseException as serr:
|
except BaseException as serr:
|
||||||
|
@ -346,28 +350,33 @@ class MongoDB:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_instances].find({"date": int(date)})))
|
self.db[self.collection_instances].find({"date": int(date)})
|
||||||
|
.hint(self.collection_instances)))
|
||||||
}
|
}
|
||||||
elif not node:
|
elif not node:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_instances].find(
|
self.db[self.collection_instances].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
{'$and': [{"date": int(date), "cluster": cluster}]})
|
||||||
|
.hint(self.collection_instances)))
|
||||||
}
|
}
|
||||||
elif not vmid:
|
elif not vmid:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_instances].find(
|
self.db[self.collection_instances].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
|
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})
|
||||||
|
.hint(self.collection_instances)))
|
||||||
|
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_instances].find(
|
self.db[self.collection_instances].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})))
|
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})
|
||||||
|
.hint(self.collection_instances)))
|
||||||
}
|
}
|
||||||
|
|
||||||
except BaseException as serr:
|
except BaseException as serr:
|
||||||
|
@ -400,21 +409,24 @@ class MongoDB:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_storages].find({"date": int(date)})))
|
self.db[self.collection_storages].find({"date": int(date)})
|
||||||
|
.hint(self.collection_storages)))
|
||||||
}
|
}
|
||||||
elif not node:
|
elif not node:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_storages].find(
|
self.db[self.collection_storages].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
{'$and': [{"date": int(date), "cluster": cluster}]})
|
||||||
|
.hint(self.collection_storages)))
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_storages].find(
|
self.db[self.collection_storages].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
|
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})
|
||||||
|
.hint(self.collection_storages)))
|
||||||
}
|
}
|
||||||
except BaseException as serr:
|
except BaseException as serr:
|
||||||
result = {
|
result = {
|
||||||
|
@ -447,28 +459,32 @@ class MongoDB:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_disks].find({"date": int(date)})))
|
self.db[self.collection_disks].find({"date": int(date)})
|
||||||
|
.hint(self.collection_disks)))
|
||||||
}
|
}
|
||||||
elif not node:
|
elif not node:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_disks].find(
|
self.db[self.collection_disks].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
{'$and': [{"date": int(date), "cluster": cluster}]})
|
||||||
|
.hint(self.collection_disks)))
|
||||||
}
|
}
|
||||||
elif not vmid:
|
elif not vmid:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_disks].find(
|
self.db[self.collection_disks].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
|
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})
|
||||||
|
.hint(self.collection_disks)))
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(
|
"value": json.loads(dumps(
|
||||||
self.db[self.collection_disks].find(
|
self.db[self.collection_disks].find(
|
||||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": str(vmid)}]})))
|
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": str(vmid)}]})
|
||||||
|
.hint(self.collection_disks)))
|
||||||
}
|
}
|
||||||
|
|
||||||
except BaseException as serr:
|
except BaseException as serr:
|
||||||
|
@ -478,3 +494,16 @@ class MongoDB:
|
||||||
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def set_indexes(self, col, list):
|
||||||
|
try:
|
||||||
|
# Add here a test if exist, pass
|
||||||
|
result = self.db[self.__mappingcol(col)].create_index(list, background=True, name=col)
|
||||||
|
except BaseException as serr:
|
||||||
|
result = {
|
||||||
|
"result": "ERROR",
|
||||||
|
"type": "MongoDB - Set Indexes",
|
||||||
|
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||||
|
}
|
||||||
|
return result
|
Loading…
Add table
Add a link
Reference in a new issue