|
|
|
@ -116,9 +116,10 @@ def launch(
|
|
|
|
|
flavor: str = DEFAULT_FLAVOR,
|
|
|
|
|
token: str = DEFAULT_TOKEN,
|
|
|
|
|
region: Optional[str] = None,
|
|
|
|
|
quote: bool = typer.Option(True, help="Require manual price confirmation."),
|
|
|
|
|
) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Attempts to launch a server.
|
|
|
|
|
Launch a server on SporeStack.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from . import utils
|
|
|
|
@ -141,40 +142,45 @@ def launch(
|
|
|
|
|
|
|
|
|
|
machine_id = utils.random_machine_id()
|
|
|
|
|
|
|
|
|
|
response = api_client.launch(
|
|
|
|
|
machine_id=machine_id,
|
|
|
|
|
days=days,
|
|
|
|
|
flavor=flavor,
|
|
|
|
|
operating_system=operating_system,
|
|
|
|
|
ssh_key=ssh_key,
|
|
|
|
|
currency="settlement",
|
|
|
|
|
region=region,
|
|
|
|
|
token=_token,
|
|
|
|
|
api_endpoint=get_api_endpoint(),
|
|
|
|
|
retry=True,
|
|
|
|
|
)
|
|
|
|
|
if quote:
|
|
|
|
|
response = api_client.launch(
|
|
|
|
|
machine_id=machine_id,
|
|
|
|
|
days=days,
|
|
|
|
|
flavor=flavor,
|
|
|
|
|
operating_system=operating_system,
|
|
|
|
|
ssh_key=ssh_key,
|
|
|
|
|
currency="settlement",
|
|
|
|
|
region=region,
|
|
|
|
|
token=_token,
|
|
|
|
|
api_endpoint=get_api_endpoint(),
|
|
|
|
|
retry=True,
|
|
|
|
|
quote=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if response.created is False:
|
|
|
|
|
tries = 360
|
|
|
|
|
while tries > 0:
|
|
|
|
|
typer.echo("Waiting for server to build...", err=True)
|
|
|
|
|
tries = tries + 1
|
|
|
|
|
# Waiting for server to spin up.
|
|
|
|
|
time.sleep(10)
|
|
|
|
|
response = api_client.launch(
|
|
|
|
|
machine_id=machine_id,
|
|
|
|
|
days=days,
|
|
|
|
|
flavor=flavor,
|
|
|
|
|
operating_system=operating_system,
|
|
|
|
|
ssh_key=ssh_key,
|
|
|
|
|
currency="settlement",
|
|
|
|
|
region=region,
|
|
|
|
|
token=_token,
|
|
|
|
|
api_endpoint=get_api_endpoint(),
|
|
|
|
|
retry=True,
|
|
|
|
|
)
|
|
|
|
|
if response.created is True:
|
|
|
|
|
break
|
|
|
|
|
msg = f"Is {response.payment.usd} for {days} day(s) of {flavor} okay?"
|
|
|
|
|
typer.echo(msg, err=True)
|
|
|
|
|
input("[Press ctrl+c to cancel, or enter to accept.]")
|
|
|
|
|
|
|
|
|
|
tries = 360
|
|
|
|
|
while tries > 0:
|
|
|
|
|
response = api_client.launch(
|
|
|
|
|
machine_id=machine_id,
|
|
|
|
|
days=days,
|
|
|
|
|
flavor=flavor,
|
|
|
|
|
operating_system=operating_system,
|
|
|
|
|
ssh_key=ssh_key,
|
|
|
|
|
currency="settlement",
|
|
|
|
|
region=region,
|
|
|
|
|
token=_token,
|
|
|
|
|
api_endpoint=get_api_endpoint(),
|
|
|
|
|
retry=True,
|
|
|
|
|
)
|
|
|
|
|
if response.created is True:
|
|
|
|
|
break
|
|
|
|
|
typer.echo("Waiting for server to build...", err=True)
|
|
|
|
|
tries = tries + 1
|
|
|
|
|
# Waiting for server to spin up.
|
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
|
|
if response.created is False:
|
|
|
|
|
typer.echo("Server creation failed, tries exceeded.", err=True)
|
|
|
|
@ -192,9 +198,10 @@ def topup(
|
|
|
|
|
hostname: str,
|
|
|
|
|
days: int = typer.Option(...),
|
|
|
|
|
token: str = DEFAULT_TOKEN,
|
|
|
|
|
quote: bool = typer.Option(True, help="Require manual price confirmation."),
|
|
|
|
|
) -> None:
|
|
|
|
|
"""
|
|
|
|
|
tops up an existing vm.
|
|
|
|
|
Extend an existing SporeStack server's lifetime.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if not machine_exists(hostname):
|
|
|
|
@ -206,6 +213,20 @@ def topup(
|
|
|
|
|
machine_info = get_machine_info(hostname)
|
|
|
|
|
machine_id = machine_info["machine_id"]
|
|
|
|
|
|
|
|
|
|
if quote:
|
|
|
|
|
response = api_client.topup(
|
|
|
|
|
machine_id=machine_id,
|
|
|
|
|
days=days,
|
|
|
|
|
currency="settlement",
|
|
|
|
|
api_endpoint=get_api_endpoint(),
|
|
|
|
|
token=_token,
|
|
|
|
|
retry=True,
|
|
|
|
|
quote=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
typer.echo(f"Is {response.payment.usd} for {days} day(s) okay?", err=True)
|
|
|
|
|
input("[Press ctrl+c to cancel, or enter to accept.]")
|
|
|
|
|
|
|
|
|
|
response = api_client.topup(
|
|
|
|
|
machine_id=machine_id,
|
|
|
|
|
days=days,
|
|
|
|
@ -214,6 +235,7 @@ def topup(
|
|
|
|
|
token=_token,
|
|
|
|
|
retry=True,
|
|
|
|
|
)
|
|
|
|
|
assert response.payment.paid is True
|
|
|
|
|
|
|
|
|
|
machine_info["expiration"] = response.expiration
|
|
|
|
|
save_machine_info(machine_info, overwrite=True)
|
|
|
|
@ -428,7 +450,7 @@ def load_token(token: str) -> str:
|
|
|
|
|
def save_token(token: str, key: str) -> None:
|
|
|
|
|
token_file = token_path().joinpath(f"{token}.json")
|
|
|
|
|
if token_file.exists():
|
|
|
|
|
msg = "Token '{token}' already exists in {token_file}. Aborting!"
|
|
|
|
|
msg = f"Token '{token}' already exists in {token_file}. Aborting!"
|
|
|
|
|
typer.echo(msg, err=True)
|
|
|
|
|
raise typer.Exit(code=1)
|
|
|
|
|
|
|
|
|
|