Skip to content

Commit 9c9eaef

Browse files
authored
feat(instance): add tags to private nics (#55)
1 parent 07496ef commit 9c9eaef

File tree

6 files changed

+336
-0
lines changed

6 files changed

+336
-0
lines changed

scaleway-async/scaleway_async/instance/v1/api.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
CreateIpRequest,
116116
UpdateIpRequest,
117117
CreatePrivateNICRequest,
118+
UpdatePrivateNICRequest,
118119
)
119120
from .types_private import (
120121
_SetImageResponse,
@@ -147,6 +148,7 @@
147148
marshal_UpdateIpRequest,
148149
marshal_UpdatePlacementGroupRequest,
149150
marshal_UpdatePlacementGroupServersRequest,
151+
marshal_UpdatePrivateNICRequest,
150152
marshal_UpdateVolumeRequest,
151153
marshal__CreateServerRequest,
152154
marshal__SetImageRequest,
@@ -155,6 +157,7 @@
155157
marshal__SetServerRequest,
156158
marshal__SetSnapshotRequest,
157159
marshal__UpdateServerRequest,
160+
unmarshal_PrivateNIC,
158161
unmarshal_CreateImageResponse,
159162
unmarshal_CreateIpResponse,
160163
unmarshal_CreatePlacementGroupResponse,
@@ -3172,11 +3175,17 @@ async def list_private_ni_cs(
31723175
*,
31733176
server_id: str,
31743177
zone: Optional[Zone] = None,
3178+
tags: Optional[List[str]] = None,
3179+
per_page: Optional[int] = None,
3180+
page: Optional[int] = None,
31753181
) -> ListPrivateNICsResponse:
31763182
"""
31773183
List all private NICs of a given server.
31783184
:param zone: Zone to target. If none is passed will use default zone from the config
31793185
:param server_id: The server the private NIC is attached to
3186+
:param tags: The private NIC tags
3187+
:param per_page: A positive integer lower or equal to 100 to select the number of items to return
3188+
:param page: A positive integer to choose the page to return
31803189
:return: :class:`ListPrivateNICsResponse <ListPrivateNICsResponse>`
31813190
31823191
Usage:
@@ -3191,23 +3200,67 @@ async def list_private_ni_cs(
31913200
res = self._request(
31923201
"GET",
31933202
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/private_nics",
3203+
params={
3204+
"page": page,
3205+
"per_page": per_page or self.client.default_page_size,
3206+
"tags": ",".join(tags) if tags and len(tags) > 0 else None,
3207+
},
31943208
)
31953209

31963210
self._throw_on_error(res)
31973211
return unmarshal_ListPrivateNICsResponse(res.json())
31983212

3213+
async def list_private_ni_cs_all(
3214+
self,
3215+
*,
3216+
server_id: str,
3217+
zone: Optional[Zone] = None,
3218+
tags: Optional[List[str]] = None,
3219+
per_page: Optional[int] = None,
3220+
page: Optional[int] = None,
3221+
) -> List[PrivateNIC]:
3222+
"""
3223+
List all private NICs of a given server.
3224+
:param zone: Zone to target. If none is passed will use default zone from the config
3225+
:param server_id: The server the private NIC is attached to
3226+
:param tags: The private NIC tags
3227+
:param per_page: A positive integer lower or equal to 100 to select the number of items to return
3228+
:param page: A positive integer to choose the page to return
3229+
:return: :class:`List[ListPrivateNICsResponse] <List[ListPrivateNICsResponse]>`
3230+
3231+
Usage:
3232+
::
3233+
3234+
result = await api.list_private_ni_cs_all(server_id="example")
3235+
"""
3236+
3237+
return await fetch_all_pages_async(
3238+
type=ListPrivateNICsResponse,
3239+
key="private_nics",
3240+
fetcher=self.list_private_ni_cs,
3241+
args={
3242+
"server_id": server_id,
3243+
"zone": zone,
3244+
"tags": tags,
3245+
"per_page": per_page,
3246+
"page": page,
3247+
},
3248+
)
3249+
31993250
async def create_private_nic(
32003251
self,
32013252
*,
32023253
server_id: str,
32033254
private_network_id: str,
32043255
zone: Optional[Zone] = None,
3256+
tags: Optional[List[str]] = None,
32053257
) -> CreatePrivateNICResponse:
32063258
"""
32073259
Create a private NIC connecting a server to a private network.
32083260
:param zone: Zone to target. If none is passed will use default zone from the config
32093261
:param server_id: UUID of the server the private NIC will be attached to
32103262
:param private_network_id: UUID of the private network where the private NIC will be attached
3263+
:param tags: The private NIC tags
32113264
:return: :class:`CreatePrivateNICResponse <CreatePrivateNICResponse>`
32123265
32133266
Usage:
@@ -3230,6 +3283,7 @@ async def create_private_nic(
32303283
server_id=server_id,
32313284
private_network_id=private_network_id,
32323285
zone=zone,
3286+
tags=tags,
32333287
),
32343288
self.client,
32353289
),
@@ -3273,6 +3327,52 @@ async def get_private_nic(
32733327
self._throw_on_error(res)
32743328
return unmarshal_GetPrivateNICResponse(res.json())
32753329

3330+
async def update_private_nic(
3331+
self,
3332+
*,
3333+
server_id: str,
3334+
private_nic_id: str,
3335+
zone: Optional[Zone] = None,
3336+
tags: Optional[List[str]] = None,
3337+
) -> PrivateNIC:
3338+
"""
3339+
Update one or more parameter/s to a given private NIC.
3340+
:param zone: Zone to target. If none is passed will use default zone from the config
3341+
:param server_id: UUID of the server the private NIC will be attached to
3342+
:param private_nic_id: The private NIC unique ID
3343+
:param tags: Tags used to select private NIC/s
3344+
:return: :class:`PrivateNIC <PrivateNIC>`
3345+
3346+
Usage:
3347+
::
3348+
3349+
result = await api.update_private_nic(
3350+
server_id="example",
3351+
private_nic_id="example",
3352+
)
3353+
"""
3354+
3355+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
3356+
param_server_id = validate_path_param("server_id", server_id)
3357+
param_private_nic_id = validate_path_param("private_nic_id", private_nic_id)
3358+
3359+
res = self._request(
3360+
"PATCH",
3361+
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/private_nics/{param_private_nic_id}",
3362+
body=marshal_UpdatePrivateNICRequest(
3363+
UpdatePrivateNICRequest(
3364+
server_id=server_id,
3365+
private_nic_id=private_nic_id,
3366+
zone=zone,
3367+
tags=tags,
3368+
),
3369+
self.client,
3370+
),
3371+
)
3372+
3373+
self._throw_on_error(res)
3374+
return unmarshal_PrivateNIC(res.json())
3375+
32763376
async def delete_private_nic(
32773377
self,
32783378
*,

scaleway-async/scaleway_async/instance/v1/marshalling.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
CreateIpRequest,
127127
UpdateIpRequest,
128128
CreatePrivateNICRequest,
129+
UpdatePrivateNICRequest,
129130
)
130131
from .types_private import (
131132
_SetImageResponse,
@@ -437,6 +438,9 @@ def unmarshal_PrivateNIC(data: Any) -> PrivateNIC:
437438
field = data.get("state")
438439
args["state"] = field
439440

441+
field = data.get("tags")
442+
args["tags"] = field
443+
440444
return PrivateNIC(**args)
441445

442446

@@ -1621,6 +1625,9 @@ def unmarshal_ListPrivateNICsResponse(data: Any) -> ListPrivateNICsResponse:
16211625
field = data.get("private_nics")
16221626
args["private_nics"] = [unmarshal_PrivateNIC(v) for v in data["private_nics"]]
16231627

1628+
field = data.get("total_count")
1629+
args["total_count"] = field
1630+
16241631
return ListPrivateNICsResponse(**args)
16251632

16261633

@@ -2102,6 +2109,7 @@ def marshal_PrivateNIC(
21022109
"private_network_id": request.private_network_id,
21032110
"server_id": request.server_id,
21042111
"state": PrivateNICState(request.state),
2112+
"tags": request.tags,
21052113
}
21062114

21072115

@@ -2330,6 +2338,7 @@ def marshal_CreatePrivateNICRequest(
23302338
) -> Dict[str, Any]:
23312339
return {
23322340
"private_network_id": request.private_network_id,
2341+
"tags": request.tags,
23332342
}
23342343

23352344

@@ -2543,6 +2552,15 @@ def marshal_UpdatePlacementGroupServersRequest(
25432552
}
25442553

25452554

2555+
def marshal_UpdatePrivateNICRequest(
2556+
request: UpdatePrivateNICRequest,
2557+
defaults: ProfileDefaults,
2558+
) -> Dict[str, Any]:
2559+
return {
2560+
"tags": request.tags,
2561+
}
2562+
2563+
25462564
def marshal_UpdateVolumeRequest(
25472565
request: UpdateVolumeRequest,
25482566
defaults: ProfileDefaults,

scaleway-async/scaleway_async/instance/v1/types.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ class ListPlacementGroupsResponse:
574574
class ListPrivateNICsResponse:
575575
private_nics: List[PrivateNIC]
576576

577+
total_count: int
578+
577579

578580
@dataclass
579581
class ListSecurityGroupRulesResponse:
@@ -796,6 +798,11 @@ class PrivateNIC:
796798
The private NIC state
797799
"""
798800

801+
tags: List[str]
802+
"""
803+
The private NIC tags
804+
"""
805+
799806

800807
@dataclass
801808
class SecurityGroup:
@@ -2964,6 +2971,21 @@ class ListPrivateNICsRequest:
29642971
The server the private NIC is attached to
29652972
"""
29662973

2974+
tags: Optional[List[str]]
2975+
"""
2976+
The private NIC tags
2977+
"""
2978+
2979+
per_page: Optional[int]
2980+
"""
2981+
A positive integer lower or equal to 100 to select the number of items to return
2982+
"""
2983+
2984+
page: Optional[int]
2985+
"""
2986+
A positive integer to choose the page to return
2987+
"""
2988+
29672989

29682990
@dataclass
29692991
class CreatePrivateNICRequest:
@@ -2982,6 +3004,11 @@ class CreatePrivateNICRequest:
29823004
UUID of the private network where the private NIC will be attached
29833005
"""
29843006

3007+
tags: Optional[List[str]]
3008+
"""
3009+
The private NIC tags
3010+
"""
3011+
29853012

29863013
@dataclass
29873014
class GetPrivateNICRequest:
@@ -3001,6 +3028,29 @@ class GetPrivateNICRequest:
30013028
"""
30023029

30033030

3031+
@dataclass
3032+
class UpdatePrivateNICRequest:
3033+
zone: Optional[Zone]
3034+
"""
3035+
Zone to target. If none is passed will use default zone from the config
3036+
"""
3037+
3038+
server_id: str
3039+
"""
3040+
UUID of the server the private NIC will be attached to
3041+
"""
3042+
3043+
private_nic_id: str
3044+
"""
3045+
The private NIC unique ID
3046+
"""
3047+
3048+
tags: Optional[List[str]]
3049+
"""
3050+
Tags used to select private NIC/s
3051+
"""
3052+
3053+
30043054
@dataclass
30053055
class DeletePrivateNICRequest:
30063056
zone: Optional[Zone]

0 commit comments

Comments
 (0)