1
0
Fork 0
mirror of https://github.com/ThomasGsp/HyperProxmox.git synced 2025-03-09 15:40:18 +00:00

uid option

init thread func
This commit is contained in:
Tlams 2018-04-29 21:55:05 +01:00
parent 9d8762e1c6
commit 226b5cc4ad
3 changed files with 36 additions and 27 deletions

View file

@ -4,7 +4,7 @@ Langage: Python
Minimum version require: 3.4 Minimum version require: 3.4
Module function: Module function:
The goal of this module is to analyse the differents clusters and node The goal of this module is to analyse clusters and nodes
to allocate news instances. to allocate news instances.
""" """
@ -56,6 +56,10 @@ class Analyse:
self.clusters_conf = self.mongo.get_clusters_conf()["value"] self.clusters_conf = self.mongo.get_clusters_conf()["value"]
def threadcrawl(self):
return
def run(self, instancetype="all"): def run(self, instancetype="all"):
""" Active logger""" """ Active logger"""
self.logger.write({"thread":threading.get_ident(), "result": "INFO", "type": "HYPERPROXMOX", "value": "Start logger - Analyst Module"}) self.logger.write({"thread":threading.get_ident(), "result": "INFO", "type": "HYPERPROXMOX", "value": "Start logger - Analyst Module"})
@ -180,33 +184,34 @@ class Analyse:
instance["macaddr"] = maclist instance["macaddr"] = maclist
""" Following instance ID """ """ Following instance ID """
getidfromdesc = re.search("id=\"([A-Z\.\d\_]+)\"", currentdesc) if self.generalconf["analyst"]["walker_uid"]:
# Set unique id if not found getidfromdesc = re.search("id=\"([A-Z\.\d\_]+)\"", currentdesc)
if getidfromdesc is None: # Set unique id if not found
# ajouter un test de duplicateid if getidfromdesc is None:
""" General description """ # ajouter un test de duplicateid
randtext = ''.join(random.choice('AZERTYUIOPQSDFGHJKLMWXCVBN') for i in range(8)) """ General description """
uniqid = "-- Please, do not change or delete this ID -- \n" \ randtext = ''.join(random.choice('AZERTYUIOPQSDFGHJKLMWXCVBN') for i in range(8))
"id=\"{0}_{1}\"\n------------------\n{2}".format(insert_time, randtext, uniqid = "-- Please, do not change or delete this ID -- \n" \
currentdesc) "id=\"{0}_{1}\"\n------------------\n{2}".format(insert_time, randtext,
instance["description"] = uniqid currentdesc)
instance["description"] = uniqid
idlist.append(uniqid) idlist.append(uniqid)
""" INSTANCE DEFINITION """ """ INSTANCE DEFINITION """
datadesc = {'description': uniqid} datadesc = {'description': uniqid}
resultsetdesc = proxmox.change_instances("{0}:{1}".format(cluster["url"], int(cluster["port"])), resultsetdesc = proxmox.change_instances("{0}:{1}".format(cluster["url"], int(cluster["port"])),
value_nodes_list["node"], instance["type"], instance["vmid"], datadesc) value_nodes_list["node"], instance["type"], instance["vmid"], datadesc)
instance["uniqid"] = "{0}_{1}".format(insert_time, randtext) instance["uniqid"] = "{0}_{1}".format(insert_time, randtext)
else:
instance["uniqid"] = getidfromdesc.group(1)
if getidfromdesc.group(1) in idlist:
self.logger.write(
{"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "Double ID detected: {0}".format(getidfromdesc.group(1))})
self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": json.dumps(instance)})
self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "-------------------"})
else: else:
idlist.append(getidfromdesc.group(1)) instance["uniqid"] = getidfromdesc.group(1)
if getidfromdesc.group(1) in idlist:
self.logger.write(
{"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "Double ID detected: {0}".format(getidfromdesc.group(1))})
self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": json.dumps(instance)})
self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "-------------------"})
else:
idlist.append(getidfromdesc.group(1))
self.mongo.insert_instances(instance) self.mongo.insert_instances(instance)

View file

@ -8,7 +8,6 @@ key_pub: private/keys/Ragnarok.pub.key
admin_mail: tlams@localhost admin_mail: tlams@localhost
[web] [web]
user: www-data user: www-data
@ -45,6 +44,9 @@ walker: 300
; Lock file -- prevent concurrent crawling ; Lock file -- prevent concurrent crawling
walker_lock: /tmp/hyperproxmoxwalker.lock walker_lock: /tmp/hyperproxmoxwalker.lock
; Set an unique ID (change comment part)
uid = False
[logger] [logger]
; logs level 1: "INFO", 2: "WARNING", 3: "ERROR", 4: "CRITICAL", 5: "DEBUG" ; logs level 1: "INFO", 2: "WARNING", 3: "ERROR", 4: "CRITICAL", 5: "DEBUG"
logs_level = 5 logs_level = 5

View file

@ -37,7 +37,9 @@ if __name__ == "__main__":
"logs_dir": localconf['logger']['logs_dir'], "bulk_write": localconf['logger']['bulk_write'], "logs_dir": localconf['logger']['logs_dir'], "bulk_write": localconf['logger']['bulk_write'],
"bulk_size": localconf['logger']['bulk_size']}, "bulk_size": localconf['logger']['bulk_size']},
"analyst": {"walker": localconf['walker']['walker'], "walker_lock": localconf['walker']['walker_lock']}, "analyst": {"walker": localconf['walker']['walker'], "walker_lock": localconf['walker']['walker_lock'],
"walker_uid": localconf['walker']['uid']
},
"mongodb": {"ip": localconf['databases']['mongodb_ip'], 'port': localconf['databases']['mongodb_port']}, "mongodb": {"ip": localconf['databases']['mongodb_ip'], 'port': localconf['databases']['mongodb_port']},