|
|
|
@ -145,12 +145,12 @@ def launch(
|
|
|
|
|
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,
|
|
|
|
|
hostname=hostname,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
msg = f"Is {response.payment.usd} for {days} day(s) of {flavor} okay?"
|
|
|
|
@ -165,9 +165,9 @@ def launch(
|
|
|
|
|
flavor=flavor,
|
|
|
|
|
operating_system=operating_system,
|
|
|
|
|
ssh_key=ssh_key,
|
|
|
|
|
currency="settlement",
|
|
|
|
|
region=region,
|
|
|
|
|
token=_token,
|
|
|
|
|
hostname=hostname,
|
|
|
|
|
api_endpoint=get_api_endpoint(),
|
|
|
|
|
retry=True,
|
|
|
|
|
)
|
|
|
|
@ -314,17 +314,63 @@ def pretty_machine_info(info: Dict[str, Any]) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@server_cli.command(name="list")
|
|
|
|
|
def server_list() -> None:
|
|
|
|
|
def server_list(token: str = DEFAULT_TOKEN) -> None:
|
|
|
|
|
"""
|
|
|
|
|
List all locally known servers.
|
|
|
|
|
List all locally known servers and all servers under the given token.
|
|
|
|
|
"""
|
|
|
|
|
from .exceptions import SporeStackUserError
|
|
|
|
|
|
|
|
|
|
directory = server_info_path()
|
|
|
|
|
infos = []
|
|
|
|
|
|
|
|
|
|
_token = load_token(token)
|
|
|
|
|
|
|
|
|
|
server_infos = api_client.servers_launched_from_token(
|
|
|
|
|
token=_token, api_endpoint=get_api_endpoint()
|
|
|
|
|
).servers
|
|
|
|
|
machine_id_hostnames = {}
|
|
|
|
|
|
|
|
|
|
for hostname_json in os.listdir(directory):
|
|
|
|
|
hostname = hostname_json.split(".")[0]
|
|
|
|
|
saved_vm_info = get_machine_info(hostname)
|
|
|
|
|
machine_id_hostnames[saved_vm_info["machine_id"]] = hostname
|
|
|
|
|
|
|
|
|
|
printed_machine_ids = []
|
|
|
|
|
|
|
|
|
|
for info in server_infos:
|
|
|
|
|
typer.echo()
|
|
|
|
|
|
|
|
|
|
hostname = info.hostname
|
|
|
|
|
if hostname == "":
|
|
|
|
|
if info.machine_id in machine_id_hostnames:
|
|
|
|
|
hostname = machine_id_hostnames[info.machine_id]
|
|
|
|
|
if hostname != "":
|
|
|
|
|
typer.echo(f"Hostname: {hostname}")
|
|
|
|
|
|
|
|
|
|
typer.echo(f"Machine ID (keep this secret!): {info.machine_id}")
|
|
|
|
|
typer.echo(f"IPv6: {info.network_interfaces[0].ipv6}")
|
|
|
|
|
typer.echo(f"IPv4: {info.network_interfaces[0].ipv4}")
|
|
|
|
|
typer.echo(f"Running: {info.running}")
|
|
|
|
|
typer.echo(f"Region: {info.region}")
|
|
|
|
|
typer.echo(f"Flavor: {info.flavor.slug}")
|
|
|
|
|
human_expiration = time.strftime(
|
|
|
|
|
"%Y-%m-%d %H:%M:%S %z", time.localtime(info.expiration)
|
|
|
|
|
)
|
|
|
|
|
typer.echo(f"Expiration: {info.expiration} ({human_expiration})")
|
|
|
|
|
time_to_live = info.expiration - int(time.time())
|
|
|
|
|
hours = time_to_live // 3600
|
|
|
|
|
typer.echo(f"Server will be deleted in {hours} hours.")
|
|
|
|
|
if info.deleted:
|
|
|
|
|
typer.echo("Server was deleted!")
|
|
|
|
|
|
|
|
|
|
printed_machine_ids.append(info.machine_id)
|
|
|
|
|
|
|
|
|
|
for hostname_json in os.listdir(directory):
|
|
|
|
|
hostname = hostname_json.split(".")[0]
|
|
|
|
|
saved_vm_info = get_machine_info(hostname)
|
|
|
|
|
machine_id = saved_vm_info["machine_id"]
|
|
|
|
|
if machine_id in printed_machine_ids:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
upstream_vm_info = api_client.info(
|
|
|
|
|
machine_id=saved_vm_info["machine_id"],
|
|
|
|
@ -332,7 +378,8 @@ def server_list() -> None:
|
|
|
|
|
)
|
|
|
|
|
saved_vm_info["expiration"] = upstream_vm_info.expiration
|
|
|
|
|
saved_vm_info["running"] = upstream_vm_info.running
|
|
|
|
|
infos.append(saved_vm_info)
|
|
|
|
|
typer.echo()
|
|
|
|
|
typer.echo(pretty_machine_info(saved_vm_info))
|
|
|
|
|
except SporeStackUserError as e:
|
|
|
|
|
expiration = saved_vm_info["expiration"]
|
|
|
|
|
human_expiration = time.strftime(
|
|
|
|
@ -343,10 +390,6 @@ def server_list() -> None:
|
|
|
|
|
msg += str(e)
|
|
|
|
|
typer.echo(msg)
|
|
|
|
|
|
|
|
|
|
for info in infos:
|
|
|
|
|
typer.echo()
|
|
|
|
|
typer.echo(pretty_machine_info(info))
|
|
|
|
|
|
|
|
|
|
typer.echo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -426,6 +469,14 @@ def rebuild(hostname: str) -> None:
|
|
|
|
|
typer.echo(f"{hostname} rebuilding.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@server_cli.command()
|
|
|
|
|
def flavors() -> None:
|
|
|
|
|
"""
|
|
|
|
|
Returns available flavors.
|
|
|
|
|
"""
|
|
|
|
|
typer.echo(api_client.flavors(api_endpoint=get_api_endpoint()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_token(token: str) -> str:
|
|
|
|
|
token_file = token_path().joinpath(f"{token}.json")
|
|
|
|
|
if not token_file.exists():
|
|
|
|
@ -581,6 +632,20 @@ def balance(token: str = typer.Argument(DEFAULT_TOKEN)) -> None:
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@token_cli.command()
|
|
|
|
|
def servers(token: str = typer.Argument(DEFAULT_TOKEN)) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Returns server info for servers launched by a given token.
|
|
|
|
|
"""
|
|
|
|
|
_token = load_token(token)
|
|
|
|
|
|
|
|
|
|
typer.echo(
|
|
|
|
|
api_client.servers_launched_from_token(
|
|
|
|
|
token=_token, api_endpoint=get_api_endpoint()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@token_cli.command(name="list")
|
|
|
|
|
def token_list() -> None:
|
|
|
|
|
"""
|
|
|
|
|