v7.1.0: Add sporestack server autorenew-enable/disable commands

This commit is contained in:
SporeStack 2022-09-27 18:52:36 +00:00
parent 6582917898
commit 7158b6953c
5 changed files with 65 additions and 8 deletions

View File

@ -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

View File

@ -2,4 +2,4 @@
__all__ = ["api", "api_client", "exceptions"]
__version__ = "7.0.0"
__version__ = "7.1.0"

View File

@ -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]

View File

@ -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.

View File

@ -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