Skip to content

Commit eace7ee

Browse files
committed
docs: document client API for python/gRPC client
1 parent ca77ec1 commit eace7ee

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

docs/.DS_Store

6 KB
Binary file not shown.

docs/source/.DS_Store

6 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Client API
2+
3+
This section provides reference documentation for Jumpstarter's client APIs. Covering topics such as:
4+
5+
- Listing exporters
6+
- Requesting a lease
7+
- Listing leases
8+
9+
please see the [Client API Reference](reference.md) for more details.
10+
11+
## Listing Exporters
12+
13+
The client library provides a function to list all exporters in the cluster.
14+
15+
```python
16+
from jumpstarter.config.client import ClientConfigV1Alpha1
17+
18+
client = ClientConfigV1Alpha1.from_file("~/.config/jumpstarter/clients/majopela.yaml")
19+
response = client.list_exporters(with_leases=True, with_online=True, page_size=1000)
20+
for exporter in response.exporters:
21+
if exporter.online:
22+
print(exporter.name)
23+
print(exporter.lease)
24+
25+
print("next page token: ", response.next_page_token)
26+
```
27+
28+
```{toctree}
29+
:maxdepth: 1
30+
:hidden:
31+
reference.md
32+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Client API Reference
2+
3+
## Loading config files
4+
```{eval-rst}
5+
.. autoclass:: jumpstarter.config.client.ClientConfigV1Alpha1()
6+
:members: from_file, from_env, load, list
7+
:exclude-members: __init__
8+
```
9+
10+
## Manipulating config files
11+
```{eval-rst}
12+
.. autoclass:: jumpstarter.config.client.ClientConfigV1Alpha1()
13+
:members: save, dump_yaml, list, delete
14+
:exclude-members: __init__
15+
```
16+
17+
## Interact with the service
18+
```{eval-rst}
19+
.. autoclass:: jumpstarter.config.client.ClientConfigV1Alpha1()
20+
:members: get_exporter, list_exporters, create_lease, delete_lease, lease, list_leases, update_lease
21+
:exclude-members: __init__
22+
```

docs/source/reference/package-apis/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This section provides reference documentation for Jumpstarter's package APIs and
44
components. The documentation covers:
55

66
- [Drivers](drivers/index.md): APIs for various driver categories
7+
- [Client API](client/index.md): APIs for the client library: listing exporters, requesting a lease, etc.
78
- [Exceptions](exceptions.md): Exceptions raised by driver clients
89

910
These references are useful for developers extending Jumpstarter or integrating
@@ -13,5 +14,6 @@ with custom hardware.
1314
:maxdepth: 1
1415
:hidden:
1516
drivers/index.md
17+
client/index.md
1618
exceptions.md
1719
```

packages/jumpstarter/jumpstarter/config/client.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ async def get_exporter(
148148
self,
149149
name: str,
150150
):
151+
"""Gets an exporter by name."""
151152
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
152153
return await svc.GetExporter(name=name)
153154

@@ -161,6 +162,20 @@ async def list_exporters(
161162
include_leases: bool = False,
162163
include_online: bool = False,
163164
):
165+
"""Lists exporters.
166+
167+
Args:
168+
* page_size: The number of exporters to return.
169+
* page_token: The token to use to get the next page of exporters.
170+
* filter: A filter to apply to the list of exporters.
171+
* include_leases: Whether to include leases in the response.
172+
* include_online: Whether to include online status in the response.
173+
Returns:
174+
.exporters: list[Exporter]
175+
.next_page_token: str | None
176+
.include_online: bool : Whether to include online status in the response.
177+
.include_leases: bool : Whether to include leases in the response.
178+
"""
164179
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
165180
exporters_response = await svc.ListExporters(page_size=page_size, page_token=page_token, filter=filter)
166181

@@ -202,6 +217,12 @@ async def create_lease(
202217
duration: timedelta,
203218
begin_time: datetime | None = None,
204219
):
220+
"""Creates a lease request.
221+
Args:
222+
selector: The selector to use to create the lease.
223+
* duration: The duration of the lease.
224+
* begin_time: The beginning time of the lease.
225+
"""
205226
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
206227
return await svc.CreateLease(
207228
selector=selector,
@@ -215,6 +236,7 @@ async def delete_lease(
215236
self,
216237
name: str,
217238
):
239+
"""Deletes a lease by name."""
218240
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
219241
await svc.DeleteLease(
220242
name=name,
@@ -229,6 +251,17 @@ async def list_leases(
229251
filter: str | None = None,
230252
only_active: bool = True,
231253
):
254+
"""Lists leases.
255+
256+
Args:
257+
* page_size: The number of leases to return.
258+
* page_token: The token to use to get the next page of leases.
259+
* filter: A filter to apply to the list of leases.
260+
* only_active: Whether to only include active leases.
261+
Returns:
262+
.leases: list[Lease]
263+
.next_page_token: str | None
264+
"""
232265
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
233266
return await svc.ListLeases(
234267
page_size=page_size,
@@ -245,6 +278,14 @@ async def update_lease(
245278
duration: timedelta | None = None,
246279
begin_time: datetime | None = None,
247280
):
281+
"""Updates a lease by name.
282+
Can be used to extend the duration of an active lease, or modify the desired begin
283+
time and duration of a lease request.
284+
Args:
285+
* name: The name of the lease to update.
286+
* duration: The duration of the lease.
287+
* begin_time: The beginning time of the lease.
288+
"""
248289
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
249290
return await svc.UpdateLease(name=name, duration=duration, begin_time=begin_time)
250291

@@ -290,6 +331,7 @@ async def lease_async(
290331

291332
@classmethod
292333
def from_file(cls, path: os.PathLike):
334+
"""Loads a client config from a file path."""
293335
with open(path) as f:
294336
v = cls.model_validate(yaml.safe_load(f))
295337
v.alias = os.path.basename(path).split(".")[0]
@@ -310,6 +352,7 @@ def try_from_env(cls):
310352

311353
@classmethod
312354
def from_env(cls):
355+
"""Loads a client config from the environment variables."""
313356
return cls()
314357

315358
@classmethod
@@ -341,6 +384,7 @@ def save(cls, config: Self, path: Optional[os.PathLike] = None) -> Path:
341384

342385
@classmethod
343386
def dump_yaml(cls, config: Self) -> str:
387+
"""Dumps a client config as YAML."""
344388
return yaml.safe_dump(config.model_dump(mode="json", exclude={"path", "alias"}), sort_keys=False)
345389

346390
@classmethod

0 commit comments

Comments
 (0)