forked from scaleway/scaleway-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
1855 lines (1621 loc) · 65.1 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from typing import Awaitable, Dict, List, Optional, Union
from scaleway_core.api import API
from scaleway_core.bridge import (
Region as ScwRegion,
ScwFile,
Zone as ScwZone,
unmarshal_ScwFile,
)
from scaleway_core.utils import (
WaitForOptions,
random_name,
validate_path_param,
fetch_all_pages_async,
wait_for_resource_async,
)
from .types import (
CNI,
ClusterStatus,
ListClustersRequestOrderBy,
ListNodesRequestOrderBy,
ListPoolsRequestOrderBy,
NodeStatus,
PoolStatus,
PoolVolumeType,
Runtime,
ACLRule,
ACLRuleRequest,
AddClusterACLRulesRequest,
AddClusterACLRulesResponse,
Cluster,
ClusterType,
CreateClusterRequest,
CreateClusterRequestAutoUpgrade,
CreateClusterRequestAutoscalerConfig,
CreateClusterRequestOpenIDConnectConfig,
CreateClusterRequestPoolConfig,
CreatePoolRequest,
CreatePoolRequestUpgradePolicy,
ExternalNode,
ExternalNodeAuth,
ListClusterACLRulesResponse,
ListClusterAvailableTypesResponse,
ListClusterAvailableVersionsResponse,
ListClusterTypesResponse,
ListClustersResponse,
ListNodesResponse,
ListPoolsResponse,
ListVersionsResponse,
Node,
NodeMetadata,
Pool,
SetClusterACLRulesRequest,
SetClusterACLRulesResponse,
SetClusterTypeRequest,
UpdateClusterRequest,
UpdateClusterRequestAutoUpgrade,
UpdateClusterRequestAutoscalerConfig,
UpdateClusterRequestOpenIDConnectConfig,
UpdatePoolRequest,
UpdatePoolRequestUpgradePolicy,
UpgradeClusterRequest,
UpgradePoolRequest,
Version,
)
from .content import (
CLUSTER_TRANSIENT_STATUSES,
NODE_TRANSIENT_STATUSES,
POOL_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Pool,
unmarshal_Version,
unmarshal_Cluster,
unmarshal_Node,
unmarshal_AddClusterACLRulesResponse,
unmarshal_ExternalNode,
unmarshal_ExternalNodeAuth,
unmarshal_ListClusterACLRulesResponse,
unmarshal_ListClusterAvailableTypesResponse,
unmarshal_ListClusterAvailableVersionsResponse,
unmarshal_ListClusterTypesResponse,
unmarshal_ListClustersResponse,
unmarshal_ListNodesResponse,
unmarshal_ListPoolsResponse,
unmarshal_ListVersionsResponse,
unmarshal_NodeMetadata,
unmarshal_SetClusterACLRulesResponse,
marshal_AddClusterACLRulesRequest,
marshal_CreateClusterRequest,
marshal_CreatePoolRequest,
marshal_SetClusterACLRulesRequest,
marshal_SetClusterTypeRequest,
marshal_UpdateClusterRequest,
marshal_UpdatePoolRequest,
marshal_UpgradeClusterRequest,
marshal_UpgradePoolRequest,
)
class K8SV1API(API):
"""
This API allows you to manage Kubernetes Kapsule and Kosmos clusters.
"""
async def list_clusters(
self,
*,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
order_by: Optional[ListClustersRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
name: Optional[str] = None,
status: Optional[ClusterStatus] = None,
type_: Optional[str] = None,
private_network_id: Optional[str] = None,
) -> ListClustersResponse:
"""
List Clusters.
List all existing Kubernetes clusters in a specific region.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: Organization ID on which to filter the returned clusters.
:param project_id: Project ID on which to filter the returned clusters.
:param order_by: Sort order of returned clusters.
:param page: Page number to return for clusters, from the paginated results.
:param page_size: Maximum number of clusters per page.
:param name: Name to filter on, only clusters containing this substring in their name will be returned.
:param status: Status to filter on, only clusters with this status will be returned.
:param type_: Type to filter on, only clusters with this type will be returned.
:param private_network_id: Private Network ID to filter on, only clusters within this Private Network will be returned.
:return: :class:`ListClustersResponse <ListClustersResponse>`
Usage:
::
result = await api.list_clusters()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters",
params={
"name": name,
"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,
"private_network_id": private_network_id,
"project_id": project_id or self.client.default_project_id,
"status": status,
"type": type_,
},
)
self._throw_on_error(res)
return unmarshal_ListClustersResponse(res.json())
async def list_clusters_all(
self,
*,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
order_by: Optional[ListClustersRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
name: Optional[str] = None,
status: Optional[ClusterStatus] = None,
type_: Optional[str] = None,
private_network_id: Optional[str] = None,
) -> List[Cluster]:
"""
List Clusters.
List all existing Kubernetes clusters in a specific region.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: Organization ID on which to filter the returned clusters.
:param project_id: Project ID on which to filter the returned clusters.
:param order_by: Sort order of returned clusters.
:param page: Page number to return for clusters, from the paginated results.
:param page_size: Maximum number of clusters per page.
:param name: Name to filter on, only clusters containing this substring in their name will be returned.
:param status: Status to filter on, only clusters with this status will be returned.
:param type_: Type to filter on, only clusters with this type will be returned.
:param private_network_id: Private Network ID to filter on, only clusters within this Private Network will be returned.
:return: :class:`List[Cluster] <List[Cluster]>`
Usage:
::
result = await api.list_clusters_all()
"""
return await fetch_all_pages_async(
type=ListClustersResponse,
key="clusters",
fetcher=self.list_clusters,
args={
"region": region,
"organization_id": organization_id,
"project_id": project_id,
"order_by": order_by,
"page": page,
"page_size": page_size,
"name": name,
"status": status,
"type_": type_,
"private_network_id": private_network_id,
},
)
async def create_cluster(
self,
*,
type_: str,
description: str,
version: str,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
name: Optional[str] = None,
tags: Optional[List[str]] = None,
cni: CNI,
pools: Optional[List[CreateClusterRequestPoolConfig]] = None,
autoscaler_config: Optional[CreateClusterRequestAutoscalerConfig] = None,
auto_upgrade: Optional[CreateClusterRequestAutoUpgrade] = None,
feature_gates: Optional[List[str]] = None,
admission_plugins: Optional[List[str]] = None,
open_id_connect_config: Optional[
CreateClusterRequestOpenIDConnectConfig
] = None,
apiserver_cert_sans: Optional[List[str]] = None,
private_network_id: Optional[str] = None,
) -> Cluster:
"""
Create a new Cluster.
Create a new Kubernetes cluster in a Scaleway region.
:param type_: Type of the cluster. See [list available cluster types](#list-available-cluster-types-for-a-cluster) for a list of valid types.
:param description: Cluster description.
:param version: Kubernetes version of the cluster.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: Organization ID in which the cluster will be created.
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
:param project_id: Project ID in which the cluster will be created.
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
:param name: Cluster name.
:param tags: Tags associated with the cluster.
:param cni: Container Network Interface (CNI) plugin running in the cluster.
:param pools: Pools created along with the cluster.
:param autoscaler_config: Autoscaler configuration for the cluster. It allows you to set (to an extent) your preferred autoscaler configuration, which is an implementation of the cluster-autoscaler (https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/).
:param auto_upgrade: Auto upgrade configuration of the cluster. This configuration enables to set a specific 2-hour time window in which the cluster can be automatically updated to the latest patch version.
:param feature_gates: List of feature gates to enable.
:param admission_plugins: List of admission plugins to enable.
:param open_id_connect_config: OpenID Connect configuration of the cluster. This configuration enables to update the OpenID Connect configuration of the Kubernetes API server.
:param apiserver_cert_sans: Additional Subject Alternative Names for the Kubernetes API server certificate.
:param private_network_id: Private network ID for internal cluster communication (cannot be changed later).
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.create_cluster(
type="example",
description="example",
version="example",
cni=CNI.unknown_cni,
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"POST",
f"/k8s/v1/regions/{param_region}/clusters",
body=marshal_CreateClusterRequest(
CreateClusterRequest(
type_=type_,
description=description,
version=version,
region=region,
name=name or random_name(prefix="k8s"),
tags=tags,
cni=cni,
pools=pools,
autoscaler_config=autoscaler_config,
auto_upgrade=auto_upgrade,
feature_gates=feature_gates,
admission_plugins=admission_plugins,
open_id_connect_config=open_id_connect_config,
apiserver_cert_sans=apiserver_cert_sans,
private_network_id=private_network_id,
project_id=project_id,
organization_id=organization_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Cluster(res.json())
async def get_cluster(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
) -> Cluster:
"""
Get a Cluster.
Retrieve information about a specific Kubernetes cluster.
:param cluster_id: ID of the requested cluster.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.get_cluster(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}",
)
self._throw_on_error(res)
return unmarshal_Cluster(res.json())
async def wait_for_cluster(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
options: Optional[WaitForOptions[Cluster, Union[bool, Awaitable[bool]]]] = None,
) -> Cluster:
"""
Get a Cluster.
Retrieve information about a specific Kubernetes cluster.
:param cluster_id: ID of the requested cluster.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.get_cluster(
cluster_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in CLUSTER_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_cluster,
options=options,
args={
"cluster_id": cluster_id,
"region": region,
},
)
async def update_cluster(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
name: Optional[str] = None,
description: Optional[str] = None,
tags: Optional[List[str]] = None,
autoscaler_config: Optional[UpdateClusterRequestAutoscalerConfig] = None,
auto_upgrade: Optional[UpdateClusterRequestAutoUpgrade] = None,
feature_gates: Optional[List[str]] = None,
admission_plugins: Optional[List[str]] = None,
open_id_connect_config: Optional[
UpdateClusterRequestOpenIDConnectConfig
] = None,
apiserver_cert_sans: Optional[List[str]] = None,
) -> Cluster:
"""
Update a Cluster.
Update information on a specific Kubernetes cluster. You can update details such as its name, description, tags and configuration. To upgrade a cluster, you will need to use the dedicated endpoint.
:param cluster_id: ID of the cluster to update.
:param region: Region to target. If none is passed will use default region from the config.
:param name: New external name for the cluster.
:param description: New description for the cluster.
:param tags: New tags associated with the cluster.
:param autoscaler_config: New autoscaler config for the cluster.
:param auto_upgrade: New auto upgrade configuration for the cluster. Note that all fields needs to be set.
:param feature_gates: List of feature gates to enable.
:param admission_plugins: List of admission plugins to enable.
:param open_id_connect_config: OpenID Connect configuration of the cluster. This configuration enables to update the OpenID Connect configuration of the Kubernetes API server.
:param apiserver_cert_sans: Additional Subject Alternative Names for the Kubernetes API server certificate.
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.update_cluster(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"PATCH",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}",
body=marshal_UpdateClusterRequest(
UpdateClusterRequest(
cluster_id=cluster_id,
region=region,
name=name,
description=description,
tags=tags,
autoscaler_config=autoscaler_config,
auto_upgrade=auto_upgrade,
feature_gates=feature_gates,
admission_plugins=admission_plugins,
open_id_connect_config=open_id_connect_config,
apiserver_cert_sans=apiserver_cert_sans,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Cluster(res.json())
async def delete_cluster(
self,
*,
cluster_id: str,
with_additional_resources: bool,
region: Optional[ScwRegion] = None,
) -> Cluster:
"""
Delete a Cluster.
Delete a specific Kubernetes cluster and all its associated pools and nodes, and possibly its associated Load Balancers or Block Volumes.
:param cluster_id: ID of the cluster to delete.
:param with_additional_resources: Defines whether all volumes (including retain volume type), empty Private Networks and Load Balancers with a name starting with the cluster ID will also be deleted.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.delete_cluster(
cluster_id="example",
with_additional_resources=False,
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"DELETE",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}",
params={
"with_additional_resources": with_additional_resources,
},
)
self._throw_on_error(res)
return unmarshal_Cluster(res.json())
async def upgrade_cluster(
self,
*,
cluster_id: str,
version: str,
upgrade_pools: bool,
region: Optional[ScwRegion] = None,
) -> Cluster:
"""
Upgrade a Cluster.
Upgrade a specific Kubernetes cluster and possibly its associated pools to a specific and supported Kubernetes version.
:param cluster_id: ID of the cluster to upgrade.
:param version: New Kubernetes version of the cluster. Note that the version should either be a higher patch version of the same minor version or the direct minor version after the current one.
:param upgrade_pools: Defines whether pools will also be upgraded once the control plane is upgraded.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.upgrade_cluster(
cluster_id="example",
version="example",
upgrade_pools=False,
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"POST",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/upgrade",
body=marshal_UpgradeClusterRequest(
UpgradeClusterRequest(
cluster_id=cluster_id,
version=version,
upgrade_pools=upgrade_pools,
region=region,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Cluster(res.json())
async def set_cluster_type(
self,
*,
cluster_id: str,
type_: str,
region: Optional[ScwRegion] = None,
) -> Cluster:
"""
Change the Cluster type.
Change the type of a specific Kubernetes cluster. To see the possible values you can enter for the `type` field, [list available cluster types](#list-available-cluster-types-for-a-cluster).
:param cluster_id: ID of the cluster to migrate from one type to another.
:param type_: Type of the cluster. Note that some migrations are not possible (please refer to product documentation).
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Cluster <Cluster>`
Usage:
::
result = await api.set_cluster_type(
cluster_id="example",
type="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"POST",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/set-type",
body=marshal_SetClusterTypeRequest(
SetClusterTypeRequest(
cluster_id=cluster_id,
type_=type_,
region=region,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Cluster(res.json())
async def list_cluster_available_versions(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
) -> ListClusterAvailableVersionsResponse:
"""
List available versions for a Cluster.
List the versions that a specific Kubernetes cluster is allowed to upgrade to. Results will include every patch version greater than the current patch, as well as one minor version ahead of the current version. Any upgrade skipping a minor version will not work.
:param cluster_id: Cluster ID for which the available Kubernetes versions will be listed.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ListClusterAvailableVersionsResponse <ListClusterAvailableVersionsResponse>`
Usage:
::
result = await api.list_cluster_available_versions(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/available-versions",
)
self._throw_on_error(res)
return unmarshal_ListClusterAvailableVersionsResponse(res.json())
async def list_cluster_available_types(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
) -> ListClusterAvailableTypesResponse:
"""
List available cluster types for a cluster.
List the cluster types that a specific Kubernetes cluster is allowed to switch to.
:param cluster_id: Cluster ID for which the available Kubernetes types will be listed.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ListClusterAvailableTypesResponse <ListClusterAvailableTypesResponse>`
Usage:
::
result = await api.list_cluster_available_types(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/available-types",
)
self._throw_on_error(res)
return unmarshal_ListClusterAvailableTypesResponse(res.json())
async def _get_cluster_kube_config(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
redacted: Optional[bool] = None,
) -> ScwFile:
"""
Download the kubeconfig for a Cluster.
Download the Kubernetes cluster config file (also known as `kubeconfig`) for a specific cluster to use it with `kubectl`.
Tip: add `?dl=1` at the end of the URL to directly retrieve the base64 decoded kubeconfig. If you choose not to, the kubeconfig will be base64 encoded.
:param cluster_id: Cluster ID for which to download the kubeconfig.
:param region: Region to target. If none is passed will use default region from the config.
:param redacted: Hide the legacy token from the kubeconfig.
:return: :class:`ScwFile <ScwFile>`
Usage:
::
result = await api._get_cluster_kube_config(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/kubeconfig",
params={
"redacted": redacted,
},
)
self._throw_on_error(res)
return unmarshal_ScwFile(res.json())
async def reset_cluster_admin_token(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
) -> None:
"""
Reset the admin token of a Cluster.
Reset the admin token for a specific Kubernetes cluster. This will revoke the old admin token (which will not be usable afterwards) and create a new one. Note that you will need to download the kubeconfig again to keep interacting with the cluster.
:param cluster_id: Cluster ID on which the admin token will be renewed.
:param region: Region to target. If none is passed will use default region from the config.
Usage:
::
result = await api.reset_cluster_admin_token(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"POST",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/reset-admin-token",
body={},
)
self._throw_on_error(res)
async def list_cluster_acl_rules(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> ListClusterACLRulesResponse:
"""
List ACLs.
List ACLs for a specific cluster.
:param cluster_id: ID of the cluster whose ACLs will be listed.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number for the returned ACLs.
:param page_size: Maximum number of ACLs per page.
:return: :class:`ListClusterACLRulesResponse <ListClusterACLRulesResponse>`
Usage:
::
result = await api.list_cluster_acl_rules(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/acls",
params={
"page": page,
"page_size": page_size or self.client.default_page_size,
},
)
self._throw_on_error(res)
return unmarshal_ListClusterACLRulesResponse(res.json())
async def list_cluster_acl_rules_all(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ACLRule]:
"""
List ACLs.
List ACLs for a specific cluster.
:param cluster_id: ID of the cluster whose ACLs will be listed.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number for the returned ACLs.
:param page_size: Maximum number of ACLs per page.
:return: :class:`List[ACLRule] <List[ACLRule]>`
Usage:
::
result = await api.list_cluster_acl_rules_all(
cluster_id="example",
)
"""
return await fetch_all_pages_async(
type=ListClusterACLRulesResponse,
key="rules",
fetcher=self.list_cluster_acl_rules,
args={
"cluster_id": cluster_id,
"region": region,
"page": page,
"page_size": page_size,
},
)
async def add_cluster_acl_rules(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
acls: Optional[List[ACLRuleRequest]] = None,
) -> AddClusterACLRulesResponse:
"""
Add new ACLs.
Add new ACL rules for a specific cluster.
:param cluster_id: ID of the cluster whose ACLs will be added.
:param region: Region to target. If none is passed will use default region from the config.
:param acls: ACLs to add.
:return: :class:`AddClusterACLRulesResponse <AddClusterACLRulesResponse>`
Usage:
::
result = await api.add_cluster_acl_rules(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"POST",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/acls",
body=marshal_AddClusterACLRulesRequest(
AddClusterACLRulesRequest(
cluster_id=cluster_id,
region=region,
acls=acls,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_AddClusterACLRulesResponse(res.json())
async def set_cluster_acl_rules(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
acls: Optional[List[ACLRuleRequest]] = None,
) -> SetClusterACLRulesResponse:
"""
Set new ACLs.
Set new ACL rules for a specific cluster.
:param cluster_id: ID of the cluster whose ACLs will be set.
:param region: Region to target. If none is passed will use default region from the config.
:param acls: ACLs to set.
:return: :class:`SetClusterACLRulesResponse <SetClusterACLRulesResponse>`
Usage:
::
result = await api.set_cluster_acl_rules(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"PUT",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/acls",
body=marshal_SetClusterACLRulesRequest(
SetClusterACLRulesRequest(
cluster_id=cluster_id,
region=region,
acls=acls,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_SetClusterACLRulesResponse(res.json())
async def delete_acl_rule(
self,
*,
acl_id: str,
region: Optional[ScwRegion] = None,
) -> None:
"""
Delete an existing ACL.
:param acl_id: ID of the ACL rule to delete.
:param region: Region to target. If none is passed will use default region from the config.
Usage:
::
result = await api.delete_acl_rule(
acl_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_acl_id = validate_path_param("acl_id", acl_id)
res = self._request(
"DELETE",
f"/k8s/v1/regions/{param_region}/acls/{param_acl_id}",
)
self._throw_on_error(res)
async def list_pools(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
order_by: Optional[ListPoolsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
name: Optional[str] = None,
status: Optional[PoolStatus] = None,
) -> ListPoolsResponse:
"""
List Pools in a Cluster.
List all the existing pools for a specific Kubernetes cluster.
:param cluster_id: ID of the cluster whose pools will be listed.
:param region: Region to target. If none is passed will use default region from the config.
:param order_by: Sort order of returned pools.
:param page: Page number for the returned pools.
:param page_size: Maximum number of pools per page.
:param name: Name to filter on, only pools containing this substring in their name will be returned.
:param status: Status to filter on, only pools with this status will be returned.
:return: :class:`ListPoolsResponse <ListPoolsResponse>`
Usage:
::
result = await api.list_pools(
cluster_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_cluster_id = validate_path_param("cluster_id", cluster_id)
res = self._request(
"GET",
f"/k8s/v1/regions/{param_region}/clusters/{param_cluster_id}/pools",
params={
"name": name,
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
"status": status,
},
)
self._throw_on_error(res)
return unmarshal_ListPoolsResponse(res.json())
async def list_pools_all(
self,
*,
cluster_id: str,
region: Optional[ScwRegion] = None,
order_by: Optional[ListPoolsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
name: Optional[str] = None,
status: Optional[PoolStatus] = None,
) -> List[Pool]:
"""
List Pools in a Cluster.
List all the existing pools for a specific Kubernetes cluster.
:param cluster_id: ID of the cluster whose pools will be listed.
:param region: Region to target. If none is passed will use default region from the config.
:param order_by: Sort order of returned pools.
:param page: Page number for the returned pools.
:param page_size: Maximum number of pools per page.
:param name: Name to filter on, only pools containing this substring in their name will be returned.
:param status: Status to filter on, only pools with this status will be returned.
:return: :class:`List[Pool] <List[Pool]>`