-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasync_snapshot.py
More file actions
125 lines (105 loc) · 3.61 KB
/
async_snapshot.py
File metadata and controls
125 lines (105 loc) · 3.61 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
118
119
120
121
122
123
124
125
"""Snapshot resource class for asynchronous operations."""
from __future__ import annotations
from typing_extensions import Unpack, override
from ._types import (
BaseRequestOptions,
LongRequestOptions,
PollingRequestOptions,
SDKDiskSnapshotUpdateParams,
SDKDevboxCreateFromImageParams,
)
from .._client import AsyncRunloop
from .async_devbox import AsyncDevbox
from ..types.devboxes import DevboxSnapshotAsyncStatusView
from ..types.devbox_snapshot_view import DevboxSnapshotView
class AsyncSnapshot:
"""Async wrapper around snapshot operations."""
def __init__(
self,
client: AsyncRunloop,
snapshot_id: str,
) -> None:
"""Initialize the wrapper.
:param client: Generated AsyncRunloop client
:type client: AsyncRunloop
:param snapshot_id: Snapshot identifier returned by the API
:type snapshot_id: str
"""
self._client = client
self._id = snapshot_id
@override
def __repr__(self) -> str:
return f"<AsyncSnapshot id={self._id!r}>"
@property
def id(self) -> str:
"""Return the snapshot identifier.
:return: Unique snapshot ID
:rtype: str
"""
return self._id
async def get_info(
self,
**options: Unpack[BaseRequestOptions],
) -> DevboxSnapshotAsyncStatusView:
"""Retrieve the latest snapshot status.
:param options: Optional request configuration
:return: Snapshot state payload
:rtype: DevboxSnapshotAsyncStatusView
"""
return await self._client.devboxes.disk_snapshots.query_status(
self._id,
**options,
)
async def update(
self,
**params: Unpack[SDKDiskSnapshotUpdateParams],
) -> DevboxSnapshotView:
"""Update snapshot metadata.
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKDiskSnapshotUpdateParams` for available parameters
:return: Updated snapshot details
:rtype: DevboxSnapshotView
"""
return await self._client.devboxes.disk_snapshots.update(
self._id,
**params,
)
async def delete(
self,
**options: Unpack[LongRequestOptions],
) -> object:
"""Delete the snapshot.
:param options: Optional long-running request configuration
:return: API response acknowledging deletion
:rtype: object
"""
return await self._client.devboxes.disk_snapshots.delete(
self._id,
**options,
)
async def await_completed(
self,
**options: Unpack[PollingRequestOptions],
) -> DevboxSnapshotAsyncStatusView:
"""Block until the snapshot operation finishes.
:param options: Polling configuration (timeouts, intervals)
:return: Final snapshot status
:rtype: DevboxSnapshotAsyncStatusView
"""
return await self._client.devboxes.disk_snapshots.await_completed(
self._id,
**options,
)
async def create_devbox(
self,
**params: Unpack[SDKDevboxCreateFromImageParams],
) -> "AsyncDevbox":
"""Create a devbox restored from this snapshot.
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKDevboxCreateFromImageParams` for available parameters
:return: Wrapper bound to the running devbox
:rtype: AsyncDevbox
"""
devbox_view = await self._client.devboxes.create_and_await_running(
snapshot_id=self._id,
**params,
)
return AsyncDevbox(self._client, devbox_view)