Skip to content

Commit

Permalink
feat(apple_silicon): add os selection fields (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Apr 25, 2024
1 parent f182837 commit dbc41ed
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from .types import ServerStatus
from .content import SERVER_TRANSIENT_STATUSES
from .types import ServerTypeStock
from .types import OS
from .types import ServerTypeCPU
from .types import ServerTypeDisk
from .types import ServerTypeMemory
from .types import OS
from .types import ServerType
from .types import Server
from .types import CreateServerRequest
Expand All @@ -31,10 +31,10 @@
"ServerStatus",
"SERVER_TRANSIENT_STATUSES",
"ServerTypeStock",
"OS",
"ServerTypeCPU",
"ServerTypeDisk",
"ServerTypeMemory",
"OS",
"ServerType",
"Server",
"CreateServerRequest",
Expand Down
16 changes: 15 additions & 1 deletion scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ListServerTypesResponse,
ListServersResponse,
OS,
ReinstallServerRequest,
Server,
ServerType,
UpdateServerRequest,
Expand All @@ -36,6 +37,7 @@
unmarshal_ListServerTypesResponse,
unmarshal_ListServersResponse,
marshal_CreateServerRequest,
marshal_ReinstallServerRequest,
marshal_UpdateServerRequest,
)

Expand Down Expand Up @@ -109,6 +111,7 @@ async def create_server(
zone: Optional[Zone] = None,
name: Optional[str] = None,
project_id: Optional[str] = None,
os_id: Optional[str] = None,
) -> Server:
"""
Create a server.
Expand All @@ -117,6 +120,7 @@ async def create_server(
: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.
:return: :class:`Server <Server>`
Usage:
Expand All @@ -138,6 +142,7 @@ async def create_server(
zone=zone,
name=name or random_name(prefix="as"),
project_id=project_id,
os_id=os_id,
),
self.client,
),
Expand Down Expand Up @@ -522,12 +527,14 @@ async def reinstall_server(
*,
server_id: str,
zone: Optional[Zone] = 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 defailt configuration values of the image (OS).
:param server_id: UUID of the server you want to reinstall.
: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:
Expand All @@ -544,7 +551,14 @@ async def reinstall_server(
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}/reinstall",
body={},
body=marshal_ReinstallServerRequest(
ReinstallServerRequest(
server_id=server_id,
zone=zone,
os_id=os_id,
),
self.client,
),
)

self._throw_on_error(res)
Expand Down
44 changes: 44 additions & 0 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ListServerTypesResponse,
ListServersResponse,
CreateServerRequest,
ReinstallServerRequest,
UpdateServerRequest,
)

Expand Down Expand Up @@ -44,6 +45,22 @@ def unmarshal_OS(data: Any) -> OS:
if field is not None:
args["image_url"] = field

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

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

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

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

field = data.get("compatible_server_types", None)
if field is not None:
args["compatible_server_types"] = field
Expand Down Expand Up @@ -148,6 +165,12 @@ def unmarshal_ServerType(data: Any) -> ServerType:
else:
args["minimum_lease_duration"] = None

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

return ServerType(**args)


Expand Down Expand Up @@ -195,6 +218,12 @@ def unmarshal_Server(data: Any) -> Server:
if field is not None:
args["zone"] = field

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

field = data.get("created_at", None)
if field is not None:
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
Expand Down Expand Up @@ -290,6 +319,21 @@ def marshal_CreateServerRequest(
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

return output


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

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

return output


Expand Down
82 changes: 61 additions & 21 deletions scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,6 @@ def __str__(self) -> str:
return str(self.value)


@dataclass
class ServerTypeCPU:
name: str

core_count: int


@dataclass
class ServerTypeDisk:
capacity: int

type_: str


@dataclass
class ServerTypeMemory:
capacity: int

type_: str


@dataclass
class OS:
id: str
Expand All @@ -92,12 +71,53 @@ class OS:
URL of the image.
"""

family: str
"""
The OS family to which this OS belongs, eg. 13 or 14.
"""

is_beta: bool
"""
Describes if the OS is in beta.
"""

version: str
"""
The OS version number, eg. Sonoma has version number 14.3.
"""

xcode_version: str
"""
The current xcode version for this OS.
"""

compatible_server_types: List[str]
"""
List of compatible server types.
"""


@dataclass
class ServerTypeCPU:
name: str

core_count: int


@dataclass
class ServerTypeDisk:
capacity: int

type_: str


@dataclass
class ServerTypeMemory:
capacity: int

type_: str


@dataclass
class ServerType:
name: str
Expand Down Expand Up @@ -130,6 +150,11 @@ class ServerType:
Minimum duration of the lease in seconds (example. 3.4s).
"""

default_os: Optional[OS]
"""
The default OS for this server type.
"""


@dataclass
class Server:
Expand Down Expand Up @@ -178,6 +203,11 @@ class Server:
Zone 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.
Expand Down Expand Up @@ -216,6 +246,11 @@ class CreateServerRequest:
Create a server in the given project ID.
"""

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


@dataclass
class DeleteServerRequest:
Expand Down Expand Up @@ -397,6 +432,11 @@ class ReinstallServerRequest:
Zone to target. If none is passed will use default zone from the config.
"""

os_id: Optional[str]
"""
Reinstall the server with the target OS, when no os_id provided the default OS for the server type is used.
"""


@dataclass
class UpdateServerRequest:
Expand Down
4 changes: 2 additions & 2 deletions scaleway/scaleway/applesilicon/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from .types import ServerStatus
from .content import SERVER_TRANSIENT_STATUSES
from .types import ServerTypeStock
from .types import OS
from .types import ServerTypeCPU
from .types import ServerTypeDisk
from .types import ServerTypeMemory
from .types import OS
from .types import ServerType
from .types import Server
from .types import CreateServerRequest
Expand All @@ -31,10 +31,10 @@
"ServerStatus",
"SERVER_TRANSIENT_STATUSES",
"ServerTypeStock",
"OS",
"ServerTypeCPU",
"ServerTypeDisk",
"ServerTypeMemory",
"OS",
"ServerType",
"Server",
"CreateServerRequest",
Expand Down
16 changes: 15 additions & 1 deletion scaleway/scaleway/applesilicon/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ListServerTypesResponse,
ListServersResponse,
OS,
ReinstallServerRequest,
Server,
ServerType,
UpdateServerRequest,
Expand All @@ -36,6 +37,7 @@
unmarshal_ListServerTypesResponse,
unmarshal_ListServersResponse,
marshal_CreateServerRequest,
marshal_ReinstallServerRequest,
marshal_UpdateServerRequest,
)

Expand Down Expand Up @@ -109,6 +111,7 @@ def create_server(
zone: Optional[Zone] = None,
name: Optional[str] = None,
project_id: Optional[str] = None,
os_id: Optional[str] = None,
) -> Server:
"""
Create a server.
Expand All @@ -117,6 +120,7 @@ def create_server(
: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.
:return: :class:`Server <Server>`
Usage:
Expand All @@ -138,6 +142,7 @@ def create_server(
zone=zone,
name=name or random_name(prefix="as"),
project_id=project_id,
os_id=os_id,
),
self.client,
),
Expand Down Expand Up @@ -522,12 +527,14 @@ def reinstall_server(
*,
server_id: str,
zone: Optional[Zone] = 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 defailt configuration values of the image (OS).
:param server_id: UUID of the server you want to reinstall.
: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:
Expand All @@ -544,7 +551,14 @@ def reinstall_server(
res = self._request(
"POST",
f"/apple-silicon/v1alpha1/zones/{param_zone}/servers/{param_server_id}/reinstall",
body={},
body=marshal_ReinstallServerRequest(
ReinstallServerRequest(
server_id=server_id,
zone=zone,
os_id=os_id,
),
self.client,
),
)

self._throw_on_error(res)
Expand Down
Loading

0 comments on commit dbc41ed

Please sign in to comment.