Skip to content

Commit

Permalink
Added volume creation to create_server. Not yet working.
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Oct 10, 2024
1 parent 303d77e commit e6a4479
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bibigrid/core/actions/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def attach_volumes(self, provider, instance, name):
for i, attach_volume in enumerate(instance.get("attachVolumes", [])):
volume_name = f"{name}-{i}"
self.log.debug(f"Created volume {volume_name}")
volume = provider.create_volume(volume_name, attach_volume.get("size", 50))
volume = provider.create_volume(size=attach_volume.get("size", 50), name=volume_name)
attach_volume["name"] = volume_name
volumes.append(volume)
return volumes
Expand Down
44 changes: 42 additions & 2 deletions resources/playbook/roles/bibigrid/files/slurm/create_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,45 @@ class ImageNotFoundException(Exception):
logging.info("Starting instances %s", start_workers)


def attach_volumes(provider, instance, name):
logging.info("Creating volumes ...")
volumes = []
logging.info(instance)
logging.info(instance.get("attachVolumes", []))
for i, attach_volume in enumerate(instance.get("attachVolumes", [])):
logging.info(f"{i}: {attach_volume}")
volume_name = f"{name}-{i}"
logging.info(f"Created volume {volume_name}")
volume = provider.create_volume(size=attach_volume.get("size", 50), name=volume_name)
attach_volume["name"] = volume_name
volumes.append(volume)
return volumes


def attached_volumes_ansible_preparation(connection, server, instance, name):
# get mount info from server
server_volumes = []
for server_volume in server["volumes"]:
print(server_volume)
volume = connection.get_volume_by_id_or_name(server_volume["id"])
for attachment in volume["attachments"]:
if attachment["server_id"] == server["id"]:
server_volumes.append({"name": volume["name"], "device": attachment["device"]})
break
# attach
attach_volumes = instance.get("attachVolumes", [])
if attach_volumes:
for attach_volume in attach_volumes:
server_volume = next((server_volume for server_volume in server_volumes if
server_volume["name"] == attach_volume["name"]), None)
attach_volume["device"] = server_volume.get("device")
logging.debug(f"Added Configuration: Instance {name} has volume {attach_volume['name']} "
f"as device {attach_volume['device']} that is going to be mounted to "
f"{attach_volume['mountPoint']}")
else:
instance["attachVolumes"] = []


def select_image(start_worker_group, connection):
image = start_worker_group["image"]
# check if image is active
Expand Down Expand Up @@ -87,11 +126,12 @@ def start_server(worker, start_worker_group, start_data):
userdata = userdata_file.read()
# create server and ...
image = select_image(start_worker_group, connection)
volumes = attach_volumes(connection, start_worker_group, worker)
server = connection.create_server(name=worker, flavor=start_worker_group["flavor"]["name"], image=image,
network=start_worker_group["network"],
key_name=f"tempKey_bibi-{common_config['cluster_id']}",
security_groups=[f"default-{common_config['cluster_id']}"], userdata=userdata,
wait=False)
volumes=volumes, wait=False)
# ... add it to server
start_data["started_servers"].append(server)
try:
Expand Down Expand Up @@ -229,7 +269,7 @@ def _run_playbook(cmdline_args):

connections = {} # connections to cloud providers
for cloud in clouds:
connections[cloud] = os_client_config.make_sdk(cloud=cloud)
connections[cloud] = os_client_config.make_sdk(cloud=cloud, volume_api_version="3")

start_server_threads = []
for worker_group in worker_groups:
Expand Down

0 comments on commit e6a4479

Please sign in to comment.