v7.1.0: Add sporestack server autorenew-enable/disable commands
This commit is contained in:
parent
6582917898
commit
7158b6953c
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [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]
|
## [7.0.0 - 2022-09-07]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
__all__ = ["api", "api_client", "exceptions"]
|
__all__ = ["api", "api_client", "exceptions"]
|
||||||
|
|
||||||
__version__ = "7.0.0"
|
__version__ = "7.1.0"
|
||||||
|
|
|
@ -11,8 +11,6 @@ from pydantic import BaseModel
|
||||||
|
|
||||||
from .models import Flavor, NetworkInterface, Payment
|
from .models import Flavor, NetworkInterface, Payment
|
||||||
|
|
||||||
LATEST_API_VERSION = 3
|
|
||||||
|
|
||||||
|
|
||||||
class TokenAdd:
|
class TokenAdd:
|
||||||
url = "/token/{token}/add"
|
url = "/token/{token}/add"
|
||||||
|
@ -60,8 +58,6 @@ class ServerLaunch:
|
||||||
"""
|
"""
|
||||||
Automatically renew the server with the token used, keeping it at 1 week
|
Automatically renew the server with the token used, keeping it at 1 week
|
||||||
expiration.
|
expiration.
|
||||||
|
|
||||||
BETA FEATURE!!!
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Response(BaseModel):
|
class Response(BaseModel):
|
||||||
|
@ -111,6 +107,7 @@ class ServerInfo:
|
||||||
expiration: int
|
expiration: int
|
||||||
running: bool
|
running: bool
|
||||||
machine_id: str
|
machine_id: str
|
||||||
|
token: str
|
||||||
ipv4: str
|
ipv4: str
|
||||||
ipv6: str
|
ipv6: str
|
||||||
region: str
|
region: str
|
||||||
|
@ -133,7 +130,6 @@ class ServerStop:
|
||||||
method = "POST"
|
method = "POST"
|
||||||
|
|
||||||
|
|
||||||
# Deprecated in favor of ServerDestroy
|
|
||||||
class ServerDelete:
|
class ServerDelete:
|
||||||
url = "/server/{machine_id}/delete"
|
url = "/server/{machine_id}/delete"
|
||||||
method = "POST"
|
method = "POST"
|
||||||
|
@ -154,6 +150,16 @@ class ServerRebuild:
|
||||||
method = "POST"
|
method = "POST"
|
||||||
|
|
||||||
|
|
||||||
|
class ServerEnableAutorenew:
|
||||||
|
url = "/server/{machine_id}/autorenew/enable"
|
||||||
|
method = "POST"
|
||||||
|
|
||||||
|
|
||||||
|
class ServerDisableAutorenew:
|
||||||
|
url = "/server/{machine_id}/autorenew/disable"
|
||||||
|
method = "POST"
|
||||||
|
|
||||||
|
|
||||||
class ServersLaunchedFromToken:
|
class ServersLaunchedFromToken:
|
||||||
url = "/token/{token}/servers"
|
url = "/token/{token}/servers"
|
||||||
method = "GET"
|
method = "GET"
|
||||||
|
@ -175,4 +181,4 @@ class OperatingSystems:
|
||||||
method = "GET"
|
method = "GET"
|
||||||
|
|
||||||
class Response(BaseModel):
|
class Response(BaseModel):
|
||||||
operating_systems: list[str]
|
operating_systems: List[str]
|
||||||
|
|
|
@ -189,6 +189,22 @@ def topup(
|
||||||
return response_object
|
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:
|
def start(machine_id: str, api_endpoint: str = API_ENDPOINT) -> None:
|
||||||
"""
|
"""
|
||||||
Boots the server.
|
Boots the server.
|
||||||
|
|
|
@ -157,7 +157,6 @@ def launch(
|
||||||
input("[Press ctrl+c to cancel, or enter to accept.]")
|
input("[Press ctrl+c to cancel, or enter to accept.]")
|
||||||
|
|
||||||
if autorenew:
|
if autorenew:
|
||||||
typer.echo("Autorenew is a BETA feature!!!", err=True)
|
|
||||||
typer.echo(
|
typer.echo(
|
||||||
"Server will be automatically renewed (from this token) to one week of expiration.", # noqa: E501
|
"Server will be automatically renewed (from this token) to one week of expiration.", # noqa: E501
|
||||||
err=True,
|
err=True,
|
||||||
|
@ -346,6 +345,8 @@ def server_list(
|
||||||
typer.echo(f"Running: {info.running}")
|
typer.echo(f"Running: {info.running}")
|
||||||
typer.echo(f"Region: {info.region}")
|
typer.echo(f"Region: {info.region}")
|
||||||
typer.echo(f"Flavor: {info.flavor.slug}")
|
typer.echo(f"Flavor: {info.flavor.slug}")
|
||||||
|
typer.echo(f"Token: {info.token}")
|
||||||
|
typer.echo(f"Autorenew: {info.autorenew}")
|
||||||
human_expiration = time.strftime(
|
human_expiration = time.strftime(
|
||||||
"%Y-%m-%d %H:%M:%S %z", time.localtime(info.expiration)
|
"%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.")
|
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()
|
@server_cli.command()
|
||||||
def destroy(
|
def destroy(
|
||||||
hostname: str = "", machine_id: str = "", token: str = DEFAULT_TOKEN
|
hostname: str = "", machine_id: str = "", token: str = DEFAULT_TOKEN
|
||||||
|
|
Loading…
Reference in New Issue