Skip to content

Commit cfc7ca8

Browse files
feat: Allow skipping graceful shutdown on instance delete
Stainless-Generated-From: 948291d549091ca6bab9d0ac22a85aeeb90e22be
1 parent 08d46ad commit cfc7ca8

5 files changed

Lines changed: 61 additions & 11 deletions

File tree

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Methods:
8787
- <code title="post /instances">client.instances.<a href="./src/hypeman/resources/instances/instances.py">create</a>(\*\*<a href="src/hypeman/types/instance_create_params.py">params</a>) -> <a href="./src/hypeman/types/instance.py">Instance</a></code>
8888
- <code title="patch /instances/{id}">client.instances.<a href="./src/hypeman/resources/instances/instances.py">update</a>(id, \*\*<a href="src/hypeman/types/instance_update_params.py">params</a>) -> <a href="./src/hypeman/types/instance.py">Instance</a></code>
8989
- <code title="get /instances">client.instances.<a href="./src/hypeman/resources/instances/instances.py">list</a>(\*\*<a href="src/hypeman/types/instance_list_params.py">params</a>) -> <a href="./src/hypeman/types/instance_list_response.py">InstanceListResponse</a></code>
90-
- <code title="delete /instances/{id}">client.instances.<a href="./src/hypeman/resources/instances/instances.py">delete</a>(id) -> None</code>
90+
- <code title="delete /instances/{id}">client.instances.<a href="./src/hypeman/resources/instances/instances.py">delete</a>(id, \*\*<a href="src/hypeman/types/instance_delete_params.py">params</a>) -> None</code>
9191
- <code title="post /instances/{id}/fork">client.instances.<a href="./src/hypeman/resources/instances/instances.py">fork</a>(id, \*\*<a href="src/hypeman/types/instance_fork_params.py">params</a>) -> <a href="./src/hypeman/types/instance.py">Instance</a></code>
9292
- <code title="get /instances/{id}">client.instances.<a href="./src/hypeman/resources/instances/instances.py">get</a>(id) -> <a href="./src/hypeman/types/instance.py">Instance</a></code>
9393
- <code title="get /instances/{id}/logs">client.instances.<a href="./src/hypeman/resources/instances/instances.py">logs</a>(id, \*\*<a href="src/hypeman/types/instance_logs_params.py">params</a>) -> str</code>

src/hypeman/resources/instances/instances.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
instance_wait_params,
1717
instance_start_params,
1818
instance_create_params,
19+
instance_delete_params,
1920
instance_update_params,
2021
instance_standby_params,
2122
)
@@ -404,6 +405,7 @@ def delete(
404405
self,
405406
id: str,
406407
*,
408+
graceful_shutdown: bool | Omit = omit,
407409
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
408410
# The extra values given here take precedence over values defined on the client or passed to this method.
409411
extra_headers: Headers | None = None,
@@ -415,6 +417,8 @@ def delete(
415417
Stop and delete instance
416418
417419
Args:
420+
graceful_shutdown: Whether to attempt graceful guest shutdown before deleting the instance
421+
418422
extra_headers: Send extra headers
419423
420424
extra_query: Add additional query parameters to the request
@@ -429,7 +433,13 @@ def delete(
429433
return self._delete(
430434
path_template("/instances/{id}", id=id),
431435
options=make_request_options(
432-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
436+
extra_headers=extra_headers,
437+
extra_query=extra_query,
438+
extra_body=extra_body,
439+
timeout=timeout,
440+
query=maybe_transform(
441+
{"graceful_shutdown": graceful_shutdown}, instance_delete_params.InstanceDeleteParams
442+
),
433443
),
434444
cast_to=NoneType,
435445
)
@@ -1217,6 +1227,7 @@ async def delete(
12171227
self,
12181228
id: str,
12191229
*,
1230+
graceful_shutdown: bool | Omit = omit,
12201231
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
12211232
# The extra values given here take precedence over values defined on the client or passed to this method.
12221233
extra_headers: Headers | None = None,
@@ -1228,6 +1239,8 @@ async def delete(
12281239
Stop and delete instance
12291240
12301241
Args:
1242+
graceful_shutdown: Whether to attempt graceful guest shutdown before deleting the instance
1243+
12311244
extra_headers: Send extra headers
12321245
12331246
extra_query: Add additional query parameters to the request
@@ -1242,7 +1255,13 @@ async def delete(
12421255
return await self._delete(
12431256
path_template("/instances/{id}", id=id),
12441257
options=make_request_options(
1245-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
1258+
extra_headers=extra_headers,
1259+
extra_query=extra_query,
1260+
extra_body=extra_body,
1261+
timeout=timeout,
1262+
query=await async_maybe_transform(
1263+
{"graceful_shutdown": graceful_shutdown}, instance_delete_params.InstanceDeleteParams
1264+
),
12461265
),
12471266
cast_to=NoneType,
12481267
)

src/hypeman/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
from .snapshot_policy_param import SnapshotPolicyParam as SnapshotPolicyParam
9191
from .health_check_tcp_param import HealthCheckTcpParam as HealthCheckTcpParam
9292
from .instance_create_params import InstanceCreateParams as InstanceCreateParams
93+
from .instance_delete_params import InstanceDeleteParams as InstanceDeleteParams
9394
from .instance_health_status import InstanceHealthStatus as InstanceHealthStatus
9495
from .instance_list_response import InstanceListResponse as InstanceListResponse
9596
from .instance_logs_response import InstanceLogsResponse as InstanceLogsResponse
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import TypedDict
6+
7+
__all__ = ["InstanceDeleteParams"]
8+
9+
10+
class InstanceDeleteParams(TypedDict, total=False):
11+
graceful_shutdown: bool
12+
"""Whether to attempt graceful guest shutdown before deleting the instance"""

tests/api_resources/test_instances.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,24 @@ def test_streaming_response_list(self, client: Hypeman) -> None:
292292
@parametrize
293293
def test_method_delete(self, client: Hypeman) -> None:
294294
instance = client.instances.delete(
295-
"id",
295+
id="id",
296+
)
297+
assert instance is None
298+
299+
@pytest.mark.skip(reason="Mock server tests are disabled")
300+
@parametrize
301+
def test_method_delete_with_all_params(self, client: Hypeman) -> None:
302+
instance = client.instances.delete(
303+
id="id",
304+
graceful_shutdown=True,
296305
)
297306
assert instance is None
298307

299308
@pytest.mark.skip(reason="Mock server tests are disabled")
300309
@parametrize
301310
def test_raw_response_delete(self, client: Hypeman) -> None:
302311
response = client.instances.with_raw_response.delete(
303-
"id",
312+
id="id",
304313
)
305314

306315
assert response.is_closed is True
@@ -312,7 +321,7 @@ def test_raw_response_delete(self, client: Hypeman) -> None:
312321
@parametrize
313322
def test_streaming_response_delete(self, client: Hypeman) -> None:
314323
with client.instances.with_streaming_response.delete(
315-
"id",
324+
id="id",
316325
) as response:
317326
assert not response.is_closed
318327
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -327,7 +336,7 @@ def test_streaming_response_delete(self, client: Hypeman) -> None:
327336
def test_path_params_delete(self, client: Hypeman) -> None:
328337
with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"):
329338
client.instances.with_raw_response.delete(
330-
"",
339+
id="",
331340
)
332341

333342
@pytest.mark.skip(reason="Mock server tests are disabled")
@@ -1101,15 +1110,24 @@ async def test_streaming_response_list(self, async_client: AsyncHypeman) -> None
11011110
@parametrize
11021111
async def test_method_delete(self, async_client: AsyncHypeman) -> None:
11031112
instance = await async_client.instances.delete(
1104-
"id",
1113+
id="id",
1114+
)
1115+
assert instance is None
1116+
1117+
@pytest.mark.skip(reason="Mock server tests are disabled")
1118+
@parametrize
1119+
async def test_method_delete_with_all_params(self, async_client: AsyncHypeman) -> None:
1120+
instance = await async_client.instances.delete(
1121+
id="id",
1122+
graceful_shutdown=True,
11051123
)
11061124
assert instance is None
11071125

11081126
@pytest.mark.skip(reason="Mock server tests are disabled")
11091127
@parametrize
11101128
async def test_raw_response_delete(self, async_client: AsyncHypeman) -> None:
11111129
response = await async_client.instances.with_raw_response.delete(
1112-
"id",
1130+
id="id",
11131131
)
11141132

11151133
assert response.is_closed is True
@@ -1121,7 +1139,7 @@ async def test_raw_response_delete(self, async_client: AsyncHypeman) -> None:
11211139
@parametrize
11221140
async def test_streaming_response_delete(self, async_client: AsyncHypeman) -> None:
11231141
async with async_client.instances.with_streaming_response.delete(
1124-
"id",
1142+
id="id",
11251143
) as response:
11261144
assert not response.is_closed
11271145
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -1136,7 +1154,7 @@ async def test_streaming_response_delete(self, async_client: AsyncHypeman) -> No
11361154
async def test_path_params_delete(self, async_client: AsyncHypeman) -> None:
11371155
with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"):
11381156
await async_client.instances.with_raw_response.delete(
1139-
"",
1157+
id="",
11401158
)
11411159

11421160
@pytest.mark.skip(reason="Mock server tests are disabled")

0 commit comments

Comments
 (0)