From ceb432527bbe4957c1294a326f74792cf3d57587 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 21 May 2021 08:51:09 +0200 Subject: [PATCH] Start implmenting #1143 --- IM/InfrastructureInfo.py | 363 ++++++++++++++++++++++++++++++++ IM/connectors/CloudConnector.py | 5 +- IM/connectors/OpenStack.py | 14 +- 3 files changed, 372 insertions(+), 10 deletions(-) diff --git a/IM/InfrastructureInfo.py b/IM/InfrastructureInfo.py index bea0d232e..4ff826bfb 100644 --- a/IM/InfrastructureInfo.py +++ b/IM/InfrastructureInfo.py @@ -19,6 +19,7 @@ import time from uuid import uuid1 import json +from random import randint import IM.ConfManager from datetime import datetime, timedelta @@ -119,6 +120,8 @@ def __init__(self): """Flag to specify that this Inf is deleting resources """ self.creation_date = int(time.time()) """ Creation time of this Inf. """ + self.name = self.generate_random_name() + """ Human readable name (unique id). """ def serialize(self): with self._lock: @@ -149,6 +152,7 @@ def serialize(self): @staticmethod def deserialize(str_data): newinf = InfrastructureInfo() + newinf.name = None newinf.creation_date = None dic = json.loads(str_data) vm_list = dic['vm_list'] @@ -272,6 +276,12 @@ def get_cont_out(self): """ return self.cont_out + def get_name(self): + """ + Returns the infrastructure name (if avaliable) + """ + return self.name if self.name else self.id + def add_vm(self, vm): """ Add, and assigns a new VM ID to the infrastructure @@ -741,3 +751,356 @@ def set_adding(self, value=True): self.add_cont_msg("Infrastructure deleted. Do not add resources.") raise Exception("Infrastructure deleted. Do not add resources.") self.adding = value + + @staticmethod + def generate_random_name(): + left = [ + "admiring", + "adoring", + "affectionate", + "agitated", + "amazing", + "angry", + "awesome", + "beautiful", + "blissful", + "bold", + "boring", + "brave", + "busy", + "charming", + "clever", + "cool", + "compassionate", + "competent", + "condescending", + "confident", + "cranky", + "crazy", + "dazzling", + "determined", + "distracted", + "dreamy", + "eager", + "ecstatic", + "elastic", + "elated", + "elegant", + "eloquent", + "epic", + "exciting", + "fervent", + "festive", + "flamboyant", + "focused", + "friendly", + "frosty", + "funny", + "gallant", + "gifted", + "goofy", + "gracious", + "great", + "happy", + "hardcore", + "heuristic", + "hopeful", + "hungry", + "infallible", + "inspiring", + "interesting", + "intelligent", + "jolly", + "jovial", + "keen", + "kind", + "laughing", + "loving", + "lucid", + "magical", + "mystifying", + "modest", + "musing", + "naughty", + "nervous", + "nice", + "nifty", + "nostalgic", + "objective", + "optimistic", + "peaceful", + "pedantic", + "pensive", + "practical", + "priceless", + "quirky", + "quizzical", + "recursing", + "relaxed", + "reverent", + "romantic", + "sad", + "serene", + "sharp", + "silly", + "sleepy", + "stoic", + "strange", + "stupefied", + "suspicious", + "sweet", + "tender", + "thirsty", + "trusting", + "unruffled", + "upbeat", + "vibrant", + "vigilant", + "vigorous", + "wizardly", + "wonderful", + "xenodochial", + "youthful", + "zealous", + "zen" + ] + rigth = [ + "albattani", + "allen", + "almeida", + "antonelli", + "agnesi", + "archimedes", + "ardinghelli", + "aryabhata", + "austin", + "babbage", + "banach", + "banzai", + "bardeen", + "bartik", + "bassi", + "beaver", + "bell", + "benz", + "bhabha", + "bhaskara", + "black", + "blackburn", + "blackwell", + "bohr", + "booth", + "borg", + "bose", + "bouman", + "boyd", + "brahmagupta", + "brattain", + "brown", + "buck", + "burnell", + "cannon", + "carson", + "cartwright", + "carver", + "cerf", + "chandrasekhar", + "chaplygin", + "chatelet", + "chatterjee", + "chebyshev", + "cohen", + "chaum", + "clarke", + "colden", + "cori", + "cray", + "curran", + "curie", + "darwin", + "davinci", + "dewdney", + "dhawan", + "diffie", + "dijkstra", + "dirac", + "driscoll", + "dubinsky", + "easley", + "edison", + "einstein", + "elbakyan", + "elgamal", + "elion", + "ellis", + "engelbart", + "euclid", + "euler", + "faraday", + "feistel", + "fermat", + "fermi", + "feynman", + "franklin", + "gagarin", + "galileo", + "galois", + "ganguly", + "gates", + "gauss", + "germain", + "goldberg", + "goldstine", + "goldwasser", + "golick", + "goodall", + "gould", + "greider", + "grothendieck", + "haibt", + "hamilton", + "haslett", + "hawking", + "hellman", + "heisenberg", + "hermann", + "herschel", + "hertz", + "heyrovsky", + "hodgkin", + "hofstadter", + "hoover", + "hopper", + "hugle", + "hypatia", + "ishizaka", + "jackson", + "jang", + "jemison", + "jennings", + "jepsen", + "johnson", + "joliot", + "jones", + "kalam", + "kapitsa", + "kare", + "keldysh", + "keller", + "kepler", + "khayyam", + "khorana", + "kilby", + "kirch", + "knuth", + "kowalevski", + "lalande", + "lamarr", + "lamport", + "leakey", + "leavitt", + "lederberg", + "lehmann", + "lewin", + "lichterman", + "liskov", + "lovelace", + "lumiere", + "mahavira", + "margulis", + "matsumoto", + "maxwell", + "mayer", + "mccarthy", + "mcclintock", + "mclaren", + "mclean", + "mcnulty", + "mendel", + "mendeleev", + "meitner", + "meninsky", + "merkle", + "mestorf", + "mirzakhani", + "montalcini", + "moore", + "morse", + "murdock", + "moser", + "napier", + "nash", + "neumann", + "newton", + "nightingale", + "nobel", + "noether", + "northcutt", + "noyce", + "panini", + "pare", + "pascal", + "pasteur", + "payne", + "perlman", + "pike", + "poincare", + "poitras", + "proskuriakova", + "ptolemy", + "raman", + "ramanujan", + "ride", + "ritchie", + "rhodes", + "robinson", + "roentgen", + "rosalind", + "rubin", + "saha", + "sammet", + "sanderson", + "satoshi", + "shamir", + "shannon", + "shaw", + "shirley", + "shockley", + "shtern", + "sinoussi", + "snyder", + "solomon", + "spence", + "stonebraker", + "sutherland", + "swanson", + "swartz", + "swirles", + "taussig", + "tereshkova", + "tesla", + "tharp", + "thompson", + "torvalds", + "tu", + "turing", + "varahamihira", + "vaughan", + "visvesvaraya", + "volhard", + "villani", + "wescoff", + "wilbur", + "wiles", + "williams", + "williamson", + "wilson", + "wing", + "wozniak", + "wright", + "wu", + "yalow", + "yonath", + "zhukovsky" + ] + return "%s-%s%d" % (left[randint(0, len(left) - 1)], rigth[randint(0, len(rigth) - 1)], randint(0, 9)) diff --git a/IM/connectors/CloudConnector.py b/IM/connectors/CloudConnector.py index 85919ee53..9c1c4f763 100644 --- a/IM/connectors/CloudConnector.py +++ b/IM/connectors/CloudConnector.py @@ -588,8 +588,7 @@ def get_free_cidr(net_cidr, used_cidrs, inf=None, init=0): return None - @staticmethod - def gen_instance_name(system, unique=True, default="im-userimage"): + def gen_instance_name(self, system, unique=True, default="im-userimage"): name = system.getValue("instance_name") if not name: name = system.getValue("disk.0.image.name") @@ -599,7 +598,7 @@ def gen_instance_name(system, unique=True, default="im-userimage"): name = default name = name.lower().replace("_", "-") if unique: - return "%s-%s" % (name, str(uuid.uuid1())) + return "%s-%s" % (name, self.inf.get_name()) else: return name diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 1f5d73034..2800f2191 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -802,7 +802,7 @@ def delete_networks(self, driver, inf): msg = "" res = True for ost_net in driver.ex_list_networks(): - net_prefix = "im-%s-" % inf.id + net_prefix = "im-%s-" % inf.get_name() if ost_net.name.startswith(net_prefix): if 'subnets' in ost_net.extra and len(ost_net.extra['subnets']) == 1: subnet_id = ost_net.extra['subnets'][0] @@ -841,7 +841,7 @@ def create_networks(self, driver, radl, inf): if network.getValue('create') == 'yes' and not network.isPublic(): ost_net_name = network.getValue('provider_id') if not ost_net_name: - ost_net_name = "im-%s-%s" % (inf.id, net_name) + ost_net_name = "im-%s-%s" % (inf.get_name(), net_name) # First check if the net already exists if self.get_ost_net(driver, name=ost_net_name): @@ -876,7 +876,7 @@ def create_networks(self, driver, radl, inf): get_ex_error(ex))) # now create the subnet - ost_subnet_name = "im-%s-sub%s" % (inf.id, net_name) + ost_subnet_name = "im-%s-sub%s" % (inf.get_name(), net_name) try: self.log_info("Creating ost subnet: %s" % ost_subnet_name) ost_subnet = driver.ex_create_subnet(ost_subnet_name, ost_net, net_cidr, @@ -1355,7 +1355,7 @@ def create_security_groups(self, driver, inf, radl): # First create a SG for the entire Infra # Use the InfrastructureInfo lock to assure that only one VM create the SG with inf._lock: - sg_name = "im-%s" % inf.id + sg_name = "im-%s" % inf.get_name() sg = self._get_security_group(driver, sg_name) if not sg: self.log_info("Creating security group: %s" % sg_name) @@ -1372,7 +1372,7 @@ def create_security_groups(self, driver, inf, radl): network = radl.get_network_by_id(network_name) sg_name = network.getValue("sg_name") if not sg_name: - sg_name = "im-%s-%s" % (str(inf.id), network_name) + sg_name = "im-%s-%s" % (str(inf.get_name()), network_name) # Use the InfrastructureInfo lock to assure that only one VM create the SG with inf._lock: @@ -1501,11 +1501,11 @@ def _get_security_names(self, inf): """ Get the list of SGs for this infra """ - sg_names = ["im-%s" % inf.id] + sg_names = ["im-%s" % inf.get_name()] for net in inf.radl.networks: sg_name = net.getValue("sg_name") if not sg_name: - sg_name = "im-%s-%s" % (inf.id, net.id) + sg_name = "im-%s-%s" % (inf.get_name(), net.id) sg_names.append(sg_name) return sg_names