Skip to content

Commit

Permalink
feat(apple_silicon): introduce monthly commitment handling (scaleway#856
Browse files Browse the repository at this point in the history
)
  • Loading branch information
scaleway-bot authored Feb 13, 2025
1 parent edbd519 commit 3dba7b8
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import CommitmentType
from .types import ConnectivityDiagnosticActionType
from .types import ConnectivityDiagnosticDiagnosticStatus
from .types import ListServerPrivateNetworksRequestOrderBy
Expand All @@ -17,10 +18,12 @@
from .types import ServerTypeGPU
from .types import ServerTypeMemory
from .types import ServerTypeNetwork
from .types import Commitment
from .types import ConnectivityDiagnosticServerHealth
from .types import ServerPrivateNetwork
from .types import ServerType
from .types import Server
from .types import CommitmentTypeValue
from .types import ConnectivityDiagnostic
from .types import CreateServerRequest
from .types import DeleteServerRequest
Expand Down Expand Up @@ -50,6 +53,7 @@
from .api import ApplesiliconV1Alpha1PrivateNetworkAPI

__all__ = [
"CommitmentType",
"ConnectivityDiagnosticActionType",
"ConnectivityDiagnosticDiagnosticStatus",
"ListServerPrivateNetworksRequestOrderBy",
Expand All @@ -67,10 +71,12 @@
"ServerTypeGPU",
"ServerTypeMemory",
"ServerTypeNetwork",
"Commitment",
"ConnectivityDiagnosticServerHealth",
"ServerPrivateNetwork",
"ServerType",
"Server",
"CommitmentTypeValue",
"ConnectivityDiagnostic",
"CreateServerRequest",
"DeleteServerRequest",
Expand Down
8 changes: 8 additions & 0 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
wait_for_resource_async,
)
from .types import (
CommitmentType,
ListServerPrivateNetworksRequestOrderBy,
ListServersRequestOrderBy,
CommitmentTypeValue,
ConnectivityDiagnostic,
CreateServerRequest,
ListOSResponse,
Expand Down Expand Up @@ -133,6 +135,7 @@ async def create_server(
name: Optional[str] = None,
project_id: Optional[str] = None,
os_id: Optional[str] = None,
commitment_type: Optional[CommitmentType] = None,
) -> Server:
"""
Create a server.
Expand All @@ -143,6 +146,7 @@ async def create_server(
: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. It can be updated with the Update Server request. Available commitment depends on server type.
:return: :class:`Server <Server>`
Usage:
Expand All @@ -167,6 +171,7 @@ async def create_server(
name=name or random_name(prefix="as"),
project_id=project_id,
os_id=os_id,
commitment_type=commitment_type,
),
self.client,
),
Expand Down Expand Up @@ -449,6 +454,7 @@ async def update_server(
name: Optional[str] = None,
schedule_deletion: Optional[bool] = None,
enable_vpc: Optional[bool] = None,
commitment_type: Optional[CommitmentTypeValue] = None,
) -> Server:
"""
Update a server.
Expand All @@ -458,6 +464,7 @@ async def update_server(
: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.
:return: :class:`Server <Server>`
Usage:
Expand All @@ -481,6 +488,7 @@ async def update_server(
name=name,
schedule_deletion=schedule_deletion,
enable_vpc=enable_vpc,
commitment_type=commitment_type,
),
self.client,
),
Expand Down
79 changes: 63 additions & 16 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ServerTypeMemory,
ServerTypeNetwork,
ServerType,
Commitment,
Server,
ConnectivityDiagnosticServerHealth,
ConnectivityDiagnostic,
Expand All @@ -29,6 +30,7 @@
PrivateNetworkApiSetServerPrivateNetworksRequest,
ReinstallServerRequest,
StartConnectivityDiagnosticRequest,
CommitmentTypeValue,
UpdateServerRequest,
)

Expand Down Expand Up @@ -285,6 +287,25 @@ def unmarshal_ServerType(data: Any) -> ServerType:
return ServerType(**args)


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

args: Dict[str, Any] = {}

field = data.get("type", None)
if field is not None:
args["type_"] = field

field = data.get("cancelled", None)
if field is not None:
args["cancelled"] = field

return Commitment(**args)


def unmarshal_Server(data: Any) -> Server:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -337,22 +358,6 @@ def unmarshal_Server(data: Any) -> Server:
if field is not None:
args["status"] = field

field = data.get("deletion_scheduled", None)
if field is not None:
args["deletion_scheduled"] = field

field = data.get("zone", None)
if field is not None:
args["zone"] = field

field = data.get("delivered", None)
if field is not None:
args["delivered"] = field

field = data.get("vpc_status", None)
if field is not None:
args["vpc_status"] = field

field = data.get("os", None)
if field is not None:
args["os"] = unmarshal_OS(field)
Expand All @@ -379,6 +384,28 @@ def unmarshal_Server(data: Any) -> Server:
else:
args["deletable_at"] = None

field = data.get("deletion_scheduled", None)
if field is not None:
args["deletion_scheduled"] = field

field = data.get("zone", None)
if field is not None:
args["zone"] = field

field = data.get("delivered", None)
if field is not None:
args["delivered"] = field

field = data.get("vpc_status", None)
if field is not None:
args["vpc_status"] = field

field = data.get("commitment", None)
if field is not None:
args["commitment"] = unmarshal_Commitment(field)
else:
args["commitment"] = None

return Server(**args)


Expand Down Expand Up @@ -605,6 +632,9 @@ def marshal_CreateServerRequest(
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)

return output


Expand Down Expand Up @@ -661,6 +691,18 @@ def marshal_StartConnectivityDiagnosticRequest(
return output


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

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

return output


def marshal_UpdateServerRequest(
request: UpdateServerRequest,
defaults: ProfileDefaults,
Expand All @@ -676,4 +718,9 @@ def marshal_UpdateServerRequest(
if request.enable_vpc is not None:
output["enable_vpc"] = request.enable_vpc

if request.commitment_type is not None:
output["commitment_type"] = marshal_CommitmentTypeValue(
request.commitment_type, defaults
)

return output
66 changes: 51 additions & 15 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
)


class CommitmentType(str, Enum, metaclass=StrEnumMeta):
DURATION_24H = "duration_24h"
RENEWED_MONTHLY = "renewed_monthly"
NONE = "none"

def __str__(self) -> str:
return str(self.value)


class ConnectivityDiagnosticActionType(str, Enum, metaclass=StrEnumMeta):
REBOOT_SERVER = "reboot_server"
REINSTALL_SERVER = "reinstall_server"
Expand Down Expand Up @@ -181,6 +190,13 @@ class ServerTypeNetwork:
public_bandwidth_bps: int


@dataclass
class Commitment:
type_: CommitmentType

cancelled: bool


@dataclass
class ConnectivityDiagnosticServerHealth:
is_server_alive: bool
Expand Down Expand Up @@ -349,6 +365,26 @@ class Server:
Current status of the server.
"""

os: Optional[OS]
"""
Initially installed OS, this does not necessarily reflect the current OS version.
"""

created_at: Optional[datetime]
"""
Date on which the server was created.
"""

updated_at: Optional[datetime]
"""
Date on which the server was last updated.
"""

deletable_at: Optional[datetime]
"""
Date from which the server can be deleted.
"""

deletion_scheduled: bool
"""
Set to true to mark the server for automatic deletion depending on `deletable_at` date. Set to false to cancel an existing deletion schedule. Leave unset otherwise.
Expand All @@ -369,25 +405,15 @@ class Server:
Activation status of optional Private Network feature support for this server.
"""

os: Optional[OS]
commitment: Optional[Commitment]
"""
Initially installed OS, this does not necessarily reflect the current OS version.
Commitment scheme applied to this server.
"""

created_at: Optional[datetime]
"""
Date on which the server was created.
"""

updated_at: Optional[datetime]
"""
Date on which the server was last updated.
"""

deletable_at: Optional[datetime]
"""
Date from which the server can be deleted.
"""
@dataclass
class CommitmentTypeValue:
commitment_type: CommitmentType


@dataclass
Expand Down Expand Up @@ -437,6 +463,11 @@ class CreateServerRequest:
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.
"""

commitment_type: Optional[CommitmentType]
"""
Activate commitment for this server. If not specified, there is a 24h commitment due to Apple licensing. It can be updated with the Update Server request. Available commitment depends on server type.
"""


@dataclass
class DeleteServerRequest:
Expand Down Expand Up @@ -806,3 +837,8 @@ class UpdateServerRequest:
"""
Activate or deactivate Private Network support for this server.
"""

commitment_type: Optional[CommitmentTypeValue]
"""
Change commitment. Use 'none' to automatically cancel a renewing commitment.
"""
6 changes: 6 additions & 0 deletions scaleway/scaleway/applesilicon/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import CommitmentType
from .types import ConnectivityDiagnosticActionType
from .types import ConnectivityDiagnosticDiagnosticStatus
from .types import ListServerPrivateNetworksRequestOrderBy
Expand All @@ -17,10 +18,12 @@
from .types import ServerTypeGPU
from .types import ServerTypeMemory
from .types import ServerTypeNetwork
from .types import Commitment
from .types import ConnectivityDiagnosticServerHealth
from .types import ServerPrivateNetwork
from .types import ServerType
from .types import Server
from .types import CommitmentTypeValue
from .types import ConnectivityDiagnostic
from .types import CreateServerRequest
from .types import DeleteServerRequest
Expand Down Expand Up @@ -50,6 +53,7 @@
from .api import ApplesiliconV1Alpha1PrivateNetworkAPI

__all__ = [
"CommitmentType",
"ConnectivityDiagnosticActionType",
"ConnectivityDiagnosticDiagnosticStatus",
"ListServerPrivateNetworksRequestOrderBy",
Expand All @@ -67,10 +71,12 @@
"ServerTypeGPU",
"ServerTypeMemory",
"ServerTypeNetwork",
"Commitment",
"ConnectivityDiagnosticServerHealth",
"ServerPrivateNetwork",
"ServerType",
"Server",
"CommitmentTypeValue",
"ConnectivityDiagnostic",
"CreateServerRequest",
"DeleteServerRequest",
Expand Down
Loading

0 comments on commit 3dba7b8

Please sign in to comment.