Skip to content

feat(vpc/v2): add ListSubnets #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
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
6 changes: 6 additions & 0 deletions scaleway-async/scaleway_async/vpc/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import ListPrivateNetworksRequestOrderBy
from .types import ListSubnetsRequestOrderBy
from .types import ListVPCsRequestOrderBy
from .types import Subnet
from .types import PrivateNetwork
Expand All @@ -19,6 +20,8 @@
from .types import GetVPCRequest
from .types import ListPrivateNetworksRequest
from .types import ListPrivateNetworksResponse
from .types import ListSubnetsRequest
from .types import ListSubnetsResponse
from .types import ListVPCsRequest
from .types import ListVPCsResponse
from .types import MigrateZonalPrivateNetworksRequest
Expand All @@ -30,6 +33,7 @@

__all__ = [
"ListPrivateNetworksRequestOrderBy",
"ListSubnetsRequestOrderBy",
"ListVPCsRequestOrderBy",
"Subnet",
"PrivateNetwork",
Expand All @@ -48,6 +52,8 @@
"GetVPCRequest",
"ListPrivateNetworksRequest",
"ListPrivateNetworksResponse",
"ListSubnetsRequest",
"ListSubnetsResponse",
"ListVPCsRequest",
"ListVPCsResponse",
"MigrateZonalPrivateNetworksRequest",
Expand Down
100 changes: 100 additions & 0 deletions scaleway-async/scaleway_async/vpc/v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from .types import (
ListPrivateNetworksRequestOrderBy,
ListSubnetsRequestOrderBy,
ListVPCsRequestOrderBy,
AddSubnetsRequest,
AddSubnetsResponse,
Expand All @@ -22,11 +23,13 @@
DeleteSubnetsRequest,
DeleteSubnetsResponse,
ListPrivateNetworksResponse,
ListSubnetsResponse,
ListVPCsResponse,
MigrateZonalPrivateNetworksRequest,
PrivateNetwork,
SetSubnetsRequest,
SetSubnetsResponse,
Subnet,
UpdatePrivateNetworkRequest,
UpdateVPCRequest,
VPC,
Expand All @@ -37,6 +40,7 @@
unmarshal_AddSubnetsResponse,
unmarshal_DeleteSubnetsResponse,
unmarshal_ListPrivateNetworksResponse,
unmarshal_ListSubnetsResponse,
unmarshal_ListVPCsResponse,
unmarshal_SetSubnetsResponse,
marshal_AddSubnetsRequest,
Expand Down Expand Up @@ -732,6 +736,102 @@ async def enable_routing(
self._throw_on_error(res)
return unmarshal_VPC(res.json())

async def list_subnets(
self,
*,
region: Optional[Region] = None,
order_by: Optional[ListSubnetsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
subnet_ids: Optional[List[str]] = None,
vpc_id: Optional[str] = None,
) -> ListSubnetsResponse:
"""
:param region: Region to target. If none is passed will use default region from the config.
:param order_by:
:param page:
:param page_size:
:param organization_id:
:param project_id:
:param subnet_ids:
:param vpc_id:
:return: :class:`ListSubnetsResponse <ListSubnetsResponse>`

Usage:
::

result = await api.list_subnets()
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"GET",
f"/vpc/v2/regions/{param_region}/subnets",
params={
"order_by": order_by,
"organization_id": organization_id
or self.client.default_organization_id,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
"subnet_ids": subnet_ids,
"vpc_id": vpc_id,
},
)

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

async def list_subnets_all(
self,
*,
region: Optional[Region] = None,
order_by: Optional[ListSubnetsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
subnet_ids: Optional[List[str]] = None,
vpc_id: Optional[str] = None,
) -> List[Subnet]:
"""
:param region: Region to target. If none is passed will use default region from the config.
:param order_by:
:param page:
:param page_size:
:param organization_id:
:param project_id:
:param subnet_ids:
:param vpc_id:
:return: :class:`List[Subnet] <List[Subnet]>`

Usage:
::

result = await api.list_subnets_all()
"""

return await fetch_all_pages_async(
type=ListSubnetsResponse,
key="subnets",
fetcher=self.list_subnets,
args={
"region": region,
"order_by": order_by,
"page": page,
"page_size": page_size,
"organization_id": organization_id,
"project_id": project_id,
"subnet_ids": subnet_ids,
"vpc_id": vpc_id,
},
)

async def set_subnets(
self,
*,
Expand Down
22 changes: 22 additions & 0 deletions scaleway-async/scaleway_async/vpc/v2/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AddSubnetsResponse,
DeleteSubnetsResponse,
ListPrivateNetworksResponse,
ListSubnetsResponse,
ListVPCsResponse,
SetSubnetsResponse,
AddSubnetsRequest,
Expand Down Expand Up @@ -231,6 +232,27 @@ def unmarshal_ListPrivateNetworksResponse(data: Any) -> ListPrivateNetworksRespo
return ListPrivateNetworksResponse(**args)


def unmarshal_ListSubnetsResponse(data: Any) -> ListSubnetsResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ListSubnetsResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("subnets", None)
if field is not None:
args["subnets"] = (
[unmarshal_Subnet(v) for v in field] if field is not None else None
)

field = data.get("total_count", None)
if field is not None:
args["total_count"] = field

return ListSubnetsResponse(**args)


def unmarshal_ListVPCsResponse(data: Any) -> ListVPCsResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down
37 changes: 37 additions & 0 deletions scaleway-async/scaleway_async/vpc/v2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def __str__(self) -> str:
return str(self.value)


class ListSubnetsRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
CREATED_AT_ASC = "created_at_asc"
CREATED_AT_DESC = "created_at_desc"

def __str__(self) -> str:
return str(self.value)


class ListVPCsRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
CREATED_AT_ASC = "created_at_asc"
CREATED_AT_DESC = "created_at_desc"
Expand Down Expand Up @@ -421,6 +429,35 @@ class ListPrivateNetworksResponse:
total_count: int


@dataclass
class ListSubnetsRequest:
region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""

order_by: Optional[ListSubnetsRequestOrderBy]

page: Optional[int]

page_size: Optional[int]

organization_id: Optional[str]

project_id: Optional[str]

subnet_ids: Optional[List[str]]

vpc_id: Optional[str]


@dataclass
class ListSubnetsResponse:
subnets: List[Subnet]

total_count: int


@dataclass
class ListVPCsRequest:
region: Optional[Region]
Expand Down
6 changes: 6 additions & 0 deletions scaleway/scaleway/vpc/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import ListPrivateNetworksRequestOrderBy
from .types import ListSubnetsRequestOrderBy
from .types import ListVPCsRequestOrderBy
from .types import Subnet
from .types import PrivateNetwork
Expand All @@ -19,6 +20,8 @@
from .types import GetVPCRequest
from .types import ListPrivateNetworksRequest
from .types import ListPrivateNetworksResponse
from .types import ListSubnetsRequest
from .types import ListSubnetsResponse
from .types import ListVPCsRequest
from .types import ListVPCsResponse
from .types import MigrateZonalPrivateNetworksRequest
Expand All @@ -30,6 +33,7 @@

__all__ = [
"ListPrivateNetworksRequestOrderBy",
"ListSubnetsRequestOrderBy",
"ListVPCsRequestOrderBy",
"Subnet",
"PrivateNetwork",
Expand All @@ -48,6 +52,8 @@
"GetVPCRequest",
"ListPrivateNetworksRequest",
"ListPrivateNetworksResponse",
"ListSubnetsRequest",
"ListSubnetsResponse",
"ListVPCsRequest",
"ListVPCsResponse",
"MigrateZonalPrivateNetworksRequest",
Expand Down
Loading