v6ctl 0.1.2__tar.gz → 0.3.0__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.
- {v6ctl-0.1.2/v6ctl.egg-info → v6ctl-0.3.0}/PKG-INFO +23 -2
- {v6ctl-0.1.2 → v6ctl-0.3.0}/README.md +21 -1
- {v6ctl-0.1.2 → v6ctl-0.3.0}/pyproject.toml +5 -1
- {v6ctl-0.1.2 → v6ctl-0.3.0/v6ctl.egg-info}/PKG-INFO +23 -2
- {v6ctl-0.1.2 → v6ctl-0.3.0}/v6ctl.egg-info/requires.txt +1 -0
- {v6ctl-0.1.2 → v6ctl-0.3.0}/v6ctl.py +409 -62
- {v6ctl-0.1.2 → v6ctl-0.3.0}/LICENSE +0 -0
- {v6ctl-0.1.2 → v6ctl-0.3.0}/setup.cfg +0 -0
- {v6ctl-0.1.2 → v6ctl-0.3.0}/v6ctl.egg-info/SOURCES.txt +0 -0
- {v6ctl-0.1.2 → v6ctl-0.3.0}/v6ctl.egg-info/dependency_links.txt +0 -0
- {v6ctl-0.1.2 → v6ctl-0.3.0}/v6ctl.egg-info/entry_points.txt +0 -0
- {v6ctl-0.1.2 → v6ctl-0.3.0}/v6ctl.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: v6ctl
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: The official CLI for the v6Node Reseller API.
|
|
5
5
|
Author-email: v6Node <support@v6node.com>
|
|
6
6
|
License: MIT
|
|
@@ -26,6 +26,7 @@ Description-Content-Type: text/markdown
|
|
|
26
26
|
License-File: LICENSE
|
|
27
27
|
Requires-Dist: click>=8.1
|
|
28
28
|
Requires-Dist: rich>=13.0
|
|
29
|
+
Requires-Dist: rich-click>=1.7
|
|
29
30
|
Requires-Dist: requests>=2.31
|
|
30
31
|
Dynamic: license-file
|
|
31
32
|
|
|
@@ -87,7 +88,8 @@ Alternatively, set `V6_TOKEN` in your environment.
|
|
|
87
88
|
```bash
|
|
88
89
|
v6ctl nodes list # list your nodes
|
|
89
90
|
v6ctl nodes show <pay-id> # full details for a node
|
|
90
|
-
v6ctl nodes create -r
|
|
91
|
+
v6ctl nodes create -r frankfurt-2 -p 8gb -k laptop -t debian-13
|
|
92
|
+
v6ctl nodes create # run on a TTY → guided prompts
|
|
91
93
|
v6ctl nodes reboot <pay-id>
|
|
92
94
|
v6ctl nodes delete <pay-id>
|
|
93
95
|
|
|
@@ -103,6 +105,25 @@ v6ctl templates # available OS templates
|
|
|
103
105
|
|
|
104
106
|
Run `v6ctl --help` or `v6ctl <command> --help` for the full reference.
|
|
105
107
|
|
|
108
|
+
### Friendly `nodes create`
|
|
109
|
+
|
|
110
|
+
`--region`, `--plan`, and `--key` each accept a numeric ID, a short slug, a
|
|
111
|
+
full slug, or an exact name. Numeric inputs are looked up as an ID first; if
|
|
112
|
+
no such ID exists, the value falls through to a name/slug match so keys with
|
|
113
|
+
numeric descriptions remain reachable.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# All equivalent (assuming the IDs/slugs exist in your account):
|
|
117
|
+
v6ctl nodes create -r 7 -p 14 -k 3
|
|
118
|
+
v6ctl nodes create -r frankfurt-2 -p 8gb -k laptop
|
|
119
|
+
v6ctl nodes create -r frankfurt-2 -p node-8gb-g2 -k laptop
|
|
120
|
+
v6ctl nodes create -r "Frankfurt 2" -p "Node 8GB G2" -k "My Laptop"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Run `v6ctl nodes create` on a terminal with any flag omitted and you'll be
|
|
124
|
+
prompted with the list of candidates. Omitting a flag in non-interactive
|
|
125
|
+
mode (pipe, CI) or with `--json` is an error — scripts stay fail-fast.
|
|
126
|
+
|
|
106
127
|
## JSON output
|
|
107
128
|
|
|
108
129
|
Every command supports `--json` for scripting:
|
|
@@ -56,7 +56,8 @@ Alternatively, set `V6_TOKEN` in your environment.
|
|
|
56
56
|
```bash
|
|
57
57
|
v6ctl nodes list # list your nodes
|
|
58
58
|
v6ctl nodes show <pay-id> # full details for a node
|
|
59
|
-
v6ctl nodes create -r
|
|
59
|
+
v6ctl nodes create -r frankfurt-2 -p 8gb -k laptop -t debian-13
|
|
60
|
+
v6ctl nodes create # run on a TTY → guided prompts
|
|
60
61
|
v6ctl nodes reboot <pay-id>
|
|
61
62
|
v6ctl nodes delete <pay-id>
|
|
62
63
|
|
|
@@ -72,6 +73,25 @@ v6ctl templates # available OS templates
|
|
|
72
73
|
|
|
73
74
|
Run `v6ctl --help` or `v6ctl <command> --help` for the full reference.
|
|
74
75
|
|
|
76
|
+
### Friendly `nodes create`
|
|
77
|
+
|
|
78
|
+
`--region`, `--plan`, and `--key` each accept a numeric ID, a short slug, a
|
|
79
|
+
full slug, or an exact name. Numeric inputs are looked up as an ID first; if
|
|
80
|
+
no such ID exists, the value falls through to a name/slug match so keys with
|
|
81
|
+
numeric descriptions remain reachable.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# All equivalent (assuming the IDs/slugs exist in your account):
|
|
85
|
+
v6ctl nodes create -r 7 -p 14 -k 3
|
|
86
|
+
v6ctl nodes create -r frankfurt-2 -p 8gb -k laptop
|
|
87
|
+
v6ctl nodes create -r frankfurt-2 -p node-8gb-g2 -k laptop
|
|
88
|
+
v6ctl nodes create -r "Frankfurt 2" -p "Node 8GB G2" -k "My Laptop"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Run `v6ctl nodes create` on a terminal with any flag omitted and you'll be
|
|
92
|
+
prompted with the list of candidates. Omitting a flag in non-interactive
|
|
93
|
+
mode (pipe, CI) or with `--json` is an error — scripts stay fail-fast.
|
|
94
|
+
|
|
75
95
|
## JSON output
|
|
76
96
|
|
|
77
97
|
Every command supports `--json` for scripting:
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "v6ctl"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
8
|
description = "The official CLI for the v6Node Reseller API."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -29,6 +29,7 @@ classifiers = [
|
|
|
29
29
|
dependencies = [
|
|
30
30
|
"click>=8.1",
|
|
31
31
|
"rich>=13.0",
|
|
32
|
+
"rich-click>=1.7",
|
|
32
33
|
"requests>=2.31",
|
|
33
34
|
]
|
|
34
35
|
|
|
@@ -42,3 +43,6 @@ v6ctl = "v6ctl:cli"
|
|
|
42
43
|
|
|
43
44
|
[tool.setuptools]
|
|
44
45
|
py-modules = ["v6ctl"]
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.dynamic]
|
|
48
|
+
version = { attr = "v6ctl.__version__" }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: v6ctl
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: The official CLI for the v6Node Reseller API.
|
|
5
5
|
Author-email: v6Node <support@v6node.com>
|
|
6
6
|
License: MIT
|
|
@@ -26,6 +26,7 @@ Description-Content-Type: text/markdown
|
|
|
26
26
|
License-File: LICENSE
|
|
27
27
|
Requires-Dist: click>=8.1
|
|
28
28
|
Requires-Dist: rich>=13.0
|
|
29
|
+
Requires-Dist: rich-click>=1.7
|
|
29
30
|
Requires-Dist: requests>=2.31
|
|
30
31
|
Dynamic: license-file
|
|
31
32
|
|
|
@@ -87,7 +88,8 @@ Alternatively, set `V6_TOKEN` in your environment.
|
|
|
87
88
|
```bash
|
|
88
89
|
v6ctl nodes list # list your nodes
|
|
89
90
|
v6ctl nodes show <pay-id> # full details for a node
|
|
90
|
-
v6ctl nodes create -r
|
|
91
|
+
v6ctl nodes create -r frankfurt-2 -p 8gb -k laptop -t debian-13
|
|
92
|
+
v6ctl nodes create # run on a TTY → guided prompts
|
|
91
93
|
v6ctl nodes reboot <pay-id>
|
|
92
94
|
v6ctl nodes delete <pay-id>
|
|
93
95
|
|
|
@@ -103,6 +105,25 @@ v6ctl templates # available OS templates
|
|
|
103
105
|
|
|
104
106
|
Run `v6ctl --help` or `v6ctl <command> --help` for the full reference.
|
|
105
107
|
|
|
108
|
+
### Friendly `nodes create`
|
|
109
|
+
|
|
110
|
+
`--region`, `--plan`, and `--key` each accept a numeric ID, a short slug, a
|
|
111
|
+
full slug, or an exact name. Numeric inputs are looked up as an ID first; if
|
|
112
|
+
no such ID exists, the value falls through to a name/slug match so keys with
|
|
113
|
+
numeric descriptions remain reachable.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# All equivalent (assuming the IDs/slugs exist in your account):
|
|
117
|
+
v6ctl nodes create -r 7 -p 14 -k 3
|
|
118
|
+
v6ctl nodes create -r frankfurt-2 -p 8gb -k laptop
|
|
119
|
+
v6ctl nodes create -r frankfurt-2 -p node-8gb-g2 -k laptop
|
|
120
|
+
v6ctl nodes create -r "Frankfurt 2" -p "Node 8GB G2" -k "My Laptop"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Run `v6ctl nodes create` on a terminal with any flag omitted and you'll be
|
|
124
|
+
prompted with the list of candidates. Omitting a flag in non-interactive
|
|
125
|
+
mode (pipe, CI) or with `--json` is an error — scripts stay fail-fast.
|
|
126
|
+
|
|
106
127
|
## JSON output
|
|
107
128
|
|
|
108
129
|
Every command supports `--json` for scripting:
|
|
@@ -13,20 +13,38 @@ from __future__ import annotations
|
|
|
13
13
|
import functools
|
|
14
14
|
import json as _json
|
|
15
15
|
import os
|
|
16
|
+
import re
|
|
16
17
|
import sys
|
|
17
18
|
from pathlib import Path
|
|
18
19
|
from typing import Any
|
|
19
20
|
|
|
20
|
-
import click
|
|
21
|
+
import rich_click as click
|
|
21
22
|
import requests
|
|
22
23
|
from rich import box
|
|
23
24
|
from rich.console import Console
|
|
24
25
|
from rich.panel import Panel
|
|
25
26
|
from rich.pretty import Pretty
|
|
27
|
+
from rich.prompt import Prompt
|
|
26
28
|
from rich.table import Table
|
|
27
29
|
from rich.text import Text
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
click.rich_click.USE_RICH_MARKUP = True
|
|
32
|
+
click.rich_click.SHOW_ARGUMENTS = True
|
|
33
|
+
click.rich_click.GROUP_ARGUMENTS_OPTIONS = False
|
|
34
|
+
click.rich_click.STYLE_OPTION = "bold cyan"
|
|
35
|
+
click.rich_click.STYLE_ARGUMENT = "bold cyan"
|
|
36
|
+
click.rich_click.STYLE_COMMAND = "bold cyan"
|
|
37
|
+
click.rich_click.STYLE_SWITCH = "bold green"
|
|
38
|
+
click.rich_click.STYLE_METAVAR = "dim cyan"
|
|
39
|
+
click.rich_click.STYLE_HEADER_TEXT = "bold"
|
|
40
|
+
click.rich_click.STYLE_HELPTEXT = ""
|
|
41
|
+
click.rich_click.STYLE_HELPTEXT_FIRST_LINE = "bold"
|
|
42
|
+
click.rich_click.STYLE_OPTIONS_PANEL_BORDER = "dim"
|
|
43
|
+
click.rich_click.STYLE_COMMANDS_PANEL_BORDER = "dim"
|
|
44
|
+
click.rich_click.STYLE_USAGE = "bold yellow"
|
|
45
|
+
click.rich_click.MAX_WIDTH = 100
|
|
46
|
+
|
|
47
|
+
__version__ = "0.3.0"
|
|
30
48
|
|
|
31
49
|
DEFAULT_API_URL = "https://cloud.v6node.com/api/v1"
|
|
32
50
|
|
|
@@ -121,12 +139,21 @@ class V6Client:
|
|
|
121
139
|
raise V6Error(resp.status_code, "BAD_RESPONSE", resp.text[:200])
|
|
122
140
|
|
|
123
141
|
if not resp.ok:
|
|
124
|
-
if isinstance(data, dict)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
142
|
+
if isinstance(data, dict):
|
|
143
|
+
base = data.get("error") or data.get("message") or str(data)[:200]
|
|
144
|
+
code = data.get("code") or (
|
|
145
|
+
"VALIDATION_ERROR" if resp.status_code == 422 else "ERROR"
|
|
146
|
+
)
|
|
147
|
+
fields = data.get("errors")
|
|
148
|
+
if isinstance(fields, dict) and fields:
|
|
149
|
+
detail = "; ".join(
|
|
150
|
+
f"{k}: {', '.join(v) if isinstance(v, list) else v}"
|
|
151
|
+
for k, v in fields.items()
|
|
152
|
+
)
|
|
153
|
+
message = f"{base} — {detail}" if base else detail
|
|
154
|
+
else:
|
|
155
|
+
message = base
|
|
156
|
+
raise V6Error(resp.status_code, code, message)
|
|
130
157
|
raise V6Error(resp.status_code, "UNKNOWN", str(data)[:200])
|
|
131
158
|
|
|
132
159
|
if isinstance(data, dict) and "data" in data:
|
|
@@ -344,9 +371,9 @@ def _print_keys(keys):
|
|
|
344
371
|
if not keys:
|
|
345
372
|
console.print("[dim]No SSH keys found.[/dim]")
|
|
346
373
|
return
|
|
347
|
-
t = Table(title="SSH Keys", box=box.
|
|
348
|
-
t.add_column("ID", style="
|
|
349
|
-
t.add_column("Description"
|
|
374
|
+
t = Table(title="SSH Keys", box=box.SIMPLE_HEAD, header_style="bold")
|
|
375
|
+
t.add_column("ID", style="cyan", justify="right")
|
|
376
|
+
t.add_column("Description")
|
|
350
377
|
t.add_column("Created", style="dim")
|
|
351
378
|
for k in keys:
|
|
352
379
|
t.add_row(str(k["id"]), k.get("description", ""), k.get("created_at", ""))
|
|
@@ -369,24 +396,24 @@ def _print_key(key):
|
|
|
369
396
|
# ── Nodes ────────────────────────────────────────────────
|
|
370
397
|
|
|
371
398
|
|
|
372
|
-
def _print_nodes(data):
|
|
399
|
+
def _print_nodes(data, all_ips: bool = False):
|
|
373
400
|
items = data.get("items", data) if isinstance(data, dict) else data
|
|
374
401
|
meta = data.get("meta") if isinstance(data, dict) else None
|
|
375
402
|
if not items:
|
|
376
403
|
console.print("[dim]No nodes found.[/dim]")
|
|
377
404
|
return
|
|
378
405
|
|
|
379
|
-
t = Table(title="Nodes", box=box.
|
|
380
|
-
for col, style in [
|
|
381
|
-
("ID", "
|
|
382
|
-
("Hostname", "
|
|
383
|
-
("Region", "
|
|
384
|
-
("Plan", "
|
|
385
|
-
("OS", "
|
|
386
|
-
("IP", "green"),
|
|
387
|
-
("Created", "dim"),
|
|
406
|
+
t = Table(title="Nodes", box=box.SIMPLE_HEAD, header_style="bold")
|
|
407
|
+
for col, style, no_wrap in [
|
|
408
|
+
("ID", "cyan", True),
|
|
409
|
+
("Hostname", "", True),
|
|
410
|
+
("Region", "", True),
|
|
411
|
+
("Plan", "", True),
|
|
412
|
+
("OS", "", True),
|
|
413
|
+
("IP", "green", not all_ips),
|
|
414
|
+
("Created", "dim", True),
|
|
388
415
|
]:
|
|
389
|
-
t.add_column(col, style=style, no_wrap=
|
|
416
|
+
t.add_column(col, style=style, no_wrap=no_wrap)
|
|
390
417
|
|
|
391
418
|
for n in items:
|
|
392
419
|
region = n.get("region") or {}
|
|
@@ -394,9 +421,13 @@ def _print_nodes(data):
|
|
|
394
421
|
region_str = region.get("title", "") if isinstance(region, dict) else str(region)
|
|
395
422
|
plan_str = plan.get("title", "") if isinstance(plan, dict) else str(plan)
|
|
396
423
|
addresses = n.get("addresses") or []
|
|
397
|
-
|
|
398
|
-
if
|
|
399
|
-
ip_str
|
|
424
|
+
ips = [a["ip"] for a in addresses if a.get("ip")]
|
|
425
|
+
if all_ips:
|
|
426
|
+
ip_str = "\n".join(ips)
|
|
427
|
+
elif len(ips) <= 2:
|
|
428
|
+
ip_str = ", ".join(ips)
|
|
429
|
+
else:
|
|
430
|
+
ip_str = ", ".join(ips[:2]) + f" [dim](+{len(ips) - 2})[/dim]"
|
|
400
431
|
locked = " [red]LOCKED[/red]" if n.get("is_locked") else ""
|
|
401
432
|
t.add_row(
|
|
402
433
|
n.get("pay_id", ""),
|
|
@@ -471,9 +502,9 @@ def _print_node(node, status=None, activity=None):
|
|
|
471
502
|
_print_node_status(status)
|
|
472
503
|
|
|
473
504
|
if activity and isinstance(activity, list):
|
|
474
|
-
t = Table(title="Recent Activity", box=box.
|
|
505
|
+
t = Table(title="Recent Activity", box=box.SIMPLE_HEAD, header_style="bold")
|
|
475
506
|
t.add_column("Date", style="dim", no_wrap=True)
|
|
476
|
-
t.add_column("Subject"
|
|
507
|
+
t.add_column("Subject")
|
|
477
508
|
t.add_column("Action", style="cyan")
|
|
478
509
|
for entry in activity[:5]:
|
|
479
510
|
t.add_row(
|
|
@@ -513,11 +544,11 @@ def _print_addresses(addresses):
|
|
|
513
544
|
if not addresses:
|
|
514
545
|
console.print("[dim]No addresses found.[/dim]")
|
|
515
546
|
return
|
|
516
|
-
t = Table(title="IP Addresses", box=box.
|
|
517
|
-
t.add_column("ID", style="
|
|
547
|
+
t = Table(title="IP Addresses", box=box.SIMPLE_HEAD, header_style="bold")
|
|
548
|
+
t.add_column("ID", style="cyan", justify="right")
|
|
518
549
|
t.add_column("IP", style="green")
|
|
519
|
-
t.add_column("Type"
|
|
520
|
-
t.add_column("Range"
|
|
550
|
+
t.add_column("Type")
|
|
551
|
+
t.add_column("Range")
|
|
521
552
|
t.add_column("Primary", justify="center")
|
|
522
553
|
t.add_column("Routing", style="dim")
|
|
523
554
|
for a in addresses:
|
|
@@ -565,10 +596,10 @@ def _print_webhooks(webhooks):
|
|
|
565
596
|
if not items:
|
|
566
597
|
console.print("[dim]No webhooks found.[/dim]")
|
|
567
598
|
return
|
|
568
|
-
t = Table(title="Webhooks", box=box.
|
|
569
|
-
t.add_column("ID", style="
|
|
570
|
-
t.add_column("URL"
|
|
571
|
-
t.add_column("Events"
|
|
599
|
+
t = Table(title="Webhooks", box=box.SIMPLE_HEAD, header_style="bold")
|
|
600
|
+
t.add_column("ID", style="cyan", justify="right")
|
|
601
|
+
t.add_column("URL")
|
|
602
|
+
t.add_column("Events")
|
|
572
603
|
t.add_column("Enabled", justify="center")
|
|
573
604
|
t.add_column("Approved", justify="center")
|
|
574
605
|
t.add_column("Created", style="dim")
|
|
@@ -612,9 +643,9 @@ def _print_webhook(webhook):
|
|
|
612
643
|
|
|
613
644
|
|
|
614
645
|
def _print_plans(plans):
|
|
615
|
-
t = Table(title="Plans", box=box.
|
|
616
|
-
t.add_column("ID", style="
|
|
617
|
-
t.add_column("Name"
|
|
646
|
+
t = Table(title="Plans", box=box.SIMPLE_HEAD, header_style="bold")
|
|
647
|
+
t.add_column("ID", style="cyan", justify="right")
|
|
648
|
+
t.add_column("Name")
|
|
618
649
|
t.add_column("Cores", justify="right")
|
|
619
650
|
t.add_column("Memory", justify="right")
|
|
620
651
|
t.add_column("Disk", justify="right")
|
|
@@ -638,9 +669,9 @@ def _print_plans(plans):
|
|
|
638
669
|
|
|
639
670
|
|
|
640
671
|
def _print_regions(regions):
|
|
641
|
-
t = Table(title="Regions", box=box.
|
|
642
|
-
t.add_column("ID", style="
|
|
643
|
-
t.add_column("Name"
|
|
672
|
+
t = Table(title="Regions", box=box.SIMPLE_HEAD, header_style="bold")
|
|
673
|
+
t.add_column("ID", style="cyan", justify="right")
|
|
674
|
+
t.add_column("Name")
|
|
644
675
|
t.add_column("Available", justify="center")
|
|
645
676
|
t.add_column("Templates", style="dim")
|
|
646
677
|
for r in regions:
|
|
@@ -653,11 +684,11 @@ def _print_regions(regions):
|
|
|
653
684
|
def _print_templates(templates):
|
|
654
685
|
# Grouped shape: [{family, label, versions: [...]}]
|
|
655
686
|
if isinstance(templates, list) and templates and "versions" in templates[0]:
|
|
656
|
-
t = Table(title="OS Templates", box=box.
|
|
657
|
-
t.add_column("Family", style="bold
|
|
687
|
+
t = Table(title="OS Templates", box=box.SIMPLE_HEAD, header_style="bold")
|
|
688
|
+
t.add_column("Family", style="bold")
|
|
658
689
|
t.add_column("ID", style="cyan", justify="right")
|
|
659
|
-
t.add_column("Slug"
|
|
660
|
-
t.add_column("Title"
|
|
690
|
+
t.add_column("Slug")
|
|
691
|
+
t.add_column("Title")
|
|
661
692
|
t.add_column("Version", style="dim")
|
|
662
693
|
t.add_column("LTS", justify="center")
|
|
663
694
|
for fam in templates:
|
|
@@ -673,9 +704,9 @@ def _print_templates(templates):
|
|
|
673
704
|
)
|
|
674
705
|
console.print(t)
|
|
675
706
|
elif isinstance(templates, list) and templates and isinstance(templates[0], dict):
|
|
676
|
-
t = Table(title="Templates", box=box.
|
|
677
|
-
t.add_column("ID", style="
|
|
678
|
-
t.add_column("Title"
|
|
707
|
+
t = Table(title="Templates", box=box.SIMPLE_HEAD, header_style="bold")
|
|
708
|
+
t.add_column("ID", style="cyan", justify="right")
|
|
709
|
+
t.add_column("Title")
|
|
679
710
|
t.add_column("Slug", style="dim")
|
|
680
711
|
for tpl in templates:
|
|
681
712
|
t.add_row(
|
|
@@ -688,6 +719,292 @@ def _print_templates(templates):
|
|
|
688
719
|
console.print(Pretty(templates))
|
|
689
720
|
|
|
690
721
|
|
|
722
|
+
# ═══════════════════════════════════════════════════════════
|
|
723
|
+
# Resolvers — accept ID, slug, or name for --region/--plan/--key
|
|
724
|
+
# ═══════════════════════════════════════════════════════════
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
def _slugify(s: str) -> str:
|
|
728
|
+
"""Normalize to lowercase kebab-case. Used for both input matching and slug generation."""
|
|
729
|
+
s = (s or "").strip().lower()
|
|
730
|
+
s = re.sub(r"\s+", "-", s)
|
|
731
|
+
return s
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def _plan_short_slug(p: dict) -> str | None:
|
|
735
|
+
"""{memory_mb/1024}gb, but only for whole-GB plans ≥1 GB. Otherwise None."""
|
|
736
|
+
mb = p.get("memory_mb") or 0
|
|
737
|
+
if mb >= 1024 and mb % 1024 == 0:
|
|
738
|
+
return f"{mb // 1024}gb"
|
|
739
|
+
return None
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
def _format_candidates(kind: str, candidates: list, rows) -> str:
|
|
743
|
+
"""Build the multi-line candidate listing appended to error messages."""
|
|
744
|
+
lines = [f" Available {kind}s:"]
|
|
745
|
+
for text in rows:
|
|
746
|
+
lines.append(f" {text}")
|
|
747
|
+
return "\n" + "\n".join(lines)
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
def _match_one(value: str, candidates: list, tiers: list):
|
|
751
|
+
"""
|
|
752
|
+
Walk match tiers against a normalized value.
|
|
753
|
+
tiers: list of functions (candidate -> str | None) — None skips that candidate in that tier.
|
|
754
|
+
Returns (matched_candidate_or_list, status) where status is "unique" | "ambiguous" | "none".
|
|
755
|
+
ID tier is built-in and runs first: if value parses as a positive int and matches a candidate's id, win.
|
|
756
|
+
If int-parse succeeds but no id matches, fall through to the other tiers (does NOT short-circuit).
|
|
757
|
+
"""
|
|
758
|
+
try:
|
|
759
|
+
as_id = int(value)
|
|
760
|
+
if as_id > 0:
|
|
761
|
+
for c in candidates:
|
|
762
|
+
if c.get("id") == as_id:
|
|
763
|
+
return c, "unique"
|
|
764
|
+
except ValueError:
|
|
765
|
+
pass
|
|
766
|
+
|
|
767
|
+
for tier_fn in tiers:
|
|
768
|
+
hits = [c for c in candidates if tier_fn(c) == value]
|
|
769
|
+
if len(hits) == 1:
|
|
770
|
+
return hits[0], "unique"
|
|
771
|
+
if len(hits) > 1:
|
|
772
|
+
return hits, "ambiguous"
|
|
773
|
+
|
|
774
|
+
return None, "none"
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
def _is_interactive() -> bool:
|
|
778
|
+
"""A prompt should fire: TTY on both streams, and --json is not set."""
|
|
779
|
+
ctx = click.get_current_context(silent=True)
|
|
780
|
+
json_mode = bool(ctx and ctx.obj and ctx.obj.get("json"))
|
|
781
|
+
return sys.stdin.isatty() and sys.stdout.isatty() and not json_mode
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _prompt_id(label: str, valid_ids: list[int]) -> int:
|
|
785
|
+
"""Prompt for an ID, retry up to 3 times, honor Ctrl-C/Ctrl-D."""
|
|
786
|
+
for _ in range(3):
|
|
787
|
+
try:
|
|
788
|
+
raw = Prompt.ask(f"[bold cyan]{label} ID[/bold cyan]")
|
|
789
|
+
except KeyboardInterrupt:
|
|
790
|
+
err_console.print("[yellow]Aborted.[/yellow]")
|
|
791
|
+
sys.exit(130)
|
|
792
|
+
except EOFError:
|
|
793
|
+
err_console.print("[yellow]Aborted (EOF).[/yellow]")
|
|
794
|
+
sys.exit(1)
|
|
795
|
+
raw = (raw or "").strip()
|
|
796
|
+
try:
|
|
797
|
+
chosen = int(raw)
|
|
798
|
+
except ValueError:
|
|
799
|
+
err_console.print(f"[red]Not a number: {raw!r}[/red]")
|
|
800
|
+
continue
|
|
801
|
+
if chosen in valid_ids:
|
|
802
|
+
return chosen
|
|
803
|
+
err_console.print(f"[red]Invalid {label.lower()} ID: {chosen}[/red]")
|
|
804
|
+
raise V6Error(422, f"INVALID_{label.upper()}", f"Too many invalid attempts for {label.lower()} ID.")
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
# ── region ──────────────────────────────────────────────
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
def _resolve_region(client, value: str | None) -> int:
|
|
811
|
+
if value is None:
|
|
812
|
+
if not _is_interactive():
|
|
813
|
+
raise V6Error(422, "MISSING_ARGUMENT", "Missing option '-r' / '--region'.")
|
|
814
|
+
return _prompt_region(client)
|
|
815
|
+
|
|
816
|
+
normalized = _slugify(value)
|
|
817
|
+
regions = client.regions() or []
|
|
818
|
+
result, status = _match_one(
|
|
819
|
+
normalized,
|
|
820
|
+
regions,
|
|
821
|
+
tiers=[
|
|
822
|
+
lambda r: _slugify(r.get("title", "")), # short slug
|
|
823
|
+
lambda r: (r.get("title", "") or "").strip().lower(), # title
|
|
824
|
+
],
|
|
825
|
+
)
|
|
826
|
+
|
|
827
|
+
if status == "none":
|
|
828
|
+
rows = [
|
|
829
|
+
f"{_slugify(r.get('title', '')):20s} (id={r['id']}{'' if r.get('available') else ', unavailable'})"
|
|
830
|
+
for r in regions
|
|
831
|
+
]
|
|
832
|
+
raise V6Error(
|
|
833
|
+
422,
|
|
834
|
+
"INVALID_REGION",
|
|
835
|
+
f'No region matches "{value}"' + _format_candidates("region", regions, rows),
|
|
836
|
+
)
|
|
837
|
+
if status == "ambiguous":
|
|
838
|
+
rows = [f"{_slugify(r.get('title', '')):20s} (id={r['id']})" for r in result]
|
|
839
|
+
raise V6Error(
|
|
840
|
+
422,
|
|
841
|
+
"AMBIGUOUS_REGION",
|
|
842
|
+
f'"{value}" matches multiple regions' + _format_candidates("region", result, rows),
|
|
843
|
+
)
|
|
844
|
+
if not result.get("available"):
|
|
845
|
+
raise V6Error(
|
|
846
|
+
422,
|
|
847
|
+
"REGION_UNAVAILABLE",
|
|
848
|
+
f'Region "{result.get("title")}" (id={result["id"]}) is not available for deployment.',
|
|
849
|
+
)
|
|
850
|
+
return result["id"]
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
def _prompt_region(client) -> int:
|
|
854
|
+
regions = client.regions() or []
|
|
855
|
+
available = [r for r in regions if r.get("available")]
|
|
856
|
+
if not available:
|
|
857
|
+
raise V6Error(422, "NO_REGIONS", "No regions are currently available for deployment.")
|
|
858
|
+
if len(available) == 1:
|
|
859
|
+
r = available[0]
|
|
860
|
+
err_console.print(f"[dim]Using region: {r.get('title')} (id={r['id']})[/dim]")
|
|
861
|
+
return r["id"]
|
|
862
|
+
_print_regions(available)
|
|
863
|
+
return _prompt_id("Region", [r["id"] for r in available])
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
# ── plan ────────────────────────────────────────────────
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
def _resolve_plan(client, value: str | None) -> int:
|
|
870
|
+
if value is None:
|
|
871
|
+
if not _is_interactive():
|
|
872
|
+
raise V6Error(422, "MISSING_ARGUMENT", "Missing option '-p' / '--plan'.")
|
|
873
|
+
return _prompt_plan(client)
|
|
874
|
+
|
|
875
|
+
normalized = _slugify(value)
|
|
876
|
+
plans = client.plans() or []
|
|
877
|
+
result, status = _match_one(
|
|
878
|
+
normalized,
|
|
879
|
+
plans,
|
|
880
|
+
tiers=[
|
|
881
|
+
_plan_short_slug, # {n}gb, or None
|
|
882
|
+
lambda p: _slugify(p.get("title", "")), # full slug
|
|
883
|
+
lambda p: (p.get("title", "") or "").strip().lower(), # title
|
|
884
|
+
],
|
|
885
|
+
)
|
|
886
|
+
|
|
887
|
+
if status == "none":
|
|
888
|
+
rows = [
|
|
889
|
+
f"{_plan_short_slug(p) or '—':6s} {_slugify(p.get('title', '')):18s} (id={p['id']})"
|
|
890
|
+
for p in plans
|
|
891
|
+
]
|
|
892
|
+
raise V6Error(
|
|
893
|
+
422,
|
|
894
|
+
"INVALID_PLAN",
|
|
895
|
+
f'No plan matches "{value}"' + _format_candidates("plan", plans, rows),
|
|
896
|
+
)
|
|
897
|
+
if status == "ambiguous":
|
|
898
|
+
rows = [f"{_slugify(p.get('title', '')):18s} (id={p['id']})" for p in result]
|
|
899
|
+
raise V6Error(
|
|
900
|
+
422,
|
|
901
|
+
"AMBIGUOUS_PLAN",
|
|
902
|
+
f'"{value}" matches multiple plans' + _format_candidates("plan", result, rows),
|
|
903
|
+
)
|
|
904
|
+
return result["id"]
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
def _prompt_plan(client) -> int:
|
|
908
|
+
plans = client.plans() or []
|
|
909
|
+
if not plans:
|
|
910
|
+
raise V6Error(422, "NO_PLANS", "No plans are available.")
|
|
911
|
+
_print_plans(plans)
|
|
912
|
+
return _prompt_id("Plan", [p["id"] for p in plans])
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
# ── SSH key ─────────────────────────────────────────────
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
def _resolve_key(client, value: str | None) -> int:
|
|
919
|
+
if value is None:
|
|
920
|
+
if not _is_interactive():
|
|
921
|
+
raise V6Error(422, "MISSING_ARGUMENT", "Missing option '-k' / '--key'.")
|
|
922
|
+
return _prompt_key(client)
|
|
923
|
+
|
|
924
|
+
normalized = _slugify(value)
|
|
925
|
+
keys = client.keys_list() or []
|
|
926
|
+
result, status = _match_one(
|
|
927
|
+
normalized,
|
|
928
|
+
keys,
|
|
929
|
+
tiers=[
|
|
930
|
+
lambda k: _slugify(k.get("description", "")),
|
|
931
|
+
lambda k: (k.get("description", "") or "").strip().lower(),
|
|
932
|
+
],
|
|
933
|
+
)
|
|
934
|
+
|
|
935
|
+
if status == "none":
|
|
936
|
+
rows = [f"{_slugify(k.get('description', '')):20s} (id={k['id']})" for k in keys]
|
|
937
|
+
raise V6Error(
|
|
938
|
+
422,
|
|
939
|
+
"INVALID_KEY",
|
|
940
|
+
f'No SSH key matches "{value}"' + _format_candidates("key", keys, rows),
|
|
941
|
+
)
|
|
942
|
+
if status == "ambiguous":
|
|
943
|
+
rows = [f"{_slugify(k.get('description', '')):20s} (id={k['id']})" for k in result]
|
|
944
|
+
raise V6Error(
|
|
945
|
+
422,
|
|
946
|
+
"AMBIGUOUS_KEY",
|
|
947
|
+
f'"{value}" matches multiple keys' + _format_candidates("key", result, rows),
|
|
948
|
+
)
|
|
949
|
+
return result["id"]
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
def _prompt_key(client) -> int:
|
|
953
|
+
keys = client.keys_list() or []
|
|
954
|
+
if not keys:
|
|
955
|
+
raise V6Error(
|
|
956
|
+
422,
|
|
957
|
+
"NO_KEYS",
|
|
958
|
+
"No SSH keys found. Add one with: v6ctl keys create -d <label> -k <pubkey>",
|
|
959
|
+
)
|
|
960
|
+
if len(keys) == 1:
|
|
961
|
+
k = keys[0]
|
|
962
|
+
err_console.print(f"[dim]Using SSH key: {k.get('description')} (id={k['id']})[/dim]")
|
|
963
|
+
return k["id"]
|
|
964
|
+
_print_keys(keys)
|
|
965
|
+
return _prompt_id("Key", [k["id"] for k in keys])
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
# ── template ───────────────────────────────────────────
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
def _prompt_template(client, region_id: int) -> str | None:
|
|
972
|
+
"""Prompt for a template slug from the region's allowed list."""
|
|
973
|
+
regions = client.regions() or []
|
|
974
|
+
region = next((r for r in regions if r.get("id") == region_id), None)
|
|
975
|
+
templates = (region or {}).get("templates") or []
|
|
976
|
+
if not templates:
|
|
977
|
+
return None # no templates exposed — let the API decide
|
|
978
|
+
|
|
979
|
+
console.print("\n[bold]Available templates:[/bold]")
|
|
980
|
+
for i, slug in enumerate(templates, 1):
|
|
981
|
+
console.print(f" [cyan]{i:2d}.[/cyan] {slug}")
|
|
982
|
+
|
|
983
|
+
default = "debian-13" if "debian-13" in templates else templates[0]
|
|
984
|
+
lower_map = {t.lower(): t for t in templates}
|
|
985
|
+
|
|
986
|
+
for _ in range(3):
|
|
987
|
+
try:
|
|
988
|
+
raw = Prompt.ask("[bold cyan]Template[/bold cyan]", default=default)
|
|
989
|
+
except KeyboardInterrupt:
|
|
990
|
+
err_console.print("[yellow]Aborted.[/yellow]")
|
|
991
|
+
sys.exit(130)
|
|
992
|
+
except EOFError:
|
|
993
|
+
err_console.print("[yellow]Aborted (EOF).[/yellow]")
|
|
994
|
+
sys.exit(1)
|
|
995
|
+
raw = (raw or "").strip()
|
|
996
|
+
try:
|
|
997
|
+
idx = int(raw)
|
|
998
|
+
if 1 <= idx <= len(templates):
|
|
999
|
+
return templates[idx - 1]
|
|
1000
|
+
except ValueError:
|
|
1001
|
+
pass
|
|
1002
|
+
if raw.lower() in lower_map:
|
|
1003
|
+
return lower_map[raw.lower()]
|
|
1004
|
+
err_console.print(f"[red]Invalid template: {raw!r}[/red]")
|
|
1005
|
+
raise V6Error(422, "INVALID_TEMPLATE", "Too many invalid attempts for template.")
|
|
1006
|
+
|
|
1007
|
+
|
|
691
1008
|
# ═══════════════════════════════════════════════════════════
|
|
692
1009
|
# Click CLI
|
|
693
1010
|
# ═══════════════════════════════════════════════════════════
|
|
@@ -707,7 +1024,14 @@ def handle_errors(fn):
|
|
|
707
1024
|
err=True,
|
|
708
1025
|
)
|
|
709
1026
|
else:
|
|
710
|
-
|
|
1027
|
+
# Multi-line messages (resolver candidate lists): keep (code) on the first line
|
|
1028
|
+
# so the list below stays visually clean.
|
|
1029
|
+
if "\n" in e.message:
|
|
1030
|
+
first, _, rest = e.message.partition("\n")
|
|
1031
|
+
print_error(f"{first} ({e.code})")
|
|
1032
|
+
err_console.print(rest)
|
|
1033
|
+
else:
|
|
1034
|
+
print_error(f"{e.message} ({e.code})")
|
|
711
1035
|
sys.exit(1)
|
|
712
1036
|
|
|
713
1037
|
return wrapper
|
|
@@ -892,7 +1216,7 @@ def keys_delete(ctx, key_id, yes):
|
|
|
892
1216
|
# ═══════════════════════════════════════════════════════════
|
|
893
1217
|
|
|
894
1218
|
|
|
895
|
-
class NodeGroup(click.
|
|
1219
|
+
class NodeGroup(click.RichGroup):
|
|
896
1220
|
"""Route unknown positional args to `show` so `nodes <pay_id>` just works."""
|
|
897
1221
|
|
|
898
1222
|
def resolve_command(self, ctx, args):
|
|
@@ -905,20 +1229,22 @@ class NodeGroup(click.Group):
|
|
|
905
1229
|
|
|
906
1230
|
|
|
907
1231
|
@cli.group(cls=NodeGroup, invoke_without_command=True)
|
|
1232
|
+
@click.option("-A", "--all-ips", is_flag=True, help="Show every IP address per node (default: up to 2).")
|
|
908
1233
|
@click.pass_context
|
|
909
|
-
def nodes(ctx):
|
|
1234
|
+
def nodes(ctx, all_ips):
|
|
910
1235
|
"""Manage VPS nodes."""
|
|
911
1236
|
if ctx.invoked_subcommand is None:
|
|
912
|
-
ctx.invoke(nodes_list)
|
|
1237
|
+
ctx.invoke(nodes_list, all_ips=all_ips)
|
|
913
1238
|
|
|
914
1239
|
|
|
915
1240
|
@nodes.command("list")
|
|
1241
|
+
@click.option("-A", "--all-ips", is_flag=True, help="Show every IP address per node (default: up to 2).")
|
|
916
1242
|
@click.pass_context
|
|
917
1243
|
@handle_errors
|
|
918
|
-
def nodes_list(ctx):
|
|
1244
|
+
def nodes_list(ctx, all_ips):
|
|
919
1245
|
"""List all nodes."""
|
|
920
1246
|
client = require_client(ctx)
|
|
921
|
-
_render(client.nodes_list(), _print_nodes)
|
|
1247
|
+
_render(client.nodes_list(), lambda d: _print_nodes(d, all_ips=all_ips))
|
|
922
1248
|
|
|
923
1249
|
|
|
924
1250
|
@nodes.command("show")
|
|
@@ -947,9 +1273,18 @@ def nodes_show(ctx, pay_id):
|
|
|
947
1273
|
|
|
948
1274
|
|
|
949
1275
|
@nodes.command("create")
|
|
950
|
-
@click.option(
|
|
951
|
-
|
|
952
|
-
|
|
1276
|
+
@click.option(
|
|
1277
|
+
"-r", "--region", "region", default=None, type=str,
|
|
1278
|
+
help='Region ID, slug, or name (e.g. 7, frankfurt-2, "Frankfurt 2").',
|
|
1279
|
+
)
|
|
1280
|
+
@click.option(
|
|
1281
|
+
"-p", "--plan", "plan", default=None, type=str,
|
|
1282
|
+
help="Plan ID, short slug, or full slug (e.g. 14, 8gb, node-8gb-g2).",
|
|
1283
|
+
)
|
|
1284
|
+
@click.option(
|
|
1285
|
+
"-k", "--key", "key", default=None, type=str,
|
|
1286
|
+
help="SSH key ID or description (numeric names resolve as ID first).",
|
|
1287
|
+
)
|
|
953
1288
|
@click.option("-h", "--hostname", default=None, help="Custom hostname.")
|
|
954
1289
|
@click.option("-t", "--template", default=None, help="Template slug (e.g. debian-13).")
|
|
955
1290
|
@click.option("--flavor", "flavor_id", default=None, type=int, help="Flavor ID.")
|
|
@@ -957,14 +1292,25 @@ def nodes_show(ctx, pay_id):
|
|
|
957
1292
|
"--address",
|
|
958
1293
|
"additional_address",
|
|
959
1294
|
default=None,
|
|
960
|
-
type=click.Choice(["
|
|
1295
|
+
type=click.Choice(["dedicated_ipv4"]),
|
|
961
1296
|
help="Additional IP address type.",
|
|
962
1297
|
)
|
|
963
1298
|
@click.pass_context
|
|
964
1299
|
@handle_errors
|
|
965
|
-
def nodes_create(ctx,
|
|
966
|
-
"""Deploy a new node.
|
|
1300
|
+
def nodes_create(ctx, region, plan, key, hostname, template, flavor_id, additional_address):
|
|
1301
|
+
"""Deploy a new node.
|
|
1302
|
+
|
|
1303
|
+
On a TTY, any of --region/--plan/--key may be omitted and you will be
|
|
1304
|
+
prompted. In non-interactive mode (pipe, CI, or --json), omitting a flag
|
|
1305
|
+
is an error. Each flag accepts a numeric ID, a short slug, a full slug,
|
|
1306
|
+
or an exact name (case-insensitive).
|
|
1307
|
+
"""
|
|
967
1308
|
client = require_client(ctx)
|
|
1309
|
+
region_id = _resolve_region(client, region)
|
|
1310
|
+
plan_id = _resolve_plan(client, plan)
|
|
1311
|
+
key_id = _resolve_key(client, key)
|
|
1312
|
+
if template is None and _is_interactive():
|
|
1313
|
+
template = _prompt_template(client, region_id)
|
|
968
1314
|
result = client.nodes_create(
|
|
969
1315
|
region_id=region_id,
|
|
970
1316
|
plan_id=plan_id,
|
|
@@ -981,13 +1327,14 @@ def nodes_create(ctx, region_id, plan_id, key_id, hostname, template, flavor_id,
|
|
|
981
1327
|
@click.argument("pay_id")
|
|
982
1328
|
@click.option("--hostname", default=None, help="New hostname.")
|
|
983
1329
|
@click.option("--description", default=None, help="New description.")
|
|
984
|
-
@click.option("--key", "
|
|
1330
|
+
@click.option("--key", "key", default=None, type=str, help="New SSH key ID or description.")
|
|
985
1331
|
@click.option("--project", "project_id", default=None, type=int, help="Project ID.")
|
|
986
1332
|
@click.pass_context
|
|
987
1333
|
@handle_errors
|
|
988
|
-
def nodes_update(ctx, pay_id, hostname, description,
|
|
1334
|
+
def nodes_update(ctx, pay_id, hostname, description, key, project_id):
|
|
989
1335
|
"""Update hostname, description, key, or project."""
|
|
990
1336
|
client = require_client(ctx)
|
|
1337
|
+
key_id = _resolve_key(client, key) if key is not None else None
|
|
991
1338
|
result = client.nodes_update(
|
|
992
1339
|
pay_id,
|
|
993
1340
|
hostname=hostname,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|