diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b0d5cc..9013514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [7.1.0 - 2022-09-27] + +### Added + +- `sporestack server autorenew-enable/disable` + +### Changed + +- Show autorenew status and associated token in `sporestack server list` (not in all cases, however) + ## [7.0.0 - 2022-09-07] ### Added diff --git a/src/sporestack/__init__.py b/src/sporestack/__init__.py index a17445b..908cb1e 100644 --- a/src/sporestack/__init__.py +++ b/src/sporestack/__init__.py @@ -2,4 +2,4 @@ __all__ = ["api", "api_client", "exceptions"] -__version__ = "7.0.0" +__version__ = "7.1.0" diff --git a/src/sporestack/api.py b/src/sporestack/api.py index 838544a..1a2e0c8 100644 --- a/src/sporestack/api.py +++ b/src/sporestack/api.py @@ -11,8 +11,6 @@ from pydantic import BaseModel from .models import Flavor, NetworkInterface, Payment -LATEST_API_VERSION = 3 - class TokenAdd: url = "/token/{token}/add" @@ -60,8 +58,6 @@ class ServerLaunch: """ Automatically renew the server with the token used, keeping it at 1 week expiration. - - BETA FEATURE!!! """ class Response(BaseModel): @@ -111,6 +107,7 @@ class ServerInfo: expiration: int running: bool machine_id: str + token: str ipv4: str ipv6: str region: str @@ -133,7 +130,6 @@ class ServerStop: method = "POST" -# Deprecated in favor of ServerDestroy class ServerDelete: url = "/server/{machine_id}/delete" method = "POST" @@ -154,6 +150,16 @@ class ServerRebuild: method = "POST" +class ServerEnableAutorenew: + url = "/server/{machine_id}/autorenew/enable" + method = "POST" + + +class ServerDisableAutorenew: + url = "/server/{machine_id}/autorenew/disable" + method = "POST" + + class ServersLaunchedFromToken: url = "/token/{token}/servers" method = "GET" @@ -175,4 +181,4 @@ class OperatingSystems: method = "GET" class Response(BaseModel): - operating_systems: list[str] + operating_systems: List[str] diff --git a/src/sporestack/api_client.py b/src/sporestack/api_client.py index 7634743..d171c88 100644 --- a/src/sporestack/api_client.py +++ b/src/sporestack/api_client.py @@ -189,6 +189,22 @@ def topup( return response_object +def autorenew_enable(machine_id: str, api_endpoint: str = API_ENDPOINT) -> None: + """ + Enable autorenew on a server. + """ + url = api_endpoint + api.ServerEnableAutorenew.url.format(machine_id=machine_id) + _api_request(url, empty_post=True) + + +def autorenew_disable(machine_id: str, api_endpoint: str = API_ENDPOINT) -> None: + """ + Disable autorenew on a server. + """ + url = api_endpoint + api.ServerDisableAutorenew.url.format(machine_id=machine_id) + _api_request(url, empty_post=True) + + def start(machine_id: str, api_endpoint: str = API_ENDPOINT) -> None: """ Boots the server. diff --git a/src/sporestack/cli.py b/src/sporestack/cli.py index c85c017..c654236 100644 --- a/src/sporestack/cli.py +++ b/src/sporestack/cli.py @@ -157,7 +157,6 @@ def launch( input("[Press ctrl+c to cancel, or enter to accept.]") if autorenew: - typer.echo("Autorenew is a BETA feature!!!", err=True) typer.echo( "Server will be automatically renewed (from this token) to one week of expiration.", # noqa: E501 err=True, @@ -346,6 +345,8 @@ def server_list( typer.echo(f"Running: {info.running}") typer.echo(f"Region: {info.region}") typer.echo(f"Flavor: {info.flavor.slug}") + typer.echo(f"Token: {info.token}") + typer.echo(f"Autorenew: {info.autorenew}") human_expiration = time.strftime( "%Y-%m-%d %H:%M:%S %z", time.localtime(info.expiration) ) @@ -454,6 +455,30 @@ def stop(hostname: str = "", machine_id: str = "", token: str = DEFAULT_TOKEN) - typer.echo(f"{hostname} stopped.") +@server_cli.command() +def autorenew_enable( + hostname: str = "", machine_id: str = "", token: str = DEFAULT_TOKEN +) -> None: + """ + Enable autorenew on a server. + """ + machine_id = _get_machine_id(machine_id=machine_id, hostname=hostname, token=token) + api_client.autorenew_enable(machine_id=machine_id, api_endpoint=get_api_endpoint()) + typer.echo("Autorenew enabled.") + + +@server_cli.command() +def autorenew_disable( + hostname: str = "", machine_id: str = "", token: str = DEFAULT_TOKEN +) -> None: + """ + Disable autorenew on a server. + """ + machine_id = _get_machine_id(machine_id=machine_id, hostname=hostname, token=token) + api_client.autorenew_disable(machine_id=machine_id, api_endpoint=get_api_endpoint()) + typer.echo("Autorenew disabled.") + + @server_cli.command() def destroy( hostname: str = "", machine_id: str = "", token: str = DEFAULT_TOKEN