Skip to content

Commit 6429fad

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

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed
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(include_leases=True, include_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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
:no-index:
14+
:members: save, dump_yaml, list, delete
15+
:exclude-members: __init__
16+
```
17+
18+
## Interact with the service
19+
```{eval-rst}
20+
.. autoclass:: jumpstarter.config.client.ClientConfigV1Alpha1()
21+
:no-index:
22+
:members: get_exporter, list_exporters, create_lease, delete_lease, lease, list_leases, update_lease
23+
:exclude-members: __init__
24+
```

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: 46 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,13 @@ async def create_lease(
202217
duration: timedelta,
203218
begin_time: datetime | None = None,
204219
):
220+
"""Creates a lease request.
221+
222+
Args:
223+
* selector: The selector to use to create the lease.
224+
* duration: The duration of the lease.
225+
* begin_time: The beginning time of the lease.
226+
"""
205227
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
206228
return await svc.CreateLease(
207229
selector=selector,
@@ -215,6 +237,7 @@ async def delete_lease(
215237
self,
216238
name: str,
217239
):
240+
"""Deletes a lease by name."""
218241
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
219242
await svc.DeleteLease(
220243
name=name,
@@ -229,6 +252,17 @@ async def list_leases(
229252
filter: str | None = None,
230253
only_active: bool = True,
231254
):
255+
"""Lists leases.
256+
257+
Args:
258+
* page_size: The number of leases to return.
259+
* page_token: The token to use to get the next page of leases.
260+
* filter: A filter to apply to the list of leases.
261+
* only_active: Whether to only include active leases.
262+
Returns:
263+
.leases: list[Lease]
264+
.next_page_token: str | None
265+
"""
232266
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
233267
return await svc.ListLeases(
234268
page_size=page_size,
@@ -245,6 +279,15 @@ async def update_lease(
245279
duration: timedelta | None = None,
246280
begin_time: datetime | None = None,
247281
):
282+
"""Updates a lease by name.
283+
Can be used to extend the duration of an active lease, or modify the desired begin
284+
time and duration of a lease request.
285+
286+
Args:
287+
* name: The name of the lease to update.
288+
* duration: The duration of the lease.
289+
* begin_time: The beginning time of the lease.
290+
"""
248291
svc = ClientService(channel=await self.channel(), namespace=self.metadata.namespace)
249292
return await svc.UpdateLease(name=name, duration=duration, begin_time=begin_time)
250293

@@ -290,6 +333,7 @@ async def lease_async(
290333

291334
@classmethod
292335
def from_file(cls, path: os.PathLike):
336+
"""Loads a client config from a file path."""
293337
with open(path) as f:
294338
v = cls.model_validate(yaml.safe_load(f))
295339
v.alias = os.path.basename(path).split(".")[0]
@@ -310,6 +354,7 @@ def try_from_env(cls):
310354

311355
@classmethod
312356
def from_env(cls):
357+
"""Loads a client config from the environment variables."""
313358
return cls()
314359

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

342387
@classmethod
343388
def dump_yaml(cls, config: Self) -> str:
389+
"""Dumps a client config as YAML."""
344390
return yaml.safe_dump(config.model_dump(mode="json", exclude={"path", "alias"}), sort_keys=False)
345391

346392
@classmethod

0 commit comments

Comments
 (0)