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
|
@ -59,11 +59,11 @@ class Crawler:
|
|||
instance["cluster"] = cluster["name"]
|
||||
instance["node"] = value_nodes_list["node"]
|
||||
# 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
|
||||
instance["commandid"] = "000000"
|
||||
self.mongo.insert_instance(instance)
|
||||
# Si elle existe déjà, on l'update:
|
||||
else:
|
||||
self.mongo.update_instance(instance, instance["vmid"], instance["node"])
|
||||
self.mongo.update_instance(instance, instance["vmid"], instance["node"], instance["cluster"])
|
||||
return
|
|
@ -211,18 +211,18 @@ class MongoDB:
|
|||
def insert_instance(self, 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(
|
||||
{"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):
|
||||
self.db[self.collection_instance].remove({"vmid": int(vmid), "node": node})
|
||||
def delete_instance(self, vmid, node, cluster):
|
||||
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:
|
||||
return json.loads(dumps(
|
||||
self.db[self.collection_instance].find_one(
|
||||
{"vmid": int(vmid), "node": node})))
|
||||
{"vmid": int(vmid), "node": node, "cluster": cluster})))
|
||||
except BaseException as 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