mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-02-13 03:32:16 +00:00
Clusters functions
This commit is contained in:
parent
dc65633f4d
commit
c6a7f3678d
3 changed files with 53 additions and 10 deletions
|
@ -105,7 +105,7 @@ class Core:
|
||||||
elif dest == "storages":
|
elif dest == "storages":
|
||||||
resultmbrequest = self.mongo.get_storage(date, cluster, node)
|
resultmbrequest = self.mongo.get_storage(date, cluster, node)
|
||||||
elif dest == "clusters":
|
elif dest == "clusters":
|
||||||
resultmbrequest = self.mongo.get_clusters_conf(date, cluster)
|
resultmbrequest = self.mongo.get_clusters(date, cluster)
|
||||||
else:
|
else:
|
||||||
resultmbrequest = json_decode({"value": "Bad request"})
|
resultmbrequest = json_decode({"value": "Bad request"})
|
||||||
|
|
||||||
|
@ -392,12 +392,12 @@ class Core:
|
||||||
#######################
|
#######################
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_cluster(self, cluster=None):
|
def get_cluster_conf(self, cluster=None):
|
||||||
""" Find cluster informations from node """
|
""" Find cluster informations from node """
|
||||||
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"]
|
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"]
|
||||||
return cluster_informations
|
return cluster_informations
|
||||||
|
|
||||||
def insert_cluster(self, data):
|
def insert_cluster_conf(self, data):
|
||||||
testdata = valid_cluster_data(data)
|
testdata = valid_cluster_data(data)
|
||||||
|
|
||||||
if not testdata:
|
if not testdata:
|
||||||
|
@ -420,12 +420,12 @@ class Core:
|
||||||
|
|
||||||
return new_cluster
|
return new_cluster
|
||||||
|
|
||||||
def change_cluster(self, cluster, data):
|
def change_cluster_conf(self, cluster, data):
|
||||||
cluster_update = self.mongo.update_cluster_conf(cluster, data)
|
cluster_update = self.mongo.update_cluster_conf(cluster, data)
|
||||||
return cluster_update
|
return cluster_update
|
||||||
|
|
||||||
|
|
||||||
def delete_cluster(self, cluster):
|
def delete_cluster_conf(self, cluster):
|
||||||
""" Find cluster informations from node """
|
""" Find cluster informations from node """
|
||||||
cluster_delete = self.mongo.delete_cluster_conf(cluster)
|
cluster_delete = self.mongo.delete_cluster_conf(cluster)
|
||||||
return cluster_delete
|
return cluster_delete
|
||||||
|
|
|
@ -73,9 +73,21 @@ class Analyse:
|
||||||
proxmox = Proxmox("Analyse")
|
proxmox = Proxmox("Analyse")
|
||||||
proxmox.get_ticket("{0}:{1}".format(cluster["url"], int(cluster["port"])), proxmox_cluster_user, proxmox_cluster_pwd)
|
proxmox.get_ticket("{0}:{1}".format(cluster["url"], int(cluster["port"])), proxmox_cluster_user, proxmox_cluster_pwd)
|
||||||
|
|
||||||
|
"""
|
||||||
|
##############
|
||||||
|
# CLUSTERS #
|
||||||
|
##############
|
||||||
|
"""
|
||||||
|
|
||||||
""" Get excluded nodes """
|
""" Get excluded nodes """
|
||||||
exclude_nodes = cluster["exclude_nodes"]
|
exclude_nodes = cluster["exclude_nodes"]
|
||||||
|
|
||||||
|
""" UPDATE CLUSTER STATUS """
|
||||||
|
clusters_status = proxmox.get_clusters("{0}:{1}".format(cluster["url"], int(cluster["port"])))
|
||||||
|
clusters_status["date"] = int(insert_time)
|
||||||
|
clusters_status["cluster"] = cluster["name"]
|
||||||
|
self.mongo.insert_cluster(instance)
|
||||||
|
|
||||||
""" UPDATE NODES LIST """
|
""" UPDATE NODES LIST """
|
||||||
nodes_list = proxmox.get_nodes("{0}:{1}".format(cluster["url"], int(cluster["port"])))
|
nodes_list = proxmox.get_nodes("{0}:{1}".format(cluster["url"], int(cluster["port"])))
|
||||||
if nodes_list["result"] == "OK":
|
if nodes_list["result"] == "OK":
|
||||||
|
|
|
@ -54,6 +54,7 @@ class MongoDB:
|
||||||
self.collection_instance = "instances"
|
self.collection_instance = "instances"
|
||||||
self.collection_nodes = "nodes"
|
self.collection_nodes = "nodes"
|
||||||
self.collection_clusters = "clusters"
|
self.collection_clusters = "clusters"
|
||||||
|
self.collection_clusters_conf = "clusters_conf"
|
||||||
self.collection_storages = "storages"
|
self.collection_storages = "storages"
|
||||||
self.collection_disks = "disks"
|
self.collection_disks = "disks"
|
||||||
self.collection_datekey = "dates"
|
self.collection_datekey = "dates"
|
||||||
|
@ -92,17 +93,47 @@ class MongoDB:
|
||||||
|
|
||||||
|
|
||||||
""" CLUSTER """
|
""" CLUSTER """
|
||||||
|
def get_clusters(self, date, cluster):
|
||||||
|
try:
|
||||||
|
if not cluster:
|
||||||
|
result = {
|
||||||
|
"result": "OK",
|
||||||
|
"value": json.loads(
|
||||||
|
dumps(self.db[self.collection_clusters].find({'date': date, 'grata': str(grata)})))
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
result = {
|
||||||
|
"result": "OK",
|
||||||
|
"value": json.loads(
|
||||||
|
dumps(self.db[self.collection_clusters].find_one(
|
||||||
|
{'$and': [{'date': date, 'cluster': cluster}]})))
|
||||||
|
}
|
||||||
|
|
||||||
|
except BaseException as serr:
|
||||||
|
result = {
|
||||||
|
"result": "ERROR",
|
||||||
|
"value": "MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
|
||||||
|
def insert_clusters(self, data):
|
||||||
|
try:
|
||||||
|
return self.db[self.collection_clusters].insert(data)
|
||||||
|
except BaseException as serr:
|
||||||
|
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||||
|
|
||||||
|
|
||||||
def get_clusters_conf(self, cluster=None):
|
def get_clusters_conf(self, cluster=None):
|
||||||
try:
|
try:
|
||||||
if cluster:
|
if cluster:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(self.db[self.collection_clusters].find_one({"name": cluster})))
|
"value": json.loads(dumps(self.db[self.collection_clusters_conf].find_one({"name": cluster})))
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": json.loads(dumps(self.db[self.collection_clusters].find({})))
|
"value": json.loads(dumps(self.db[self.collection_clusters_conf].find({})))
|
||||||
}
|
}
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
result = {
|
result = {
|
||||||
|
@ -113,7 +144,7 @@ class MongoDB:
|
||||||
|
|
||||||
def insert_clusters_conf(self, data):
|
def insert_clusters_conf(self, data):
|
||||||
try:
|
try:
|
||||||
self.db[self.collection_clusters].insert(data)
|
self.db[self.collection_clusters_conf].insert(data)
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": "{0} is now available".format(data["name"])
|
"value": "{0} is now available".format(data["name"])
|
||||||
|
@ -127,7 +158,7 @@ class MongoDB:
|
||||||
|
|
||||||
def update_cluster_conf(self, cluster, data):
|
def update_cluster_conf(self, cluster, data):
|
||||||
try:
|
try:
|
||||||
self.db[self.collection_clusters].update({"vmid": str(cluster)}, {'$set': data}, upsert=False)
|
self.db[self.collection_clusters_conf].update({"vmid": str(cluster)}, {'$set': data}, upsert=False)
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": "{0} has been updated".format(data["name"])
|
"value": "{0} has been updated".format(data["name"])
|
||||||
|
@ -141,7 +172,7 @@ class MongoDB:
|
||||||
|
|
||||||
def delete_cluster_conf(self, cluster):
|
def delete_cluster_conf(self, cluster):
|
||||||
try:
|
try:
|
||||||
self.db[self.collection_clusters].remove({"cluster": str(cluster)})
|
self.db[self.collection_clusters_conf].remove({"cluster": str(cluster)})
|
||||||
result = {
|
result = {
|
||||||
"result": "OK",
|
"result": "OK",
|
||||||
"value": "{0} has been deleted".format(cluster)
|
"value": "{0} has been deleted".format(cluster)
|
||||||
|
|
Loading…
Reference in a new issue