-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathapi.py
More file actions
1349 lines (1165 loc) · 48.5 KB
/
api.py
File metadata and controls
1349 lines (1165 loc) · 48.5 KB
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, Optional, Union
from scaleway_core.api import API
from scaleway_core.bridge import (
Zone as ScwZone,
)
from scaleway_core.utils import (
WaitForOptions,
random_name,
validate_path_param,
fetch_all_pages_async,
wait_for_resource_async,
)
from .types import (
CommitmentType,
ListServerPrivateNetworksRequestOrderBy,
ListServersRequestOrderBy,
AppliedRunnerConfigurations,
BatchCreateServersRequest,
BatchCreateServersRequestBatchInnerCreateServerRequest,
BatchCreateServersResponse,
CommitmentTypeValue,
ConnectivityDiagnostic,
CreateRunnerRequest,
CreateServerRequest,
ListOSResponse,
ListRunnersResponse,
ListServerPrivateNetworksResponse,
ListServerTypesResponse,
ListServersResponse,
OS,
PrivateNetworkApiAddServerPrivateNetworkRequest,
PrivateNetworkApiSetServerPrivateNetworksRequest,
ReinstallServerRequest,
Runner,
RunnerConfiguration,
RunnerConfigurationV2,
Server,
ServerPrivateNetwork,
ServerType,
SetServerPrivateNetworksResponse,
StartConnectivityDiagnosticRequest,
StartConnectivityDiagnosticResponse,
UpdateRunnerRequest,
UpdateServerRequest,
)
from .content import (
RUNNER_TRANSIENT_STATUSES,
SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES,
SERVER_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_OS,
unmarshal_Server,
unmarshal_Runner,
unmarshal_ServerPrivateNetwork,
unmarshal_ServerType,
unmarshal_BatchCreateServersResponse,
unmarshal_ConnectivityDiagnostic,
unmarshal_ListOSResponse,
unmarshal_ListRunnersResponse,
unmarshal_ListServerPrivateNetworksResponse,
unmarshal_ListServerTypesResponse,
unmarshal_ListServersResponse,
unmarshal_SetServerPrivateNetworksResponse,
unmarshal_StartConnectivityDiagnosticResponse,
marshal_BatchCreateServersRequest,
marshal_CreateRunnerRequest,
marshal_CreateServerRequest,
marshal_PrivateNetworkApiAddServerPrivateNetworkRequest,
marshal_PrivateNetworkApiSetServerPrivateNetworksRequest,
marshal_ReinstallServerRequest,
marshal_StartConnectivityDiagnosticRequest,
marshal_UpdateRunnerRequest,
marshal_UpdateServerRequest,
)
class ApplesiliconV1Alpha1API(API):
"""
This API allows you to manage your Apple silicon machines.
"""
async def list_server_types(
self,
*,
zone: Optional[ScwZone] = None,
) -> ListServerTypesResponse:
"""
List server types.
List all technical details about Apple silicon server types available in the specified zone. Since there is only one Availability Zone for Apple silicon servers, the targeted value is `fr-par-3`.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`ListServerTypesResponse <ListServerTypesResponse>`
Usage:
::
result = await api.list_server_types()
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/server-types",
)
self._throw_on_error(res)
return unmarshal_ListServerTypesResponse(res.json())
async def get_server_type(
self,
*,
server_type: str,
zone: Optional[ScwZone] = None,
) -> ServerType:
"""
Get a server type.
Get technical details (CPU, disk size etc.) of a server type.
:param server_type: Server type identifier.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`ServerType <ServerType>`
Usage:
::
result = await api.get_server_type(
server_type="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_type = validate_path_param("server_type", server_type)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/server-type/{param_server_type}",
)
self._throw_on_error(res)
return unmarshal_ServerType(res.json())
async def create_server(
self,
*,
type_: str,
enable_vpc: bool,
public_bandwidth_bps: int,
enable_kext: bool,
zone: Optional[ScwZone] = None,
name: Optional[str] = None,
project_id: Optional[str] = None,
os_id: Optional[str] = None,
commitment_type: Optional[CommitmentType] = None,
runner_configuration: Optional[RunnerConfiguration] = None,
applied_runner_configurations: Optional[AppliedRunnerConfigurations] = None,
) -> Server:
"""
Create a server.
Create a new server in the targeted zone, specifying its configuration including name and type.
:param type_: Create a server of the given type.
:param enable_vpc: Activate the Private Network feature for this server. This feature is configured through the Apple Silicon - Private Networks API.
:param public_bandwidth_bps: Public bandwidth to configure for this server. This defaults to the minimum bandwidth for this server type. For compatible server types, the bandwidth can be increased which incurs additional costs.
:param enable_kext: Enable kernel extensions in this install of mac OS.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param name: Create a server with this given name.
:param project_id: Create a server in the given project ID.
:param os_id: Create a server & install the given os_id, when no os_id provided the default OS for this server type is chosen. Requesting a non-default OS will induce an extended delivery time.
:param commitment_type: Activate commitment for this server. If not specified, there is a 24h commitment due to Apple licensing (commitment_type `duration_24h`). It can be updated with the Update Server request. Available commitment depends on server type.
:param runner_configuration: Specify the configuration to install an optional CICD runner on the server during installation.
:param applied_runner_configurations: Runner configurations to apply on the server, existing ones missing from the specified configuration will be removed from the server.
:return: :class:`Server <Server>`
Usage:
::
result = await api.create_server(
type="example",
enable_vpc=False,
public_bandwidth_bps=1,
enable_kext=False,
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers",
body=marshal_CreateServerRequest(
CreateServerRequest(
type_=type_,
enable_vpc=enable_vpc,
public_bandwidth_bps=public_bandwidth_bps,
enable_kext=enable_kext,
zone=zone,
name=name or random_name(prefix="as"),
project_id=project_id,
os_id=os_id,
commitment_type=commitment_type,
runner_configuration=runner_configuration,
applied_runner_configurations=applied_runner_configurations,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Server(res.json())
async def batch_create_servers(
self,
*,
type_: str,
enable_vpc: bool,
public_bandwidth_bps: int,
enable_kext: bool,
zone: Optional[ScwZone] = None,
project_id: Optional[str] = None,
os_id: Optional[str] = None,
commitment_type: Optional[CommitmentType] = None,
requests: Optional[
list[BatchCreateServersRequestBatchInnerCreateServerRequest]
] = None,
) -> BatchCreateServersResponse:
"""
Create multiple servers atomically.
Create multiple servers in the targeted zone specifying their configurations. If the request cannot entirely be fulfilled, no servers are created.
:param type_: Create servers of the given type.
:param enable_vpc: Activate the Private Network feature for these servers. This feature is configured through the Apple Silicon - Private Networks API.
:param public_bandwidth_bps: Public bandwidth to configure for these servers. This defaults to the minimum bandwidth for the corresponding server type. For compatible server types, the bandwidth can be increased which incurs additional costs.
:param enable_kext: Enable kernel extensions in this install of mac OS.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param project_id: Create servers in the given project ID.
:param os_id: Create servers & install the given os_id, when no os_id provided the default OS for this server type is chosen. Requesting a non-default OS will induce an extended delivery time.
:param commitment_type: Activate commitment for these servers. If not specified, there is a 24h commitment due to Apple licensing (commitment_type `duration_24h`). It can be updated with the Update Server request. Available commitment depends on server type.
:param requests: List of servers to create.
:return: :class:`BatchCreateServersResponse <BatchCreateServersResponse>`
Usage:
::
result = await api.batch_create_servers(
type="example",
enable_vpc=False,
public_bandwidth_bps=1,
enable_kext=False,
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/batch-create-servers",
body=marshal_BatchCreateServersRequest(
BatchCreateServersRequest(
type_=type_,
enable_vpc=enable_vpc,
public_bandwidth_bps=public_bandwidth_bps,
enable_kext=enable_kext,
zone=zone,
project_id=project_id,
os_id=os_id,
commitment_type=commitment_type,
requests=requests,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_BatchCreateServersResponse(res.json())
async def list_servers(
self,
*,
zone: Optional[ScwZone] = None,
order_by: Optional[ListServersRequestOrderBy] = None,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> ListServersResponse:
"""
List all servers.
List all servers in the specified zone. By default, returned servers in the list are ordered by creation date in ascending order, though this can be modified via the `order_by` field.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param order_by: Sort order of the returned servers.
:param project_id: Only list servers of this project ID.
:param organization_id: Only list servers of this Organization ID.
:param page: Positive integer to choose the page to return.
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
:return: :class:`ListServersResponse <ListServersResponse>`
Usage:
::
result = await api.list_servers()
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers",
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,
},
)
self._throw_on_error(res)
return unmarshal_ListServersResponse(res.json())
async def list_servers_all(
self,
*,
zone: Optional[ScwZone] = None,
order_by: Optional[ListServersRequestOrderBy] = None,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> list[Server]:
"""
List all servers.
List all servers in the specified zone. By default, returned servers in the list are ordered by creation date in ascending order, though this can be modified via the `order_by` field.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param order_by: Sort order of the returned servers.
:param project_id: Only list servers of this project ID.
:param organization_id: Only list servers of this Organization ID.
:param page: Positive integer to choose the page to return.
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
:return: :class:`list[Server] <list[Server]>`
Usage:
::
result = await api.list_servers_all()
"""
return await fetch_all_pages_async(
type=ListServersResponse,
key="servers",
fetcher=self.list_servers,
args={
"zone": zone,
"order_by": order_by,
"project_id": project_id,
"organization_id": organization_id,
"page": page,
"page_size": page_size,
},
)
async def list_os(
self,
*,
zone: Optional[ScwZone] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
server_type: Optional[str] = None,
name: Optional[str] = None,
) -> ListOSResponse:
"""
List all Operating Systems (OS).
List all Operating Systems (OS). The response will include the total number of OS as well as their associated IDs, names and labels.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param page: Positive integer to choose the page to return.
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
:param server_type: List of compatible server types.
:param name: Filter OS by name (note that "11.1" will return "11.1.2" and "11.1" but not "12")).
:return: :class:`ListOSResponse <ListOSResponse>`
Usage:
::
result = await api.list_os()
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/os",
params={
"name": name,
"page": page,
"page_size": page_size or self.client.default_page_size,
"server_type": server_type,
},
)
self._throw_on_error(res)
return unmarshal_ListOSResponse(res.json())
async def list_os_all(
self,
*,
zone: Optional[ScwZone] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
server_type: Optional[str] = None,
name: Optional[str] = None,
) -> list[OS]:
"""
List all Operating Systems (OS).
List all Operating Systems (OS). The response will include the total number of OS as well as their associated IDs, names and labels.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param page: Positive integer to choose the page to return.
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
:param server_type: List of compatible server types.
:param name: Filter OS by name (note that "11.1" will return "11.1.2" and "11.1" but not "12")).
:return: :class:`list[OS] <list[OS]>`
Usage:
::
result = await api.list_os_all()
"""
return await fetch_all_pages_async(
type=ListOSResponse,
key="os",
fetcher=self.list_os,
args={
"zone": zone,
"page": page,
"page_size": page_size,
"server_type": server_type,
"name": name,
},
)
async def get_os(
self,
*,
os_id: str,
zone: Optional[ScwZone] = None,
) -> OS:
"""
Get an Operating System (OS).
Get an Operating System (OS). The response will include the OS's unique ID as well as its name and label.
:param os_id: UUID of the OS you want to get.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`OS <OS>`
Usage:
::
result = await api.get_os(
os_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_os_id = validate_path_param("os_id", os_id)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/os/{param_os_id}",
)
self._throw_on_error(res)
return unmarshal_OS(res.json())
async def get_server(
self,
*,
server_id: str,
zone: Optional[ScwZone] = None,
) -> Server:
"""
Get a server.
Retrieve information about an existing Apple silicon server, specified by its server ID. Its full details, including name, status and IP address, are returned in the response object.
:param server_id: UUID of the server you want to get.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`Server <Server>`
Usage:
::
result = await api.get_server(
server_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}",
)
self._throw_on_error(res)
return unmarshal_Server(res.json())
async def wait_for_server(
self,
*,
server_id: str,
zone: Optional[ScwZone] = None,
options: Optional[WaitForOptions[Server, Union[bool, Awaitable[bool]]]] = None,
) -> Server:
"""
Get a server.
Retrieve information about an existing Apple silicon server, specified by its server ID. Its full details, including name, status and IP address, are returned in the response object.
:param server_id: UUID of the server you want to get.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`Server <Server>`
Usage:
::
result = await api.get_server(
server_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in SERVER_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_server,
options=options,
args={
"server_id": server_id,
"zone": zone,
},
)
async def update_server(
self,
*,
server_id: str,
zone: Optional[ScwZone] = None,
name: Optional[str] = None,
schedule_deletion: Optional[bool] = None,
enable_vpc: Optional[bool] = None,
commitment_type: Optional[CommitmentTypeValue] = None,
public_bandwidth_bps: Optional[int] = None,
applied_runner_configurations: Optional[AppliedRunnerConfigurations] = None,
) -> Server:
"""
Update a server.
Update the parameters of an existing Apple silicon server, specified by its server ID.
:param server_id: UUID of the server you want to update.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param name: Updated name for your server.
:param schedule_deletion: Specify whether the server should be flagged for automatic deletion.
:param enable_vpc: Activate or deactivate Private Network support for this server.
:param commitment_type: Change commitment. Use 'none' to automatically cancel a renewing commitment.
:param public_bandwidth_bps: Public bandwidth to configure for this server. Setting an higher bandwidth incurs additional costs. Supported bandwidth levels depends on server type and can be queried using the `/server-types` endpoint.
:param applied_runner_configurations: Runner configurations to apply on the server, existing ones missing from the specified configuration will be removed from the server.
:return: :class:`Server <Server>`
Usage:
::
result = await api.update_server(
server_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)
res = self._request(
"PATCH",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}",
body=marshal_UpdateServerRequest(
UpdateServerRequest(
server_id=server_id,
zone=zone,
name=name,
schedule_deletion=schedule_deletion,
enable_vpc=enable_vpc,
commitment_type=commitment_type,
public_bandwidth_bps=public_bandwidth_bps,
applied_runner_configurations=applied_runner_configurations,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Server(res.json())
async def delete_server(
self,
*,
server_id: str,
zone: Optional[ScwZone] = None,
) -> None:
"""
Delete a server.
Delete an existing Apple silicon server, specified by its server ID. Deleting a server is permanent, and cannot be undone. Note that the minimum allocation period for Apple silicon-as-a-service is 24 hours, meaning you cannot delete your server prior to that.
:param server_id: UUID of the server you want to delete.
:param zone: Zone to target. If none is passed will use default zone from the config.
Usage:
::
result = await api.delete_server(
server_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)
res = self._request(
"DELETE",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}",
)
self._throw_on_error(res)
async def reboot_server(
self,
*,
server_id: str,
zone: Optional[ScwZone] = None,
) -> Server:
"""
Reboot a server.
Reboot an existing Apple silicon server, specified by its server ID.
:param server_id: UUID of the server you want to reboot.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`Server <Server>`
Usage:
::
result = await api.reboot_server(
server_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}/reboot",
body={},
)
self._throw_on_error(res)
return unmarshal_Server(res.json())
async def reinstall_server(
self,
*,
server_id: str,
enable_kext: bool,
zone: Optional[ScwZone] = None,
os_id: Optional[str] = None,
) -> Server:
"""
Reinstall a server.
Reinstall an existing Apple silicon server (specified by its server ID) from a new image (OS). All the data on the disk is deleted and all configuration is reset to the default configuration values of the image (OS).
:param server_id: UUID of the server you want to reinstall.
:param enable_kext: Enable kernel extensions in this install of mac OS.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param os_id: Reinstall the server with the target OS, when no os_id provided the default OS for the server type is used.
:return: :class:`Server <Server>`
Usage:
::
result = await api.reinstall_server(
server_id="example",
enable_kext=False,
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}/reinstall",
body=marshal_ReinstallServerRequest(
ReinstallServerRequest(
server_id=server_id,
enable_kext=enable_kext,
zone=zone,
os_id=os_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Server(res.json())
async def start_connectivity_diagnostic(
self,
*,
server_id: str,
zone: Optional[ScwZone] = None,
) -> StartConnectivityDiagnosticResponse:
"""
:param server_id:
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`StartConnectivityDiagnosticResponse <StartConnectivityDiagnosticResponse>`
Usage:
::
result = await api.start_connectivity_diagnostic(
server_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/connectivity-diagnostics",
body=marshal_StartConnectivityDiagnosticRequest(
StartConnectivityDiagnosticRequest(
server_id=server_id,
zone=zone,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_StartConnectivityDiagnosticResponse(res.json())
async def get_connectivity_diagnostic(
self,
*,
diagnostic_id: str,
zone: Optional[ScwZone] = None,
) -> ConnectivityDiagnostic:
"""
:param diagnostic_id:
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`ConnectivityDiagnostic <ConnectivityDiagnostic>`
Usage:
::
result = await api.get_connectivity_diagnostic(
diagnostic_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_diagnostic_id = validate_path_param("diagnostic_id", diagnostic_id)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/connectivity-diagnostics/{param_diagnostic_id}",
)
self._throw_on_error(res)
return unmarshal_ConnectivityDiagnostic(res.json())
async def create_runner(
self,
*,
runner_configuration: RunnerConfigurationV2,
zone: Optional[ScwZone] = None,
project_id: Optional[str] = None,
) -> Runner:
"""
Create a new runner configuration.
:param runner_configuration: Configuration details for the runner.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param project_id: Creates a runner in the given project_id.
:return: :class:`Runner <Runner>`
Usage:
::
result = await api.create_runner(
runner_configuration=RunnerConfigurationV2(),
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/runners",
body=marshal_CreateRunnerRequest(
CreateRunnerRequest(
runner_configuration=runner_configuration,
zone=zone,
project_id=project_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Runner(res.json())
async def get_runner(
self,
*,
runner_id: str,
zone: Optional[ScwZone] = None,
) -> Runner:
"""
Retrieve a runner configuration.
:param runner_id: ID of the runner configuration to get.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`Runner <Runner>`
Usage:
::
result = await api.get_runner(
runner_id="example",
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_runner_id = validate_path_param("runner_id", runner_id)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/runners/{param_runner_id}",
)
self._throw_on_error(res)
return unmarshal_Runner(res.json())
async def wait_for_runner(
self,
*,
runner_id: str,
zone: Optional[ScwZone] = None,
options: Optional[WaitForOptions[Runner, Union[bool, Awaitable[bool]]]] = None,
) -> Runner:
"""
Retrieve a runner configuration.
:param runner_id: ID of the runner configuration to get.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`Runner <Runner>`
Usage:
::
result = await api.get_runner(
runner_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in RUNNER_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_runner,
options=options,
args={
"runner_id": runner_id,
"zone": zone,
},
)
async def list_runners(
self,
*,
zone: Optional[ScwZone] = None,
server_id: Optional[str] = None,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> ListRunnersResponse:
"""
List runner configurations associated with a server.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param server_id: ID of the server for which to list applied runner configurations.
:param project_id: Only list servers of this project ID.
:param organization_id: Only list servers of this Organization ID.
:param page: Positive integer to choose the page to return.
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
:return: :class:`ListRunnersResponse <ListRunnersResponse>`
Usage:
::
result = await api.list_runners()
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
res = self._request(
"GET",
f"/apple-silicon/v1alpha1/zones/{param_zone}/runners",
params={
"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,
"server_id": server_id,
},
)
self._throw_on_error(res)
return unmarshal_ListRunnersResponse(res.json())
async def list_runners_all(
self,
*,
zone: Optional[ScwZone] = None,
server_id: Optional[str] = None,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> list[Runner]:
"""
List runner configurations associated with a server.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param server_id: ID of the server for which to list applied runner configurations.
:param project_id: Only list servers of this project ID.
:param organization_id: Only list servers of this Organization ID.
:param page: Positive integer to choose the page to return.
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
:return: :class:`list[Runner] <list[Runner]>`
Usage:
::
result = await api.list_runners_all()
"""
return await fetch_all_pages_async(
type=ListRunnersResponse,
key="runners",
fetcher=self.list_runners,
args={
"zone": zone,
"server_id": server_id,
"project_id": project_id,
"organization_id": organization_id,
"page": page,
"page_size": page_size,
},
)
async def update_runner(
self,
*,
runner_id: str,
runner_configuration: RunnerConfigurationV2,
zone: Optional[ScwZone] = None,
) -> Runner:
"""
Create a new runner configuration.
:param runner_id: ID of the runner configuration to update.
:param runner_configuration: Configuration details for the runner.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`Runner <Runner>`
Usage:
::
result = await api.update_runner(
runner_id="example",
runner_configuration=RunnerConfigurationV2(),
)
"""
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_runner_id = validate_path_param("runner_id", runner_id)
res = self._request(
"PATCH",
f"/apple-silicon/v1alpha1/zones/{param_zone}/runners/{param_runner_id}",
body=marshal_UpdateRunnerRequest(
UpdateRunnerRequest(
runner_id=runner_id,
runner_configuration=runner_configuration,
zone=zone,