voltagegpu-cli 2.0.3__tar.gz → 2.0.4__tar.gz
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.
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/.gitignore +14 -14
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/LICENSE +21 -21
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/PKG-INFO +7 -1
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/README.md +6 -0
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/pyproject.toml +2 -1
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/__init__.py +1 -1
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/__main__.py +5 -5
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/__init__.py +5 -5
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/cmd_account.py +179 -179
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/cmd_deploy.py +218 -218
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/cmd_machines.py +103 -103
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/cmd_misc.py +105 -105
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/cmd_pods.py +188 -188
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/main.py +132 -132
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/output.py +98 -98
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/state.py +35 -35
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/cli/vgpu.py +500 -500
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/mcp/__init__.py +1 -1
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/mcp/server.py +351 -351
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/__init__.py +36 -36
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/attest.py +317 -317
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/catalog.py +163 -163
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/client.py +240 -240
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/config.py +202 -202
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/errors.py +82 -82
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/fleet.py +220 -220
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/models.py +336 -336
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/remote.py +140 -140
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/ssh.py +157 -157
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/ttl.py +104 -104
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/scripts/snp-proof-in-the-vm.sh +0 -0
- {voltagegpu_cli-2.0.3 → voltagegpu_cli-2.0.4}/volt/sdk/scripts/two-proofs-in-the-vm.sh +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
__pycache__/
|
|
2
|
-
*.py[cod]
|
|
3
|
-
*.egg-info/
|
|
4
|
-
.venv*/
|
|
5
|
-
venv*/
|
|
6
|
-
build/
|
|
7
|
-
dist/
|
|
8
|
-
.pytest_cache/
|
|
9
|
-
.ruff_cache/
|
|
10
|
-
.coverage
|
|
11
|
-
htmlcov/
|
|
12
|
-
.env
|
|
13
|
-
*.ini
|
|
14
|
-
!pytest.ini
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
.venv*/
|
|
5
|
+
venv*/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.coverage
|
|
11
|
+
htmlcov/
|
|
12
|
+
.env
|
|
13
|
+
*.ini
|
|
14
|
+
!pytest.ini
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-2026 VOLTAGE EI (VoltageGPU)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 VOLTAGE EI (VoltageGPU)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: voltagegpu-cli
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.4
|
|
4
4
|
Summary: VoltageGPU CLI and Python SDK: Confidential VMs (Intel TDX), Confidential CPU (AMD SEV-SNP), standard GPU pods, dedicated machines and sandboxes, with the vgpu command for scripts and AI agents.
|
|
5
5
|
Project-URL: Homepage, https://voltagegpu.com
|
|
6
6
|
Project-URL: Documentation, https://docs.voltagegpu.com/cli
|
|
@@ -263,6 +263,8 @@ With `--json`, an error is also printed on stdout as
|
|
|
263
263
|
|
|
264
264
|
### Local MCP server
|
|
265
265
|
|
|
266
|
+
<!-- mcp-name: io.github.VoltageGPU/voltagegpu-cli -->
|
|
267
|
+
|
|
266
268
|
`vgpu mcp` serves the tools `ls`, `up`, `ps`, `exec`, `scp`, `rm`, `attest`,
|
|
267
269
|
`inference` and `whoami` over stdio. It runs on your machine because `exec`,
|
|
268
270
|
`scp` and `attest` use your SSH private key, which never leaves it. Same
|
|
@@ -278,6 +280,10 @@ which takes the `volt_` key from `VOLT_API_KEY`.
|
|
|
278
280
|
claude mcp add voltagegpu -e VOLT_API_KEY=volt_... -- vgpu mcp # Claude Code
|
|
279
281
|
```
|
|
280
282
|
|
|
283
|
+
A client that starts servers from the package name runs the same program with
|
|
284
|
+
`uvx voltagegpu-cli mcp`: the package installs a `voltagegpu-cli` executable,
|
|
285
|
+
the same entry point as `vgpu`.
|
|
286
|
+
|
|
281
287
|
```toml
|
|
282
288
|
# Codex: ~/.codex/config.toml
|
|
283
289
|
[mcp_servers.voltagegpu]
|
|
@@ -199,6 +199,8 @@ With `--json`, an error is also printed on stdout as
|
|
|
199
199
|
|
|
200
200
|
### Local MCP server
|
|
201
201
|
|
|
202
|
+
<!-- mcp-name: io.github.VoltageGPU/voltagegpu-cli -->
|
|
203
|
+
|
|
202
204
|
`vgpu mcp` serves the tools `ls`, `up`, `ps`, `exec`, `scp`, `rm`, `attest`,
|
|
203
205
|
`inference` and `whoami` over stdio. It runs on your machine because `exec`,
|
|
204
206
|
`scp` and `attest` use your SSH private key, which never leaves it. Same
|
|
@@ -214,6 +216,10 @@ which takes the `volt_` key from `VOLT_API_KEY`.
|
|
|
214
216
|
claude mcp add voltagegpu -e VOLT_API_KEY=volt_... -- vgpu mcp # Claude Code
|
|
215
217
|
```
|
|
216
218
|
|
|
219
|
+
A client that starts servers from the package name runs the same program with
|
|
220
|
+
`uvx voltagegpu-cli mcp`: the package installs a `voltagegpu-cli` executable,
|
|
221
|
+
the same entry point as `vgpu`.
|
|
222
|
+
|
|
217
223
|
```toml
|
|
218
224
|
# Codex: ~/.codex/config.toml
|
|
219
225
|
[mcp_servers.voltagegpu]
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "voltagegpu-cli"
|
|
7
|
-
version = "2.0.
|
|
7
|
+
version = "2.0.4"
|
|
8
8
|
description = "VoltageGPU CLI and Python SDK: Confidential VMs (Intel TDX), Confidential CPU (AMD SEV-SNP), standard GPU pods, dedicated machines and sandboxes, with the vgpu command for scripts and AI agents."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -53,6 +53,7 @@ dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.6", "build>=1.2", "twine>=5"]
|
|
|
53
53
|
voltagegpu = "volt.cli.main:main"
|
|
54
54
|
volt = "volt.cli.main:main"
|
|
55
55
|
vgpu = "volt.cli.vgpu:main"
|
|
56
|
+
voltagegpu-cli = "volt.cli.vgpu:main"
|
|
56
57
|
|
|
57
58
|
[project.urls]
|
|
58
59
|
Homepage = "https://voltagegpu.com"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"""`python -m volt` runs the CLI."""
|
|
2
|
-
|
|
3
|
-
from .cli.main import main
|
|
4
|
-
|
|
5
|
-
main()
|
|
1
|
+
"""`python -m volt` runs the CLI."""
|
|
2
|
+
|
|
3
|
+
from .cli.main import main
|
|
4
|
+
|
|
5
|
+
main()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"""The `voltagegpu` command line."""
|
|
2
|
-
|
|
3
|
-
from .main import cli, main
|
|
4
|
-
|
|
5
|
-
__all__ = ["cli", "main"]
|
|
1
|
+
"""The `voltagegpu` command line."""
|
|
2
|
+
|
|
3
|
+
from .main import cli, main
|
|
4
|
+
|
|
5
|
+
__all__ = ["cli", "main"]
|
|
@@ -1,179 +1,179 @@
|
|
|
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, esc, 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 {esc(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 {esc(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 {esc(cfg.base_url)}")
|
|
90
|
-
info(f"API key {esc(cfg.masked_key)} from {esc(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
|
-
if bal.balance is None:
|
|
111
|
-
info(f"Balance hidden: {esc(bal.balance_hidden or 'this key cannot read the account balance')}")
|
|
112
|
-
else:
|
|
113
|
-
console.print(f"Balance [bold green]{money(bal.balance)}[/bold green] {esc(bal.currency)}")
|
|
114
|
-
if bal.active_pods is not None:
|
|
115
|
-
info(f"Running {bal.active_pods} pod{'s' if bal.active_pods != 1 else ''}")
|
|
116
|
-
hint(f"Top up: {esc(bal.top_up_url)}")
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@click.group("ssh-keys")
|
|
120
|
-
def ssh_keys_group() -> None:
|
|
121
|
-
"""Manage the SSH public keys injected into your pods."""
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
@ssh_keys_group.command("list")
|
|
125
|
-
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
126
|
-
@pass_state
|
|
127
|
-
def ssh_keys_list(state: AppState, as_json: bool) -> None:
|
|
128
|
-
"""List your SSH keys."""
|
|
129
|
-
keys = state.client().list_ssh_keys()
|
|
130
|
-
if as_json:
|
|
131
|
-
echo_json([k.to_dict() for k in keys])
|
|
132
|
-
return
|
|
133
|
-
if not keys:
|
|
134
|
-
info("No SSH key yet. Add one: voltagegpu ssh-keys add")
|
|
135
|
-
return
|
|
136
|
-
table("SSH keys", [("KEY ID", {"style": "cyan", "no_wrap": True}), ("NAME",), ("KEY",), ("ADDED",)],
|
|
137
|
-
[(k.id, k.name, k.summary, (k.created_at or "")[:10]) for k in keys])
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
@ssh_keys_group.command("add")
|
|
141
|
-
@click.option("--name", help="Label for the key (default: the file name).")
|
|
142
|
-
@click.option("--file", "key_file", type=click.Path(exists=True, dir_okay=False, path_type=Path),
|
|
143
|
-
help="Public key file (default: ~/.ssh/id_ed25519.pub, id_ecdsa.pub or id_rsa.pub).")
|
|
144
|
-
@click.option("--key", "key_text", help="Public key string instead of a file.")
|
|
145
|
-
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
146
|
-
@pass_state
|
|
147
|
-
def ssh_keys_add(state: AppState, name: Optional[str], key_file: Optional[Path], key_text: Optional[str], as_json: bool) -> None:
|
|
148
|
-
"""Register an SSH public key."""
|
|
149
|
-
if key_file and key_text:
|
|
150
|
-
fail("Give --file or --key, not both.", code=2)
|
|
151
|
-
if not key_text:
|
|
152
|
-
path = key_file or default_public_key_file()
|
|
153
|
-
if path is None:
|
|
154
|
-
fail("No public key found in ~/.ssh. Create one with: ssh-keygen -t ed25519", code=2)
|
|
155
|
-
if path.suffix != ".pub" and path.with_suffix(path.suffix + ".pub").exists():
|
|
156
|
-
fail(f"{path} looks like a private key. Use {path}.pub", code=2)
|
|
157
|
-
key_text = path.read_text(encoding="utf-8", errors="replace")
|
|
158
|
-
name = name or path.name
|
|
159
|
-
public_key = read_public_key(key_text)
|
|
160
|
-
key = state.client().add_ssh_key(name or "cli-key", public_key)
|
|
161
|
-
if as_json:
|
|
162
|
-
echo_json(key.to_dict())
|
|
163
|
-
else:
|
|
164
|
-
console.print(f"[green]Added.[/green] {esc(key.name)} ({esc(key.id)})")
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
@ssh_keys_group.command("delete")
|
|
168
|
-
@click.argument("key_id")
|
|
169
|
-
@click.option("-y", "--yes", is_flag=True, help="Do not ask for confirmation.")
|
|
170
|
-
@pass_state
|
|
171
|
-
def ssh_keys_delete(state: AppState, key_id: str, yes: bool) -> None:
|
|
172
|
-
"""Delete an SSH key (running pods keep the keys they were created with)."""
|
|
173
|
-
if not yes:
|
|
174
|
-
if not is_interactive():
|
|
175
|
-
fail("Re-run with --yes to confirm in a script.", code=2)
|
|
176
|
-
if not click.confirm(f"Delete SSH key {key_id}?", default=False):
|
|
177
|
-
raise click.exceptions.Exit(1)
|
|
178
|
-
state.client().delete_ssh_key(key_id)
|
|
179
|
-
console.print(f"[green]Deleted.[/green] {esc(key_id)}")
|
|
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, esc, 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 {esc(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 {esc(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 {esc(cfg.base_url)}")
|
|
90
|
+
info(f"API key {esc(cfg.masked_key)} from {esc(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
|
+
if bal.balance is None:
|
|
111
|
+
info(f"Balance hidden: {esc(bal.balance_hidden or 'this key cannot read the account balance')}")
|
|
112
|
+
else:
|
|
113
|
+
console.print(f"Balance [bold green]{money(bal.balance)}[/bold green] {esc(bal.currency)}")
|
|
114
|
+
if bal.active_pods is not None:
|
|
115
|
+
info(f"Running {bal.active_pods} pod{'s' if bal.active_pods != 1 else ''}")
|
|
116
|
+
hint(f"Top up: {esc(bal.top_up_url)}")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@click.group("ssh-keys")
|
|
120
|
+
def ssh_keys_group() -> None:
|
|
121
|
+
"""Manage the SSH public keys injected into your pods."""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@ssh_keys_group.command("list")
|
|
125
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
126
|
+
@pass_state
|
|
127
|
+
def ssh_keys_list(state: AppState, as_json: bool) -> None:
|
|
128
|
+
"""List your SSH keys."""
|
|
129
|
+
keys = state.client().list_ssh_keys()
|
|
130
|
+
if as_json:
|
|
131
|
+
echo_json([k.to_dict() for k in keys])
|
|
132
|
+
return
|
|
133
|
+
if not keys:
|
|
134
|
+
info("No SSH key yet. Add one: voltagegpu ssh-keys add")
|
|
135
|
+
return
|
|
136
|
+
table("SSH keys", [("KEY ID", {"style": "cyan", "no_wrap": True}), ("NAME",), ("KEY",), ("ADDED",)],
|
|
137
|
+
[(k.id, k.name, k.summary, (k.created_at or "")[:10]) for k in keys])
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@ssh_keys_group.command("add")
|
|
141
|
+
@click.option("--name", help="Label for the key (default: the file name).")
|
|
142
|
+
@click.option("--file", "key_file", type=click.Path(exists=True, dir_okay=False, path_type=Path),
|
|
143
|
+
help="Public key file (default: ~/.ssh/id_ed25519.pub, id_ecdsa.pub or id_rsa.pub).")
|
|
144
|
+
@click.option("--key", "key_text", help="Public key string instead of a file.")
|
|
145
|
+
@click.option("--json", "as_json", is_flag=True, help="Machine-readable output.")
|
|
146
|
+
@pass_state
|
|
147
|
+
def ssh_keys_add(state: AppState, name: Optional[str], key_file: Optional[Path], key_text: Optional[str], as_json: bool) -> None:
|
|
148
|
+
"""Register an SSH public key."""
|
|
149
|
+
if key_file and key_text:
|
|
150
|
+
fail("Give --file or --key, not both.", code=2)
|
|
151
|
+
if not key_text:
|
|
152
|
+
path = key_file or default_public_key_file()
|
|
153
|
+
if path is None:
|
|
154
|
+
fail("No public key found in ~/.ssh. Create one with: ssh-keygen -t ed25519", code=2)
|
|
155
|
+
if path.suffix != ".pub" and path.with_suffix(path.suffix + ".pub").exists():
|
|
156
|
+
fail(f"{path} looks like a private key. Use {path}.pub", code=2)
|
|
157
|
+
key_text = path.read_text(encoding="utf-8", errors="replace")
|
|
158
|
+
name = name or path.name
|
|
159
|
+
public_key = read_public_key(key_text)
|
|
160
|
+
key = state.client().add_ssh_key(name or "cli-key", public_key)
|
|
161
|
+
if as_json:
|
|
162
|
+
echo_json(key.to_dict())
|
|
163
|
+
else:
|
|
164
|
+
console.print(f"[green]Added.[/green] {esc(key.name)} ({esc(key.id)})")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@ssh_keys_group.command("delete")
|
|
168
|
+
@click.argument("key_id")
|
|
169
|
+
@click.option("-y", "--yes", is_flag=True, help="Do not ask for confirmation.")
|
|
170
|
+
@pass_state
|
|
171
|
+
def ssh_keys_delete(state: AppState, key_id: str, yes: bool) -> None:
|
|
172
|
+
"""Delete an SSH key (running pods keep the keys they were created with)."""
|
|
173
|
+
if not yes:
|
|
174
|
+
if not is_interactive():
|
|
175
|
+
fail("Re-run with --yes to confirm in a script.", code=2)
|
|
176
|
+
if not click.confirm(f"Delete SSH key {key_id}?", default=False):
|
|
177
|
+
raise click.exceptions.Exit(1)
|
|
178
|
+
state.client().delete_ssh_key(key_id)
|
|
179
|
+
console.print(f"[green]Deleted.[/green] {esc(key_id)}")
|