in source/idea/idea-virtual-desktop-controller/src/ideavirtualdesktopcontroller/app/virtual_desktop_controller_utils.py [0:0]
def get_valid_instance_types_by_software_stack(self, hibernation_support: bool, software_stack: VirtualDesktopSoftwareStack = None, gpu: VirtualDesktopGPU = None) -> List[Dict]:
allowed_instance_types = self.context.config().get_list('virtual-desktop-controller.dcv_session.instance_types.allow', default=[])
valid_instance_types_dict = self.get_valid_instance_types_by_allowed_list(hibernation_support, allowed_instance_types)
valid_instance_types_names = []
valid_instance_types = []
for instance_type_name in valid_instance_types_dict.keys():
instance_type_family = instance_type_name.split('.')[0]
instance_info = valid_instance_types_dict[instance_type_name]
self._logger.debug(f"Processing - Instance Name: {instance_type_name} Family: {instance_type_family}")
if Utils.is_not_empty(software_stack) and software_stack.base_os == VirtualDesktopBaseOS.RHEL8 and instance_type_family == 'g4dn':
# Disabling g4dn instances for RHEL8
self._logger.debug(f"g4dn instances are disabled for RHEL8 instances")
continue
if not self.validate_min_ram(instance_type_name, software_stack):
continue
supported_archs = Utils.get_value_as_list('SupportedArchitectures', Utils.get_value_as_dict('ProcessorInfo', instance_info, {}), [])
if Utils.is_not_empty(software_stack) and software_stack.architecture.value not in supported_archs:
# not desired architecture
self._logger.debug(f"Software Stack arch ({software_stack.architecture.value}) != Instance {instance_type_name} ({supported_archs}) Skipped.")
continue
if software_stack and software_stack.base_os == VirtualDesktopBaseOS.WINDOWS:
image_info = self.describe_image_id(software_stack.ami_id)
instance_boot_modes = instance_info.get('SupportedBootModes', [])
image_boot_mode = image_info.get('BootMode', '')
if image_boot_mode:
if image_boot_mode != 'uefi-preferred' and image_boot_mode not in instance_boot_modes:
# image has boot mode specified and boot mode is not supported by instance
self._logger.debug(f"Software stack ({software_stack}) restrictions on BootMode ({image_boot_mode}): Instance {instance_type_name} doesn't support ({image_boot_mode}). Skipped.")
continue
else:
if 'legacy-bios' not in instance_boot_modes:
# image has no boot mode specified and default legacy-bios is not supported by instance
self._logger.debug(f"Software stack ({software_stack}) restrictions on BootMode (legacy-bios): Instance {instance_type_name} doesn't support legacy-bios. Skipped.")
continue
supported_gpus = Utils.get_value_as_list('Gpus', Utils.get_value_as_dict('GpuInfo', instance_info, {}), [])
self._logger.debug(f"Instance {instance_type_name} GPU ({supported_gpus})")
gpu_to_check_against = None
if Utils.is_not_empty(gpu):
gpu_to_check_against = gpu
elif Utils.is_not_empty(software_stack):
gpu_to_check_against = software_stack.gpu
if gpu_to_check_against == VirtualDesktopGPU.NO_GPU:
# we don't need GPU
if len(supported_gpus) > 0:
# this instance SHOULD NOT have GPU support, but it does.
self._logger.debug(f"Instance {instance_type_name} Should not have GPU ({supported_gpus}) but it does.")
continue
elif gpu_to_check_against is not None:
# we need GPU
gpu_found = False
for supported_gpu in supported_gpus:
gpu_found = gpu_to_check_against.value.lower() == Utils.get_value_as_string('Manufacturer', supported_gpu, '').lower()
if gpu_found:
break
if not gpu_found:
# we needed a GPU, but we didn't find any
self._logger.debug(f"Instance {instance_type_name} - Needed a GPU but didn't find one.")
continue
if software_stack and software_stack.placement:
if software_stack.placement.tenancy == VirtualDesktopTenancy.HOST and not self.dedicated_hosts_supported(instance_type_name):
self._logger.debug(f"Instance {instance_type_name} doesn't support tenancy {software_stack.placement.tenancy}. Skipped.")
continue
# All checks passed if we make it this far
self._logger.debug(f"Instance {instance_type_name} - Added as valid_instance_types for software_stack")
valid_instance_types_names.append(instance_type_name)
valid_instance_types.append(instance_info)
self._logger.debug(f"Returning valid_instance_types for software_stack: {valid_instance_types_names}")
return valid_instance_types