mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
Massive syntax fix
This commit is contained in:
parent
0eee74e730
commit
855b81dc65
5 changed files with 159 additions and 160 deletions
|
@ -56,22 +56,22 @@ class Analyse:
|
|||
|
||||
""" Create lock file """
|
||||
locker = Locker()
|
||||
locker.createlock(self.generalconf["analyst"]["walker_lock"], insert_time)
|
||||
locker.createlock(self.generalconf["analyst"]["walker_lock"], "analyst", insert_time)
|
||||
|
||||
self.mongo.insert_datekey(insert_time, 'running')
|
||||
|
||||
for cluster in self.clusters_conf:
|
||||
""" Decode data """
|
||||
|
||||
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster["user"]),
|
||||
proxmox_clusters_user = pdecrypt(base64.b64decode(cluster["user"]),
|
||||
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
|
||||
|
||||
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster["password"]),
|
||||
proxmox_clusters_pwd = pdecrypt(base64.b64decode(cluster["password"]),
|
||||
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
|
||||
|
||||
""" AUTH """
|
||||
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_clusters_user, proxmox_clusters_pwd)
|
||||
|
||||
"""
|
||||
##############
|
||||
|
@ -86,7 +86,7 @@ class Analyse:
|
|||
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)
|
||||
self.mongo.insert_clusters(instance)
|
||||
|
||||
""" UPDATE NODES LIST """
|
||||
nodes_list = proxmox.get_nodes("{0}:{1}".format(cluster["url"], int(cluster["port"])))
|
||||
|
@ -98,11 +98,11 @@ class Analyse:
|
|||
types = ["lxc", "qemu"] # vz...
|
||||
for type in types:
|
||||
list_instances.update(
|
||||
proxmox.get_instance("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
proxmox.get_instances("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"], type)["value"])
|
||||
else:
|
||||
list_instances = \
|
||||
proxmox.get_instance("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
proxmox.get_instances("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"], instancetype)["value"]
|
||||
|
||||
totalcpu = 0
|
||||
|
@ -123,7 +123,7 @@ class Analyse:
|
|||
instance["cluster"] = cluster["name"]
|
||||
instance["node"] = value_nodes_list["node"]
|
||||
instance["date"] = int(insert_time)
|
||||
self.mongo.insert_instance(instance)
|
||||
self.mongo.insert_instances(instance)
|
||||
|
||||
"""
|
||||
#############
|
||||
|
@ -153,7 +153,7 @@ class Analyse:
|
|||
else:
|
||||
value_nodes_list["grata"] = 1
|
||||
|
||||
self.mongo.insert_node(value_nodes_list)
|
||||
self.mongo.insert_nodes(value_nodes_list)
|
||||
|
||||
"""
|
||||
#############
|
||||
|
@ -167,7 +167,7 @@ class Analyse:
|
|||
storage["date"] = int(insert_time)
|
||||
storage["cluster"] = cluster["name"]
|
||||
|
||||
self.mongo.insert_storage(storage)
|
||||
self.mongo.insert_storages(storage)
|
||||
disks_list = proxmox.get_storages("{0}:{1}".format(cluster["url"], int(cluster["port"])),
|
||||
value_nodes_list["node"], storage["storage"])
|
||||
|
||||
|
@ -176,7 +176,7 @@ class Analyse:
|
|||
disk["node"] = value_nodes_list["node"]
|
||||
disk["date"] = int(insert_time)
|
||||
disk["cluster"] = cluster["name"]
|
||||
self.mongo.insert_disk(disk)
|
||||
self.mongo.insert_disks(disk)
|
||||
|
||||
else:
|
||||
print(nodes_list)
|
||||
|
@ -184,7 +184,7 @@ class Analyse:
|
|||
self.mongo.update_datekey(int(insert_time), "OK")
|
||||
|
||||
""" Unlock file """
|
||||
locker.unlock(self.generalconf["analyst"]["walker_lock"])
|
||||
locker.unlock(self.generalconf["analyst"]["walker_lock"], "alanyst")
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class Redis_wrapper:
|
|||
conn = False
|
||||
return conn
|
||||
|
||||
def insert_instance_queue(self, logtext, expir=3000):
|
||||
def insert_instances_queue(self, logtext, expir=3000):
|
||||
self.r.set(time.time(), logtext, expir)
|
||||
|
||||
def insert_logs(self, logtext, expir=86400*4):
|
||||
|
@ -51,7 +51,7 @@ class MongoDB:
|
|||
self.server = server
|
||||
self.port = port
|
||||
self.collection_system = "system"
|
||||
self.collection_instance = "instances"
|
||||
self.collection_instances = "instances"
|
||||
self.collection_nodes = "nodes"
|
||||
self.collection_clusters = "clusters"
|
||||
self.collection_clusters_conf = "clusters_conf"
|
||||
|
@ -121,7 +121,6 @@ class MongoDB:
|
|||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
|
||||
def get_clusters_conf(self, cluster=None):
|
||||
try:
|
||||
if cluster:
|
||||
|
@ -155,7 +154,7 @@ class MongoDB:
|
|||
}
|
||||
return result
|
||||
|
||||
def update_cluster_conf(self, cluster, data):
|
||||
def update_clusters_conf(self, cluster, data):
|
||||
try:
|
||||
self.db[self.collection_clusters_conf].update({"vmid": str(cluster)}, {'$set': data}, upsert=False)
|
||||
result = {
|
||||
|
@ -169,7 +168,7 @@ class MongoDB:
|
|||
}
|
||||
return result
|
||||
|
||||
def delete_cluster_conf(self, cluster):
|
||||
def delete_clusters_conf(self, cluster):
|
||||
try:
|
||||
self.db[self.collection_clusters_conf].remove({"cluster": str(cluster)})
|
||||
result = {
|
||||
|
@ -187,10 +186,10 @@ class MongoDB:
|
|||
def get_system_info(self):
|
||||
return self.db[self.collection_system].find_one({"_id": "0"})
|
||||
|
||||
def update_system_instance_id(self, value):
|
||||
def update_system_instances_id(self, value):
|
||||
self.db[self.collection_system].update({'_id': "0"}, {'$set': {'instances_number': value}})
|
||||
|
||||
def update_system_instance_ip(self, value):
|
||||
def update_system_instances_ip(self, value):
|
||||
self.db[self.collection_system].update({'_id': "0"}, {'$set': {'IP_current': value}})
|
||||
|
||||
def update_system_free_ip(self, value):
|
||||
|
@ -213,13 +212,13 @@ class MongoDB:
|
|||
return {"value": int(json.loads(dumps(last_id))[0]['date'])}
|
||||
|
||||
""" NODES MANAGEMENT"""
|
||||
def insert_node(self, data):
|
||||
def insert_nodes(self, data):
|
||||
try:
|
||||
return self.db[self.collection_nodes].insert(data)
|
||||
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=0):
|
||||
def get_nodes(self, date, cluster, node, grata=0):
|
||||
try:
|
||||
if not cluster:
|
||||
result = {
|
||||
|
@ -251,39 +250,39 @@ class MongoDB:
|
|||
return result
|
||||
|
||||
""" INSTANCE MANAGEMENT"""
|
||||
def insert_instance(self, data):
|
||||
def insert_instances(self, data):
|
||||
try:
|
||||
return self.db[self.collection_instance].insert(data)
|
||||
return self.db[self.collection_instances].insert(data)
|
||||
except BaseException as serr:
|
||||
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, serr))
|
||||
|
||||
def get_instance(self, date, cluster, node, vmid):
|
||||
def get_instances(self, date, cluster, node, vmid):
|
||||
try:
|
||||
if not cluster:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_instance].find({"date": int(date)})))
|
||||
self.db[self.collection_instances].find({"date": int(date)})))
|
||||
}
|
||||
elif not node:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_instance].find(
|
||||
self.db[self.collection_instances].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster}]})))
|
||||
}
|
||||
elif not vmid:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_instance].find(
|
||||
self.db[self.collection_instances].find(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
|
||||
}
|
||||
else:
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": json.loads(dumps(
|
||||
self.db[self.collection_instance].find_one(
|
||||
self.db[self.collection_instances].find_one(
|
||||
{'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})))
|
||||
}
|
||||
|
||||
|
@ -296,13 +295,13 @@ class MongoDB:
|
|||
|
||||
|
||||
""" STORAGE MANAGEMENT"""
|
||||
def insert_storage(self, data):
|
||||
def insert_storages(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):
|
||||
def get_storages(self, date, cluster, node):
|
||||
try:
|
||||
if not cluster:
|
||||
result = {
|
||||
|
@ -334,13 +333,13 @@ class MongoDB:
|
|||
|
||||
|
||||
""" DISKS MANAGEMENT"""
|
||||
def insert_disk(self, data):
|
||||
def insert_disks(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):
|
||||
def get_disks(self, date, cluster, node, vmid):
|
||||
try:
|
||||
if not cluster:
|
||||
result = {
|
||||
|
|
|
@ -205,7 +205,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def get_instance(self, url, nodename, category):
|
||||
def get_instances(self, url, nodename, category):
|
||||
"""
|
||||
Get basic VMs informations from nodes
|
||||
:param url: Generic qemu url
|
||||
|
@ -241,7 +241,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def get_config(self, url, nodename, category, instanceid):
|
||||
def get_configs(self, url, nodename, category, instanceid):
|
||||
"""
|
||||
Get avanced VM information from nodes
|
||||
:param url: Generic qemu config url
|
||||
|
@ -275,7 +275,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def create_instance(self, url, nodename, category, data):
|
||||
def create_instances(self, url, nodename, category, data):
|
||||
"""
|
||||
:param url:
|
||||
:param nodename:
|
||||
|
@ -314,7 +314,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def delete_instance(self, url, nodename, category, vmid):
|
||||
def delete_instances(self, url, nodename, category, vmid):
|
||||
"""
|
||||
:param url:
|
||||
:param nodename:
|
||||
|
@ -354,7 +354,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def status_instance(self, url, nodename, category, vmid, action):
|
||||
def status_instances(self, url, nodename, category, vmid, action):
|
||||
"""
|
||||
:param url:
|
||||
:param nodename:
|
||||
|
@ -399,7 +399,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def resize_instance(self, url, nodename, category, instanceid, data):
|
||||
def resize_instances(self, url, nodename, category, instanceid, data):
|
||||
"""
|
||||
:param url:
|
||||
:param nodename:
|
||||
|
@ -440,7 +440,7 @@ class Proxmox:
|
|||
|
||||
return result
|
||||
|
||||
def stats_instance(self, url, nodename, category, instanceid):
|
||||
def stats_instances(self, url, nodename, category, instanceid):
|
||||
"""
|
||||
:param url:
|
||||
:param nodename:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue