Skip to content

Commit 649c3d4

Browse files
committed
feat(Cluster):added slurm version
1 parent 811e287 commit 649c3d4

File tree

4 files changed

+95
-23
lines changed

4 files changed

+95
-23
lines changed

portal_client.thrift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ service VirtualMachineService {
443443
9:list <string> additional_keys,
444444
10:optional string research_environment
445445
11:optional list<string> additional_security_group_ids,
446+
12:optional string slurm_version,
446447

447448
)
448449

simple_vm_client/VirtualMachineService-remote

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help":
5353
print(" void delete_security_group_rule(string openstack_id)")
5454
print(" void delete_server(string openstack_id)")
5555
print(
56-
" 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)"
56+
" 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)"
5757
)
5858
print(" bool is_bibigrid_available()")
5959
print(" void detach_ip_from_server(string server_id, string floating_ip)")
@@ -389,8 +389,8 @@ elif cmd == "delete_server":
389389
)
390390

391391
elif cmd == "start_server":
392-
if len(args) != 10:
393-
print("start_server requires 10 args")
392+
if len(args) != 11:
393+
print("start_server requires 11 args")
394394
sys.exit(1)
395395
pp.pprint(
396396
client.start_server(
@@ -404,6 +404,7 @@ elif cmd == "start_server":
404404
eval(args[7]),
405405
args[8],
406406
eval(args[9]),
407+
args[10],
407408
)
408409
)
409410

simple_vm_client/VirtualMachineService.py

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simple_vm_client/openstack_connector/openstack_connector.py

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,10 @@ def get_servers_by_bibigrid_id(self, bibigrid_id: str) -> list[Server]:
501501
def get_active_image_by_os_version(self, os_version: str, os_distro: str) -> Image:
502502
logger.info(f"Get active Image by os-version: {os_version}")
503503
images = self.openstack_connection.list_images()
504-
for img in images:
505-
image: Image = img
506-
metadata = image["metadata"]
507-
image_os_version = metadata.get("os_version", None)
508-
image_os_distro = metadata.get("os_distro", None)
509-
base_image_ref = metadata.get("base_image_ref", None)
504+
for image in images:
505+
image_os_version = image.get("os_version", None)
506+
image_os_distro = image.get("os_distro", None)
507+
base_image_ref = image.get("properties", {}).get("base_image_ref", None)
510508
if (
511509
os_version == image_os_version
512510
and image.status == "active"
@@ -521,13 +519,35 @@ def get_active_image_by_os_version(self, os_version: str, os_distro: str) -> Ima
521519
name_or_id="",
522520
)
523521

522+
def get_active_image_by_os_version_and_slurm_version(
523+
self, os_version, os_distro, slurm_version
524+
) -> Image:
525+
logger.info(
526+
f"Get active Image by os-version: {os_version} and slurm_version {slurm_version}"
527+
)
528+
images = self.openstack_connection.list_images()
529+
backup_image = None
530+
for image in images:
531+
if image and image.status == "active":
532+
image_os_version = image.get("os_version", None)
533+
image_os_distro = image.get("os_distro", None)
534+
properties = image.get("properties", None)
535+
if os_version == image_os_version and "worker" in image.get("tags", []):
536+
if os_distro and os_distro == image_os_distro:
537+
backup_image = image
538+
if properties.get("slurm_version" == slurm_version):
539+
return image
540+
541+
return backup_image
542+
524543
def get_image(
525544
self,
526545
name_or_id: str,
527546
replace_inactive: bool = False,
528547
ignore_not_active: bool = False,
529-
ignore_not_found: bool = False,
530548
replace_not_found: bool = False,
549+
ignore_not_found: bool = False,
550+
slurm_version: str = None,
531551
) -> Image:
532552
logger.info(f"Get Image {name_or_id}")
533553

@@ -536,21 +556,33 @@ def get_image(
536556
raise ImageNotFoundException(
537557
message=f"Image {name_or_id} not found!", name_or_id=name_or_id
538558
)
539-
elif not image and replace_not_found:
540-
for version in ["18.04", "20.04", "22.04", "1804", "2004", "2204"]:
559+
elif image is None and replace_not_found:
560+
for version in ["20.04", "22.04", "2004", "2204"]:
541561
if version in name_or_id:
542-
image = self.get_active_image_by_os_version(
543-
os_version=version, os_distro="ubuntu"
544-
)
545-
break
562+
if slurm_version:
563+
image = self.get_active_image_by_os_version_and_slurm_version(
564+
os_version=version,
565+
os_distro="ubuntu",
566+
slurm_version=slurm_version,
567+
)
568+
else:
569+
image = self.get_active_image_by_os_version(
570+
os_version=version, os_distro="ubuntu"
571+
)
546572

547573
elif image and image.status != "active" and replace_inactive:
548-
metadata = image.get("metadata", None)
549-
image_os_version = metadata.get("os_version", None)
550-
image_os_distro = metadata.get("os_distro", None)
551-
image = self.get_active_image_by_os_version(
552-
os_version=image_os_version, os_distro=image_os_distro
553-
)
574+
image_os_version = image["os_version"]
575+
image_os_distro = image["os_distro"]
576+
if slurm_version:
577+
image = self.get_active_image_by_os_version_and_slurm_version(
578+
os_version=image_os_version,
579+
os_distro=image_os_distro,
580+
slurm_version=slurm_version,
581+
)
582+
else:
583+
image = self.get_active_image_by_os_version(
584+
os_version=image_os_version, os_distro=image_os_distro
585+
)
554586
elif image and image.status != "active" and not ignore_not_active:
555587
raise ImageNotFoundException(
556588
message=f"Image {name_or_id} found but not active!",
@@ -1217,16 +1249,19 @@ def start_server(
12171249
volume_ids_path_attach: Union[list[dict[str, str]], None] = None,
12181250
additional_keys: Union[list[str], None] = None,
12191251
additional_security_group_ids: Union[list[str], None] = None,
1252+
slurm_version: str = None,
12201253
) -> str:
12211254
logger.info(f"Start Server {servername}")
12221255

12231256
key_name: str = None # type: ignore
12241257
try:
1258+
12251259
image: Image = self.get_image(
12261260
name_or_id=image_name,
1227-
replace_not_found=True,
12281261
replace_inactive=True,
12291262
ignore_not_found=True,
1263+
replace_not_found=True,
1264+
slurm_version=slurm_version,
12301265
)
12311266
flavor: Flavor = self.get_flavor(name_or_id=flavor_name)
12321267
network: Network = self.get_network()

0 commit comments

Comments
 (0)