drukbox-python-sdk 0.5.1__tar.gz → 0.6.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: drukbox-python-sdk
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: Async Python client for Drukbox.
5
5
  Project-URL: Homepage, https://github.com/clawhaven/drukbox-python-sdk
6
6
  Project-URL: Repository, https://github.com/clawhaven/drukbox-python-sdk
@@ -94,10 +94,11 @@ Supported host operations:
94
94
  - `aclose`
95
95
 
96
96
  `create_host` supports the service's optional `image`, `env`, `expires_at`,
97
- `permanent`, `provider`, `instance_type`, `disk_gb`, `template`, `secrets`,
98
- and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
97
+ `permanent`, `provider`, `instance_type`, `disk_gb`, `cpu`, `memory_gb`, `template`,
98
+ `secrets`, and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
99
99
  `t3.xlarge` / `cx33`) and `disk_gb` pin the VM shape; omit either for the
100
- provider default. Omit `expires_at` for the default lease, pass a datetime for
100
+ provider default. `cpu` (vCPUs) and `memory_gb` size the VM by what it needs, on a
101
+ provider that can. Omit `expires_at` for the default lease, pass a datetime for
101
102
  an explicit expiry, or pass `permanent=True` for a never-reaped host.
102
103
  `template` accepts a template ID. An explicit `image` wins over it.
103
104
 
@@ -157,8 +158,9 @@ Supported template operations:
157
158
  - `delete_template`
158
159
 
159
160
  `create_template` returns immediately with a `building` record. Poll
160
- `get_template` until the status is `available` or `failed`. A failed record
161
- carries the reason in `last_error`.
161
+ `get_template` until the status is `available` or `failed`. While it builds,
162
+ `build_step` names the step the build is in. A failed record keeps that step
163
+ and carries the reason in `last_error`.
162
164
 
163
165
  Supported HTTP-proxy operations:
164
166
 
@@ -81,10 +81,11 @@ Supported host operations:
81
81
  - `aclose`
82
82
 
83
83
  `create_host` supports the service's optional `image`, `env`, `expires_at`,
84
- `permanent`, `provider`, `instance_type`, `disk_gb`, `template`, `secrets`,
85
- and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
84
+ `permanent`, `provider`, `instance_type`, `disk_gb`, `cpu`, `memory_gb`, `template`,
85
+ `secrets`, and `Idempotency-Key` inputs. `instance_type` (provider-native size, e.g.
86
86
  `t3.xlarge` / `cx33`) and `disk_gb` pin the VM shape; omit either for the
87
- provider default. Omit `expires_at` for the default lease, pass a datetime for
87
+ provider default. `cpu` (vCPUs) and `memory_gb` size the VM by what it needs, on a
88
+ provider that can. Omit `expires_at` for the default lease, pass a datetime for
88
89
  an explicit expiry, or pass `permanent=True` for a never-reaped host.
89
90
  `template` accepts a template ID. An explicit `image` wins over it.
90
91
 
@@ -144,8 +145,9 @@ Supported template operations:
144
145
  - `delete_template`
145
146
 
146
147
  `create_template` returns immediately with a `building` record. Poll
147
- `get_template` until the status is `available` or `failed`. A failed record
148
- carries the reason in `last_error`.
148
+ `get_template` until the status is `available` or `failed`. While it builds,
149
+ `build_step` names the step the build is in. A failed record keeps that step
150
+ and carries the reason in `last_error`.
149
151
 
150
152
  Supported HTTP-proxy operations:
151
153
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "drukbox-python-sdk"
7
- version = "0.5.1"
7
+ version = "0.6.0"
8
8
  description = "Async Python client for Drukbox."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -163,9 +163,12 @@ class SandboxTemplate:
163
163
  """Snapshot of a reusable sandbox template as returned by the service.
164
164
 
165
165
  ``status`` moves from ``"building"`` to ``"available"`` or
166
- ``"failed"``. While the build runs, ``image`` is empty. A failed
167
- build carries its reason in ``last_error``. The record has no
168
- ``setup_script`` because the service never echoes it back.
166
+ ``"failed"``. While the build runs, ``image`` is empty and
167
+ ``build_step`` names the step the build is in. A failed build keeps
168
+ the step it failed in and carries its reason in ``last_error``.
169
+ ``build_step`` is empty from a service that does not send it. The
170
+ record has no ``setup_script`` because the service never echoes it
171
+ back.
169
172
  """
170
173
 
171
174
  id: str
@@ -179,6 +182,7 @@ class SandboxTemplate:
179
182
  created_at: str
180
183
  updated_at: str
181
184
  last_used_at: str | None
185
+ build_step: str = ""
182
186
 
183
187
 
184
188
  @dataclass(frozen=True)
@@ -292,12 +296,14 @@ class SandboxAPI:
292
296
  async def create_host(
293
297
  self,
294
298
  *,
299
+ cpu: int | None = None,
295
300
  disk_gb: int | None = None,
296
301
  env: dict[str, str] | None = None,
297
302
  expires_at: datetime | None = None,
298
303
  idempotency_key: str | None = None,
299
304
  image: str | None = None,
300
305
  instance_type: str | None = None,
306
+ memory_gb: int | None = None,
301
307
  permanent: bool = False,
302
308
  provider: str | None = None,
303
309
  secrets: dict[str, Secret | Issuer] | None = None,
@@ -332,6 +338,13 @@ class SandboxAPI:
332
338
  either to use the provider's configured default. A size the active
333
339
  provider can't serve raises :class:`SandboxResponseError` (400).
334
340
 
341
+ ``cpu`` (vCPUs) and ``memory_gb`` size the VM by what it needs, not by a
342
+ provider's name for it; omit either to use the provider's default. A
343
+ provider that can't size a VM this way raises
344
+ :class:`SandboxResponseError` (400). A size the provider's account
345
+ does not allow fails the host: it goes to ``"error"`` with the reason
346
+ in ``last_error``.
347
+
335
348
  Lease: omit ``expires_at`` for the service's default lease, pass a
336
349
  ``datetime`` for an explicit expiry, or pass ``permanent=True`` for
337
350
  a host the janitor never reaps.
@@ -344,6 +357,8 @@ class SandboxAPI:
344
357
  raise ValueError("a permanent host cannot carry an expires_at")
345
358
 
346
359
  payload: dict[str, Any] = {}
360
+ if cpu is not None:
361
+ payload["cpu"] = cpu
347
362
  if disk_gb is not None:
348
363
  payload["disk_gb"] = disk_gb
349
364
  if env is not None:
@@ -357,6 +372,8 @@ class SandboxAPI:
357
372
  payload["image"] = image
358
373
  if instance_type is not None:
359
374
  payload["instance_type"] = instance_type
375
+ if memory_gb is not None:
376
+ payload["memory_gb"] = memory_gb
360
377
  if provider is not None:
361
378
  payload["provider"] = provider
362
379
  if secrets:
@@ -190,6 +190,8 @@ async def test_create_host_omits_image_and_env_when_unset(api: SandboxAPI):
190
190
  assert "provider" not in body
191
191
  assert "instance_type" not in body
192
192
  assert "disk_gb" not in body
193
+ assert "cpu" not in body
194
+ assert "memory_gb" not in body
193
195
  assert "template" not in body
194
196
  assert "Idempotency-Key" not in route.calls.last.request.headers
195
197
 
@@ -234,6 +236,32 @@ async def test_create_host_sends_sizing_when_set(api: SandboxAPI):
234
236
  assert host.disk_gb == 100
235
237
 
236
238
 
239
+ @respx.mock
240
+ async def test_create_host_sends_cpu_and_memory_when_set(api: SandboxAPI):
241
+ route = respx.post(f"{BASE_URL}/hosts").mock(
242
+ return_value=httpx.Response(201, json=_host_payload()),
243
+ )
244
+
245
+ await api.create_host(cpu=8, memory_gb=16)
246
+
247
+ body = route.calls.last.request.content.decode()
248
+ assert '"cpu":8' in body
249
+ assert '"memory_gb":16' in body
250
+
251
+
252
+ @respx.mock
253
+ async def test_create_host_sends_only_the_size_it_is_given(api: SandboxAPI):
254
+ route = respx.post(f"{BASE_URL}/hosts").mock(
255
+ return_value=httpx.Response(201, json=_host_payload()),
256
+ )
257
+
258
+ await api.create_host(cpu=4)
259
+
260
+ body = route.calls.last.request.content.decode()
261
+ assert '"cpu":4' in body
262
+ assert "memory_gb" not in body
263
+
264
+
237
265
  @respx.mock
238
266
  async def test_create_host_sends_provider_when_set(api: SandboxAPI):
239
267
  payload = _host_payload(provider="hetzner")
@@ -633,6 +661,19 @@ async def test_get_template_returns_parsed_template(api: SandboxAPI):
633
661
  assert template.status == "available"
634
662
  assert template.image == "derived:image"
635
663
  assert template.last_used_at == payload["last_used_at"]
664
+ assert template.build_step == ""
665
+
666
+
667
+ @respx.mock
668
+ async def test_get_template_carries_the_build_step(api: SandboxAPI):
669
+ payload = _template_payload(build_step="running setup script: Installing nodejs")
670
+ respx.get(f"{BASE_URL}/templates/{payload['id']}").mock(
671
+ return_value=httpx.Response(200, json=payload),
672
+ )
673
+
674
+ template = await api.get_template(payload["id"])
675
+
676
+ assert template.build_step == "running setup script: Installing nodejs"
636
677
 
637
678
 
638
679
  @respx.mock