diff --git a/bibigrid/core/actions/create.py b/bibigrid/core/actions/create.py index 85408412..8baf25ef 100644 --- a/bibigrid/core/actions/create.py +++ b/bibigrid/core/actions/create.py @@ -8,7 +8,6 @@ import threading import traceback from functools import partial -from itertools import count import paramiko import sympy @@ -65,7 +64,7 @@ class Create: # pylint: disable=too-many-instance-attributes,too-many-arguments The class Create holds necessary methods to execute the Create-Action """ - def __init__(self, providers, configurations, config_path, log, debug=False, cluster_id=None): + def __init__(self, providers, configurations, config_path, log, debug=False, cluster_id=None): # pylint: disable=too-many-positional-arguments """ Additionally sets (unique) cluster_id, public_key_commands (to copy public keys to master) and key_name. Call create() to actually start server. @@ -306,7 +305,8 @@ def create_server_volumes(self, provider, instance, name): infix = "perm" else: infix = "tmp" - volume["name"] = f"{name}-{infix}-{i}-{volume.get('name')}" + postfix = f"-{volume.get('name')}" if volume.get('name') else '' + volume["name"] = f"{name}-{infix}-{i}{postfix}" self.log.debug(f"Trying to find volume {volume['name']}") return_volume = provider.get_volume_by_id_or_name(volume["name"]) diff --git a/bibigrid/core/utility/ansible_configurator.py b/bibigrid/core/utility/ansible_configurator.py index fd496198..0a31e357 100644 --- a/bibigrid/core/utility/ansible_configurator.py +++ b/bibigrid/core/utility/ansible_configurator.py @@ -53,7 +53,7 @@ def generate_site_file_yaml(user_roles): return site_yaml -def write_host_and_group_vars(configurations, providers, cluster_id, log): # pylint: disable=too-many-locals +def write_host_and_group_vars(configurations, providers, cluster_id, log): # pylint: disable=too-many-locals,too-many-branches,too-many-statements,too-many-positional-arguments """ Filters unnecessary information @param log: @@ -66,7 +66,7 @@ def write_host_and_group_vars(configurations, providers, cluster_id, log): # py flavor_keys = ["name", "ram", "vcpus", "disk", "ephemeral"] worker_count = 0 vpn_count = 0 - for configuration, provider in zip(configurations, providers): + for configuration, provider in zip(configurations, providers): # pylint: disable=too-many-nested-blocks configuration_features = configuration.get("features", []) if isinstance(configuration_features, str): configuration_features = [configuration_features] @@ -100,8 +100,18 @@ def write_host_and_group_vars(configurations, providers, cluster_id, log): # py name = create.WORKER_IDENTIFIER(cluster_id=cluster_id, additional=worker_count + worker_number) write_volumes = [] for i, volume in enumerate(worker.get("volumes")): - semiperm_infix = 'semiperm-' if volume.get("semiPermanent") else '' - write_volumes.append({**volume, "name":volume.get("name", f"{name}-{semiperm_infix}{i}")}) + if not volume.get("exists"): + if volume.get("semiPermanent"): + infix = "semiperm" + elif volume.get("permanent"): + infix = "perm" + else: + infix = "tmp" + postfix = f"-{volume.get('name')}" if volume.get('name') else '' + volume_name = f"{name}-{infix}-{i}{postfix}" + else: + volume_name = volume["name"] + write_volumes.append({**volume, "name":volume_name}) write_yaml(os.path.join(aRP.HOST_VARS_FOLDER, f"{name}.yaml"), {"volumes": write_volumes}, log) @@ -160,7 +170,7 @@ def pass_through(dict_from, dict_to, key_from, key_to=None): dict_to[key_to] = dict_from[key_from] -def generate_common_configuration_yaml(cidrs, configurations, cluster_id, ssh_user, default_user, log): +def generate_common_configuration_yaml(cidrs, configurations, cluster_id, ssh_user, default_user, log): # pylint: disable=too-many-positional-arguments """ Generates common_configuration yaml (dict) @param cidrs: str subnet cidrs (provider generated) diff --git a/resources/playbook/roles/bibigrid/files/slurm/create_server.py b/resources/playbook/roles/bibigrid/files/slurm/create_server.py index 92f7e871..342b3778 100644 --- a/resources/playbook/roles/bibigrid/files/slurm/create_server.py +++ b/resources/playbook/roles/bibigrid/files/slurm/create_server.py @@ -121,31 +121,20 @@ def create_server_volumes(connection, host_vars, name): return_volumes = [] logging.info(f"Instance Volumes {volumes}") - for i, volume in enumerate(volumes): - if not volume.get("exists"): - if volume.get("semiPermanent"): - infix = "semiperm" - elif volume.get("permanent"): - infix = "perm" - else: - infix = "tmp" - volume_name = f"{name}-{infix}-{i}-{volume.get('name')}" - else: - volume_name = volume["name"] - + for volume in volumes: logging.debug(f"Trying to find volume {volume['name']}") - return_volume = connection.get_volume(volume_name) + return_volume = connection.get_volume(volume['name']) if not return_volume: logging.debug(f"Volume {volume['name']} not found.") if volume.get('snapshot'): logging.debug("Creating volume from snapshot...") - return_volume = create_volume_from_snapshot(connection, volume['snapshot'], volume_name) + return_volume = create_volume_from_snapshot(connection, volume['snapshot'], volume['name']) if not return_volume: raise ConfigurationException(f"Snapshot {volume['snapshot']} not found!") else: logging.debug("Creating volume...") - return_volume = connection.create_volume(size=volume.get("size", 50), name=volume_name, + return_volume = connection.create_volume(size=volume.get("size", 50), name=volume['name'], description=f"Created for {name}") return_volumes.append(return_volume) return return_volumes diff --git a/resources/playbook/roles/bibigrid/files/slurm/delete_server.py b/resources/playbook/roles/bibigrid/files/slurm/delete_server.py index 3363b4b1..d81a3d84 100644 --- a/resources/playbook/roles/bibigrid/files/slurm/delete_server.py +++ b/resources/playbook/roles/bibigrid/files/slurm/delete_server.py @@ -68,7 +68,7 @@ if terminate_worker in possible_workers: connection = connections[worker_group["cloud_identifier"]] result = connection.delete_server(terminate_worker, wait=True) - logging.info(f"Deleting Volumes") + logging.info("Deleting Volumes") volume_list = connection.list_volumes() volume_regex = re.compile(fr"^{terminate_worker}-(tmp)-\d+(-.+)?$") for volume in volume_list: