Skip to content

Commit

Permalink
rm default and adds explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 18, 2024
1 parent 63bdc45 commit c899568
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
14 changes: 5 additions & 9 deletions packages/aws-library/src/aws_library/ec2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from collections.abc import Iterable, Sequence
from dataclasses import dataclass
from typing import cast
from typing import Literal, cast

import aioboto3
import botocore.exceptions
Expand Down Expand Up @@ -30,9 +30,6 @@
_logger = logging.getLogger(__name__)


ALL = None


@dataclass()
class SimcoreEC2API:
client: EC2Client
Expand Down Expand Up @@ -69,25 +66,24 @@ async def ping(self) -> bool:
@ec2_exception_handler(_logger)
async def get_ec2_instance_capabilities(
self,
instance_type_names: set[InstanceTypeType] | None = ALL,
instance_type_names: set[InstanceTypeType] | Literal["ALL"],
) -> list[EC2InstanceType]:
"""Returns the ec2 instance types from a list of instance type names (sorted by name)
Arguments:
instance_type_names -- the types to filter with
instance_type_names -- the types to filter with or "ALL", to return all EC2 possible instances
Raises:
Ec2InstanceTypeInvalidError: some invalid types were used as filter
ClustersKeeperRuntimeError: unexpected error communicating with EC2
"""
if instance_type_names is None:
assert ALL is None # nosec
if instance_type_names == "ALL":
selection_or_all_if_empty = []
else:
selection_or_all_if_empty = list(instance_type_names)
if len(selection_or_all_if_empty) == 0:
msg = "`instance_type_names` cannot be an empty set. Set as None if all"
msg = "`instance_type_names` cannot be an empty set. Use either a selection or 'ALL'"
raise ValueError(msg)

instance_types = await self.client.describe_instance_types(
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-library/tests/test_ec2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def test_get_ec2_instance_capabilities(
async def test_get_ec2_instance_capabilities_returns_all_options(
simcore_ec2_api: SimcoreEC2API,
):
instance_types = await simcore_ec2_api.get_ec2_instance_capabilities()
instance_types = await simcore_ec2_api.get_ec2_instance_capabilities("ALL")
assert instance_types
# NOTE: this might need adaptation when moto is updated
assert 700 < len(instance_types) < 828
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

from models_library.api_schemas_clusters_keeper import CLUSTERS_KEEPER_RPC_NAMESPACE
from models_library.api_schemas_clusters_keeper.ec2_instances import EC2InstanceTypeGet
from models_library.rabbitmq_basic_types import RPCMethodName
Expand All @@ -7,7 +9,7 @@


async def get_instance_type_details(
client: RabbitMQRPCClient, *, instance_type_names: set[str]
client: RabbitMQRPCClient, *, instance_type_names: set[str] | Literal["ALL"]
) -> list[EC2InstanceTypeGet]:
"""**Remote method**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

from aws_library.ec2 import EC2InstanceType
from fastapi import FastAPI
from models_library.api_schemas_clusters_keeper.ec2_instances import EC2InstanceTypeGet
Expand All @@ -10,7 +12,7 @@

@router.expose()
async def get_instance_type_details(
app: FastAPI, *, instance_type_names: set[str]
app: FastAPI, *, instance_type_names: set[str] | Literal["ALL"]
) -> list[EC2InstanceTypeGet]:
instance_capabilities: list[EC2InstanceType] = await get_ec2_client(
app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_get_instance_type_details_all_options(
# an empty set returns all options

rpc_response = await get_instance_type_details(
clusters_keeper_rabbitmq_rpc_client, instance_type_names=set()
clusters_keeper_rabbitmq_rpc_client, instance_type_names="ALL"
)
assert rpc_response
assert isinstance(rpc_response, list)
Expand Down

0 comments on commit c899568

Please sign in to comment.