mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
disks and storages
This commit is contained in:
parent
4075c24e58
commit
c269bad3c3
2 changed files with 123 additions and 12 deletions
|
@ -95,6 +95,12 @@ class Analyse:
|
|||
|
||||
totalcpu = 0
|
||||
totalram = 0
|
||||
|
||||
"""
|
||||
#############
|
||||
# INSTANCES #
|
||||
#############
|
||||
"""
|
||||
for key_list_instances, value_list_instances in list_instances.items():
|
||||
for instances in value_list_instances:
|
||||
""" Update cpu and ram for node """
|
||||
|
@ -106,18 +112,12 @@ class Analyse:
|
|||
instance["node"] = value_nodes_list["node"]
|
||||
instance["date"] = int(insert_time)
|
||||
self.mongo.insert_instance(instance)
|
||||
"""
|
||||
# Test si l'instance existe
|
||||
if not self.mongo.get_instance(instance["vmid"], instance["node"], instance["cluster"]):
|
||||
# si non existante, alors il s'agit d'une instance manuelle
|
||||
instance["commandid"] = "000000"
|
||||
self.mongo.insert_instance(instance)
|
||||
|
||||
# Si elle existe deja, on l'update:
|
||||
else:
|
||||
self.mongo.update_instance(instance, instance["vmid"], instance["node"], instance["cluster"])
|
||||
"""
|
||||
|
||||
"""
|
||||
#############
|
||||
# NODES #
|
||||
#############
|
||||
"""
|
||||
value_nodes_list["totalalloccpu"] = totalcpu
|
||||
value_nodes_list["totalallocram"] = totalram
|
||||
value_nodes_list["vmcount"] = len(list_instances.items())
|
||||
|
@ -143,6 +143,34 @@ class Analyse:
|
|||
|
||||
self.mongo.insert_node(value_nodes_list)
|
||||
|
||||
"""
|
||||
#############
|
||||
# STORAGES #
|
||||
#############
|
||||
"""
|
||||
storages_list = proxmox.get_storages("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"])
|
||||
for storage in storages_list:
|
||||
storage["node"] = value_nodes_list["node"]
|
||||
storage["date"] = int(insert_time)
|
||||
storage["cluster"] = cluster["name"]
|
||||
|
||||
self.mongo.insert_storage(storage)
|
||||
disks_list = proxmox.get_storages("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"], storage["storage"])
|
||||
|
||||
for disk in disks_list:
|
||||
disk["storage"] = storage["storage"]
|
||||
disk["node"] = value_nodes_list["node"]
|
||||
disk["date"] = int(insert_time)
|
||||
disk["cluster"] = cluster["name"]
|
||||
self.mongo.insert_disk(disk)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else:
|
||||
print(nodes_list)
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ class MongoDB:
|
|||
self.collection_nodes = "nodes"
|
||||
self.collection_clusters = "clusters"
|
||||
self.collection_storages = "storages"
|
||||
self.collection_disks = "disks"
|
||||
self.collection_datekey = "dates"
|
||||
self.port = port
|
||||
self.db = None
|
||||
|
@ -226,7 +227,6 @@ class MongoDB:
|
|||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
# Revoir la multiplicite des instances/nodes
|
||||
def get_instance(self, date, cluster, node, vmid):
|
||||
try:
|
||||
if not cluster:
|
||||
|
@ -263,3 +263,86 @@ class MongoDB:
|
|||
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
""" STORAGE MANAGEMENT"""
|
||||
def insert_storage(self, data):
|
||||
try:
|
||||
return self.db[self.collection_storages].insert(data)
|
||||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
def get_storage(self, date, cluster, node):
|
||||
try:
|
||||
if not cluster:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find({"date": int(date)})))
|
||||
}
|
||||
elif not node:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
||||
}
|
||||
else:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find_one(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})))
|
||||
}
|
||||
except BaseException as serr:
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
|
||||
""" DISKS MANAGEMENT"""
|
||||
def insert_disk(self, data):
|
||||
try:
|
||||
return self.db[self.collection_disks].insert(data)
|
||||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
def get_disk(self, date, cluster, node, vmid):
|
||||
try:
|
||||
if not cluster:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find({"date": int(date)})))
|
||||
}
|
||||
elif not node:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
||||
}
|
||||
elif not vmid:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
|
||||
}
|
||||
else:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_disks].find_one(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})))
|
||||
}
|
||||
|
||||
except BaseException as serr:
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"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