|
30 | 30 | _logger = logging.getLogger(__name__) |
31 | 31 |
|
32 | 32 |
|
| 33 | +ALL = None |
| 34 | + |
| 35 | + |
33 | 36 | @dataclass() |
34 | 37 | class SimcoreEC2API: |
35 | 38 | client: EC2Client |
@@ -66,20 +69,30 @@ async def ping(self) -> bool: |
66 | 69 | @ec2_exception_handler(_logger) |
67 | 70 | async def get_ec2_instance_capabilities( |
68 | 71 | self, |
69 | | - instance_type_names: set[InstanceTypeType], |
| 72 | + instance_type_names: set[InstanceTypeType] | None = ALL, |
70 | 73 | ) -> list[EC2InstanceType]: |
71 | 74 | """Returns the ec2 instance types from a list of instance type names (sorted by name) |
72 | 75 |
|
73 | 76 | Arguments: |
74 | | - instance_type_names -- the types to filter with. If an empty set, it returns all. |
| 77 | + instance_type_names -- the types to filter with |
75 | 78 |
|
76 | 79 | Raises: |
77 | 80 | Ec2InstanceTypeInvalidError: some invalid types were used as filter |
78 | 81 | ClustersKeeperRuntimeError: unexpected error communicating with EC2 |
79 | 82 |
|
80 | 83 | """ |
| 84 | + if instance_type_names is None: |
| 85 | + assert ALL is None # nosec |
| 86 | + selected_instance_types = [] |
| 87 | + else: |
| 88 | + selected_instance_types = list(instance_type_names) |
| 89 | + |
| 90 | + if len(selected_instance_types) == 0: |
| 91 | + msg = "`instance_type_names` cannot be an empty set. Set as None if all" |
| 92 | + raise ValueError(msg) |
| 93 | + |
81 | 94 | instance_types = await self.client.describe_instance_types( |
82 | | - InstanceTypes=list(instance_type_names) |
| 95 | + InstanceTypes=selected_instance_types |
83 | 96 | ) |
84 | 97 | list_instances: list[EC2InstanceType] = [] |
85 | 98 | for instance in instance_types.get("InstanceTypes", []): |
|
0 commit comments