proxy-platform 0.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.
Potentially problematic release.
This version of proxy-platform might be problematic. Click here for more details.
- proxy_platform/__init__.py +3 -0
- proxy_platform/client.py +324 -0
- proxy_platform/commands/__init__.py +1 -0
- proxy_platform/commands/auth.py +151 -0
- proxy_platform/commands/clusters.py +472 -0
- proxy_platform/commands/deployments.py +124 -0
- proxy_platform/commands/feedback.py +603 -0
- proxy_platform/commands/firewalls.py +894 -0
- proxy_platform/commands/orders.py +509 -0
- proxy_platform/commands/products.py +143 -0
- proxy_platform/commands/support.py +323 -0
- proxy_platform/commands/users.py +221 -0
- proxy_platform/config.py +224 -0
- proxy_platform/main.py +155 -0
- proxy_platform/main_public.py +135 -0
- proxy_platform-0.3.0.dist-info/METADATA +400 -0
- proxy_platform-0.3.0.dist-info/RECORD +20 -0
- proxy_platform-0.3.0.dist-info/WHEEL +5 -0
- proxy_platform-0.3.0.dist-info/entry_points.txt +2 -0
- proxy_platform-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
"""Cluster management commands."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.prompt import Confirm
|
|
8
|
+
from rich.table import Table
|
|
9
|
+
|
|
10
|
+
from ..client import APIClient
|
|
11
|
+
from ..config import get_default_api_type
|
|
12
|
+
|
|
13
|
+
app = typer.Typer()
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command(name="list")
|
|
18
|
+
def list_clusters(
|
|
19
|
+
limit: int = typer.Option(10, "--limit", "-l", help="Number of clusters to fetch"),
|
|
20
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
21
|
+
) -> None:
|
|
22
|
+
"""List your clusters.
|
|
23
|
+
|
|
24
|
+
Shows clusters owned by the authenticated user.
|
|
25
|
+
For admin view of all clusters, use: pbd admin clusters
|
|
26
|
+
"""
|
|
27
|
+
if api is None:
|
|
28
|
+
api = get_default_api_type()
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
client = APIClient(api_type=api)
|
|
32
|
+
response = client.get(f"/api/v1/clusters?limit={limit}")
|
|
33
|
+
|
|
34
|
+
if response.status_code == 200:
|
|
35
|
+
data = response.json()
|
|
36
|
+
clusters = data.get("data", [])
|
|
37
|
+
|
|
38
|
+
if not clusters:
|
|
39
|
+
console.print("[yellow]No clusters found[/yellow]")
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
table = Table(title=f"Clusters ({len(clusters)} of {data.get('total', 0)})")
|
|
43
|
+
table.add_column("ID", style="cyan", no_wrap=True)
|
|
44
|
+
table.add_column("Name", style="green")
|
|
45
|
+
table.add_column("Status", style="yellow")
|
|
46
|
+
table.add_column("Provider", style="blue")
|
|
47
|
+
table.add_column("Region", style="magenta")
|
|
48
|
+
|
|
49
|
+
for cluster in clusters:
|
|
50
|
+
table.add_row(
|
|
51
|
+
cluster.get("cluster_id", "N/A"),
|
|
52
|
+
cluster.get("cluster_name", "N/A"),
|
|
53
|
+
cluster.get("status", "N/A"),
|
|
54
|
+
cluster.get("provider", "N/A"),
|
|
55
|
+
cluster.get("region_name") or cluster.get("region", "N/A"),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
console.print()
|
|
59
|
+
console.print(table)
|
|
60
|
+
console.print()
|
|
61
|
+
else:
|
|
62
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
63
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
64
|
+
raise typer.Exit(1)
|
|
65
|
+
|
|
66
|
+
except Exception as e:
|
|
67
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
68
|
+
raise typer.Exit(1) from None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@app.command(name="get")
|
|
72
|
+
def get_cluster(
|
|
73
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID (full UUID or partial)"),
|
|
74
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
75
|
+
) -> None:
|
|
76
|
+
"""Get details about a specific cluster."""
|
|
77
|
+
if api is None:
|
|
78
|
+
api = get_default_api_type()
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
client = APIClient(api_type=api)
|
|
82
|
+
response = client.get(f"/api/v1/clusters/{cluster_id}")
|
|
83
|
+
|
|
84
|
+
if response.status_code == 200:
|
|
85
|
+
cluster = response.json()
|
|
86
|
+
|
|
87
|
+
name = cluster.get("cluster_name", "N/A")
|
|
88
|
+
|
|
89
|
+
console.print()
|
|
90
|
+
console.print(f"[bold]Cluster Details: {name}[/bold]")
|
|
91
|
+
console.print("─" * 70)
|
|
92
|
+
console.print(f"ID: [cyan]{cluster.get('cluster_id')}[/cyan]")
|
|
93
|
+
console.print(f"Name: [green]{name}[/green]")
|
|
94
|
+
if cluster.get("display_name"):
|
|
95
|
+
console.print(f"Internal: [dim]{cluster.get('cluster_name')}[/dim]")
|
|
96
|
+
console.print(f"Status: [yellow]{cluster.get('status')}[/yellow]")
|
|
97
|
+
console.print(f"Provider: [blue]{cluster.get('provider', 'N/A')}[/blue]")
|
|
98
|
+
console.print(
|
|
99
|
+
f"Region: [magenta]{cluster.get('region_name') or cluster.get('region', 'N/A')}[/magenta]"
|
|
100
|
+
)
|
|
101
|
+
console.print(f"Nodes: {cluster.get('node_count', 'N/A')}")
|
|
102
|
+
|
|
103
|
+
if cluster.get("created_at"):
|
|
104
|
+
console.print(f"Created: {cluster.get('created_at')}")
|
|
105
|
+
|
|
106
|
+
console.print()
|
|
107
|
+
else:
|
|
108
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
109
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
110
|
+
raise typer.Exit(1)
|
|
111
|
+
|
|
112
|
+
except Exception as e:
|
|
113
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
114
|
+
raise typer.Exit(1) from None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@app.command(name="rename")
|
|
118
|
+
def rename_cluster(
|
|
119
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID"),
|
|
120
|
+
name: str = typer.Option(..., "--name", "-n", help="New display name"),
|
|
121
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
122
|
+
) -> None:
|
|
123
|
+
"""Rename a cluster (sets the display name)."""
|
|
124
|
+
if api is None:
|
|
125
|
+
api = get_default_api_type()
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
client = APIClient(api_type=api)
|
|
129
|
+
response = client.patch(f"/api/v1/clusters/{cluster_id}", data={"display_name": name})
|
|
130
|
+
|
|
131
|
+
if response.status_code == 200:
|
|
132
|
+
cluster = response.json()
|
|
133
|
+
console.print(f"[green]✓[/green] Cluster renamed to [bold]{cluster.get('cluster_name')}[/bold]")
|
|
134
|
+
else:
|
|
135
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
136
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
137
|
+
raise typer.Exit(1)
|
|
138
|
+
|
|
139
|
+
except typer.Exit:
|
|
140
|
+
raise
|
|
141
|
+
except Exception as e:
|
|
142
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
143
|
+
raise typer.Exit(1) from None
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@app.command(name="delete")
|
|
147
|
+
def delete_cluster(
|
|
148
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID"),
|
|
149
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation"),
|
|
150
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
151
|
+
) -> None:
|
|
152
|
+
"""Delete a cluster and all its resources."""
|
|
153
|
+
if api is None:
|
|
154
|
+
api = get_default_api_type()
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
client = APIClient(api_type=api)
|
|
158
|
+
|
|
159
|
+
# Show deletion preview
|
|
160
|
+
preview_response = client.get(f"/api/v1/clusters/{cluster_id}/deletion-preview")
|
|
161
|
+
if preview_response.status_code == 200:
|
|
162
|
+
preview = preview_response.json()
|
|
163
|
+
cluster_name = preview.get("cluster_name", cluster_id)
|
|
164
|
+
resources = preview.get("resources", {})
|
|
165
|
+
estimated_time = preview.get("estimated_deletion_time", "unknown")
|
|
166
|
+
|
|
167
|
+
console.print()
|
|
168
|
+
console.print(f"[bold red]Delete cluster: {cluster_name}[/bold red]")
|
|
169
|
+
console.print("─" * 70)
|
|
170
|
+
console.print("[yellow]The following resources will be permanently deleted:[/yellow]")
|
|
171
|
+
console.print()
|
|
172
|
+
for resource_type, items in resources.items():
|
|
173
|
+
if isinstance(items, list) and items:
|
|
174
|
+
console.print(f" [red]•[/red] {resource_type}: {len(items)} item(s)")
|
|
175
|
+
elif items:
|
|
176
|
+
console.print(f" [red]•[/red] {resource_type}: {items}")
|
|
177
|
+
console.print()
|
|
178
|
+
console.print(f"[dim]Estimated deletion time: {estimated_time}[/dim]")
|
|
179
|
+
console.print()
|
|
180
|
+
|
|
181
|
+
validation = preview.get("validation", {})
|
|
182
|
+
if validation.get("warnings"):
|
|
183
|
+
for warning in validation["warnings"]:
|
|
184
|
+
console.print(f"[yellow]⚠ {warning}[/yellow]")
|
|
185
|
+
console.print()
|
|
186
|
+
elif preview_response.status_code == 404:
|
|
187
|
+
console.print(f"[red]Cluster not found: {cluster_id}[/red]")
|
|
188
|
+
raise typer.Exit(1)
|
|
189
|
+
|
|
190
|
+
if not yes:
|
|
191
|
+
if not typer.confirm("[bold red]This action is irreversible. Continue?[/bold red]"):
|
|
192
|
+
console.print("[yellow]Deletion cancelled.[/yellow]")
|
|
193
|
+
raise typer.Exit(0)
|
|
194
|
+
|
|
195
|
+
response = client.delete(f"/api/v1/clusters/{cluster_id}")
|
|
196
|
+
|
|
197
|
+
if response.status_code in [200, 202, 204]:
|
|
198
|
+
console.print("[green]✓[/green] Cluster deletion started. This may take a minute.")
|
|
199
|
+
else:
|
|
200
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
201
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
202
|
+
raise typer.Exit(1)
|
|
203
|
+
|
|
204
|
+
except typer.Exit:
|
|
205
|
+
raise
|
|
206
|
+
except Exception as e:
|
|
207
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
208
|
+
raise typer.Exit(1) from None
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@app.command(name="kubeconfig")
|
|
212
|
+
def get_kubeconfig(
|
|
213
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID"),
|
|
214
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Save to file (e.g. ~/.kube/config)"),
|
|
215
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
216
|
+
) -> None:
|
|
217
|
+
"""Download kubeconfig for a cluster."""
|
|
218
|
+
if api is None:
|
|
219
|
+
api = get_default_api_type()
|
|
220
|
+
|
|
221
|
+
try:
|
|
222
|
+
client = APIClient(api_type=api)
|
|
223
|
+
response = client.get(f"/api/v1/clusters/{cluster_id}/kubeconfig")
|
|
224
|
+
|
|
225
|
+
if response.status_code == 200:
|
|
226
|
+
data = response.json()
|
|
227
|
+
kubeconfig_b64 = data.get("kubeconfig", "")
|
|
228
|
+
|
|
229
|
+
try:
|
|
230
|
+
kubeconfig = base64.b64decode(kubeconfig_b64).decode("utf-8")
|
|
231
|
+
except Exception:
|
|
232
|
+
kubeconfig = kubeconfig_b64
|
|
233
|
+
|
|
234
|
+
if output:
|
|
235
|
+
import os
|
|
236
|
+
|
|
237
|
+
path = os.path.expanduser(output)
|
|
238
|
+
os.makedirs(os.path.dirname(path) if os.path.dirname(path) else ".", exist_ok=True)
|
|
239
|
+
with open(path, "w") as f:
|
|
240
|
+
f.write(kubeconfig)
|
|
241
|
+
os.chmod(path, 0o600)
|
|
242
|
+
console.print(f"[green]✓[/green] Kubeconfig saved to [cyan]{path}[/cyan]")
|
|
243
|
+
else:
|
|
244
|
+
console.print(kubeconfig)
|
|
245
|
+
|
|
246
|
+
elif response.status_code == 404:
|
|
247
|
+
console.print("[red]Kubeconfig not available (cluster may still be deploying)[/red]")
|
|
248
|
+
raise typer.Exit(1)
|
|
249
|
+
else:
|
|
250
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
251
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
252
|
+
raise typer.Exit(1)
|
|
253
|
+
|
|
254
|
+
except typer.Exit:
|
|
255
|
+
raise
|
|
256
|
+
except Exception as e:
|
|
257
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
258
|
+
raise typer.Exit(1) from None
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@app.command(name="etcd-key")
|
|
262
|
+
def get_etcd_key(
|
|
263
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID"),
|
|
264
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
265
|
+
) -> None:
|
|
266
|
+
"""Show the etcd encryption key for a cluster."""
|
|
267
|
+
if api is None:
|
|
268
|
+
api = get_default_api_type()
|
|
269
|
+
|
|
270
|
+
try:
|
|
271
|
+
client = APIClient(api_type=api)
|
|
272
|
+
response = client.get(f"/api/v1/clusters/{cluster_id}/etcd-encryption-key")
|
|
273
|
+
|
|
274
|
+
if response.status_code == 200:
|
|
275
|
+
data = response.json()
|
|
276
|
+
console.print()
|
|
277
|
+
console.print(f"[bold]Etcd Encryption Key: {data.get('cluster_name')}[/bold]")
|
|
278
|
+
console.print("─" * 70)
|
|
279
|
+
console.print("[yellow]⚠ Keep this key safe — it encrypts your cluster secrets.[/yellow]")
|
|
280
|
+
console.print()
|
|
281
|
+
console.print(data.get("etcd_encryption_key", "N/A"))
|
|
282
|
+
console.print()
|
|
283
|
+
elif response.status_code == 404:
|
|
284
|
+
console.print("[red]Encryption key not available (cluster may still be deploying)[/red]")
|
|
285
|
+
raise typer.Exit(1)
|
|
286
|
+
else:
|
|
287
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
288
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
289
|
+
raise typer.Exit(1)
|
|
290
|
+
|
|
291
|
+
except typer.Exit:
|
|
292
|
+
raise
|
|
293
|
+
except Exception as e:
|
|
294
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
295
|
+
raise typer.Exit(1) from None
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
@app.command(name="deployment")
|
|
299
|
+
def get_deployment(
|
|
300
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID (full UUID or partial)"),
|
|
301
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
302
|
+
) -> None:
|
|
303
|
+
"""Get deployment information for a cluster."""
|
|
304
|
+
if api is None:
|
|
305
|
+
api = get_default_api_type()
|
|
306
|
+
|
|
307
|
+
try:
|
|
308
|
+
client = APIClient(api_type=api)
|
|
309
|
+
response = client.get(f"/api/v1/clusters/{cluster_id}/deployment")
|
|
310
|
+
|
|
311
|
+
if response.status_code == 200:
|
|
312
|
+
deployment = response.json()
|
|
313
|
+
|
|
314
|
+
console.print()
|
|
315
|
+
console.print(f"[bold]Deployment Info for Cluster {cluster_id}[/bold]")
|
|
316
|
+
console.print("─" * 70)
|
|
317
|
+
|
|
318
|
+
for key, value in deployment.items():
|
|
319
|
+
console.print(f"{key}: [cyan]{value}[/cyan]")
|
|
320
|
+
|
|
321
|
+
console.print()
|
|
322
|
+
else:
|
|
323
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
324
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
325
|
+
raise typer.Exit(1)
|
|
326
|
+
|
|
327
|
+
except Exception as e:
|
|
328
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
329
|
+
raise typer.Exit(1) from None
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
@app.command(name="firewall")
|
|
333
|
+
def get_firewall(
|
|
334
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID (full UUID or partial)"),
|
|
335
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
336
|
+
) -> None:
|
|
337
|
+
"""Get firewall configuration for a cluster."""
|
|
338
|
+
if api is None:
|
|
339
|
+
api = get_default_api_type()
|
|
340
|
+
|
|
341
|
+
try:
|
|
342
|
+
client = APIClient(api_type=api)
|
|
343
|
+
response = client.get(f"/api/v1/clusters/{cluster_id}/firewall")
|
|
344
|
+
|
|
345
|
+
if response.status_code == 200:
|
|
346
|
+
firewall = response.json()
|
|
347
|
+
|
|
348
|
+
console.print()
|
|
349
|
+
console.print(f"[bold]Firewall Configuration for Cluster {cluster_id}[/bold]")
|
|
350
|
+
console.print("─" * 70)
|
|
351
|
+
|
|
352
|
+
rules = firewall.get("rules", [])
|
|
353
|
+
if rules:
|
|
354
|
+
table = Table()
|
|
355
|
+
table.add_column("Direction", style="cyan")
|
|
356
|
+
table.add_column("Protocol", style="green")
|
|
357
|
+
table.add_column("Port", style="yellow")
|
|
358
|
+
table.add_column("Source/Dest", style="blue")
|
|
359
|
+
|
|
360
|
+
for rule in rules:
|
|
361
|
+
table.add_row(
|
|
362
|
+
rule.get("direction", "N/A"),
|
|
363
|
+
rule.get("protocol", "N/A"),
|
|
364
|
+
str(rule.get("port", "N/A")),
|
|
365
|
+
rule.get("source_ip", rule.get("destination_ip", "N/A")),
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
console.print(table)
|
|
369
|
+
else:
|
|
370
|
+
console.print("[yellow]No firewall rules configured[/yellow]")
|
|
371
|
+
|
|
372
|
+
console.print()
|
|
373
|
+
else:
|
|
374
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
375
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
376
|
+
raise typer.Exit(1)
|
|
377
|
+
|
|
378
|
+
except Exception as e:
|
|
379
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
380
|
+
raise typer.Exit(1) from None
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
@app.command(name="assign-firewall")
|
|
384
|
+
def assign_firewall(
|
|
385
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID (full UUID or partial)"),
|
|
386
|
+
firewall: str | None = typer.Option(None, "--firewall", "-f", help="Firewall name or ID"),
|
|
387
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation"),
|
|
388
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
389
|
+
) -> None:
|
|
390
|
+
"""Assign or change the firewall on a cluster."""
|
|
391
|
+
if api is None:
|
|
392
|
+
api = get_default_api_type()
|
|
393
|
+
|
|
394
|
+
try:
|
|
395
|
+
client = APIClient(api_type=api)
|
|
396
|
+
|
|
397
|
+
# Fetch available firewalls
|
|
398
|
+
fw_response = client.get("/api/v1/firewalls")
|
|
399
|
+
firewalls = fw_response.json() if fw_response.status_code == 200 else []
|
|
400
|
+
if isinstance(firewalls, dict):
|
|
401
|
+
firewalls = firewalls.get("items", firewalls.get("data", []))
|
|
402
|
+
|
|
403
|
+
selected_firewall_id: str | None = None
|
|
404
|
+
selected_firewall_name: str = "None"
|
|
405
|
+
|
|
406
|
+
if firewall:
|
|
407
|
+
matched = next(
|
|
408
|
+
(
|
|
409
|
+
fw
|
|
410
|
+
for fw in firewalls
|
|
411
|
+
if str(fw.get("id", "")).startswith(firewall) or fw.get("name", "").lower() == firewall.lower()
|
|
412
|
+
),
|
|
413
|
+
None,
|
|
414
|
+
)
|
|
415
|
+
if not matched:
|
|
416
|
+
console.print(f"[red]Firewall not found: {firewall}[/red]")
|
|
417
|
+
raise typer.Exit(1)
|
|
418
|
+
selected_firewall_id = matched.get("id")
|
|
419
|
+
selected_firewall_name = matched.get("name", selected_firewall_id or "Unknown")
|
|
420
|
+
elif firewalls:
|
|
421
|
+
table = Table()
|
|
422
|
+
table.add_column("#", style="cyan", width=4)
|
|
423
|
+
table.add_column("Name", style="green")
|
|
424
|
+
table.add_column("Description", style="dim")
|
|
425
|
+
for i, fw in enumerate(firewalls, 1):
|
|
426
|
+
table.add_row(str(i), fw.get("name", "N/A"), fw.get("description") or "")
|
|
427
|
+
console.print()
|
|
428
|
+
console.print(table)
|
|
429
|
+
console.print()
|
|
430
|
+
|
|
431
|
+
fw_options = [str(i) for i in range(1, len(firewalls) + 1)]
|
|
432
|
+
fw_choice = typer.prompt(f"Select firewall [{'/'.join(fw_options)}/none]", default="1")
|
|
433
|
+
if fw_choice.lower() != "none" and fw_choice in fw_options:
|
|
434
|
+
selected_fw = firewalls[int(fw_choice) - 1]
|
|
435
|
+
selected_firewall_id = selected_fw.get("id")
|
|
436
|
+
selected_firewall_name = selected_fw.get("name", selected_firewall_id or "Unknown")
|
|
437
|
+
else:
|
|
438
|
+
console.print("[yellow]No firewall selected. Aborted.[/yellow]")
|
|
439
|
+
raise typer.Exit(0)
|
|
440
|
+
else:
|
|
441
|
+
console.print("[red]No firewalls available.[/red]")
|
|
442
|
+
raise typer.Exit(1)
|
|
443
|
+
|
|
444
|
+
if not yes:
|
|
445
|
+
if not Confirm.ask(
|
|
446
|
+
f"Firewall [bold]{selected_firewall_name}[/bold] koppelen aan cluster [cyan]{cluster_id[:8]}…[/cyan]"
|
|
447
|
+
):
|
|
448
|
+
console.print("[yellow]Geannuleerd.[/yellow]")
|
|
449
|
+
raise typer.Exit(0)
|
|
450
|
+
|
|
451
|
+
response = client.put(
|
|
452
|
+
f"/api/v1/clusters/{cluster_id}/firewall",
|
|
453
|
+
data={"firewall_id": selected_firewall_id},
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
if response.status_code in [200, 201, 204]:
|
|
457
|
+
console.print(
|
|
458
|
+
f"[green]✓[/green] Firewall [bold]{selected_firewall_name}[/bold] gekoppeld aan cluster [cyan]{cluster_id[:8]}…[/cyan]"
|
|
459
|
+
)
|
|
460
|
+
else:
|
|
461
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
462
|
+
try:
|
|
463
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
464
|
+
except Exception:
|
|
465
|
+
console.print(response.text or "Unknown error")
|
|
466
|
+
raise typer.Exit(1)
|
|
467
|
+
|
|
468
|
+
except typer.Exit:
|
|
469
|
+
raise
|
|
470
|
+
except Exception as e:
|
|
471
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
472
|
+
raise typer.Exit(1) from None
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Deployment management commands.
|
|
2
|
+
|
|
3
|
+
NOTE: Deployments are triggered automatically after successful payment.
|
|
4
|
+
Use the 'orders' commands to create orders and initiate deployments.
|
|
5
|
+
|
|
6
|
+
This module is for checking deployment status only.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.table import Table
|
|
12
|
+
|
|
13
|
+
from ..client import APIClient
|
|
14
|
+
from ..config import get_default_api_type
|
|
15
|
+
|
|
16
|
+
app = typer.Typer()
|
|
17
|
+
console = Console()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@app.command(name="list")
|
|
21
|
+
def list_deployments(
|
|
22
|
+
limit: int = typer.Option(10, "--limit", "-l", help="Number of deployments to fetch"),
|
|
23
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
24
|
+
) -> None:
|
|
25
|
+
"""List user deployments.
|
|
26
|
+
|
|
27
|
+
Deployments are created automatically after successful payment.
|
|
28
|
+
To create a new deployment, use: pbd orders create
|
|
29
|
+
"""
|
|
30
|
+
if api is None:
|
|
31
|
+
api = get_default_api_type()
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
client = APIClient(api_type=api)
|
|
35
|
+
response = client.get(f"/api/v1/clusters?limit={limit}")
|
|
36
|
+
|
|
37
|
+
if response.status_code == 200:
|
|
38
|
+
data = response.json()
|
|
39
|
+
deployments = data.get("data", [])
|
|
40
|
+
|
|
41
|
+
if not deployments:
|
|
42
|
+
console.print("[yellow]No deployments found[/yellow]")
|
|
43
|
+
console.print()
|
|
44
|
+
console.print("[cyan]Tip: Create an order to trigger a deployment:[/cyan]")
|
|
45
|
+
console.print("[cyan] pbd orders create-interactive[/cyan]")
|
|
46
|
+
return
|
|
47
|
+
|
|
48
|
+
total = data.get("total", len(deployments))
|
|
49
|
+
table = Table(title=f"Deployments ({len(deployments)} of {total})")
|
|
50
|
+
table.add_column("ID", style="cyan", no_wrap=True)
|
|
51
|
+
table.add_column("Name", style="green")
|
|
52
|
+
table.add_column("Status", style="yellow")
|
|
53
|
+
table.add_column("Type", style="blue")
|
|
54
|
+
table.add_column("Region", style="magenta")
|
|
55
|
+
table.add_column("Date", style="dim")
|
|
56
|
+
|
|
57
|
+
for deployment in deployments:
|
|
58
|
+
created = deployment.get("created_at") or "N/A"
|
|
59
|
+
table.add_row(
|
|
60
|
+
deployment.get("cluster_id", "N/A"),
|
|
61
|
+
deployment.get("cluster_name", "N/A"),
|
|
62
|
+
deployment.get("status", "N/A"),
|
|
63
|
+
deployment.get("cluster_type", "N/A"),
|
|
64
|
+
deployment.get("region_name") or deployment.get("region", "N/A"),
|
|
65
|
+
created[:10],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
console.print()
|
|
69
|
+
console.print(table)
|
|
70
|
+
console.print()
|
|
71
|
+
else:
|
|
72
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
73
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
74
|
+
raise typer.Exit(1)
|
|
75
|
+
|
|
76
|
+
except typer.Exit:
|
|
77
|
+
raise
|
|
78
|
+
except Exception as e:
|
|
79
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
80
|
+
raise typer.Exit(1) from None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@app.command(name="get")
|
|
84
|
+
def get_deployment(
|
|
85
|
+
cluster_id: str = typer.Argument(..., help="Cluster ID (UUID or partial)"),
|
|
86
|
+
api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
|
|
87
|
+
) -> None:
|
|
88
|
+
"""Get deployment details for a cluster."""
|
|
89
|
+
if api is None:
|
|
90
|
+
api = get_default_api_type()
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
client = APIClient(api_type=api)
|
|
94
|
+
response = client.get(f"/api/v1/clusters/{cluster_id}/deployment")
|
|
95
|
+
|
|
96
|
+
if response.status_code == 200:
|
|
97
|
+
deployment = response.json()
|
|
98
|
+
|
|
99
|
+
console.print()
|
|
100
|
+
console.print(f"[bold]Deployment Details: {cluster_id}[/bold]")
|
|
101
|
+
console.print("─" * 70)
|
|
102
|
+
console.print(f"Status: [yellow]{deployment.get('status')}[/yellow]")
|
|
103
|
+
console.print(f"Type: [blue]{deployment.get('deployment_type', 'N/A')}[/blue]")
|
|
104
|
+
|
|
105
|
+
if deployment.get("created_at"):
|
|
106
|
+
console.print(f"Created: {deployment.get('created_at')}")
|
|
107
|
+
|
|
108
|
+
if deployment.get("completed_at"):
|
|
109
|
+
console.print(f"Completed: {deployment.get('completed_at')}")
|
|
110
|
+
|
|
111
|
+
console.print()
|
|
112
|
+
elif response.status_code == 404:
|
|
113
|
+
console.print(f"[red]Cluster not found: {cluster_id}[/red]")
|
|
114
|
+
raise typer.Exit(1)
|
|
115
|
+
else:
|
|
116
|
+
console.print(f"[red]Error: {response.status_code}[/red]")
|
|
117
|
+
console.print(response.json().get("detail", "Unknown error"))
|
|
118
|
+
raise typer.Exit(1)
|
|
119
|
+
|
|
120
|
+
except typer.Exit:
|
|
121
|
+
raise
|
|
122
|
+
except Exception as e:
|
|
123
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
124
|
+
raise typer.Exit(1) from None
|