diff --git a/code/scripts/main/api/v1/api.py b/code/scripts/main/api/v1/api.py index 2e245ec..98dbf13 100644 --- a/code/scripts/main/api/v1/api.py +++ b/code/scripts/main/api/v1/api.py @@ -82,9 +82,9 @@ class Cluster: def GET(self, cluster=None): try: if cluster: - result = core.get_cluster(cluster) + result = core.get_clusters_conf(cluster) else: - result = core.get_cluster() + result = core.get_clusters_conf() except BaseException as e: result = { "result": "ERROR", @@ -96,7 +96,7 @@ class Cluster: def POST(self): try: data = json.loads(web.data().decode('utf-8')) - result = core.insert_cluster(data) + result = core.insert_clusters_conf(data) except BaseException as e: result = { "result": "ERROR", @@ -108,7 +108,7 @@ class Cluster: def PUT(self, cluster): try: data = json.loads(web.data().decode('utf-8')) - result = core.change_cluster(cluster, data) + result = core.change_clusters_conf(cluster, data) except BaseException as e: result = { "result": "ERROR", @@ -119,7 +119,7 @@ class Cluster: def DELETE(self, cluster): try: - result = core.delete_cluste(cluster) + result = core.delete_clusters_conf(cluster) except BaseException as e: result = { "result": "ERROR", @@ -134,10 +134,10 @@ class Instance: try: if status: """ GET INSTANCE STATUS """ - result = core.status_instance(vmid, status) + result = core.status_instances(vmid, status) else: """ GET INSTANCE INFORMATION """ - result = core.info_instance(vmid) + result = core.info_instances(vmid) except BaseException as e: result = { "result": "ERROR", @@ -150,7 +150,7 @@ class Instance: try: if vmid: """ GET INSTANCE INFORMATION """ - result = core.status_instance(vmid, status) + result = core.status_instances(vmid, status) else: """ CREATE NEWS INSTANCES""" count = json.loads(web.data().decode('utf-8'))["count"] @@ -198,7 +198,7 @@ class Instance: def PUT(self, vmid): try: data = json.loads(web.data().decode('utf-8')) - result = core.change_instance(vmid, data) + result = core.change_instances(vmid, data) except BaseException as e: result = { "result": "ERROR", @@ -209,7 +209,7 @@ class Instance: def DELETE(self, vmid): try: - result = core.delete_instance(vmid) + result = core.delete_instances(vmid) except BaseException as e: result = { "result": "ERROR", diff --git a/code/scripts/main/core/core.py b/code/scripts/main/core/core.py index 79b9b10..acd228a 100644 --- a/code/scripts/main/core/core.py +++ b/code/scripts/main/core/core.py @@ -60,7 +60,7 @@ class Core: """ Clean previous lockers """ locker = Locker() - locker.unlock(generalconf["analyst"]["walker_lock"]) + locker.unlock(generalconf["analyst"]["walker_lock"], "startup") thc = threading.Thread(name="Update statistics", target=RunAnalyse, @@ -97,13 +97,13 @@ class Core: if cache is None: if dest == "instances": - resultmbrequest = self.mongo.get_instance(date, cluster, node, vmid) + resultmbrequest = self.mongo.get_instances(date, cluster, node, vmid) elif dest == "nodes": - resultmbrequest = self.mongo.get_node(date, cluster, node) + resultmbrequest = self.mongo.get_nodes(date, cluster, node) elif dest == "disks": - resultmbrequest = self.mongo.get_disk(date, cluster, node, vmid) + resultmbrequest = self.mongo.get_disks(date, cluster, node, vmid) elif dest == "storages": - resultmbrequest = self.mongo.get_storage(date, cluster, node) + resultmbrequest = self.mongo.get_storages(date, cluster, node) elif dest == "clusters": resultmbrequest = self.mongo.get_clusters(date, cluster) else: @@ -120,31 +120,31 @@ class Core: # INSTANCE MANAGEMENT # ####################### """ - def insert_instance(self, node, cluster, count=1, command_id=000000, instancetype="lxc"): + def insert_instances(self, node, cluster, count=1, command_id=000000, instancetype="lxc"): """ Find cluster informations from node """ lastkeyvalid = self.mongo.get_last_datekey() - node_informations = self.mongo.get_nodes_informations((int(lastkeyvalid["value"])), node, cluster) - cluster_informations = self.mongo.get_clusters_conf(cluster)["value"] + nodes_informations = self.mongo.get_nodes_informations((int(lastkeyvalid["value"])), node, cluster) + clusters_informations = self.mongo.get_clusters_conf(cluster)["value"] - proxmox_cluster_url = cluster_informations["url"] - proxmox_cluster_port = cluster_informations["port"] - proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), + proxmox_clusters_url = clusters_informations["url"] + proxmox_clusters_port = clusters_informations["port"] + proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') - proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]), + proxmox_clusters_pwd = pdecrypt(base64.b64decode(clusters_informations["password"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') - proxmox_template = cluster_informations["template"] - proxmox_storage_disk = cluster_informations["storage_disk"] + proxmox_template = clusters_informations["template"] + proxmox_storages_disk = clusters_informations["storages_disk"] """ LOAD PROXMOX """ proxmox = Proxmox(node) - proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - proxmox_cluster_user, - proxmox_cluster_pwd) + proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + proxmox_clusters_user, + proxmox_clusters_pwd) returnlistresult = [] currentcount = 0 @@ -158,15 +158,15 @@ class Core: get_info_system = self.mongo.get_system_info() """ FIND NEXT INSTANCE ID AVAILABLE AND INCREMENT IT""" - next_instance_id = int(get_info_system["instances_number"]+1) + next_instances_id = int(get_info_system["instances_number"]+1) """ TEST THIS ID """ """ FIND LAST LAST IP USE AND INCREMENT IT""" if not get_info_system["IP_free"]: - get_instance_ip = get_info_system["IP_current"] - next_ip = iter_iprange(get_instance_ip, '172.16.255.250', step=1) + get_instances_ip = get_info_system["IP_current"] + next_ip = iter_iprange(get_instances_ip, '172.16.255.250', step=1) # Revoir pour un truc plus clean .... next(next_ip) ip = str(next(next_ip)) @@ -178,8 +178,8 @@ class Core: """ INSTANCE DEFINITION """ data = { 'ostemplate': proxmox_template, - 'vmid': next_instance_id, - 'storage': proxmox_storage_disk, + 'vmid': next_instances_id, + 'storage': proxmox_storages_disk, 'cores': 1, 'cpulimit': 1, 'cpuunits': 512, @@ -194,34 +194,34 @@ class Core: } """ INSTANCE INSERTION """ - result_new = proxmox.create_instance("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), node, instancetype, + result_new = proxmox.create_instances("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), node, instancetype, data) """ Get first digest """ - digest_init = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - node, instancetype, next_instance_id)['value']['data']['digest'] + digest_init = proxmox.get_config("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + node, instancetype, next_instances_id)['value']['data']['digest'] """ VERIFY THE RESULT BY PROXMOX STATUS REQUEST CODE """ if result_new['result'] == "OK": """ INCREMENT INSTANCE ID IN DATABASE """ - self.mongo.update_system_instance_id(next_instance_id) + self.mongo.update_system_instances_id(next_instances_id) """ INCREMENT INSTANCE IP IN DATABASE """ - self.mongo.update_system_instance_ip(ip) + self.mongo.update_system_instances_ip(ip) """ INSERT THIS NEW SERVER IN DATABASE """ data["commandid"] = command_id - data["cluster"] = node_informations["cluster"] + data["cluster"] = nodes_informations["cluster"] data["node"] = target data["ip"] = ip data["date"] = lastkeyvalid["value"] - self.mongo.insert_instance(data) + self.mongo.insert_instances(data) """ Limit creation DDOS based on digest """ - while digest_init == proxmox.get_config("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - node, instancetype, next_instance_id)['value']['data']['digest']: + while digest_init == proxmox.get_config("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + node, instancetype, next_instances_id)['value']['data']['digest']: time.sleep(5) returnlistresult.append(result_new) @@ -231,36 +231,36 @@ class Core: return - def delete_instance(self, vmid, instancetype="lxc"): + def delete_instances(self, vmid, instancetype="lxc"): try: """ Find node/cluster informations from vmid """ - instance_informations = self.mongo.get_instance(vmid) + instances_informations = self.mongo.get_instances(vmid) """ Find cluster informations from node """ - cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"] + clusters_informations = self.mongo.get_clusters_conf(instances_informations['cluster'])["value"] - proxmox_cluster_url = cluster_informations["url"] - proxmox_cluster_port = cluster_informations["port"] - proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), + proxmox_clusters_url = clusters_informations["url"] + proxmox_clusters_port = clusters_informations["port"] + proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') - proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]), + proxmox_clusters_pwd = pdecrypt(base64.b64decode(clusters_informations["password"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') """ LOAD PROXMOX """ - proxmox = Proxmox(instance_informations['node']) - proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - proxmox_cluster_user, - proxmox_cluster_pwd) + proxmox = Proxmox(instances_informations['node']) + proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + proxmox_clusters_user, + proxmox_clusters_pwd) - result = proxmox.delete_instance("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - instance_informations['node'], instancetype, vmid) + result = proxmox.delete_instances("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + instances_informations['node'], instancetype, vmid) if result['result'] == "OK": - self.mongo.delete_instance(vmid) - self.mongo.update_system_free_ip(instance_informations['ip']) + self.mongo.delete_instances(vmid) + self.mongo.update_system_free_ip(instances_informations['ip']) except IndexError as ierror: result = { @@ -271,31 +271,31 @@ class Core: return result - def status_instance(self, vmid, action, instancetype="lxc"): + def status_instances(self, vmid, action, instancetype="lxc"): """ Find node/cluster informations from vmid """ try: - instance_informations = self.mongo.get_instance(vmid) + instances_informations = self.mongo.get_instances(vmid) """ Find cluster informations from node """ - cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"] + clusters_informations = self.mongo.get_clusters_conf(instances_informations['cluster'])["value"] - proxmox_cluster_url = cluster_informations["url"] - proxmox_cluster_port = cluster_informations["port"] - proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), + proxmox_clusters_url = clusters_informations["url"] + proxmox_clusters_port = clusters_informations["port"] + proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') - proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]), + proxmox_clusters_pwd = pdecrypt(base64.b64decode(clusters_informations["password"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') """ LOAD PROXMOX """ - proxmox = Proxmox(instance_informations['node']) - proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - proxmox_cluster_user, - proxmox_cluster_pwd) + proxmox = Proxmox(instances_informations['node']) + proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + proxmox_clusters_user, + proxmox_clusters_pwd) - result = proxmox.status_instance("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - instance_informations['node'], + result = proxmox.status_instances("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + instances_informations['node'], instancetype, vmid, action) @@ -308,31 +308,31 @@ class Core: return result - def info_instance(self, vmid, instancetype="lxc"): + def info_instances(self, vmid, instancetype="lxc"): """ Find node/cluster informations from vmid """ try: - instance_informations = self.mongo.get_instance(vmid) + instances_informations = self.mongo.get_instances(vmid) """ Find cluster informations from node """ - cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"] + clusters_informations = self.mongo.get_clusters_conf(instances_informations['cluster'])["value"] - proxmox_cluster_url = cluster_informations["url"] - proxmox_cluster_port = cluster_informations["port"] - proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), + proxmox_clusters_url = clusters_informations["url"] + proxmox_clusters_port = clusters_informations["port"] + proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') - proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]), + proxmox_clusters_pwd = pdecrypt(base64.b64decode(clusters_informations["password"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') """ LOAD PROXMOX """ - proxmox = Proxmox(instance_informations['node']) - proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - proxmox_cluster_user, - proxmox_cluster_pwd) + proxmox = Proxmox(instances_informations['node']) + proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + proxmox_clusters_user, + proxmox_clusters_pwd) - result = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - instance_informations['node'], + result = proxmox.get_config("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + instances_informations['node'], instancetype, vmid) @@ -345,37 +345,37 @@ class Core: return result - def change_instance(self, vmid, data, instancetype="lxc"): + def change_instances(self, vmid, data, instancetype="lxc"): """ Find node/cluster informations from vmid """ try: - instance_informations = self.mongo.get_instance(vmid) + instances_informations = self.mongo.get_instances(vmid) """ Find cluster informations from node """ - cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"] + clusters_informations = self.mongo.get_clusters_conf(instances_informations['cluster'])["value"] - proxmox_cluster_url = cluster_informations["url"] - proxmox_cluster_port = cluster_informations["port"] - proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), + proxmox_clusters_url = clusters_informations["url"] + proxmox_clusters_port = clusters_informations["port"] + proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') - proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]), + proxmox_clusters_pwd = pdecrypt(base64.b64decode(clusters_informations["password"]), self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') """ LOAD PROXMOX """ - proxmox = Proxmox(instance_informations['node']) - proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - proxmox_cluster_user, - proxmox_cluster_pwd) + proxmox = Proxmox(instances_informations['node']) + proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + proxmox_clusters_user, + proxmox_clusters_pwd) - result = proxmox.resize_instance("{0}:{1}".format(proxmox_cluster_url, - int(proxmox_cluster_port)), - instance_informations['node'], + result = proxmox.resize_instances("{0}:{1}".format(proxmox_clusters_url, + int(proxmox_clusters_port)), + instances_informations['node'], instancetype, vmid, data) if result['result'] == "OK": - self.mongo.update_instance(data, vmid) + self.mongo.update_instances(data, vmid) except IndexError as ierror: result = { @@ -392,13 +392,13 @@ class Core: ####################### """ - def get_cluster_conf(self, cluster=None): + def get_clusters_conf(self, cluster=None): """ Find cluster informations from node """ - cluster_informations = self.mongo.get_clusters_conf(cluster)["value"] - return cluster_informations + clusters_informations = self.mongo.get_clusters_conf(cluster)["value"] + return clusters_informations - def insert_cluster_conf(self, data): - testdata = valid_cluster_data(data) + def insert_clusters_conf(self, data): + testdata = valid_clusters_data(data) if not testdata: if not self.mongo.get_clusters_conf(data["name"])["value"]: @@ -420,15 +420,15 @@ class Core: return new_cluster - def change_cluster_conf(self, cluster, data): - cluster_update = self.mongo.update_cluster_conf(cluster, data) - return cluster_update + def change_clusters_conf(self, cluster, data): + clusters_update = self.mongo.update_clusters_conf(cluster, data) + return clusters_update - def delete_cluster_conf(self, cluster): + def delete_clusters_conf(self, cluster): """ Find cluster informations from node """ - cluster_delete = self.mongo.delete_cluster_conf(cluster) - return cluster_delete + clusters_delete = self.mongo.delete_clusters_conf(cluster) + return clusters_delete """ @@ -445,8 +445,8 @@ class Core: -def valid_cluster_data(data): - key_required = ["name", "url", "port", "user", "password", "template", "storage_disk", "weight", "exclude_nodes"] +def valid_clusters_data(data): + key_required = ["name", "url", "port", "user", "password", "template", "storages_disk", "weight", "exclude_nodes"] result = [] for key in key_required: if key not in data: diff --git a/code/scripts/main/core/modules/mod_analyst.py b/code/scripts/main/core/modules/mod_analyst.py index 4759b4b..80c3cf0 100644 --- a/code/scripts/main/core/modules/mod_analyst.py +++ b/code/scripts/main/core/modules/mod_analyst.py @@ -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 diff --git a/code/scripts/main/core/modules/mod_database.py b/code/scripts/main/core/modules/mod_database.py index 37e6d3b..a0787e8 100644 --- a/code/scripts/main/core/modules/mod_database.py +++ b/code/scripts/main/core/modules/mod_database.py @@ -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 = { diff --git a/code/scripts/main/core/modules/mod_proxmox.py b/code/scripts/main/core/modules/mod_proxmox.py index 92661f6..f6c261e 100644 --- a/code/scripts/main/core/modules/mod_proxmox.py +++ b/code/scripts/main/core/modules/mod_proxmox.py @@ -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: