Skip to content

Commit

Permalink
small naming fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Nov 6, 2024
1 parent 4a598ab commit 16ab5d4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
6 changes: 3 additions & 3 deletions bibigrid/core/actions/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import threading
import traceback
from functools import partial
from itertools import count

import paramiko
import sympy
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"])
Expand Down
20 changes: 15 additions & 5 deletions bibigrid/core/utility/ansible_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 4 additions & 15 deletions resources/playbook/roles/bibigrid/files/slurm/create_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 16ab5d4

Please sign in to comment.