Skip to content

Commit 3eaff4e

Browse files
authored
feat(k8s): list cluster types (#210)
1 parent 3cbd7c3 commit 3eaff4e

File tree

8 files changed

+350
-0
lines changed

8 files changed

+350
-0
lines changed

scaleway-async/scaleway_async/k8s/v1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .types import AutoscalerExpander
55
from .types import CNI
66
from .types import ClusterStatus
7+
from .types import ClusterTypeAvailability
78
from .types import Ingress
89
from .types import ListClustersRequestOrderBy
910
from .types import ListNodesRequestOrderBy
@@ -17,6 +18,7 @@
1718
from .types import ClusterAutoUpgrade
1819
from .types import ClusterAutoscalerConfig
1920
from .types import ClusterOpenIDConnectConfig
21+
from .types import ClusterType
2022
from .types import CreateClusterRequestAutoUpgrade
2123
from .types import CreateClusterRequestAutoscalerConfig
2224
from .types import CreateClusterRequestOpenIDConnectConfig
@@ -25,6 +27,7 @@
2527
from .types import CreatePoolRequestUpgradePolicy
2628
from .types import ExternalNode
2729
from .types import ListClusterAvailableVersionsResponse
30+
from .types import ListClusterTypesResponse
2831
from .types import ListClustersResponse
2932
from .types import ListNodesResponse
3033
from .types import ListPoolsResponse
@@ -48,6 +51,7 @@
4851
"AutoscalerExpander",
4952
"CNI",
5053
"ClusterStatus",
54+
"ClusterTypeAvailability",
5155
"Ingress",
5256
"ListClustersRequestOrderBy",
5357
"ListNodesRequestOrderBy",
@@ -61,6 +65,7 @@
6165
"ClusterAutoUpgrade",
6266
"ClusterAutoscalerConfig",
6367
"ClusterOpenIDConnectConfig",
68+
"ClusterType",
6469
"CreateClusterRequestAutoUpgrade",
6570
"CreateClusterRequestAutoscalerConfig",
6671
"CreateClusterRequestOpenIDConnectConfig",
@@ -69,6 +74,7 @@
6974
"CreatePoolRequestUpgradePolicy",
7075
"ExternalNode",
7176
"ListClusterAvailableVersionsResponse",
77+
"ListClusterTypesResponse",
7278
"ListClustersResponse",
7379
"ListNodesResponse",
7480
"ListPoolsResponse",

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
PoolVolumeType,
3030
Runtime,
3131
Cluster,
32+
ClusterType,
3233
CreateClusterRequestAutoUpgrade,
3334
CreateClusterRequestAutoscalerConfig,
3435
CreateClusterRequestOpenIDConnectConfig,
3536
CreateClusterRequestPoolConfig,
3637
CreatePoolRequestUpgradePolicy,
3738
ExternalNode,
3839
ListClusterAvailableVersionsResponse,
40+
ListClusterTypesResponse,
3941
ListClustersResponse,
4042
ListNodesResponse,
4143
ListPoolsResponse,
@@ -76,6 +78,7 @@
7678
unmarshal_Version,
7779
unmarshal_ExternalNode,
7880
unmarshal_ListClusterAvailableVersionsResponse,
81+
unmarshal_ListClusterTypesResponse,
7982
unmarshal_ListClustersResponse,
8083
unmarshal_ListNodesResponse,
8184
unmarshal_ListPoolsResponse,
@@ -1471,3 +1474,72 @@ async def get_version(
14711474

14721475
self._throw_on_error(res)
14731476
return unmarshal_Version(res.json())
1477+
1478+
async def list_cluster_types(
1479+
self,
1480+
*,
1481+
region: Optional[Region] = None,
1482+
page: Optional[int] = None,
1483+
page_size: Optional[int] = None,
1484+
) -> ListClusterTypesResponse:
1485+
"""
1486+
List cluster types.
1487+
List available cluster types and their technical details.
1488+
:param region: Region to target. If none is passed will use default region from the config.
1489+
:param page: Page number, from the paginated results, to return for cluster-types.
1490+
:param page_size: Maximum number of clusters per page.
1491+
:return: :class:`ListClusterTypesResponse <ListClusterTypesResponse>`
1492+
1493+
Usage:
1494+
::
1495+
1496+
result = await api.list_cluster_types()
1497+
"""
1498+
1499+
param_region = validate_path_param(
1500+
"region", region or self.client.default_region
1501+
)
1502+
1503+
res = self._request(
1504+
"GET",
1505+
f"/k8s/v1/regions/{param_region}/cluster-types",
1506+
params={
1507+
"page": page,
1508+
"page_size": page_size or self.client.default_page_size,
1509+
},
1510+
)
1511+
1512+
self._throw_on_error(res)
1513+
return unmarshal_ListClusterTypesResponse(res.json())
1514+
1515+
async def list_cluster_types_all(
1516+
self,
1517+
*,
1518+
region: Optional[Region] = None,
1519+
page: Optional[int] = None,
1520+
page_size: Optional[int] = None,
1521+
) -> List[ClusterType]:
1522+
"""
1523+
List cluster types.
1524+
List available cluster types and their technical details.
1525+
:param region: Region to target. If none is passed will use default region from the config.
1526+
:param page: Page number, from the paginated results, to return for cluster-types.
1527+
:param page_size: Maximum number of clusters per page.
1528+
:return: :class:`List[ListClusterTypesResponse] <List[ListClusterTypesResponse]>`
1529+
1530+
Usage:
1531+
::
1532+
1533+
result = await api.list_cluster_types_all()
1534+
"""
1535+
1536+
return await fetch_all_pages_async(
1537+
type=ListClusterTypesResponse,
1538+
key="cluster_types",
1539+
fetcher=self.list_cluster_types,
1540+
args={
1541+
"region": region,
1542+
"page": page,
1543+
"page_size": page_size,
1544+
},
1545+
)

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ClusterAutoUpgrade,
2222
ClusterAutoscalerConfig,
2323
ClusterOpenIDConnectConfig,
24+
ClusterType,
2425
CreateClusterRequestAutoUpgrade,
2526
CreateClusterRequestAutoscalerConfig,
2627
CreateClusterRequestOpenIDConnectConfig,
@@ -29,6 +30,7 @@
2930
CreatePoolRequestUpgradePolicy,
3031
ExternalNode,
3132
ListClusterAvailableVersionsResponse,
33+
ListClusterTypesResponse,
3234
ListClustersResponse,
3335
ListNodesResponse,
3436
ListPoolsResponse,
@@ -271,6 +273,23 @@ def unmarshal_Cluster(data: Any) -> Cluster:
271273
return Cluster(**args)
272274

273275

276+
def unmarshal_ClusterType(data: Any) -> ClusterType:
277+
if type(data) is not dict:
278+
raise TypeError(
279+
f"Unmarshalling the type 'ClusterType' failed as data isn't a dictionary."
280+
)
281+
282+
args: Dict[str, Any] = {}
283+
284+
field = data.get("availability")
285+
args["availability"] = field
286+
287+
field = data.get("name")
288+
args["name"] = field
289+
290+
return ClusterType(**args)
291+
292+
274293
def unmarshal_Node(data: Any) -> Node:
275294
if type(data) is not dict:
276295
raise TypeError(
@@ -489,6 +508,23 @@ def unmarshal_ListClusterAvailableVersionsResponse(
489508
return ListClusterAvailableVersionsResponse(**args)
490509

491510

511+
def unmarshal_ListClusterTypesResponse(data: Any) -> ListClusterTypesResponse:
512+
if type(data) is not dict:
513+
raise TypeError(
514+
f"Unmarshalling the type 'ListClusterTypesResponse' failed as data isn't a dictionary."
515+
)
516+
517+
args: Dict[str, Any] = {}
518+
519+
field = data.get("cluster_types")
520+
args["cluster_types"] = [unmarshal_ClusterType(v) for v in data["cluster_types"]]
521+
522+
field = data.get("total_count")
523+
args["total_count"] = field
524+
525+
return ListClusterTypesResponse(**args)
526+
527+
492528
def unmarshal_ListClustersResponse(data: Any) -> ListClustersResponse:
493529
if type(data) is not dict:
494530
raise TypeError(

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ def __str__(self) -> str:
5959
return str(self.value)
6060

6161

62+
class ClusterTypeAvailability(str, Enum):
63+
AVAILABLE = "available"
64+
SCARCE = "scarce"
65+
SHORTAGE = "shortage"
66+
67+
def __str__(self) -> str:
68+
return str(self.value)
69+
70+
6271
class Ingress(str, Enum):
6372
UNKNOWN_INGRESS = "unknown_ingress"
6473
NONE = "none"
@@ -425,6 +434,23 @@ class ClusterOpenIDConnectConfig:
425434
"""
426435

427436

437+
@dataclass
438+
class ClusterType:
439+
"""
440+
Cluster type.
441+
"""
442+
443+
name: str
444+
"""
445+
Cluster type name.
446+
"""
447+
448+
availability: ClusterTypeAvailability
449+
"""
450+
Cluster type availability.
451+
"""
452+
453+
428454
@dataclass
429455
class CreateClusterRequestAutoUpgrade:
430456
"""
@@ -678,6 +704,23 @@ class ListClusterAvailableVersionsResponse:
678704
"""
679705

680706

707+
@dataclass
708+
class ListClusterTypesResponse:
709+
"""
710+
List cluster types response.
711+
"""
712+
713+
total_count: int
714+
"""
715+
Total number of cluster-types.
716+
"""
717+
718+
cluster_types: List[ClusterType]
719+
"""
720+
Paginated returned cluster-types.
721+
"""
722+
723+
681724
@dataclass
682725
class ListClustersResponse:
683726
"""
@@ -1829,3 +1872,21 @@ class GetVersionRequest:
18291872
"""
18301873
Requested version name.
18311874
"""
1875+
1876+
1877+
@dataclass
1878+
class ListClusterTypesRequest:
1879+
region: Optional[Region]
1880+
"""
1881+
Region to target. If none is passed will use default region from the config.
1882+
"""
1883+
1884+
page: Optional[int]
1885+
"""
1886+
Page number, from the paginated results, to return for cluster-types.
1887+
"""
1888+
1889+
page_size: Optional[int]
1890+
"""
1891+
Maximum number of clusters per page.
1892+
"""

scaleway/scaleway/k8s/v1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .types import AutoscalerExpander
55
from .types import CNI
66
from .types import ClusterStatus
7+
from .types import ClusterTypeAvailability
78
from .types import Ingress
89
from .types import ListClustersRequestOrderBy
910
from .types import ListNodesRequestOrderBy
@@ -17,6 +18,7 @@
1718
from .types import ClusterAutoUpgrade
1819
from .types import ClusterAutoscalerConfig
1920
from .types import ClusterOpenIDConnectConfig
21+
from .types import ClusterType
2022
from .types import CreateClusterRequestAutoUpgrade
2123
from .types import CreateClusterRequestAutoscalerConfig
2224
from .types import CreateClusterRequestOpenIDConnectConfig
@@ -25,6 +27,7 @@
2527
from .types import CreatePoolRequestUpgradePolicy
2628
from .types import ExternalNode
2729
from .types import ListClusterAvailableVersionsResponse
30+
from .types import ListClusterTypesResponse
2831
from .types import ListClustersResponse
2932
from .types import ListNodesResponse
3033
from .types import ListPoolsResponse
@@ -48,6 +51,7 @@
4851
"AutoscalerExpander",
4952
"CNI",
5053
"ClusterStatus",
54+
"ClusterTypeAvailability",
5155
"Ingress",
5256
"ListClustersRequestOrderBy",
5357
"ListNodesRequestOrderBy",
@@ -61,6 +65,7 @@
6165
"ClusterAutoUpgrade",
6266
"ClusterAutoscalerConfig",
6367
"ClusterOpenIDConnectConfig",
68+
"ClusterType",
6469
"CreateClusterRequestAutoUpgrade",
6570
"CreateClusterRequestAutoscalerConfig",
6671
"CreateClusterRequestOpenIDConnectConfig",
@@ -69,6 +74,7 @@
6974
"CreatePoolRequestUpgradePolicy",
7075
"ExternalNode",
7176
"ListClusterAvailableVersionsResponse",
77+
"ListClusterTypesResponse",
7278
"ListClustersResponse",
7379
"ListNodesResponse",
7480
"ListPoolsResponse",

0 commit comments

Comments
 (0)