Skip to content

Commit

Permalink
Merge branch 'dev' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Apr 3, 2024
2 parents 679b904 + d954efb commit 17c166b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 16 deletions.
1 change: 1 addition & 0 deletions portal_client.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ service VirtualMachineService {
9:list <string> additional_keys,
10:optional string research_environment
11:optional list<string> additional_security_group_ids,
12:optional string slurm_version,

)

Expand Down
7 changes: 4 additions & 3 deletions simple_vm_client/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help":
print(" void delete_security_group_rule(string openstack_id)")
print(" void delete_server(string openstack_id)")
print(
" string start_server(string flavor_name, string image_name, string public_key, string servername, metadata, volume_ids_path_new, volume_ids_path_attach, additional_keys, string research_environment, additional_security_group_ids)"
" string start_server(string flavor_name, string image_name, string public_key, string servername, metadata, volume_ids_path_new, volume_ids_path_attach, additional_keys, string research_environment, additional_security_group_ids, string slurm_version)"
)
print(" bool is_bibigrid_available()")
print(" void detach_ip_from_server(string server_id, string floating_ip)")
Expand Down Expand Up @@ -389,8 +389,8 @@ elif cmd == "delete_server":
)

elif cmd == "start_server":
if len(args) != 10:
print("start_server requires 10 args")
if len(args) != 11:
print("start_server requires 11 args")
sys.exit(1)
pp.pprint(
client.start_server(
Expand All @@ -404,6 +404,7 @@ elif cmd == "start_server":
eval(args[7]),
args[8],
eval(args[9]),
args[10],
)
)

Expand Down
35 changes: 35 additions & 0 deletions simple_vm_client/VirtualMachineService.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 60 additions & 13 deletions simple_vm_client/openstack_connector/openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,10 @@ def get_servers_by_bibigrid_id(self, bibigrid_id: str) -> list[Server]:
def get_active_image_by_os_version(self, os_version: str, os_distro: str) -> Image:
logger.info(f"Get active Image by os-version: {os_version}")
images = self.openstack_connection.list_images()
for img in images:
image: Image = img
metadata = image["metadata"]
image_os_version = metadata.get("os_version", None)
image_os_distro = metadata.get("os_distro", None)
base_image_ref = metadata.get("base_image_ref", None)
for image in images:
image_os_version = image.get("os_version", None)
image_os_distro = image.get("os_distro", None)
base_image_ref = image.get("properties", {}).get("base_image_ref", None)
if (
os_version == image_os_version
and image.status == "active"
Expand All @@ -521,12 +519,35 @@ def get_active_image_by_os_version(self, os_version: str, os_distro: str) -> Ima
name_or_id="",
)

def get_active_image_by_os_version_and_slurm_version(
self, os_version, os_distro, slurm_version
) -> Image:
logger.info(
f"Get active Image by os-version: {os_version} and slurm_version {slurm_version}"
)
images = self.openstack_connection.list_images()
backup_image = None
for image in images:
if image and image.status == "active":
image_os_version = image.get("os_version", None)
image_os_distro = image.get("os_distro", None)
properties = image.get("properties", None)
if os_version == image_os_version and "worker" in image.get("tags", []):
if os_distro and os_distro == image_os_distro:
backup_image = image
if properties.get("slurm_version" == slurm_version):
return image

return backup_image

def get_image(
self,
name_or_id: str,
replace_inactive: bool = False,
ignore_not_active: bool = False,
replace_not_found: bool = False,
ignore_not_found: bool = False,
slurm_version: str = None,
) -> Image:
logger.info(f"Get Image {name_or_id}")

Expand All @@ -535,13 +556,33 @@ def get_image(
raise ImageNotFoundException(
message=f"Image {name_or_id} not found!", name_or_id=name_or_id
)
elif image is None and replace_not_found:
for version in ["20.04", "22.04", "2004", "2204"]:
if version in name_or_id:
if slurm_version:
image = self.get_active_image_by_os_version_and_slurm_version(
os_version=version,
os_distro="ubuntu",
slurm_version=slurm_version,
)
else:
image = self.get_active_image_by_os_version(
os_version=version, os_distro="ubuntu"
)

elif image and image.status != "active" and replace_inactive:
metadata = image.get("metadata", None)
image_os_version = metadata.get("os_version", None)
image_os_distro = metadata.get("os_distro", None)
image = self.get_active_image_by_os_version(
os_version=image_os_version, os_distro=image_os_distro
)
image_os_version = image["os_version"]
image_os_distro = image["os_distro"]
if slurm_version:
image = self.get_active_image_by_os_version_and_slurm_version(
os_version=image_os_version,
os_distro=image_os_distro,
slurm_version=slurm_version,
)
else:
image = self.get_active_image_by_os_version(
os_version=image_os_version, os_distro=image_os_distro
)
elif image and image.status != "active" and not ignore_not_active:
raise ImageNotFoundException(
message=f"Image {name_or_id} found but not active!",
Expand Down Expand Up @@ -1208,13 +1249,19 @@ def start_server(
volume_ids_path_attach: Union[list[dict[str, str]], None] = None,
additional_keys: Union[list[str], None] = None,
additional_security_group_ids: Union[list[str], None] = None,
slurm_version: str = None,
) -> str:
logger.info(f"Start Server {servername}")

key_name: str = None # type: ignore
try:

image: Image = self.get_image(
name_or_id=image_name, replace_inactive=True, ignore_not_found=True
name_or_id=image_name,
replace_inactive=True,
ignore_not_found=True,
replace_not_found=True,
slurm_version=slurm_version,
)
flavor: Flavor = self.get_flavor(name_or_id=flavor_name)
network: Network = self.get_network()
Expand Down

0 comments on commit 17c166b

Please sign in to comment.