Skip to content

Commit fe9552c

Browse files
scaleway-botLaure-dijremy42remyleone
authored
feat(apple_silicon): enable bulk order in public sdk (#1059)
Co-authored-by: Laure-di <[email protected]> Co-authored-by: Jonathan R. <[email protected]> Co-authored-by: Rémy Léone <[email protected]>
1 parent f62d04b commit fe9552c

File tree

9 files changed

+395
-0
lines changed

9 files changed

+395
-0
lines changed

scaleway-async/scaleway_async/applesilicon/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
from .types import ServerTypeGPU
2020
from .types import ServerTypeMemory
2121
from .types import ServerTypeNetwork
22+
from .types import BatchCreateServersRequestBatchInnerCreateServerRequest
2223
from .types import Server
2324
from .types import ConnectivityDiagnosticServerHealth
2425
from .types import ServerPrivateNetwork
2526
from .types import ServerType
2627
from .types import CommitmentTypeValue
28+
from .types import BatchCreateServersRequest
29+
from .types import BatchCreateServersResponse
2730
from .types import ConnectivityDiagnostic
2831
from .types import CreateServerRequest
2932
from .types import DeleteServerRequest
@@ -72,11 +75,14 @@
7275
"ServerTypeGPU",
7376
"ServerTypeMemory",
7477
"ServerTypeNetwork",
78+
"BatchCreateServersRequestBatchInnerCreateServerRequest",
7579
"Server",
7680
"ConnectivityDiagnosticServerHealth",
7781
"ServerPrivateNetwork",
7882
"ServerType",
7983
"CommitmentTypeValue",
84+
"BatchCreateServersRequest",
85+
"BatchCreateServersResponse",
8086
"ConnectivityDiagnostic",
8187
"CreateServerRequest",
8288
"DeleteServerRequest",

scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
CommitmentType,
1919
ListServerPrivateNetworksRequestOrderBy,
2020
ListServersRequestOrderBy,
21+
BatchCreateServersRequest,
22+
BatchCreateServersRequestBatchInnerCreateServerRequest,
23+
BatchCreateServersResponse,
2124
CommitmentTypeValue,
2225
ConnectivityDiagnostic,
2326
CreateServerRequest,
@@ -46,13 +49,15 @@
4649
unmarshal_Server,
4750
unmarshal_ServerPrivateNetwork,
4851
unmarshal_ServerType,
52+
unmarshal_BatchCreateServersResponse,
4953
unmarshal_ConnectivityDiagnostic,
5054
unmarshal_ListOSResponse,
5155
unmarshal_ListServerPrivateNetworksResponse,
5256
unmarshal_ListServerTypesResponse,
5357
unmarshal_ListServersResponse,
5458
unmarshal_SetServerPrivateNetworksResponse,
5559
unmarshal_StartConnectivityDiagnosticResponse,
60+
marshal_BatchCreateServersRequest,
5661
marshal_CreateServerRequest,
5762
marshal_PrivateNetworkApiAddServerPrivateNetworkRequest,
5863
marshal_PrivateNetworkApiSetServerPrivateNetworksRequest,
@@ -184,6 +189,66 @@ async def create_server(
184189
self._throw_on_error(res)
185190
return unmarshal_Server(res.json())
186191

192+
async def batch_create_servers(
193+
self,
194+
*,
195+
type_: str,
196+
enable_vpc: bool,
197+
public_bandwidth_bps: int,
198+
zone: Optional[ScwZone] = None,
199+
project_id: Optional[str] = None,
200+
os_id: Optional[str] = None,
201+
commitment_type: Optional[CommitmentType] = None,
202+
requests: Optional[
203+
List[BatchCreateServersRequestBatchInnerCreateServerRequest]
204+
] = None,
205+
) -> BatchCreateServersResponse:
206+
"""
207+
Create multiple servers atomically.
208+
Create multiple servers in the targeted zone specifying their configurations. If the request cannot entirely be fullfilled, no servers are created.
209+
:param type_: Create servers of the given type.
210+
:param enable_vpc: Activate the Private Network feature for these servers. This feature is configured through the Apple Silicon - Private Networks API.
211+
: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.
212+
:param zone: Zone to target. If none is passed will use default zone from the config.
213+
:param project_id: Create servers in the given project ID.
214+
: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.
215+
: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.
216+
:param requests: List of servers to create.
217+
:return: :class:`BatchCreateServersResponse <BatchCreateServersResponse>`
218+
219+
Usage:
220+
::
221+
222+
result = await api.batch_create_servers(
223+
type="example",
224+
enable_vpc=False,
225+
public_bandwidth_bps=1,
226+
)
227+
"""
228+
229+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
230+
231+
res = self._request(
232+
"POST",
233+
f"/apple-silicon/v1alpha1/zones/{param_zone}/batch-create-servers",
234+
body=marshal_BatchCreateServersRequest(
235+
BatchCreateServersRequest(
236+
type_=type_,
237+
enable_vpc=enable_vpc,
238+
public_bandwidth_bps=public_bandwidth_bps,
239+
zone=zone,
240+
project_id=project_id,
241+
os_id=os_id,
242+
commitment_type=commitment_type,
243+
requests=requests,
244+
),
245+
self.client,
246+
),
247+
)
248+
249+
self._throw_on_error(res)
250+
return unmarshal_BatchCreateServersResponse(res.json())
251+
187252
async def list_servers(
188253
self,
189254
*,

scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ServerTypeMemory,
1818
ServerTypeNetwork,
1919
ServerType,
20+
BatchCreateServersResponse,
2021
ConnectivityDiagnosticServerHealth,
2122
ConnectivityDiagnostic,
2223
ListOSResponse,
@@ -25,6 +26,8 @@
2526
ListServersResponse,
2627
SetServerPrivateNetworksResponse,
2728
StartConnectivityDiagnosticResponse,
29+
BatchCreateServersRequestBatchInnerCreateServerRequest,
30+
BatchCreateServersRequest,
2831
CreateServerRequest,
2932
PrivateNetworkApiAddServerPrivateNetworkRequest,
3033
PrivateNetworkApiSetServerPrivateNetworksRequest,
@@ -417,6 +420,23 @@ def unmarshal_ServerType(data: Any) -> ServerType:
417420
return ServerType(**args)
418421

419422

423+
def unmarshal_BatchCreateServersResponse(data: Any) -> BatchCreateServersResponse:
424+
if not isinstance(data, dict):
425+
raise TypeError(
426+
"Unmarshalling the type 'BatchCreateServersResponse' failed as data isn't a dictionary."
427+
)
428+
429+
args: Dict[str, Any] = {}
430+
431+
field = data.get("servers", None)
432+
if field is not None:
433+
args["servers"] = (
434+
[unmarshal_Server(v) for v in field] if field is not None else None
435+
)
436+
437+
return BatchCreateServersResponse(**args)
438+
439+
420440
def unmarshal_ConnectivityDiagnosticServerHealth(
421441
data: Any,
422442
) -> ConnectivityDiagnosticServerHealth:
@@ -619,6 +639,53 @@ def unmarshal_StartConnectivityDiagnosticResponse(
619639
return StartConnectivityDiagnosticResponse(**args)
620640

621641

642+
def marshal_BatchCreateServersRequestBatchInnerCreateServerRequest(
643+
request: BatchCreateServersRequestBatchInnerCreateServerRequest,
644+
defaults: ProfileDefaults,
645+
) -> Dict[str, Any]:
646+
output: Dict[str, Any] = {}
647+
648+
if request.name is not None:
649+
output["name"] = request.name
650+
651+
return output
652+
653+
654+
def marshal_BatchCreateServersRequest(
655+
request: BatchCreateServersRequest,
656+
defaults: ProfileDefaults,
657+
) -> Dict[str, Any]:
658+
output: Dict[str, Any] = {}
659+
660+
if request.type_ is not None:
661+
output["type"] = request.type_
662+
663+
if request.enable_vpc is not None:
664+
output["enable_vpc"] = request.enable_vpc
665+
666+
if request.public_bandwidth_bps is not None:
667+
output["public_bandwidth_bps"] = request.public_bandwidth_bps
668+
669+
if request.project_id is not None:
670+
output["project_id"] = request.project_id or defaults.default_project_id
671+
672+
if request.os_id is not None:
673+
output["os_id"] = request.os_id
674+
675+
if request.commitment_type is not None:
676+
output["commitment_type"] = str(request.commitment_type)
677+
678+
if request.requests is not None:
679+
output["requests"] = [
680+
marshal_BatchCreateServersRequestBatchInnerCreateServerRequest(
681+
item, defaults
682+
)
683+
for item in request.requests
684+
]
685+
686+
return output
687+
688+
622689
def marshal_CreateServerRequest(
623690
request: CreateServerRequest,
624691
defaults: ProfileDefaults,

scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ class ServerTypeNetwork:
199199
supported_bandwidth: List[int]
200200

201201

202+
@dataclass
203+
class BatchCreateServersRequestBatchInnerCreateServerRequest:
204+
name: str
205+
206+
202207
@dataclass
203208
class Server:
204209
id: str
@@ -423,6 +428,57 @@ class CommitmentTypeValue:
423428
commitment_type: CommitmentType
424429

425430

431+
@dataclass
432+
class BatchCreateServersRequest:
433+
type_: str
434+
"""
435+
Create servers of the given type.
436+
"""
437+
438+
enable_vpc: bool
439+
"""
440+
Activate the Private Network feature for these servers. This feature is configured through the Apple Silicon - Private Networks API.
441+
"""
442+
443+
public_bandwidth_bps: int
444+
"""
445+
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.
446+
"""
447+
448+
zone: Optional[ScwZone]
449+
"""
450+
Zone to target. If none is passed will use default zone from the config.
451+
"""
452+
453+
project_id: Optional[str]
454+
"""
455+
Create servers in the given project ID.
456+
"""
457+
458+
os_id: Optional[str]
459+
"""
460+
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.
461+
"""
462+
463+
commitment_type: Optional[CommitmentType]
464+
"""
465+
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.
466+
"""
467+
468+
requests: Optional[List[BatchCreateServersRequestBatchInnerCreateServerRequest]]
469+
"""
470+
List of servers to create.
471+
"""
472+
473+
474+
@dataclass
475+
class BatchCreateServersResponse:
476+
servers: List[Server]
477+
"""
478+
List of created servers.
479+
"""
480+
481+
426482
@dataclass
427483
class ConnectivityDiagnostic:
428484
id: str

scaleway-core/scaleway_core/utils/resolve_one_of.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def resolve_one_of(
2828
# Get the first non-empty default
2929
for possibility in possibilities:
3030
if possibility.default is not None:
31+
if possibility.marshal_func is not None:
32+
# When no actual value, call with None as value
33+
return {
34+
possibility.param: possibility.marshal_func(
35+
None, possibility.default
36+
)
37+
}
3138
return {possibility.param: possibility.default}
3239

3340
# If required, raise an error

scaleway/scaleway/applesilicon/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
from .types import ServerTypeGPU
2020
from .types import ServerTypeMemory
2121
from .types import ServerTypeNetwork
22+
from .types import BatchCreateServersRequestBatchInnerCreateServerRequest
2223
from .types import Server
2324
from .types import ConnectivityDiagnosticServerHealth
2425
from .types import ServerPrivateNetwork
2526
from .types import ServerType
2627
from .types import CommitmentTypeValue
28+
from .types import BatchCreateServersRequest
29+
from .types import BatchCreateServersResponse
2730
from .types import ConnectivityDiagnostic
2831
from .types import CreateServerRequest
2932
from .types import DeleteServerRequest
@@ -72,11 +75,14 @@
7275
"ServerTypeGPU",
7376
"ServerTypeMemory",
7477
"ServerTypeNetwork",
78+
"BatchCreateServersRequestBatchInnerCreateServerRequest",
7579
"Server",
7680
"ConnectivityDiagnosticServerHealth",
7781
"ServerPrivateNetwork",
7882
"ServerType",
7983
"CommitmentTypeValue",
84+
"BatchCreateServersRequest",
85+
"BatchCreateServersResponse",
8086
"ConnectivityDiagnostic",
8187
"CreateServerRequest",
8288
"DeleteServerRequest",

0 commit comments

Comments
 (0)