This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathget.py
More file actions
117 lines (107 loc) · 3.6 KB
/
get.py
File metadata and controls
117 lines (107 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import logging
from typing import Optional
import asyncclick as click
from jumpstarter_cli_common import (
AliasedGroup,
OutputType,
opt_context,
opt_kubeconfig,
opt_log_level,
opt_namespace,
opt_output_auto,
)
from jumpstarter_kubernetes import (
ClientsV1Alpha1Api,
ExportersV1Alpha1Api,
LeasesV1Alpha1Api,
V1Alpha1Client,
V1Alpha1Exporter,
V1Alpha1Lease,
)
from kubernetes_asyncio.client.exceptions import ApiException
from kubernetes_asyncio.config.config_exception import ConfigException
from .k8s import (
handle_k8s_api_exception,
handle_k8s_config_exception,
)
from .print import print_client, print_clients, print_exporter, print_exporters, print_lease, print_leases
@click.group(cls=AliasedGroup)
@opt_log_level
def get(log_level: Optional[str]):
"""Get Jumpstarter Kubernetes objects"""
if log_level:
logging.basicConfig(level=log_level.upper())
else:
logging.basicConfig(level=logging.INFO)
@get.command("client")
@click.argument("name", type=str, required=False, default=None)
@opt_namespace
@opt_kubeconfig
@opt_context
@opt_output_auto(V1Alpha1Client)
async def get_client(
name: Optional[str], kubeconfig: Optional[str], context: Optional[str], namespace: str, output: OutputType
):
"""Get the client objects in a Kubernetes cluster"""
try:
async with ClientsV1Alpha1Api(namespace, kubeconfig, context) as api:
if name is not None:
client = await api.get_client(name)
print_client(client, output)
else:
clients = await api.list_clients()
print_clients(clients, namespace, output)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
handle_k8s_config_exception(e)
@get.command("exporter")
@click.argument("name", type=str, required=False, default=None)
@opt_namespace
@opt_kubeconfig
@opt_context
@opt_output_auto(V1Alpha1Exporter)
@click.option("-d", "--devices", is_flag=True, help="Display the devices hosted by the exporter(s)")
async def get_exporter(
name: Optional[str],
kubeconfig: Optional[str],
context: Optional[str],
namespace: str,
devices: bool,
output: OutputType,
):
"""Get the exporter objects in a Kubernetes cluster"""
try:
async with ExportersV1Alpha1Api(namespace, kubeconfig, context) as api:
if name is not None:
exporter = await api.get_exporter(name)
print_exporter(exporter, devices, output)
else:
exporters = await api.list_exporters()
print_exporters(exporters, namespace, devices, output)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
handle_k8s_config_exception(e)
@get.command("lease")
@click.argument("name", type=str, required=False, default=None)
@opt_namespace
@opt_kubeconfig
@opt_context
@opt_output_auto(V1Alpha1Lease)
async def get_lease(
name: Optional[str], kubeconfig: Optional[str], context: Optional[str], namespace: str, output: OutputType
):
"""Get the lease objects in a Kubernetes cluster"""
try:
async with LeasesV1Alpha1Api(namespace, kubeconfig, context) as api:
if name is not None:
lease = await api.get_lease(name)
print_lease(lease, output)
else:
leases = await api.list_leases()
print_leases(leases, namespace, output)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
handle_k8s_config_exception(e)