@@ -501,12 +501,10 @@ def get_servers_by_bibigrid_id(self, bibigrid_id: str) -> list[Server]:
501
501
def get_active_image_by_os_version (self , os_version : str , os_distro : str ) -> Image :
502
502
logger .info (f"Get active Image by os-version: { os_version } " )
503
503
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 )
510
508
if (
511
509
os_version == image_os_version
512
510
and image .status == "active"
@@ -521,13 +519,35 @@ def get_active_image_by_os_version(self, os_version: str, os_distro: str) -> Ima
521
519
name_or_id = "" ,
522
520
)
523
521
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
+
524
543
def get_image (
525
544
self ,
526
545
name_or_id : str ,
527
546
replace_inactive : bool = False ,
528
547
ignore_not_active : bool = False ,
529
- ignore_not_found : bool = False ,
530
548
replace_not_found : bool = False ,
549
+ ignore_not_found : bool = False ,
550
+ slurm_version : str = None ,
531
551
) -> Image :
532
552
logger .info (f"Get Image { name_or_id } " )
533
553
@@ -536,21 +556,33 @@ def get_image(
536
556
raise ImageNotFoundException (
537
557
message = f"Image { name_or_id } not found!" , name_or_id = name_or_id
538
558
)
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" ]:
541
561
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
+ )
546
572
547
573
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
+ )
554
586
elif image and image .status != "active" and not ignore_not_active :
555
587
raise ImageNotFoundException (
556
588
message = f"Image { name_or_id } found but not active!" ,
@@ -1217,16 +1249,19 @@ def start_server(
1217
1249
volume_ids_path_attach : Union [list [dict [str , str ]], None ] = None ,
1218
1250
additional_keys : Union [list [str ], None ] = None ,
1219
1251
additional_security_group_ids : Union [list [str ], None ] = None ,
1252
+ slurm_version : str = None ,
1220
1253
) -> str :
1221
1254
logger .info (f"Start Server { servername } " )
1222
1255
1223
1256
key_name : str = None # type: ignore
1224
1257
try :
1258
+
1225
1259
image : Image = self .get_image (
1226
1260
name_or_id = image_name ,
1227
- replace_not_found = True ,
1228
1261
replace_inactive = True ,
1229
1262
ignore_not_found = True ,
1263
+ replace_not_found = True ,
1264
+ slurm_version = slurm_version ,
1230
1265
)
1231
1266
flavor : Flavor = self .get_flavor (name_or_id = flavor_name )
1232
1267
network : Network = self .get_network ()
0 commit comments