|
5 | 5 | import functools |
6 | 6 | import itertools |
7 | 7 | import logging |
8 | | -import typing |
9 | 8 | from typing import Final, cast |
10 | 9 |
|
11 | 10 | import arrow |
@@ -338,29 +337,22 @@ async def _sorted_allowed_instance_types(app: FastAPI) -> list[EC2InstanceType]: |
338 | 337 | allowed_instance_type_names = list( |
339 | 338 | app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES |
340 | 339 | ) |
341 | | - assert set(allowed_instance_type_names).issubset( |
342 | | - typing.get_args(InstanceTypeType) |
343 | | - ) # nosec |
| 340 | + |
| 341 | + assert ( |
| 342 | + allowed_instance_type_names |
| 343 | + ), "EC2_INSTANCES_ALLOWED_TYPES cannot be empty!" # nosec |
344 | 344 |
|
345 | 345 | allowed_instance_types: list[ |
346 | 346 | EC2InstanceType |
347 | 347 | ] = await ec2_client.get_ec2_instance_capabilities( |
348 | 348 | cast(set[InstanceTypeType], set(allowed_instance_type_names)) |
349 | 349 | ) |
350 | 350 |
|
351 | | - if allowed_instance_type_names: |
352 | | - |
353 | | - def _as_selection(instance_type: EC2InstanceType) -> int: |
354 | | - return allowed_instance_type_names.index(f"{instance_type.name}") |
| 351 | + def _as_selection(instance_type: EC2InstanceType) -> int: |
| 352 | + # NOTE: will raise ValueError if allowed_instance_types not in allowed_instance_type_names |
| 353 | + return allowed_instance_type_names.index(f"{instance_type.name}") |
355 | 354 |
|
356 | | - allowed_instance_types.sort(key=_as_selection) |
357 | | - else: |
358 | | - # NOTE An empty set to get_ec2_instance_capabilities it will return ALL of the instances |
359 | | - _logger.warning( |
360 | | - "All %s instances are allowed since EC2_INSTANCES_ALLOWED_TYPES is set to empty (=%s)", |
361 | | - len(allowed_instance_types), |
362 | | - allowed_instance_type_names, |
363 | | - ) |
| 355 | + allowed_instance_types.sort(key=_as_selection) |
364 | 356 | return allowed_instance_types |
365 | 357 |
|
366 | 358 |
|
|
0 commit comments