voltagegpu-cli 1.2.0__py3-none-any.whl → 1.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- volt/__init__.py +3 -4
- volt/__main__.py +5 -0
- volt/cli/__init__.py +5 -3
- volt/cli/cmd_account.py +176 -0
- volt/cli/cmd_deploy.py +192 -0
- volt/cli/cmd_machines.py +103 -0
- volt/cli/cmd_misc.py +88 -0
- volt/cli/cmd_pods.py +179 -0
- volt/cli/main.py +126 -0
- volt/cli/output.py +75 -0
- volt/cli/state.py +35 -0
- volt/sdk/__init__.py +34 -5
- volt/sdk/client.py +203 -184
- volt/sdk/config.py +166 -46
- volt/sdk/errors.py +71 -0
- volt/sdk/models.py +320 -0
- volt/sdk/ssh.py +112 -0
- voltagegpu_cli-1.3.0.dist-info/METADATA +247 -0
- voltagegpu_cli-1.3.0.dist-info/RECORD +22 -0
- {voltagegpu_cli-1.2.0.dist-info → voltagegpu_cli-1.3.0.dist-info}/WHEEL +1 -1
- voltagegpu_cli-1.3.0.dist-info/entry_points.txt +3 -0
- {voltagegpu_cli-1.2.0.dist-info → voltagegpu_cli-1.3.0.dist-info}/licenses/LICENSE +21 -21
- volt/cli/cli.py +0 -476
- voltagegpu_cli-1.2.0.dist-info/METADATA +0 -211
- voltagegpu_cli-1.2.0.dist-info/RECORD +0 -11
- voltagegpu_cli-1.2.0.dist-info/entry_points.txt +0 -2
volt/__init__.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"""VoltageGPU
|
|
1
|
+
"""VoltageGPU command-line interface and Python SDK."""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
__version__ = "1.3.0"
|
|
4
4
|
|
|
5
|
-
__all__ = ["
|
|
6
|
-
__version__ = "1.2.0"
|
|
5
|
+
__all__ = ["__version__"]
|
volt/__main__.py
ADDED
volt/cli/__init__.py
CHANGED
volt/cli/cmd_account.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""`login`, `logout`, `config`, `balance` and `ssh-keys`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from ..sdk.config import (
|
|
11
|
+
API_KEYS_PAGE,
|
|
12
|
+
Config,
|
|
13
|
+
default_config_path,
|
|
14
|
+
is_valid_api_key,
|
|
15
|
+
permissions_warning,
|
|
16
|
+
remove_api_key,
|
|
17
|
+
save_api_key,
|
|
18
|
+
)
|
|
19
|
+
from ..sdk.errors import ApiError, ConfigError
|
|
20
|
+
from .output import console, echo_json, fail, hint, info, is_interactive, money, table, warn
|
|
21
|
+
from .state import AppState, pass_state
|
|
22
|
+
|
|
23
|
+
_PUBLIC_KEY_PREFIXES = ("ssh-ed25519 ", "ssh-rsa ", "ecdsa-sha2-", "sk-ssh-ed25519@openssh.com ", "sk-ecdsa-sha2-")
|
|
24
|
+
_DEFAULT_PUBLIC_KEYS = ("id_ed25519.pub", "id_ecdsa.pub", "id_rsa.pub")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def read_public_key(text: str) -> str:
|
|
28
|
+
"""Validate an OpenSSH public key; refuse private keys loudly."""
|
|
29
|
+
key = (text or "").strip()
|
|
30
|
+
if "PRIVATE KEY" in key:
|
|
31
|
+
raise click.BadParameter("this is a PRIVATE key. Never upload it: pass the matching .pub file instead.")
|
|
32
|
+
lines = [line for line in key.splitlines() if line.strip()]
|
|
33
|
+
if len(lines) != 1 or not lines[0].startswith(_PUBLIC_KEY_PREFIXES) or len(lines[0]) > 16384:
|
|
34
|
+
raise click.BadParameter("expected one OpenSSH public key line, e.g. 'ssh-ed25519 AAAA... you@laptop'.")
|
|
35
|
+
return lines[0].strip()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def default_public_key_file() -> Optional[Path]:
|
|
39
|
+
ssh_dir = Path.home() / ".ssh"
|
|
40
|
+
for name in _DEFAULT_PUBLIC_KEYS:
|
|
41
|
+
candidate = ssh_dir / name
|
|
42
|
+
if candidate.is_file():
|
|
43
|
+
return candidate
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@click.command("login")
|
|
48
|
+
@click.option("--api-key", envvar=None, help="Key to store (prompted, hidden, if omitted). Prefer the prompt: "
|
|
49
|
+
"a key on the command line lands in your shell history.")
|
|
50
|
+
@pass_state
|
|
51
|
+
def login_cmd(state: AppState, api_key: Optional[str]) -> None:
|
|
52
|
+
"""Store your API key in ~/.volt/config.ini (readable by you only)."""
|
|
53
|
+
if not api_key:
|
|
54
|
+
if not is_interactive():
|
|
55
|
+
fail("No terminal to prompt on. Export VOLT_API_KEY instead, or pass --api-key.", code=2)
|
|
56
|
+
info(f"Create a key at {API_KEYS_PAGE} (it is shown once).")
|
|
57
|
+
api_key = click.prompt("API key", hide_input=True).strip()
|
|
58
|
+
if not is_valid_api_key(api_key):
|
|
59
|
+
fail(f"That does not look like a VoltageGPU API key (volt_...). Create one at {API_KEYS_PAGE}.")
|
|
60
|
+
try:
|
|
61
|
+
with state.client_with_key(api_key) as client:
|
|
62
|
+
client.list_ssh_keys() # cheapest authenticated call: proves the key works
|
|
63
|
+
except ApiError as exc:
|
|
64
|
+
if exc.is_auth_error:
|
|
65
|
+
fail("The API refused this key. Check it on " + API_KEYS_PAGE)
|
|
66
|
+
raise
|
|
67
|
+
path = save_api_key(api_key)
|
|
68
|
+
console.print(f"[green]Logged in.[/green] Key saved to {path}")
|
|
69
|
+
hint("Environment variables (VOLT_API_KEY) take precedence over this file.")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@click.command("logout")
|
|
73
|
+
def logout_cmd() -> None:
|
|
74
|
+
"""Remove the stored API key from ~/.volt/config.ini."""
|
|
75
|
+
if remove_api_key():
|
|
76
|
+
info(f"Removed the key from {default_config_path()}. Revoke it too on {API_KEYS_PAGE} if it may have leaked.")
|
|
77
|
+
else:
|
|
78
|
+
info("No stored key.")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@click.command("config")
|
|
82
|
+
@pass_state
|
|
83
|
+
def config_cmd(state: AppState) -> None:
|
|
84
|
+
"""Show where the API key comes from (masked) and the API base URL."""
|
|
85
|
+
try:
|
|
86
|
+
cfg = Config.load(base_url=state.base_url)
|
|
87
|
+
except ConfigError as exc:
|
|
88
|
+
fail(str(exc))
|
|
89
|
+
info(f"API base URL {cfg.base_url}")
|
|
90
|
+
info(f"API key {cfg.masked_key} from {cfg.source}")
|
|
91
|
+
warning = permissions_warning(default_config_path())
|
|
92
|
+
if warning:
|
|
93
|
+
warn(warning)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@click.command("balance")
|
|
97
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
98
|
+
@pass_state
|
|
99
|
+
def balance_cmd(state: AppState, as_json: bool) -> None:
|
|
100
|
+
"""Your balance and number of running pods."""
|
|
101
|
+
try:
|
|
102
|
+
bal = state.client().get_balance()
|
|
103
|
+
except ApiError as exc:
|
|
104
|
+
if exc.is_not_found:
|
|
105
|
+
fail("This API server does not expose the balance yet. See it on https://voltagegpu.com/billing")
|
|
106
|
+
raise
|
|
107
|
+
if as_json:
|
|
108
|
+
echo_json(bal.to_dict())
|
|
109
|
+
return
|
|
110
|
+
console.print(f"Balance [bold green]{money(bal.balance)}[/bold green] {bal.currency}")
|
|
111
|
+
if bal.active_pods is not None:
|
|
112
|
+
info(f"Running {bal.active_pods} pod{'s' if bal.active_pods != 1 else ''}")
|
|
113
|
+
hint(f"Top up: {bal.top_up_url}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@click.group("ssh-keys")
|
|
117
|
+
def ssh_keys_group() -> None:
|
|
118
|
+
"""Manage the SSH public keys injected into your pods."""
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@ssh_keys_group.command("list")
|
|
122
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
123
|
+
@pass_state
|
|
124
|
+
def ssh_keys_list(state: AppState, as_json: bool) -> None:
|
|
125
|
+
"""List your SSH keys."""
|
|
126
|
+
keys = state.client().list_ssh_keys()
|
|
127
|
+
if as_json:
|
|
128
|
+
echo_json([k.to_dict() for k in keys])
|
|
129
|
+
return
|
|
130
|
+
if not keys:
|
|
131
|
+
info("No SSH key yet. Add one: voltagegpu ssh-keys add")
|
|
132
|
+
return
|
|
133
|
+
table("SSH keys", [("KEY ID", {"style": "cyan", "no_wrap": True}), ("NAME",), ("KEY",), ("ADDED",)],
|
|
134
|
+
[(k.id, k.name, k.summary, (k.created_at or "")[:10]) for k in keys])
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@ssh_keys_group.command("add")
|
|
138
|
+
@click.option("--name", help="Label for the key (default: the file name).")
|
|
139
|
+
@click.option("--file", "key_file", type=click.Path(exists=True, dir_okay=False, path_type=Path),
|
|
140
|
+
help="Public key file (default: ~/.ssh/id_ed25519.pub, id_ecdsa.pub or id_rsa.pub).")
|
|
141
|
+
@click.option("--key", "key_text", help="Public key string instead of a file.")
|
|
142
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
143
|
+
@pass_state
|
|
144
|
+
def ssh_keys_add(state: AppState, name: Optional[str], key_file: Optional[Path], key_text: Optional[str], as_json: bool) -> None:
|
|
145
|
+
"""Register an SSH public key."""
|
|
146
|
+
if key_file and key_text:
|
|
147
|
+
fail("Give --file or --key, not both.", code=2)
|
|
148
|
+
if not key_text:
|
|
149
|
+
path = key_file or default_public_key_file()
|
|
150
|
+
if path is None:
|
|
151
|
+
fail("No public key found in ~/.ssh. Create one with: ssh-keygen -t ed25519", code=2)
|
|
152
|
+
if path.suffix != ".pub" and path.with_suffix(path.suffix + ".pub").exists():
|
|
153
|
+
fail(f"{path} looks like a private key. Use {path}.pub", code=2)
|
|
154
|
+
key_text = path.read_text(encoding="utf-8", errors="replace")
|
|
155
|
+
name = name or path.name
|
|
156
|
+
public_key = read_public_key(key_text)
|
|
157
|
+
key = state.client().add_ssh_key(name or "cli-key", public_key)
|
|
158
|
+
if as_json:
|
|
159
|
+
echo_json(key.to_dict())
|
|
160
|
+
else:
|
|
161
|
+
console.print(f"[green]Added.[/green] {key.name} ({key.id})")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@ssh_keys_group.command("delete")
|
|
165
|
+
@click.argument("key_id")
|
|
166
|
+
@click.option("-y", "--yes", is_flag=True, help="Do not ask for confirmation.")
|
|
167
|
+
@pass_state
|
|
168
|
+
def ssh_keys_delete(state: AppState, key_id: str, yes: bool) -> None:
|
|
169
|
+
"""Delete an SSH key (running pods keep the keys they were created with)."""
|
|
170
|
+
if not yes:
|
|
171
|
+
if not is_interactive():
|
|
172
|
+
fail("Re-run with --yes to confirm in a script.", code=2)
|
|
173
|
+
if not click.confirm(f"Delete SSH key {key_id}?", default=False):
|
|
174
|
+
raise click.exceptions.Exit(1)
|
|
175
|
+
state.client().delete_ssh_key(key_id)
|
|
176
|
+
console.print(f"[green]Deleted.[/green] {key_id}")
|
volt/cli/cmd_deploy.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""`voltagegpu deploy standard` and `voltagegpu deploy confidential`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import secrets
|
|
7
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
8
|
+
|
|
9
|
+
import click
|
|
10
|
+
|
|
11
|
+
from ..sdk.errors import ApiError
|
|
12
|
+
from ..sdk.models import CONFIDENTIAL, STANDARD, DeployResult, Machine, Pod
|
|
13
|
+
from .cmd_machines import filter_machines
|
|
14
|
+
from .output import console, echo_json, fail, hint, info, is_interactive, money, status_style, warn
|
|
15
|
+
from .state import AppState, pass_state
|
|
16
|
+
|
|
17
|
+
NAME_RE = re.compile(r"^[a-z0-9][a-z0-9-]{0,39}$")
|
|
18
|
+
_PORT_RE = re.compile(r"^(\d{1,5})(?:/(tcp|udp))?$", re.IGNORECASE)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def default_name() -> str:
|
|
22
|
+
return f"pod-{secrets.token_hex(3)}"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def check_name(name: str) -> str:
|
|
26
|
+
if not NAME_RE.match(name):
|
|
27
|
+
raise click.BadParameter("use 1-40 lowercase letters, digits and hyphens, starting with a letter or digit", param_hint="--name")
|
|
28
|
+
return name
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def parse_port_spec(spec: str) -> Dict[str, Any]:
|
|
32
|
+
"""'8000' / '8000/tcp' / '53/udp' -> {"port": 8000, "protocol": "tcp"}."""
|
|
33
|
+
match = _PORT_RE.match(spec.strip())
|
|
34
|
+
if not match:
|
|
35
|
+
raise click.BadParameter(f"{spec!r}: expected PORT or PORT/tcp or PORT/udp", param_hint="--port")
|
|
36
|
+
port = int(match.group(1))
|
|
37
|
+
if not 1 <= port <= 65535:
|
|
38
|
+
raise click.BadParameter(f"{port} is not between 1 and 65535", param_hint="--port")
|
|
39
|
+
if port == 22:
|
|
40
|
+
raise click.BadParameter("port 22 (SSH) is already mapped for you", param_hint="--port")
|
|
41
|
+
return {"port": port, "protocol": (match.group(2) or "tcp").lower()}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def pick_machine(machines: List[Machine], machine_id: Optional[str], cheapest: bool, gpu: Optional[str],
|
|
45
|
+
max_price: Optional[float]) -> Machine:
|
|
46
|
+
"""The machine to deploy: an explicit id, or the cheapest one matching the filters."""
|
|
47
|
+
if machine_id:
|
|
48
|
+
for m in machines:
|
|
49
|
+
if m.id == machine_id:
|
|
50
|
+
return m
|
|
51
|
+
raise LookupError(f"Machine {machine_id} is not in the deployable list right now. "
|
|
52
|
+
"List machines with: voltagegpu machines --standard")
|
|
53
|
+
candidates = filter_machines(machines, gpu=gpu, max_price=max_price)
|
|
54
|
+
priced = [m for m in candidates if m.price_per_hour is not None]
|
|
55
|
+
if not priced:
|
|
56
|
+
raise LookupError("No standard machine matches these filters right now.")
|
|
57
|
+
return min(priced, key=lambda m: m.price_per_hour or 0.0)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _confirm_charge(amount: Optional[float], yes: bool) -> None:
|
|
61
|
+
if yes:
|
|
62
|
+
return
|
|
63
|
+
if not is_interactive():
|
|
64
|
+
fail("This deploy charges your balance. Re-run with --yes to confirm in a script.", code=2)
|
|
65
|
+
if not click.confirm(f"Charge {money(amount)} now (first hour, prepaid) and deploy?", default=False):
|
|
66
|
+
raise click.exceptions.Exit(1)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _wait(state: AppState, pod_id: str, timeout: int) -> Pod:
|
|
70
|
+
seen: Dict[str, str] = {}
|
|
71
|
+
|
|
72
|
+
def on_poll(pod: Pod) -> None:
|
|
73
|
+
label = pod.provider_status or pod.status
|
|
74
|
+
if seen.get("s") != label:
|
|
75
|
+
seen["s"] = label
|
|
76
|
+
console.print(f" status: [{status_style(pod.status)}]{label}[/]")
|
|
77
|
+
|
|
78
|
+
info(f"Waiting for SSH on {pod_id} (up to {timeout} s)...")
|
|
79
|
+
return state.client().wait_until_reachable(pod_id, timeout=timeout, interval=10.0, on_poll=on_poll)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _after_deploy(state: AppState, result: DeployResult, wait: bool, timeout: int, as_json: bool) -> None:
|
|
83
|
+
pod: Optional[Pod] = None
|
|
84
|
+
if wait:
|
|
85
|
+
try:
|
|
86
|
+
pod = _wait(state, result.pod_id, timeout) if not as_json else state.client().wait_until_reachable(result.pod_id, timeout=timeout)
|
|
87
|
+
except TimeoutError as exc:
|
|
88
|
+
warn(str(exc))
|
|
89
|
+
if as_json:
|
|
90
|
+
echo_json({"deploy": result.to_dict(), "pod": pod.to_dict() if pod else None})
|
|
91
|
+
return
|
|
92
|
+
if pod and pod.ssh_command:
|
|
93
|
+
console.print(f"[green]Ready.[/green] SSH: {pod.ssh_command}")
|
|
94
|
+
info("")
|
|
95
|
+
info("Next:")
|
|
96
|
+
info(f" voltagegpu pods wait {result.pod_id} # until SSH is ready" if not pod else f" voltagegpu ssh {result.pod_id}")
|
|
97
|
+
info(f" voltagegpu pods stop {result.pod_id} # release it (billing stops)")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@click.group("deploy")
|
|
101
|
+
def deploy_group() -> None:
|
|
102
|
+
"""Deploy a standard pod or a Confidential VM (charges the first hour)."""
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@deploy_group.command("standard")
|
|
106
|
+
@click.option("--machine", "machine_id", help="machine_id from `voltagegpu machines --standard`.")
|
|
107
|
+
@click.option("--cheapest", is_flag=True, help="Pick the cheapest available machine (combine with --gpu/--max-price).")
|
|
108
|
+
@click.option("--gpu", help="With --cheapest: GPU model filter, e.g. A6000.")
|
|
109
|
+
@click.option("--max-price", type=float, help="With --cheapest: maximum price per hour (USD).")
|
|
110
|
+
@click.option("--name", help="Pod name: lowercase letters, digits, hyphens (default: pod-xxxxxx).")
|
|
111
|
+
@click.option("--template", "template_id", help="Template id from `voltagegpu templates` (default: PyTorch).")
|
|
112
|
+
@click.option("--ssh-key", "ssh_key_id", help="SSH key id (required if your account has several keys).")
|
|
113
|
+
@click.option("--jupyter", is_flag=True, default=None, help="Start Jupyter on the pod.")
|
|
114
|
+
@click.option("--ports", "port_count", type=click.IntRange(1, 31), help="Number of extra public ports to map.")
|
|
115
|
+
@click.option("--auto-terminate", "auto_terminate_hours", type=click.IntRange(1, 720), help="Release automatically after N hours.")
|
|
116
|
+
@click.option("--wait", is_flag=True, help="Wait until SSH is ready and print the command.")
|
|
117
|
+
@click.option("--timeout", type=click.IntRange(30, 3600), default=900, show_default=True, help="Seconds to wait with --wait.")
|
|
118
|
+
@click.option("-y", "--yes", is_flag=True, help="Do not ask for confirmation before charging.")
|
|
119
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
120
|
+
@pass_state
|
|
121
|
+
def deploy_standard(state: AppState, machine_id: Optional[str], cheapest: bool, gpu: Optional[str], max_price: Optional[float],
|
|
122
|
+
name: Optional[str], template_id: Optional[str], ssh_key_id: Optional[str], jupyter: Optional[bool],
|
|
123
|
+
port_count: Optional[int], auto_terminate_hours: Optional[int], wait: bool, timeout: int,
|
|
124
|
+
yes: bool, as_json: bool) -> None:
|
|
125
|
+
"""Deploy a standard pod: a whole machine, no enclave, for non-sensitive workloads."""
|
|
126
|
+
if bool(machine_id) == bool(cheapest):
|
|
127
|
+
fail("Give exactly one of --machine MACHINE_ID or --cheapest.", code=2)
|
|
128
|
+
pod_name = check_name(name) if name else default_name()
|
|
129
|
+
client = state.client()
|
|
130
|
+
try:
|
|
131
|
+
machine = pick_machine(client.list_machines(STANDARD), machine_id, cheapest, gpu, max_price)
|
|
132
|
+
except LookupError as exc:
|
|
133
|
+
fail(str(exc))
|
|
134
|
+
if not as_json:
|
|
135
|
+
info(f"Standard pod [bold]{pod_name}[/bold] on {machine.gpu_count}x {machine.gpu_type}"
|
|
136
|
+
f"{' (' + machine.location + ')' if machine.location else ''}, {money(machine.price_per_hour)}/hour")
|
|
137
|
+
hint(f"machine {machine.id}. No enclave: use a Confidential VM for sensitive data.")
|
|
138
|
+
_confirm_charge(machine.price_per_hour, yes)
|
|
139
|
+
result = client.deploy_standard(
|
|
140
|
+
machine.id, pod_name, template_id=template_id, ssh_key_id=ssh_key_id, gpu_count=None,
|
|
141
|
+
jupyter=jupyter, port_count=port_count, auto_terminate_hours=auto_terminate_hours,
|
|
142
|
+
)
|
|
143
|
+
if not as_json:
|
|
144
|
+
console.print(f"[green]Deployed.[/green] Pod {result.pod_id}, {money(result.hourly_price)}/hour, "
|
|
145
|
+
f"{money(result.prepaid_amount)} prepaid.")
|
|
146
|
+
_after_deploy(state, result, wait, timeout, as_json)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@deploy_group.command("confidential")
|
|
150
|
+
@click.option("--tier", required=True, help="Tier from `voltagegpu machines --confidential`, e.g. rtx6000b-small.")
|
|
151
|
+
@click.option("--name", help="VM name: lowercase letters, digits, hyphens (default: pod-xxxxxx).")
|
|
152
|
+
@click.option("--hardstop", "hardstop_hours", type=click.IntRange(0, 720), help="Release automatically after N hours.")
|
|
153
|
+
@click.option("--port", "ports", multiple=True, metavar="PORT[/tcp|udp]", help="Extra inbound port, repeatable (single-GPU tiers).")
|
|
154
|
+
@click.option("--wait", is_flag=True, help="Wait until SSH is ready and print the command.")
|
|
155
|
+
@click.option("--timeout", type=click.IntRange(30, 3600), default=900, show_default=True, help="Seconds to wait with --wait.")
|
|
156
|
+
@click.option("-y", "--yes", is_flag=True, help="Do not ask for confirmation before charging.")
|
|
157
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output (includes the one-time sudo password).")
|
|
158
|
+
@pass_state
|
|
159
|
+
def deploy_confidential(state: AppState, tier: str, name: Optional[str], hardstop_hours: Optional[int], ports: Tuple[str, ...],
|
|
160
|
+
wait: bool, timeout: int, yes: bool, as_json: bool) -> None:
|
|
161
|
+
"""Deploy a Confidential VM: Intel TDX, your SSH keys only, attestation you verify yourself."""
|
|
162
|
+
pod_name = check_name(name) if name else default_name()
|
|
163
|
+
port_list = [parse_port_spec(p) for p in ports]
|
|
164
|
+
client = state.client()
|
|
165
|
+
tiers = {m.id: m for m in client.list_machines(CONFIDENTIAL)}
|
|
166
|
+
machine = tiers.get(tier)
|
|
167
|
+
if machine is None:
|
|
168
|
+
fail(f"'{tier}' is not an available Confidential VM tier right now. List tiers with: voltagegpu machines --confidential")
|
|
169
|
+
if not client.list_ssh_keys():
|
|
170
|
+
fail("Add an SSH key first (voltagegpu ssh-keys add). A Confidential VM binds your keys at creation "
|
|
171
|
+
"and cannot be given one afterwards.")
|
|
172
|
+
if not as_json:
|
|
173
|
+
info(f"Confidential VM [bold]{pod_name}[/bold] on {machine.id} ({machine.gpu_count}x {machine.gpu_type}), "
|
|
174
|
+
f"{money(machine.price_per_hour)}/hour")
|
|
175
|
+
hint("Every SSH key on your account is bound to the VM. We keep no key on it.")
|
|
176
|
+
_confirm_charge(machine.price_per_hour, yes)
|
|
177
|
+
result = client.deploy_confidential(tier, pod_name, hardstop_hours=hardstop_hours, ports=port_list)
|
|
178
|
+
if not as_json:
|
|
179
|
+
console.print(f"[green]Deployed.[/green] VM {result.pod_id}, {money(result.hourly_price)}/hour, booting.")
|
|
180
|
+
if result.sudo_password:
|
|
181
|
+
console.print(f" sudo password (shown once, we do not keep it): [bold]{result.sudo_password}[/bold]")
|
|
182
|
+
if result.hard_stop_at:
|
|
183
|
+
info(f" automatic release at {result.hard_stop_at}")
|
|
184
|
+
commands = (result.attestation or {}).get("verifyInsideTheVm")
|
|
185
|
+
if isinstance(commands, list) and commands:
|
|
186
|
+
hint("Verify the attestation inside the VM (then check the bundle with `voltagegpu verify`):")
|
|
187
|
+
for line in commands:
|
|
188
|
+
hint(f" {line}")
|
|
189
|
+
_after_deploy(state, result, wait, timeout, as_json)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
__all__ = ["deploy_group", "parse_port_spec", "pick_machine", "check_name", "default_name", "ApiError"]
|
volt/cli/cmd_machines.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""`voltagegpu machines` and `voltagegpu templates`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import List, Optional
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from ..sdk.models import CONFIDENTIAL, STANDARD, Machine
|
|
10
|
+
from .output import echo_json, hint, info, money, table
|
|
11
|
+
from .state import AppState, pass_state
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def filter_machines(
|
|
15
|
+
machines: List[Machine],
|
|
16
|
+
gpu: Optional[str] = None,
|
|
17
|
+
max_price: Optional[float] = None,
|
|
18
|
+
min_gpus: Optional[int] = None,
|
|
19
|
+
) -> List[Machine]:
|
|
20
|
+
"""Pure filter used by `machines` and `deploy standard --cheapest`."""
|
|
21
|
+
needle = (gpu or "").lower().replace(" ", "")
|
|
22
|
+
out = []
|
|
23
|
+
for m in machines:
|
|
24
|
+
if needle and needle not in f"{m.gpu_type} {m.name}".lower().replace(" ", ""):
|
|
25
|
+
continue
|
|
26
|
+
if max_price is not None and (m.price_per_hour is None or m.price_per_hour > max_price):
|
|
27
|
+
continue
|
|
28
|
+
if min_gpus is not None and m.gpu_count < min_gpus:
|
|
29
|
+
continue
|
|
30
|
+
out.append(m)
|
|
31
|
+
return out
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _print_confidential(machines: List[Machine]) -> None:
|
|
35
|
+
table(
|
|
36
|
+
"Confidential VMs (Intel TDX)",
|
|
37
|
+
[("TIER", {"style": "cyan"}), ("GPU",), ("GPUS", {"justify": "right"}), ("VCPU", {"justify": "right"}),
|
|
38
|
+
("RAM GB", {"justify": "right"}), ("$/HOUR", {"justify": "right", "style": "green"}), ("AVAILABLE", {"justify": "right"})],
|
|
39
|
+
[(m.id, m.gpu_type, m.gpu_count, m.vcpu, m.ram_gb, money(m.price_per_hour), m.available) for m in machines],
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _print_standard(machines: List[Machine], total: int) -> None:
|
|
44
|
+
title = "Standard machines (no enclave, for non-sensitive workloads)"
|
|
45
|
+
if total > len(machines):
|
|
46
|
+
title += f", {len(machines)} of {total} shown"
|
|
47
|
+
table(
|
|
48
|
+
title,
|
|
49
|
+
[("MACHINE ID", {"style": "cyan", "no_wrap": True}), ("GPU", {"no_wrap": True}), ("GPUS", {"justify": "right"}),
|
|
50
|
+
("VRAM GB", {"justify": "right"}), ("$/HOUR", {"justify": "right", "style": "green"}),
|
|
51
|
+
("LOCATION", {"no_wrap": True, "max_width": 22, "overflow": "ellipsis"})],
|
|
52
|
+
[(m.id, m.gpu_type, m.gpu_count, m.gpu_memory_gb, money(m.price_per_hour), m.location) for m in machines],
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@click.command("machines")
|
|
57
|
+
@click.option("--standard", "kind", flag_value=STANDARD, help="Standard machines only (no enclave).")
|
|
58
|
+
@click.option("--confidential", "kind", flag_value=CONFIDENTIAL, help="Confidential VM tiers only (Intel TDX).")
|
|
59
|
+
@click.option("--gpu", help="Filter by GPU model, e.g. H100, A6000, 4090.")
|
|
60
|
+
@click.option("--max-price", type=float, help="Maximum price per hour (USD).")
|
|
61
|
+
@click.option("--min-gpus", type=click.IntRange(1, 64), help="Minimum number of GPUs.")
|
|
62
|
+
@click.option("--limit", type=click.IntRange(1, 1000), default=15, show_default=True, help="Rows per kind.")
|
|
63
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output (no row limit).")
|
|
64
|
+
@pass_state
|
|
65
|
+
def machines_cmd(state: AppState, kind: Optional[str], gpu: Optional[str], max_price: Optional[float],
|
|
66
|
+
min_gpus: Optional[int], limit: int, as_json: bool) -> None:
|
|
67
|
+
"""List deployable machines with the hourly price you are charged."""
|
|
68
|
+
found = filter_machines(state.client().list_machines(kind or "all"), gpu, max_price, min_gpus)
|
|
69
|
+
if as_json:
|
|
70
|
+
echo_json([m.to_dict() for m in found])
|
|
71
|
+
return
|
|
72
|
+
conf = [m for m in found if m.confidential]
|
|
73
|
+
std = [m for m in found if not m.confidential]
|
|
74
|
+
if not found:
|
|
75
|
+
info("No machine matches these filters right now.")
|
|
76
|
+
return
|
|
77
|
+
if conf:
|
|
78
|
+
_print_confidential(conf[:limit])
|
|
79
|
+
hint("Deploy: voltagegpu deploy confidential --tier TIER")
|
|
80
|
+
if conf and std:
|
|
81
|
+
info("")
|
|
82
|
+
if std:
|
|
83
|
+
_print_standard(std[:limit], len(std))
|
|
84
|
+
hint("Deploy: voltagegpu deploy standard --machine MACHINE_ID (or --cheapest)")
|
|
85
|
+
hint("Prices are per hour for the whole machine. The first hour is charged at deploy, then per second; "
|
|
86
|
+
"the unused part is refunded when you stop a standard pod.")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@click.command("templates")
|
|
90
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
91
|
+
@pass_state
|
|
92
|
+
def templates_cmd(state: AppState, as_json: bool) -> None:
|
|
93
|
+
"""List the images available for standard pods (--template of `deploy standard`)."""
|
|
94
|
+
items = state.client().list_templates()
|
|
95
|
+
if as_json:
|
|
96
|
+
echo_json([t.to_dict() for t in items])
|
|
97
|
+
return
|
|
98
|
+
table(
|
|
99
|
+
"Standard pod templates",
|
|
100
|
+
[("TEMPLATE ID", {"style": "cyan", "no_wrap": True}), ("NAME",), ("DEFAULT", {"justify": "center"})],
|
|
101
|
+
[(t.id, t.name, "yes" if t.default else "") for t in items],
|
|
102
|
+
)
|
|
103
|
+
hint("Confidential VMs run Ubuntu 24.04 LTS; they take no template.")
|
volt/cli/cmd_misc.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""`voltagegpu verify` (delegates to voltage-verify) and retired commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib.util
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from typing import List, Sequence, Tuple
|
|
9
|
+
|
|
10
|
+
import click
|
|
11
|
+
|
|
12
|
+
from .output import fail, info
|
|
13
|
+
from .state import AppState, pass_state
|
|
14
|
+
|
|
15
|
+
VERIFY_SUBCOMMANDS = ("manifest", "attest", "verify", "quote", "inspect", "selftest")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def verify_argv(args: Sequence[str]) -> List[str]:
|
|
19
|
+
"""`voltagegpu verify bundle.json --offline` -> `voltage-verify verify bundle.json --offline`.
|
|
20
|
+
|
|
21
|
+
Any voltage-verify subcommand (manifest, attest, quote, ...) passes through
|
|
22
|
+
unchanged; with no argument, voltage-verify prints its own help.
|
|
23
|
+
"""
|
|
24
|
+
rest = list(args)
|
|
25
|
+
if rest and rest[0] not in VERIFY_SUBCOMMANDS and not rest[0].startswith("-"):
|
|
26
|
+
rest = ["verify", *rest]
|
|
27
|
+
return [sys.executable, "-m", "voltage_verify", *rest]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@click.command("verify", context_settings={"ignore_unknown_options": True, "allow_extra_args": True, "help_option_names": []})
|
|
31
|
+
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
|
|
32
|
+
def verify_cmd(args: Tuple[str, ...]) -> None:
|
|
33
|
+
"""Verify a Confidential VM attestation bundle offline (runs voltage-verify).
|
|
34
|
+
|
|
35
|
+
\b
|
|
36
|
+
Examples:
|
|
37
|
+
voltagegpu verify bundle.json --offline
|
|
38
|
+
voltagegpu verify bundle.json --challenge <hex> --gpus 1
|
|
39
|
+
voltagegpu verify quote quote.bin
|
|
40
|
+
voltagegpu verify --help # voltage-verify's own help
|
|
41
|
+
\b
|
|
42
|
+
Needs: pip install voltage-verify (or: pip install "voltagegpu-cli[verify]")
|
|
43
|
+
"""
|
|
44
|
+
if importlib.util.find_spec("voltage_verify") is None:
|
|
45
|
+
fail('voltage-verify is not installed in this environment. Run: pip install voltage-verify', code=2)
|
|
46
|
+
# A list, never a shell: arguments reach voltage-verify exactly as typed.
|
|
47
|
+
raise click.exceptions.Exit(subprocess.call(verify_argv(args))) # noqa: S603
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
_RETIRED = (
|
|
51
|
+
"Confidential containers were retired on 2026-10-01. Use a Confidential VM instead:\n"
|
|
52
|
+
" voltagegpu machines --confidential\n"
|
|
53
|
+
" voltagegpu deploy confidential --tier rtx6000b-small"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@click.group("cc", hidden=True)
|
|
58
|
+
def cc_group() -> None:
|
|
59
|
+
"""Retired: Confidential containers. Use `voltagegpu deploy confidential`."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@cc_group.command("inventory", context_settings={"ignore_unknown_options": True, "allow_extra_args": True})
|
|
63
|
+
def cc_inventory() -> None:
|
|
64
|
+
fail(_RETIRED, code=2)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@cc_group.command("deploy", context_settings={"ignore_unknown_options": True, "allow_extra_args": True})
|
|
68
|
+
def cc_deploy() -> None:
|
|
69
|
+
fail(_RETIRED, code=2)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@click.group("account", hidden=True)
|
|
73
|
+
def account_group() -> None:
|
|
74
|
+
"""Earlier releases: use `voltagegpu balance`."""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@account_group.command("balance")
|
|
78
|
+
@click.pass_context
|
|
79
|
+
def account_balance(ctx: click.Context) -> None:
|
|
80
|
+
from .cmd_account import balance_cmd
|
|
81
|
+
|
|
82
|
+
ctx.invoke(balance_cmd, as_json=False)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@account_group.command("info")
|
|
86
|
+
@pass_state
|
|
87
|
+
def account_info(state: AppState) -> None:
|
|
88
|
+
info("Account details are on https://voltagegpu.com/settings. Balance: voltagegpu balance")
|