1
0
Fork 0
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:
Tlams 2018-02-09 12:17:50 +00:00
parent 0eee74e730
commit 855b81dc65
5 changed files with 159 additions and 160 deletions

View file

@ -82,9 +82,9 @@ class Cluster:
def GET(self, cluster=None): def GET(self, cluster=None):
try: try:
if cluster: if cluster:
result = core.get_cluster(cluster) result = core.get_clusters_conf(cluster)
else: else:
result = core.get_cluster() result = core.get_clusters_conf()
except BaseException as e: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",
@ -96,7 +96,7 @@ class Cluster:
def POST(self): def POST(self):
try: try:
data = json.loads(web.data().decode('utf-8')) data = json.loads(web.data().decode('utf-8'))
result = core.insert_cluster(data) result = core.insert_clusters_conf(data)
except BaseException as e: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",
@ -108,7 +108,7 @@ class Cluster:
def PUT(self, cluster): def PUT(self, cluster):
try: try:
data = json.loads(web.data().decode('utf-8')) 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: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",
@ -119,7 +119,7 @@ class Cluster:
def DELETE(self, cluster): def DELETE(self, cluster):
try: try:
result = core.delete_cluste(cluster) result = core.delete_clusters_conf(cluster)
except BaseException as e: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",
@ -134,10 +134,10 @@ class Instance:
try: try:
if status: if status:
""" GET INSTANCE STATUS """ """ GET INSTANCE STATUS """
result = core.status_instance(vmid, status) result = core.status_instances(vmid, status)
else: else:
""" GET INSTANCE INFORMATION """ """ GET INSTANCE INFORMATION """
result = core.info_instance(vmid) result = core.info_instances(vmid)
except BaseException as e: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",
@ -150,7 +150,7 @@ class Instance:
try: try:
if vmid: if vmid:
""" GET INSTANCE INFORMATION """ """ GET INSTANCE INFORMATION """
result = core.status_instance(vmid, status) result = core.status_instances(vmid, status)
else: else:
""" CREATE NEWS INSTANCES""" """ CREATE NEWS INSTANCES"""
count = json.loads(web.data().decode('utf-8'))["count"] count = json.loads(web.data().decode('utf-8'))["count"]
@ -198,7 +198,7 @@ class Instance:
def PUT(self, vmid): def PUT(self, vmid):
try: try:
data = json.loads(web.data().decode('utf-8')) data = json.loads(web.data().decode('utf-8'))
result = core.change_instance(vmid, data) result = core.change_instances(vmid, data)
except BaseException as e: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",
@ -209,7 +209,7 @@ class Instance:
def DELETE(self, vmid): def DELETE(self, vmid):
try: try:
result = core.delete_instance(vmid) result = core.delete_instances(vmid)
except BaseException as e: except BaseException as e:
result = { result = {
"result": "ERROR", "result": "ERROR",

View file

@ -60,7 +60,7 @@ class Core:
""" Clean previous lockers """ """ Clean previous lockers """
locker = Locker() locker = Locker()
locker.unlock(generalconf["analyst"]["walker_lock"]) locker.unlock(generalconf["analyst"]["walker_lock"], "startup")
thc = threading.Thread(name="Update statistics", thc = threading.Thread(name="Update statistics",
target=RunAnalyse, target=RunAnalyse,
@ -97,13 +97,13 @@ class Core:
if cache is None: if cache is None:
if dest == "instances": if dest == "instances":
resultmbrequest = self.mongo.get_instance(date, cluster, node, vmid) resultmbrequest = self.mongo.get_instances(date, cluster, node, vmid)
elif dest == "nodes": elif dest == "nodes":
resultmbrequest = self.mongo.get_node(date, cluster, node) resultmbrequest = self.mongo.get_nodes(date, cluster, node)
elif dest == "disks": elif dest == "disks":
resultmbrequest = self.mongo.get_disk(date, cluster, node, vmid) resultmbrequest = self.mongo.get_disks(date, cluster, node, vmid)
elif dest == "storages": elif dest == "storages":
resultmbrequest = self.mongo.get_storage(date, cluster, node) resultmbrequest = self.mongo.get_storages(date, cluster, node)
elif dest == "clusters": elif dest == "clusters":
resultmbrequest = self.mongo.get_clusters(date, cluster) resultmbrequest = self.mongo.get_clusters(date, cluster)
else: else:
@ -120,31 +120,31 @@ class Core:
# INSTANCE MANAGEMENT # # 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 """ """ Find cluster informations from node """
lastkeyvalid = self.mongo.get_last_datekey() lastkeyvalid = self.mongo.get_last_datekey()
node_informations = self.mongo.get_nodes_informations((int(lastkeyvalid["value"])), node, cluster) nodes_informations = self.mongo.get_nodes_informations((int(lastkeyvalid["value"])), node, cluster)
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"] clusters_informations = self.mongo.get_clusters_conf(cluster)["value"]
proxmox_cluster_url = cluster_informations["url"] proxmox_clusters_url = clusters_informations["url"]
proxmox_cluster_port = cluster_informations["port"] proxmox_clusters_port = clusters_informations["port"]
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]),
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') 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') self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
proxmox_template = cluster_informations["template"] proxmox_template = clusters_informations["template"]
proxmox_storage_disk = cluster_informations["storage_disk"] proxmox_storages_disk = clusters_informations["storages_disk"]
""" LOAD PROXMOX """ """ LOAD PROXMOX """
proxmox = Proxmox(node) proxmox = Proxmox(node)
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
proxmox_cluster_user, proxmox_clusters_user,
proxmox_cluster_pwd) proxmox_clusters_pwd)
returnlistresult = [] returnlistresult = []
currentcount = 0 currentcount = 0
@ -158,15 +158,15 @@ class Core:
get_info_system = self.mongo.get_system_info() get_info_system = self.mongo.get_system_info()
""" FIND NEXT INSTANCE ID AVAILABLE AND INCREMENT IT""" """ 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 """ """ TEST THIS ID """
""" FIND LAST LAST IP USE AND INCREMENT IT""" """ FIND LAST LAST IP USE AND INCREMENT IT"""
if not get_info_system["IP_free"]: if not get_info_system["IP_free"]:
get_instance_ip = get_info_system["IP_current"] get_instances_ip = get_info_system["IP_current"]
next_ip = iter_iprange(get_instance_ip, '172.16.255.250', step=1) next_ip = iter_iprange(get_instances_ip, '172.16.255.250', step=1)
# Revoir pour un truc plus clean .... # Revoir pour un truc plus clean ....
next(next_ip) next(next_ip)
ip = str(next(next_ip)) ip = str(next(next_ip))
@ -178,8 +178,8 @@ class Core:
""" INSTANCE DEFINITION """ """ INSTANCE DEFINITION """
data = { data = {
'ostemplate': proxmox_template, 'ostemplate': proxmox_template,
'vmid': next_instance_id, 'vmid': next_instances_id,
'storage': proxmox_storage_disk, 'storage': proxmox_storages_disk,
'cores': 1, 'cores': 1,
'cpulimit': 1, 'cpulimit': 1,
'cpuunits': 512, 'cpuunits': 512,
@ -194,34 +194,34 @@ class Core:
} }
""" INSTANCE INSERTION """ """ INSTANCE INSERTION """
result_new = proxmox.create_instance("{0}:{1}".format(proxmox_cluster_url, result_new = proxmox.create_instances("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), node, instancetype, int(proxmox_clusters_port)), node, instancetype,
data) data)
""" Get first digest """ """ Get first digest """
digest_init = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url, digest_init = proxmox.get_config("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
node, instancetype, next_instance_id)['value']['data']['digest'] node, instancetype, next_instances_id)['value']['data']['digest']
""" VERIFY THE RESULT BY PROXMOX STATUS REQUEST CODE """ """ VERIFY THE RESULT BY PROXMOX STATUS REQUEST CODE """
if result_new['result'] == "OK": if result_new['result'] == "OK":
""" INCREMENT INSTANCE ID IN DATABASE """ """ 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 """ """ 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 """ """ INSERT THIS NEW SERVER IN DATABASE """
data["commandid"] = command_id data["commandid"] = command_id
data["cluster"] = node_informations["cluster"] data["cluster"] = nodes_informations["cluster"]
data["node"] = target data["node"] = target
data["ip"] = ip data["ip"] = ip
data["date"] = lastkeyvalid["value"] data["date"] = lastkeyvalid["value"]
self.mongo.insert_instance(data) self.mongo.insert_instances(data)
""" Limit creation DDOS based on digest """ """ Limit creation DDOS based on digest """
while digest_init == proxmox.get_config("{0}:{1}".format(proxmox_cluster_url, while digest_init == proxmox.get_config("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
node, instancetype, next_instance_id)['value']['data']['digest']: node, instancetype, next_instances_id)['value']['data']['digest']:
time.sleep(5) time.sleep(5)
returnlistresult.append(result_new) returnlistresult.append(result_new)
@ -231,36 +231,36 @@ class Core:
return return
def delete_instance(self, vmid, instancetype="lxc"): def delete_instances(self, vmid, instancetype="lxc"):
try: try:
""" Find node/cluster informations from vmid """ """ 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 """ """ 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_clusters_url = clusters_informations["url"]
proxmox_cluster_port = cluster_informations["port"] proxmox_clusters_port = clusters_informations["port"]
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]),
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') 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') self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
""" LOAD PROXMOX """ """ LOAD PROXMOX """
proxmox = Proxmox(instance_informations['node']) proxmox = Proxmox(instances_informations['node'])
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
proxmox_cluster_user, proxmox_clusters_user,
proxmox_cluster_pwd) proxmox_clusters_pwd)
result = proxmox.delete_instance("{0}:{1}".format(proxmox_cluster_url, result = proxmox.delete_instances("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
instance_informations['node'], instancetype, vmid) instances_informations['node'], instancetype, vmid)
if result['result'] == "OK": if result['result'] == "OK":
self.mongo.delete_instance(vmid) self.mongo.delete_instances(vmid)
self.mongo.update_system_free_ip(instance_informations['ip']) self.mongo.update_system_free_ip(instances_informations['ip'])
except IndexError as ierror: except IndexError as ierror:
result = { result = {
@ -271,31 +271,31 @@ class Core:
return result return result
def status_instance(self, vmid, action, instancetype="lxc"): def status_instances(self, vmid, action, instancetype="lxc"):
""" Find node/cluster informations from vmid """ """ Find node/cluster informations from vmid """
try: try:
instance_informations = self.mongo.get_instance(vmid) instances_informations = self.mongo.get_instances(vmid)
""" Find cluster informations from node """ """ 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_clusters_url = clusters_informations["url"]
proxmox_cluster_port = cluster_informations["port"] proxmox_clusters_port = clusters_informations["port"]
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]),
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') 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') self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
""" LOAD PROXMOX """ """ LOAD PROXMOX """
proxmox = Proxmox(instance_informations['node']) proxmox = Proxmox(instances_informations['node'])
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
proxmox_cluster_user, proxmox_clusters_user,
proxmox_cluster_pwd) proxmox_clusters_pwd)
result = proxmox.status_instance("{0}:{1}".format(proxmox_cluster_url, result = proxmox.status_instances("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
instance_informations['node'], instances_informations['node'],
instancetype, instancetype,
vmid, action) vmid, action)
@ -308,31 +308,31 @@ class Core:
return result return result
def info_instance(self, vmid, instancetype="lxc"): def info_instances(self, vmid, instancetype="lxc"):
""" Find node/cluster informations from vmid """ """ Find node/cluster informations from vmid """
try: try:
instance_informations = self.mongo.get_instance(vmid) instances_informations = self.mongo.get_instances(vmid)
""" Find cluster informations from node """ """ 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_clusters_url = clusters_informations["url"]
proxmox_cluster_port = cluster_informations["port"] proxmox_clusters_port = clusters_informations["port"]
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]),
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') 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') self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
""" LOAD PROXMOX """ """ LOAD PROXMOX """
proxmox = Proxmox(instance_informations['node']) proxmox = Proxmox(instances_informations['node'])
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
proxmox_cluster_user, proxmox_clusters_user,
proxmox_cluster_pwd) proxmox_clusters_pwd)
result = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url, result = proxmox.get_config("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
instance_informations['node'], instances_informations['node'],
instancetype, instancetype,
vmid) vmid)
@ -345,37 +345,37 @@ class Core:
return result return result
def change_instance(self, vmid, data, instancetype="lxc"): def change_instances(self, vmid, data, instancetype="lxc"):
""" Find node/cluster informations from vmid """ """ Find node/cluster informations from vmid """
try: try:
instance_informations = self.mongo.get_instance(vmid) instances_informations = self.mongo.get_instances(vmid)
""" Find cluster informations from node """ """ 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_clusters_url = clusters_informations["url"]
proxmox_cluster_port = cluster_informations["port"] proxmox_clusters_port = clusters_informations["port"]
proxmox_cluster_user = pdecrypt(base64.b64decode(cluster_informations["user"]), proxmox_clusters_user = pdecrypt(base64.b64decode(clusters_informations["user"]),
self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8') 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') self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
""" LOAD PROXMOX """ """ LOAD PROXMOX """
proxmox = Proxmox(instance_informations['node']) proxmox = Proxmox(instances_informations['node'])
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url, proxmox.get_ticket("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
proxmox_cluster_user, proxmox_clusters_user,
proxmox_cluster_pwd) proxmox_clusters_pwd)
result = proxmox.resize_instance("{0}:{1}".format(proxmox_cluster_url, result = proxmox.resize_instances("{0}:{1}".format(proxmox_clusters_url,
int(proxmox_cluster_port)), int(proxmox_clusters_port)),
instance_informations['node'], instances_informations['node'],
instancetype, instancetype,
vmid, data) vmid, data)
if result['result'] == "OK": if result['result'] == "OK":
self.mongo.update_instance(data, vmid) self.mongo.update_instances(data, vmid)
except IndexError as ierror: except IndexError as ierror:
result = { 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 """ """ Find cluster informations from node """
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"] clusters_informations = self.mongo.get_clusters_conf(cluster)["value"]
return cluster_informations return clusters_informations
def insert_cluster_conf(self, data): def insert_clusters_conf(self, data):
testdata = valid_cluster_data(data) testdata = valid_clusters_data(data)
if not testdata: if not testdata:
if not self.mongo.get_clusters_conf(data["name"])["value"]: if not self.mongo.get_clusters_conf(data["name"])["value"]:
@ -420,15 +420,15 @@ class Core:
return new_cluster return new_cluster
def change_cluster_conf(self, cluster, data): def change_clusters_conf(self, cluster, data):
cluster_update = self.mongo.update_cluster_conf(cluster, data) clusters_update = self.mongo.update_clusters_conf(cluster, data)
return cluster_update return clusters_update
def delete_cluster_conf(self, cluster): def delete_clusters_conf(self, cluster):
""" Find cluster informations from node """ """ Find cluster informations from node """
cluster_delete = self.mongo.delete_cluster_conf(cluster) clusters_delete = self.mongo.delete_clusters_conf(cluster)
return cluster_delete return clusters_delete
""" """
@ -445,8 +445,8 @@ class Core:
def valid_cluster_data(data): def valid_clusters_data(data):
key_required = ["name", "url", "port", "user", "password", "template", "storage_disk", "weight", "exclude_nodes"] key_required = ["name", "url", "port", "user", "password", "template", "storages_disk", "weight", "exclude_nodes"]
result = [] result = []
for key in key_required: for key in key_required:
if key not in data: if key not in data:

View file

@ -56,22 +56,22 @@ class Analyse:
""" Create lock file """ """ Create lock file """
locker = Locker() 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') self.mongo.insert_datekey(insert_time, 'running')
for cluster in self.clusters_conf: for cluster in self.clusters_conf:
""" Decode data """ """ 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') 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') self.generalconf["keys"]["key_pvt"])["data"].decode('utf-8')
""" AUTH """ """ AUTH """
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_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 = proxmox.get_clusters("{0}:{1}".format(cluster["url"], int(cluster["port"])))
clusters_status["date"] = int(insert_time) clusters_status["date"] = int(insert_time)
clusters_status["cluster"] = cluster["name"] clusters_status["cluster"] = cluster["name"]
self.mongo.insert_cluster(instance) self.mongo.insert_clusters(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"])))
@ -98,11 +98,11 @@ class Analyse:
types = ["lxc", "qemu"] # vz... types = ["lxc", "qemu"] # vz...
for type in types: for type in types:
list_instances.update( 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"]) value_nodes_list["node"], type)["value"])
else: else:
list_instances = \ 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"] value_nodes_list["node"], instancetype)["value"]
totalcpu = 0 totalcpu = 0
@ -123,7 +123,7 @@ class Analyse:
instance["cluster"] = cluster["name"] instance["cluster"] = cluster["name"]
instance["node"] = value_nodes_list["node"] instance["node"] = value_nodes_list["node"]
instance["date"] = int(insert_time) instance["date"] = int(insert_time)
self.mongo.insert_instance(instance) self.mongo.insert_instances(instance)
""" """
############# #############
@ -153,7 +153,7 @@ class Analyse:
else: else:
value_nodes_list["grata"] = 1 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["date"] = int(insert_time)
storage["cluster"] = cluster["name"] 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"])), disks_list = proxmox.get_storages("{0}:{1}".format(cluster["url"], int(cluster["port"])),
value_nodes_list["node"], storage["storage"]) value_nodes_list["node"], storage["storage"])
@ -176,7 +176,7 @@ class Analyse:
disk["node"] = value_nodes_list["node"] disk["node"] = value_nodes_list["node"]
disk["date"] = int(insert_time) disk["date"] = int(insert_time)
disk["cluster"] = cluster["name"] disk["cluster"] = cluster["name"]
self.mongo.insert_disk(disk) self.mongo.insert_disks(disk)
else: else:
print(nodes_list) print(nodes_list)
@ -184,7 +184,7 @@ class Analyse:
self.mongo.update_datekey(int(insert_time), "OK") self.mongo.update_datekey(int(insert_time), "OK")
""" Unlock file """ """ Unlock file """
locker.unlock(self.generalconf["analyst"]["walker_lock"]) locker.unlock(self.generalconf["analyst"]["walker_lock"], "alanyst")
return return

View file

@ -29,7 +29,7 @@ class Redis_wrapper:
conn = False conn = False
return conn 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) self.r.set(time.time(), logtext, expir)
def insert_logs(self, logtext, expir=86400*4): def insert_logs(self, logtext, expir=86400*4):
@ -51,7 +51,7 @@ class MongoDB:
self.server = server self.server = server
self.port = port self.port = port
self.collection_system = "system" self.collection_system = "system"
self.collection_instance = "instances" self.collection_instances = "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_clusters_conf = "clusters_conf"
@ -121,7 +121,6 @@ class MongoDB:
except BaseException as serr: except BaseException as serr:
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, 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:
@ -155,7 +154,7 @@ class MongoDB:
} }
return result return result
def update_cluster_conf(self, cluster, data): def update_clusters_conf(self, cluster, data):
try: try:
self.db[self.collection_clusters_conf].update({"vmid": str(cluster)}, {'$set': data}, upsert=False) self.db[self.collection_clusters_conf].update({"vmid": str(cluster)}, {'$set': data}, upsert=False)
result = { result = {
@ -169,7 +168,7 @@ class MongoDB:
} }
return result return result
def delete_cluster_conf(self, cluster): def delete_clusters_conf(self, cluster):
try: try:
self.db[self.collection_clusters_conf].remove({"cluster": str(cluster)}) self.db[self.collection_clusters_conf].remove({"cluster": str(cluster)})
result = { result = {
@ -187,10 +186,10 @@ class MongoDB:
def get_system_info(self): def get_system_info(self):
return self.db[self.collection_system].find_one({"_id": "0"}) 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}}) 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}}) self.db[self.collection_system].update({'_id': "0"}, {'$set': {'IP_current': value}})
def update_system_free_ip(self, value): def update_system_free_ip(self, value):
@ -213,13 +212,13 @@ class MongoDB:
return {"value": int(json.loads(dumps(last_id))[0]['date'])} return {"value": int(json.loads(dumps(last_id))[0]['date'])}
""" NODES MANAGEMENT""" """ NODES MANAGEMENT"""
def insert_node(self, data): def insert_nodes(self, data):
try: try:
return self.db[self.collection_nodes].insert(data) return self.db[self.collection_nodes].insert(data)
except BaseException as serr: except BaseException as serr:
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, 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: try:
if not cluster: if not cluster:
result = { result = {
@ -251,39 +250,39 @@ class MongoDB:
return result return result
""" INSTANCE MANAGEMENT""" """ INSTANCE MANAGEMENT"""
def insert_instance(self, data): def insert_instances(self, data):
try: try:
return self.db[self.collection_instance].insert(data) return self.db[self.collection_instances].insert(data)
except BaseException as serr: except BaseException as serr:
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, 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: try:
if not cluster: if not cluster:
result = { result = {
"result": "OK", "result": "OK",
"value": json.loads(dumps( "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: elif not node:
result = { result = {
"result": "OK", "result": "OK",
"value": json.loads(dumps( "value": json.loads(dumps(
self.db[self.collection_instance].find( self.db[self.collection_instances].find(
{'$and': [{"date": int(date), "cluster": cluster}]}))) {'$and': [{"date": int(date), "cluster": cluster}]})))
} }
elif not vmid: elif not vmid:
result = { result = {
"result": "OK", "result": "OK",
"value": json.loads(dumps( "value": json.loads(dumps(
self.db[self.collection_instance].find( self.db[self.collection_instances].find(
{'$and': [{"date": int(date), "cluster": cluster, "node": node}]}))) {'$and': [{"date": int(date), "cluster": cluster, "node": node}]})))
} }
else: else:
result = { result = {
"result": "OK", "result": "OK",
"value": json.loads(dumps( "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)}]}))) {'$and': [{"date": int(date), "cluster": cluster, "node": node, "vmid": int(vmid)}]})))
} }
@ -296,13 +295,13 @@ class MongoDB:
""" STORAGE MANAGEMENT""" """ STORAGE MANAGEMENT"""
def insert_storage(self, data): def insert_storages(self, data):
try: try:
return self.db[self.collection_storages].insert(data) return self.db[self.collection_storages].insert(data)
except BaseException as serr: except BaseException as serr:
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, 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: try:
if not cluster: if not cluster:
result = { result = {
@ -334,13 +333,13 @@ class MongoDB:
""" DISKS MANAGEMENT""" """ DISKS MANAGEMENT"""
def insert_disk(self, data): def insert_disks(self, data):
try: try:
return self.db[self.collection_disks].insert(data) return self.db[self.collection_disks].insert(data)
except BaseException as serr: except BaseException as serr:
raise ("MongoDB error on {0}:{1} ({2})".format(self.server, self.port, 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: try:
if not cluster: if not cluster:
result = { result = {

View file

@ -205,7 +205,7 @@ class Proxmox:
return result return result
def get_instance(self, url, nodename, category): def get_instances(self, url, nodename, category):
""" """
Get basic VMs informations from nodes Get basic VMs informations from nodes
:param url: Generic qemu url :param url: Generic qemu url
@ -241,7 +241,7 @@ class Proxmox:
return result return result
def get_config(self, url, nodename, category, instanceid): def get_configs(self, url, nodename, category, instanceid):
""" """
Get avanced VM information from nodes Get avanced VM information from nodes
:param url: Generic qemu config url :param url: Generic qemu config url
@ -275,7 +275,7 @@ class Proxmox:
return result return result
def create_instance(self, url, nodename, category, data): def create_instances(self, url, nodename, category, data):
""" """
:param url: :param url:
:param nodename: :param nodename:
@ -314,7 +314,7 @@ class Proxmox:
return result return result
def delete_instance(self, url, nodename, category, vmid): def delete_instances(self, url, nodename, category, vmid):
""" """
:param url: :param url:
:param nodename: :param nodename:
@ -354,7 +354,7 @@ class Proxmox:
return result return result
def status_instance(self, url, nodename, category, vmid, action): def status_instances(self, url, nodename, category, vmid, action):
""" """
:param url: :param url:
:param nodename: :param nodename:
@ -399,7 +399,7 @@ class Proxmox:
return result return result
def resize_instance(self, url, nodename, category, instanceid, data): def resize_instances(self, url, nodename, category, instanceid, data):
""" """
:param url: :param url:
:param nodename: :param nodename:
@ -440,7 +440,7 @@ class Proxmox:
return result return result
def stats_instance(self, url, nodename, category, instanceid): def stats_instances(self, url, nodename, category, instanceid):
""" """
:param url: :param url:
:param nodename: :param nodename: