Skip to content

Commit a0f8a75

Browse files
pedrodeoliveirastainless-app[bot]claude
authored
feat(cloud): add create_and_poll and update_and_poll methods for security groups
Adds new `create_and_poll` and `update_and_poll` methods to both sync and async SecurityGroupsResource classes that combine creating/updating a security group with task polling. This follows the same pattern as existing polling methods in other resources. The methods: - Accept all parameters from the `create`/`update` methods plus polling parameters - Handle idempotent updates where no task is created - Poll the task if one is returned - Return the created/updated SecurityGroup object Updates the security groups examples to demonstrate: - Using create_and_poll to create security groups with tags - Using update_and_poll to update tags - Using update_and_poll to update security group properties Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 31501d3 commit a0f8a75

4 files changed

Lines changed: 275 additions & 14 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 645
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gcore%2Fgcore-deca3f038598c9e7614c191a88510b5e50b6a1e482ddeb6e33ce3a226dc05c39.yml
3-
openapi_spec_hash: 2ee17c1f251ec32cf95b91fb2e643657
4-
config_hash: e9e5b750687e9071d8b606963f0ffd6d
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gcore%2Fgcore-3fc43b72b82321f8d4ceea9ea44d7ab14e75872dbe66e3e698e1f59ba300ec55.yml
3+
openapi_spec_hash: 1b1043a0ef7bcf106abf14f9187f5755
4+
config_hash: 87d6d4b4ff43a53e634d01c4ba23b393

examples/cloud/security_groups.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from gcore import Gcore
2-
from gcore.types.cloud.security_group_create_params import SecurityGroup
32

43

54
def main() -> None:
@@ -20,6 +19,7 @@ def main() -> None:
2019
security_group_id = create_security_group(client=gcore)
2120
list_security_groups(client=gcore)
2221
get_security_group(client=gcore, security_group_id=security_group_id)
22+
update_tags_security_group(client=gcore, security_group_id=security_group_id)
2323
update_security_group(client=gcore, security_group_id=security_group_id)
2424

2525
# Rules
@@ -32,7 +32,10 @@ def main() -> None:
3232

3333
def create_security_group(*, client: Gcore) -> str:
3434
print("\n=== CREATE SECURITY GROUP ===")
35-
security_group = client.cloud.security_groups.create(security_group=SecurityGroup(name="gcore-go-example")) # pyright: ignore[reportDeprecated]
35+
security_group = client.cloud.security_groups.create_and_poll(
36+
name="gcore-python-example",
37+
tags={"environment": "development"},
38+
)
3639
print(f"Created security group: ID={security_group.id}, name={security_group.name}")
3740
print("========================")
3841
return security_group.id
@@ -55,11 +58,21 @@ def get_security_group(*, client: Gcore, security_group_id: str) -> None:
5558
print("========================")
5659

5760

61+
def update_tags_security_group(*, client: Gcore, security_group_id: str) -> None:
62+
print("\n=== UPDATE TAGS SECURITY GROUP ===")
63+
security_group = client.cloud.security_groups.update_and_poll(
64+
group_id=security_group_id,
65+
tags={"environment": "production", "team": "backend"},
66+
)
67+
print(f"Updated security group tags: ID={security_group.id}, tags={security_group.tags_v2}")
68+
print("========================")
69+
70+
5871
def update_security_group(*, client: Gcore, security_group_id: str) -> None:
5972
print("\n=== UPDATE SECURITY GROUP ===")
60-
security_group = client.cloud.security_groups.update( # pyright: ignore[reportDeprecated]
73+
security_group = client.cloud.security_groups.update_and_poll(
6174
group_id=security_group_id,
62-
name="gcore-go-example-updated",
75+
name="gcore-python-example-updated",
6376
)
6477
print(f"Updated security group: ID={security_group.id}, name={security_group.name}")
6578
print("========================")

examples/cloud/security_groups_async.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22

33
from gcore import AsyncGcore
4-
from gcore.types.cloud.security_group_create_params import SecurityGroup
54

65

76
async def main() -> None:
@@ -22,6 +21,7 @@ async def main() -> None:
2221
security_group_id = await create_security_group(client=gcore)
2322
await list_security_groups(client=gcore)
2423
await get_security_group(client=gcore, security_group_id=security_group_id)
24+
await update_tags_security_group(client=gcore, security_group_id=security_group_id)
2525
await update_security_group(client=gcore, security_group_id=security_group_id)
2626

2727
# Rules
@@ -34,17 +34,19 @@ async def main() -> None:
3434

3535
async def create_security_group(client: AsyncGcore) -> str:
3636
print("\n=== CREATE SECURITY GROUP ===")
37-
security_group = await client.cloud.security_groups.create(security_group=SecurityGroup(name="gcore-go-example")) # pyright: ignore[reportDeprecated]
37+
security_group = await client.cloud.security_groups.create_and_poll(
38+
name="gcore-python-example",
39+
tags={"environment": "development"},
40+
)
3841
print(f"Created security group: ID={security_group.id}, name={security_group.name}")
3942
print("========================")
4043
return security_group.id
4144

4245

4346
async def list_security_groups(*, client: AsyncGcore) -> None:
4447
print("\n=== LIST SECURITY GROUPS ===")
45-
security_groups = await client.cloud.security_groups.list()
4648
count = 0
47-
async for security_group in security_groups:
49+
async for security_group in client.cloud.security_groups.list():
4850
count += 1
4951
print(f"{count}. Security group: ID={security_group.id}, name={security_group.name}")
5052
print("========================")
@@ -59,11 +61,21 @@ async def get_security_group(*, client: AsyncGcore, security_group_id: str) -> N
5961
print("========================")
6062

6163

64+
async def update_tags_security_group(*, client: AsyncGcore, security_group_id: str) -> None:
65+
print("\n=== UPDATE TAGS SECURITY GROUP ===")
66+
security_group = await client.cloud.security_groups.update_and_poll(
67+
group_id=security_group_id,
68+
tags={"environment": "production", "team": "backend"},
69+
)
70+
print(f"Updated security group tags: ID={security_group.id}, tags={security_group.tags_v2}")
71+
print("========================")
72+
73+
6274
async def update_security_group(*, client: AsyncGcore, security_group_id: str) -> None:
6375
print("\n=== UPDATE SECURITY GROUP ===")
64-
security_group = await client.cloud.security_groups.update( # pyright: ignore[reportDeprecated]
76+
security_group = await client.cloud.security_groups.update_and_poll(
6577
group_id=security_group_id,
66-
name="gcore-go-example-updated",
78+
name="gcore-python-example-updated",
6779
)
6880
print(f"Updated security group: ID={security_group.id}, name={security_group.name}")
6981
print("========================")

0 commit comments

Comments
 (0)