mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
Fix duplicate vmid issue
This commit is contained in:
parent
e82ef279db
commit
1c91761921
3 changed files with 30 additions and 30 deletions
|
@ -173,14 +173,14 @@ class Core:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def delete_instance(self, vmid, instancetype="lxc"):
|
def delete_instance(self, vmid, node, cluster, instancetype="lxc"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
""" Find node/cluster informations from vmid """
|
""" Find node/cluster informations from vmid """
|
||||||
instance_informations = self.mongo.get_instance(vmid)
|
# instance_informations = self.mongo.get_instance(vmid, node, cluster)
|
||||||
|
|
||||||
""" Find cluster informations from node """
|
""" Find cluster informations from node """
|
||||||
cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"]
|
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"]
|
||||||
|
|
||||||
proxmox_cluster_url = cluster_informations["url"]
|
proxmox_cluster_url = cluster_informations["url"]
|
||||||
proxmox_cluster_port = cluster_informations["port"]
|
proxmox_cluster_port = cluster_informations["port"]
|
||||||
|
@ -190,7 +190,7 @@ class Core:
|
||||||
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]),
|
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_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(node)
|
||||||
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
proxmox_cluster_user,
|
proxmox_cluster_user,
|
||||||
|
@ -198,10 +198,10 @@ class Core:
|
||||||
|
|
||||||
result = proxmox.delete_instance("{0}:{1}".format(proxmox_cluster_url,
|
result = proxmox.delete_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
instance_informations['node'], instancetype, vmid)
|
node, instancetype, vmid)
|
||||||
|
|
||||||
if result['result'] == "OK":
|
if result['result'] == "OK":
|
||||||
self.mongo.delete_instance(vmid)
|
self.mongo.delete_instance(vmid, node, cluster)
|
||||||
self.mongo.update_system_free_ip(instance_informations['ip'])
|
self.mongo.update_system_free_ip(instance_informations['ip'])
|
||||||
|
|
||||||
except IndexError as ierror:
|
except IndexError as ierror:
|
||||||
|
@ -213,13 +213,13 @@ class Core:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def status_instance(self, vmid, action, instancetype="lxc"):
|
def status_instance(self, vmid, node, cluster, action, instancetype="lxc"):
|
||||||
""" Find node/cluster informations from vmid """
|
""" Find node/cluster informations from vmid """
|
||||||
try:
|
try:
|
||||||
instance_informations = self.mongo.get_instance(vmid)
|
#instance_informations = self.mongo.get_instance(vmid, node, cluster)
|
||||||
|
|
||||||
""" Find cluster informations from node """
|
""" Find cluster informations from node """
|
||||||
cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"]
|
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"]
|
||||||
|
|
||||||
proxmox_cluster_url = cluster_informations["url"]
|
proxmox_cluster_url = cluster_informations["url"]
|
||||||
proxmox_cluster_port = cluster_informations["port"]
|
proxmox_cluster_port = cluster_informations["port"]
|
||||||
|
@ -229,7 +229,7 @@ class Core:
|
||||||
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]),
|
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_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(node)
|
||||||
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
proxmox_cluster_user,
|
proxmox_cluster_user,
|
||||||
|
@ -237,7 +237,7 @@ class Core:
|
||||||
|
|
||||||
result = proxmox.status_instance("{0}:{1}".format(proxmox_cluster_url,
|
result = proxmox.status_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
instance_informations['node'],
|
node,
|
||||||
instancetype,
|
instancetype,
|
||||||
vmid, action)
|
vmid, action)
|
||||||
|
|
||||||
|
@ -250,13 +250,13 @@ class Core:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def info_instance(self, vmid, instancetype="lxc"):
|
def info_instance(self, vmid, node, cluster, instancetype="lxc"):
|
||||||
""" Find node/cluster informations from vmid """
|
""" Find node/cluster informations from vmid """
|
||||||
try:
|
try:
|
||||||
instance_informations = self.mongo.get_instance(vmid)
|
#instance_informations = self.mongo.get_instance(vmid, node, cluster)
|
||||||
|
|
||||||
""" Find cluster informations from node """
|
""" Find cluster informations from node """
|
||||||
cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"]
|
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"]
|
||||||
|
|
||||||
proxmox_cluster_url = cluster_informations["url"]
|
proxmox_cluster_url = cluster_informations["url"]
|
||||||
proxmox_cluster_port = cluster_informations["port"]
|
proxmox_cluster_port = cluster_informations["port"]
|
||||||
|
@ -266,7 +266,7 @@ class Core:
|
||||||
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_informations["password"]),
|
proxmox_cluster_pwd = pdecrypt(base64.b64decode(cluster_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(node)
|
||||||
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
proxmox_cluster_user,
|
proxmox_cluster_user,
|
||||||
|
@ -274,7 +274,7 @@ class Core:
|
||||||
|
|
||||||
result = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url,
|
result = proxmox.get_config("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
instance_informations['node'],
|
node,
|
||||||
instancetype,
|
instancetype,
|
||||||
vmid)
|
vmid)
|
||||||
|
|
||||||
|
@ -287,13 +287,13 @@ class Core:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def change_instance(self, vmid, data, instancetype="lxc"):
|
def change_instance(self, vmid, node, cluster, data, instancetype="lxc"):
|
||||||
""" Find node/cluster informations from vmid """
|
""" Find node/cluster informations from vmid """
|
||||||
try:
|
try:
|
||||||
instance_informations = self.mongo.get_instance(vmid)
|
#instance_informations = self.mongo.get_instance(vmid, node, cluster)
|
||||||
|
|
||||||
""" Find cluster informations from node """
|
""" Find cluster informations from node """
|
||||||
cluster_informations = self.mongo.get_clusters_conf(instance_informations['cluster'])["value"]
|
cluster_informations = self.mongo.get_clusters_conf(cluster)["value"]
|
||||||
|
|
||||||
proxmox_cluster_url = cluster_informations["url"]
|
proxmox_cluster_url = cluster_informations["url"]
|
||||||
proxmox_cluster_port = cluster_informations["port"]
|
proxmox_cluster_port = cluster_informations["port"]
|
||||||
|
@ -304,7 +304,7 @@ class Core:
|
||||||
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(node)
|
||||||
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
proxmox.get_ticket("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
proxmox_cluster_user,
|
proxmox_cluster_user,
|
||||||
|
@ -312,12 +312,12 @@ class Core:
|
||||||
|
|
||||||
result = proxmox.resize_instance("{0}:{1}".format(proxmox_cluster_url,
|
result = proxmox.resize_instance("{0}:{1}".format(proxmox_cluster_url,
|
||||||
int(proxmox_cluster_port)),
|
int(proxmox_cluster_port)),
|
||||||
instance_informations['node'],
|
node,
|
||||||
instancetype,
|
instancetype,
|
||||||
vmid, data)
|
vmid, data)
|
||||||
|
|
||||||
if result['result'] == "OK":
|
if result['result'] == "OK":
|
||||||
self.mongo.update_instance(vmid, data)
|
self.mongo.update_instance(data, vmid, instance_informations['node'], instance_informations['cluster'])
|
||||||
|
|
||||||
except IndexError as ierror:
|
except IndexError as ierror:
|
||||||
result = {
|
result = {
|
||||||
|
|
|
@ -59,11 +59,11 @@ class Crawler:
|
||||||
instance["cluster"] = cluster["name"]
|
instance["cluster"] = cluster["name"]
|
||||||
instance["node"] = value_nodes_list["node"]
|
instance["node"] = value_nodes_list["node"]
|
||||||
# Test si l'instance existe
|
# Test si l'instance existe
|
||||||
if not self.mongo.get_instance(instance["vmid"], instance["node"]):
|
if not self.mongo.get_instance(instance["vmid"], instance["node"], instance["cluster"]):
|
||||||
# si non existante, alors il s'agit d'une instance manuelle
|
# si non existante, alors il s'agit d'une instance manuelle
|
||||||
instance["commandid"] = "000000"
|
instance["commandid"] = "000000"
|
||||||
self.mongo.insert_instance(instance)
|
self.mongo.insert_instance(instance)
|
||||||
# Si elle existe déjà, on l'update:
|
# Si elle existe déjà, on l'update:
|
||||||
else:
|
else:
|
||||||
self.mongo.update_instance(instance, instance["vmid"], instance["node"])
|
self.mongo.update_instance(instance, instance["vmid"], instance["node"], instance["cluster"])
|
||||||
return
|
return
|
|
@ -211,18 +211,18 @@ class MongoDB:
|
||||||
def insert_instance(self, data):
|
def insert_instance(self, data):
|
||||||
return self.db[self.collection_instance].insert(data)
|
return self.db[self.collection_instance].insert(data)
|
||||||
|
|
||||||
def update_instance(self, data, vmid, node):
|
def update_instance(self, data, vmid, node, cluster):
|
||||||
return self.db[self.collection_instance].update(
|
return self.db[self.collection_instance].update(
|
||||||
{"vmid": int(vmid), "node": node}, {'$set': data}, upsert=False
|
{"vmid": int(vmid), "node": node, "cluster": cluster}, {'$set': data}, upsert=False
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_instance(self, vmid, node):
|
def delete_instance(self, vmid, node, cluster):
|
||||||
self.db[self.collection_instance].remove({"vmid": int(vmid), "node": node})
|
self.db[self.collection_instance].remove({"vmid": int(vmid), "node": node, "cluster": cluster})
|
||||||
|
|
||||||
def get_instance(self, vmid, node):
|
def get_instance(self, vmid, node, cluster):
|
||||||
try:
|
try:
|
||||||
return json.loads(dumps(
|
return json.loads(dumps(
|
||||||
self.db[self.collection_instance].find_one(
|
self.db[self.collection_instance].find_one(
|
||||||
{"vmid": int(vmid), "node": node})))
|
{"vmid": int(vmid), "node": node, "cluster": cluster})))
|
||||||
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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue