diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e50b42..4501df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Nothing yet. +## [11.0.1 - 2024-02-29] + +## Fixed + +- If a server is deleted during the launch wait phase, it will give up rather than trying to wait forever for an IP address that will never come. +- `--hostname` matching is smarter in case of duplicate hostnames. + ## [11.0.0 - 2024-02-26] ## Changed diff --git a/src/sporestack/__init__.py b/src/sporestack/__init__.py index e71f16f..a02c6db 100644 --- a/src/sporestack/__init__.py +++ b/src/sporestack/__init__.py @@ -2,4 +2,4 @@ __all__ = ["api", "api_client", "client", "exceptions"] -__version__ = "11.0.0" +__version__ = "11.0.1" diff --git a/src/sporestack/cli.py b/src/sporestack/cli.py index 0f2bcc0..da372f9 100644 --- a/src/sporestack/cli.py +++ b/src/sporestack/cli.py @@ -199,6 +199,11 @@ def launch( tries = 360 while tries > 0: response = server.info() + if response.deleted_at > 0: + typer.echo( + "Server creation failed, was deleted while waiting.", err=True + ) + raise typer.Exit(code=1) if response.ipv4 != "": break typer.echo("Waiting for server to build...", err=True) @@ -523,11 +528,29 @@ def _get_machine_id(machine_id: str, hostname: str, token: str) -> str: api_client = APIClient(api_endpoint=get_api_endpoint()) + candidates = [] for server in api_client.servers_launched_from_token(token=_token).servers: if server.forgotten_at is not None: continue if server.hostname == hostname: - return server.machine_id + candidates.append(server) + + if len(candidates) == 1: + return candidates[0].machine_id + + remaining_candidates = [] + for candidate in candidates: + if candidate.deleted_at == 0: + remaining_candidates.append(candidate) + + if len(remaining_candidates) == 1: + return remaining_candidates[0].machine_id + elif len(remaining_candidates) > 1: + typer.echo( + "Too many servers match that hostname. Please use --machine-id, instead.", + err=True, + ) + raise typer.Exit(code=1) typer.echo( f"Could not find any servers matching the hostname: {hostname}", err=True @@ -970,7 +993,7 @@ def token_info(token: Annotated[str, typer.Argument()] = DEFAULT_TOKEN) -> None: @token_cli.command() def servers(token: Annotated[str, typer.Argument()] = DEFAULT_TOKEN) -> None: - """Returns server info for servers launched by a given token.""" + """Use sporestack server list --token TOKEN instead!""" _token = load_token(token) from .api_client import APIClient