Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
CreateIpRequest,
UpdateIpRequest,
CreatePrivateNICRequest,
UpdatePrivateNICRequest,
)
from .types_private import (
_SetImageResponse,
Expand Down Expand Up @@ -147,6 +148,7 @@
marshal_UpdateIpRequest,
marshal_UpdatePlacementGroupRequest,
marshal_UpdatePlacementGroupServersRequest,
marshal_UpdatePrivateNICRequest,
marshal_UpdateVolumeRequest,
marshal__CreateServerRequest,
marshal__SetImageRequest,
Expand All @@ -155,6 +157,7 @@
marshal__SetServerRequest,
marshal__SetSnapshotRequest,
marshal__UpdateServerRequest,
unmarshal_PrivateNIC,
unmarshal_CreateImageResponse,
unmarshal_CreateIpResponse,
unmarshal_CreatePlacementGroupResponse,
Expand Down Expand Up @@ -3172,11 +3175,17 @@ async def list_private_ni_cs(
*,
server_id: str,
zone: Optional[Zone] = None,
tags: Optional[List[str]] = None,
per_page: Optional[int] = None,
page: Optional[int] = None,
) -> ListPrivateNICsResponse:
"""
List all private NICs of a given server.
:param zone: Zone to target. If none is passed will use default zone from the config
:param server_id: The server the private NIC is attached to
:param tags: The private NIC tags
:param per_page: A positive integer lower or equal to 100 to select the number of items to return
:param page: A positive integer to choose the page to return
:return: :class:`ListPrivateNICsResponse <ListPrivateNICsResponse>`

Usage:
Expand All @@ -3191,23 +3200,67 @@ async def list_private_ni_cs(
res = self._request(
"GET",
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/private_nics",
params={
"page": page,
"per_page": per_page or self.client.default_page_size,
"tags": ",".join(tags) if tags and len(tags) > 0 else None,
},
)

self._throw_on_error(res)
return unmarshal_ListPrivateNICsResponse(res.json())

async def list_private_ni_cs_all(
self,
*,
server_id: str,
zone: Optional[Zone] = None,
tags: Optional[List[str]] = None,
per_page: Optional[int] = None,
page: Optional[int] = None,
) -> List[PrivateNIC]:
"""
List all private NICs of a given server.
:param zone: Zone to target. If none is passed will use default zone from the config
:param server_id: The server the private NIC is attached to
:param tags: The private NIC tags
:param per_page: A positive integer lower or equal to 100 to select the number of items to return
:param page: A positive integer to choose the page to return
:return: :class:`List[ListPrivateNICsResponse] <List[ListPrivateNICsResponse]>`

Usage:
::

result = await api.list_private_ni_cs_all(server_id="example")
"""

return await fetch_all_pages_async(
type=ListPrivateNICsResponse,
key="private_nics",
fetcher=self.list_private_ni_cs,
args={
"server_id": server_id,
"zone": zone,
"tags": tags,
"per_page": per_page,
"page": page,
},
)

async def create_private_nic(
self,
*,
server_id: str,
private_network_id: str,
zone: Optional[Zone] = None,
tags: Optional[List[str]] = None,
) -> CreatePrivateNICResponse:
"""
Create a private NIC connecting a server to a private network.
:param zone: Zone to target. If none is passed will use default zone from the config
:param server_id: UUID of the server the private NIC will be attached to
:param private_network_id: UUID of the private network where the private NIC will be attached
:param tags: The private NIC tags
:return: :class:`CreatePrivateNICResponse <CreatePrivateNICResponse>`

Usage:
Expand All @@ -3230,6 +3283,7 @@ async def create_private_nic(
server_id=server_id,
private_network_id=private_network_id,
zone=zone,
tags=tags,
),
self.client,
),
Expand Down Expand Up @@ -3273,6 +3327,52 @@ async def get_private_nic(
self._throw_on_error(res)
return unmarshal_GetPrivateNICResponse(res.json())

async def update_private_nic(
self,
*,
server_id: str,
private_nic_id: str,
zone: Optional[Zone] = None,
tags: Optional[List[str]] = None,
) -> PrivateNIC:
"""
Update one or more parameter/s to a given private NIC.
:param zone: Zone to target. If none is passed will use default zone from the config
:param server_id: UUID of the server the private NIC will be attached to
:param private_nic_id: The private NIC unique ID
:param tags: Tags used to select private NIC/s
:return: :class:`PrivateNIC <PrivateNIC>`

Usage:
::

result = await api.update_private_nic(
server_id="example",
private_nic_id="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)
param_private_nic_id = validate_path_param("private_nic_id", private_nic_id)

res = self._request(
"PATCH",
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/private_nics/{param_private_nic_id}",
body=marshal_UpdatePrivateNICRequest(
UpdatePrivateNICRequest(
server_id=server_id,
private_nic_id=private_nic_id,
zone=zone,
tags=tags,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_PrivateNIC(res.json())

async def delete_private_nic(
self,
*,
Expand Down
18 changes: 18 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
CreateIpRequest,
UpdateIpRequest,
CreatePrivateNICRequest,
UpdatePrivateNICRequest,
)
from .types_private import (
_SetImageResponse,
Expand Down Expand Up @@ -437,6 +438,9 @@ def unmarshal_PrivateNIC(data: Any) -> PrivateNIC:
field = data.get("state")
args["state"] = field

field = data.get("tags")
args["tags"] = field

return PrivateNIC(**args)


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

field = data.get("total_count")
args["total_count"] = field

return ListPrivateNICsResponse(**args)


Expand Down Expand Up @@ -2102,6 +2109,7 @@ def marshal_PrivateNIC(
"private_network_id": request.private_network_id,
"server_id": request.server_id,
"state": PrivateNICState(request.state),
"tags": request.tags,
}


Expand Down Expand Up @@ -2330,6 +2338,7 @@ def marshal_CreatePrivateNICRequest(
) -> Dict[str, Any]:
return {
"private_network_id": request.private_network_id,
"tags": request.tags,
}


Expand Down Expand Up @@ -2543,6 +2552,15 @@ def marshal_UpdatePlacementGroupServersRequest(
}


def marshal_UpdatePrivateNICRequest(
request: UpdatePrivateNICRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
return {
"tags": request.tags,
}


def marshal_UpdateVolumeRequest(
request: UpdateVolumeRequest,
defaults: ProfileDefaults,
Expand Down
50 changes: 50 additions & 0 deletions scaleway-async/scaleway_async/instance/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ class ListPlacementGroupsResponse:
class ListPrivateNICsResponse:
private_nics: List[PrivateNIC]

total_count: int


@dataclass
class ListSecurityGroupRulesResponse:
Expand Down Expand Up @@ -796,6 +798,11 @@ class PrivateNIC:
The private NIC state
"""

tags: List[str]
"""
The private NIC tags
"""


@dataclass
class SecurityGroup:
Expand Down Expand Up @@ -2964,6 +2971,21 @@ class ListPrivateNICsRequest:
The server the private NIC is attached to
"""

tags: Optional[List[str]]
"""
The private NIC tags
"""

per_page: Optional[int]
"""
A positive integer lower or equal to 100 to select the number of items to return
"""

page: Optional[int]
"""
A positive integer to choose the page to return
"""


@dataclass
class CreatePrivateNICRequest:
Expand All @@ -2982,6 +3004,11 @@ class CreatePrivateNICRequest:
UUID of the private network where the private NIC will be attached
"""

tags: Optional[List[str]]
"""
The private NIC tags
"""


@dataclass
class GetPrivateNICRequest:
Expand All @@ -3001,6 +3028,29 @@ class GetPrivateNICRequest:
"""


@dataclass
class UpdatePrivateNICRequest:
zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config
"""

server_id: str
"""
UUID of the server the private NIC will be attached to
"""

private_nic_id: str
"""
The private NIC unique ID
"""

tags: Optional[List[str]]
"""
Tags used to select private NIC/s
"""


@dataclass
class DeletePrivateNICRequest:
zone: Optional[Zone]
Expand Down
Loading