Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
from .types import ServerTypeGPU
from .types import ServerTypeMemory
from .types import ServerTypeNetwork
from .types import BatchCreateServersRequestBatchInnerCreateServerRequest
from .types import Server
from .types import ConnectivityDiagnosticServerHealth
from .types import ServerPrivateNetwork
from .types import ServerType
from .types import CommitmentTypeValue
from .types import BatchCreateServersRequest
from .types import BatchCreateServersResponse
from .types import ConnectivityDiagnostic
from .types import CreateServerRequest
from .types import DeleteServerRequest
Expand Down Expand Up @@ -72,11 +75,14 @@
"ServerTypeGPU",
"ServerTypeMemory",
"ServerTypeNetwork",
"BatchCreateServersRequestBatchInnerCreateServerRequest",
"Server",
"ConnectivityDiagnosticServerHealth",
"ServerPrivateNetwork",
"ServerType",
"CommitmentTypeValue",
"BatchCreateServersRequest",
"BatchCreateServersResponse",
"ConnectivityDiagnostic",
"CreateServerRequest",
"DeleteServerRequest",
Expand Down
65 changes: 65 additions & 0 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
CommitmentType,
ListServerPrivateNetworksRequestOrderBy,
ListServersRequestOrderBy,
BatchCreateServersRequest,
BatchCreateServersRequestBatchInnerCreateServerRequest,
BatchCreateServersResponse,
CommitmentTypeValue,
ConnectivityDiagnostic,
CreateServerRequest,
Expand Down Expand Up @@ -46,13 +49,15 @@
unmarshal_Server,
unmarshal_ServerPrivateNetwork,
unmarshal_ServerType,
unmarshal_BatchCreateServersResponse,
unmarshal_ConnectivityDiagnostic,
unmarshal_ListOSResponse,
unmarshal_ListServerPrivateNetworksResponse,
unmarshal_ListServerTypesResponse,
unmarshal_ListServersResponse,
unmarshal_SetServerPrivateNetworksResponse,
unmarshal_StartConnectivityDiagnosticResponse,
marshal_BatchCreateServersRequest,
marshal_CreateServerRequest,
marshal_PrivateNetworkApiAddServerPrivateNetworkRequest,
marshal_PrivateNetworkApiSetServerPrivateNetworksRequest,
Expand Down Expand Up @@ -184,6 +189,66 @@ async def create_server(
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,
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 fullfilled, 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 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,
)
"""

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,
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,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ServerTypeMemory,
ServerTypeNetwork,
ServerType,
BatchCreateServersResponse,
ConnectivityDiagnosticServerHealth,
ConnectivityDiagnostic,
ListOSResponse,
Expand All @@ -25,6 +26,8 @@
ListServersResponse,
SetServerPrivateNetworksResponse,
StartConnectivityDiagnosticResponse,
BatchCreateServersRequestBatchInnerCreateServerRequest,
BatchCreateServersRequest,
CreateServerRequest,
PrivateNetworkApiAddServerPrivateNetworkRequest,
PrivateNetworkApiSetServerPrivateNetworksRequest,
Expand Down Expand Up @@ -417,6 +420,23 @@ def unmarshal_ServerType(data: Any) -> ServerType:
return ServerType(**args)


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

args: Dict[str, Any] = {}

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

return BatchCreateServersResponse(**args)


def unmarshal_ConnectivityDiagnosticServerHealth(
data: Any,
) -> ConnectivityDiagnosticServerHealth:
Expand Down Expand Up @@ -619,6 +639,53 @@ def unmarshal_StartConnectivityDiagnosticResponse(
return StartConnectivityDiagnosticResponse(**args)


def marshal_BatchCreateServersRequestBatchInnerCreateServerRequest(
request: BatchCreateServersRequestBatchInnerCreateServerRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.name is not None:
output["name"] = request.name

return output


def marshal_BatchCreateServersRequest(
request: BatchCreateServersRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.type_ is not None:
output["type"] = request.type_

if request.enable_vpc is not None:
output["enable_vpc"] = request.enable_vpc

if request.public_bandwidth_bps is not None:
output["public_bandwidth_bps"] = request.public_bandwidth_bps

if request.project_id is not None:
output["project_id"] = request.project_id or defaults.default_project_id

if request.os_id is not None:
output["os_id"] = request.os_id

if request.commitment_type is not None:
output["commitment_type"] = str(request.commitment_type)

if request.requests is not None:
output["requests"] = [
marshal_BatchCreateServersRequestBatchInnerCreateServerRequest(
item, defaults
)
for item in request.requests
]

return output


def marshal_CreateServerRequest(
request: CreateServerRequest,
defaults: ProfileDefaults,
Expand Down
56 changes: 56 additions & 0 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ class ServerTypeNetwork:
supported_bandwidth: List[int]


@dataclass
class BatchCreateServersRequestBatchInnerCreateServerRequest:
name: str


@dataclass
class Server:
id: str
Expand Down Expand Up @@ -423,6 +428,57 @@ class CommitmentTypeValue:
commitment_type: CommitmentType


@dataclass
class BatchCreateServersRequest:
type_: str
"""
Create servers of the given type.
"""

enable_vpc: bool
"""
Activate the Private Network feature for these servers. This feature is configured through the Apple Silicon - Private Networks API.
"""

public_bandwidth_bps: int
"""
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.
"""

zone: Optional[ScwZone]
"""
Zone to target. If none is passed will use default zone from the config.
"""

project_id: Optional[str]
"""
Create servers in the given project ID.
"""

os_id: Optional[str]
"""
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.
"""

commitment_type: Optional[CommitmentType]
"""
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.
"""

requests: Optional[List[BatchCreateServersRequestBatchInnerCreateServerRequest]]
"""
List of servers to create.
"""


@dataclass
class BatchCreateServersResponse:
servers: List[Server]
"""
List of created servers.
"""


@dataclass
class ConnectivityDiagnostic:
id: str
Expand Down
7 changes: 7 additions & 0 deletions scaleway-core/scaleway_core/utils/resolve_one_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def resolve_one_of(
# Get the first non-empty default
for possibility in possibilities:
if possibility.default is not None:
if possibility.marshal_func is not None:
# When no actual value, call with None as value
return {
possibility.param: possibility.marshal_func(
None, possibility.default
)
}
return {possibility.param: possibility.default}

# If required, raise an error
Expand Down
6 changes: 6 additions & 0 deletions scaleway/scaleway/applesilicon/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
from .types import ServerTypeGPU
from .types import ServerTypeMemory
from .types import ServerTypeNetwork
from .types import BatchCreateServersRequestBatchInnerCreateServerRequest
from .types import Server
from .types import ConnectivityDiagnosticServerHealth
from .types import ServerPrivateNetwork
from .types import ServerType
from .types import CommitmentTypeValue
from .types import BatchCreateServersRequest
from .types import BatchCreateServersResponse
from .types import ConnectivityDiagnostic
from .types import CreateServerRequest
from .types import DeleteServerRequest
Expand Down Expand Up @@ -72,11 +75,14 @@
"ServerTypeGPU",
"ServerTypeMemory",
"ServerTypeNetwork",
"BatchCreateServersRequestBatchInnerCreateServerRequest",
"Server",
"ConnectivityDiagnosticServerHealth",
"ServerPrivateNetwork",
"ServerType",
"CommitmentTypeValue",
"BatchCreateServersRequest",
"BatchCreateServersResponse",
"ConnectivityDiagnostic",
"CreateServerRequest",
"DeleteServerRequest",
Expand Down
Loading
Loading