Skip to content

Commit adab033

Browse files
committed
retrieves only Ubuntu images
1 parent b28c078 commit adab033

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/ibm_ray_config/modules/gen2/image.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def get_image_objects(self):
1616
"""
1717
images = []
1818
res = self.ibm_vpc_client.list_images().get_result()
19-
filtered_res = filter_images(res['images'],['operating_system','architecture'],"amd" )
19+
filtered_res = filter_images_ubuntu_amd(res['images'])
2020
images.extend(filtered_res)
2121
while res.get('next',None):
2222
link_to_next = res['next']['href'].split('start=')[1].split('&limit')[0]
2323
res = self.ibm_vpc_client.list_images(start=link_to_next).get_result()
24-
filtered_res = filter_images(res['images'],['operating_system','architecture'],"amd" )
24+
filtered_res = filter_images_ubuntu_amd(res['images'])
2525
images.extend(filtered_res)
2626

2727
return sorted(images,key = lambda img:img['name'])
@@ -31,7 +31,7 @@ def run(self) -> Dict[str, Any]:
3131

3232
image_objects = self.get_image_objects()
3333

34-
default = find_default({'name': 'ibm-ubuntu-20-04-'}, image_objects, name='name', substring=True)
34+
default = find_default({'name': 'ibm-ubuntu-22-04-'}, image_objects, name='name', substring=True)
3535
image_obj = find_obj(image_objects, 'Please choose an image. Ubuntu image is advised as node setup is using apt.', default=default)
3636

3737
if 'ubuntu' not in image_obj['name']:
@@ -47,31 +47,24 @@ def verify(self, base_config):
4747
image_obj = find_obj(image_objects, 'dummy', obj_id=image_id)
4848
else:
4949
# find first occurrence
50-
image_obj = next((obj for obj in image_objects if 'ibm-ubuntu-20-04-' in obj['name']), None)
50+
image_obj = next((obj for obj in image_objects if 'ibm-ubuntu-22-04-' in obj['name']), None)
5151

5252
return image_obj['id'], image_obj['minimum_provisioned_size'], image_obj['owner_type'] == 'user'
5353

5454
@update_decorator
5555
def create_default(self):
5656
image_objects = self.ibm_vpc_client.list_images().get_result()['images']
5757

58-
image_obj = next((image for image in image_objects if 'ibm-ubuntu-20-04-' in image['name']), None)
58+
image_obj = next((image for image in image_objects if 'ibm-ubuntu-22-04-' in image['name']), None)
5959

60-
print(f'Selected \033[92mUbuntu\033[0m 20.04 VM image, {image_obj["name"]}')
60+
print(f'Selected \033[92mUbuntu\033[0m 22.04 VM image, {image_obj["name"]}')
6161
return image_obj['id'], image_obj['minimum_provisioned_size'], image_obj['owner_type'] == 'user'
6262

63-
def filter_images(images, fields, value):
64-
"""returns filtered list of images matching the prefix of the specified value of a given field
63+
def filter_images_ubuntu_amd(images):
64+
"""returns Ubuntu images with amd architecture
6565
66-
images (dict)
67-
fields (str) - list of dict possibly multilevel dict fields
68-
value (str) - prefix of required value
66+
images (dict): image objects
6967
"""
70-
filtered_images = []
71-
for image in images:
72-
img_copy = image.copy()
73-
for field in fields:
74-
img_copy = img_copy.get(field)
75-
if img_copy and img_copy.startswith(value):
76-
filtered_images.append(image)
77-
return filtered_images
68+
return [image for image in images if 'amd' in
69+
image['operating_system']['architecture']
70+
and 'ubuntu' in image['operating_system']['name']]

0 commit comments

Comments
 (0)