diff --git a/scaleway-async/scaleway_async/applesilicon/v1alpha1/__init__.py b/scaleway-async/scaleway_async/applesilicon/v1alpha1/__init__.py index 228aec6ec..93f2c5ddc 100644 --- a/scaleway-async/scaleway_async/applesilicon/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/applesilicon/v1alpha1/__init__.py @@ -6,6 +6,9 @@ from .types import ListServerPrivateNetworksRequestOrderBy from .types import ListServersRequestOrderBy from .types import RunnerConfigurationProvider +from .types import RunnerConfigurationV2Provider +from .types import RunnerStatus +from .content import RUNNER_TRANSIENT_STATUSES from .types import ServerPrivateNetworkServerStatus from .content import SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES from .types import ServerPrivateNetworkStatus @@ -14,9 +17,12 @@ from .content import SERVER_TRANSIENT_STATUSES from .types import ServerTypeStock from .types import OSSupportedServerType +from .types import GithubRunnerConfiguration +from .types import GitlabRunnerConfiguration from .types import Commitment from .types import OS from .types import RunnerConfiguration +from .types import RunnerConfigurationV2 from .types import ServerTypeCPU from .types import ServerTypeDisk from .types import ServerTypeGPU @@ -26,20 +32,27 @@ from .types import BatchCreateServersRequestBatchInnerCreateServerRequest from .types import Server from .types import ConnectivityDiagnosticServerHealth +from .types import AppliedRunnerConfigurations +from .types import Runner 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 CreateRunnerRequest from .types import CreateServerRequest +from .types import DeleteRunnerRequest from .types import DeleteServerRequest from .types import GetConnectivityDiagnosticRequest from .types import GetOSRequest +from .types import GetRunnerRequest from .types import GetServerRequest from .types import GetServerTypeRequest from .types import ListOSRequest from .types import ListOSResponse +from .types import ListRunnersRequest +from .types import ListRunnersResponse from .types import ListServerPrivateNetworksResponse from .types import ListServerTypesRequest from .types import ListServerTypesResponse @@ -55,6 +68,7 @@ from .types import SetServerPrivateNetworksResponse from .types import StartConnectivityDiagnosticRequest from .types import StartConnectivityDiagnosticResponse +from .types import UpdateRunnerRequest from .types import UpdateServerRequest from .api import ApplesiliconV1Alpha1API from .api import ApplesiliconV1Alpha1PrivateNetworkAPI @@ -66,6 +80,9 @@ "ListServerPrivateNetworksRequestOrderBy", "ListServersRequestOrderBy", "RunnerConfigurationProvider", + "RunnerConfigurationV2Provider", + "RunnerStatus", + "RUNNER_TRANSIENT_STATUSES", "ServerPrivateNetworkServerStatus", "SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES", "ServerPrivateNetworkStatus", @@ -74,9 +91,12 @@ "SERVER_TRANSIENT_STATUSES", "ServerTypeStock", "OSSupportedServerType", + "GithubRunnerConfiguration", + "GitlabRunnerConfiguration", "Commitment", "OS", "RunnerConfiguration", + "RunnerConfigurationV2", "ServerTypeCPU", "ServerTypeDisk", "ServerTypeGPU", @@ -86,20 +106,27 @@ "BatchCreateServersRequestBatchInnerCreateServerRequest", "Server", "ConnectivityDiagnosticServerHealth", + "AppliedRunnerConfigurations", + "Runner", "ServerPrivateNetwork", "ServerType", "CommitmentTypeValue", "BatchCreateServersRequest", "BatchCreateServersResponse", "ConnectivityDiagnostic", + "CreateRunnerRequest", "CreateServerRequest", + "DeleteRunnerRequest", "DeleteServerRequest", "GetConnectivityDiagnosticRequest", "GetOSRequest", + "GetRunnerRequest", "GetServerRequest", "GetServerTypeRequest", "ListOSRequest", "ListOSResponse", + "ListRunnersRequest", + "ListRunnersResponse", "ListServerPrivateNetworksResponse", "ListServerTypesRequest", "ListServerTypesResponse", @@ -115,6 +142,7 @@ "SetServerPrivateNetworksResponse", "StartConnectivityDiagnosticRequest", "StartConnectivityDiagnosticResponse", + "UpdateRunnerRequest", "UpdateServerRequest", "ApplesiliconV1Alpha1API", "ApplesiliconV1Alpha1PrivateNetworkAPI", diff --git a/scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py b/scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py index 93a41d7da..d73ca259f 100644 --- a/scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/applesilicon/v1alpha1/api.py @@ -18,13 +18,16 @@ CommitmentType, ListServerPrivateNetworksRequestOrderBy, ListServersRequestOrderBy, + AppliedRunnerConfigurations, BatchCreateServersRequest, BatchCreateServersRequestBatchInnerCreateServerRequest, BatchCreateServersResponse, CommitmentTypeValue, ConnectivityDiagnostic, + CreateRunnerRequest, CreateServerRequest, ListOSResponse, + ListRunnersResponse, ListServerPrivateNetworksResponse, ListServerTypesResponse, ListServersResponse, @@ -32,38 +35,46 @@ 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, ) @@ -144,6 +155,7 @@ async def create_server( 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. @@ -157,6 +169,7 @@ async def create_server( :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 ` Usage: @@ -185,6 +198,7 @@ async def create_server( os_id=os_id, commitment_type=commitment_type, runner_configuration=runner_configuration, + applied_runner_configurations=applied_runner_configurations, ), self.client, ), @@ -529,6 +543,7 @@ async def update_server( 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. @@ -540,6 +555,7 @@ async def update_server( :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 ` Usage: @@ -565,6 +581,7 @@ async def update_server( enable_vpc=enable_vpc, commitment_type=commitment_type, public_bandwidth_bps=public_bandwidth_bps, + applied_runner_configurations=applied_runner_configurations, ), self.client, ), @@ -744,6 +761,268 @@ async def get_connectivity_diagnostic( 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 ` + + 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 ` + + 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 ` + + 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 ` + + 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] ` + + 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 ` + + 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, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Runner(res.json()) + + async def delete_runner( + self, + *, + runner_id: str, + zone: Optional[ScwZone] = None, + ) -> None: + """ + Create a new runner configuration. + :param runner_id: ID of the runner configuration to delete. + :param zone: Zone to target. If none is passed will use default zone from the config. + + Usage: + :: + + result = await api.delete_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( + "DELETE", + f"/apple-silicon/v1alpha1/zones/{param_zone}/runners/{param_runner_id}", + ) + + self._throw_on_error(res) + class ApplesiliconV1Alpha1PrivateNetworkAPI(API): """ diff --git a/scaleway-async/scaleway_async/applesilicon/v1alpha1/content.py b/scaleway-async/scaleway_async/applesilicon/v1alpha1/content.py index 67fc6b73e..4088a1714 100644 --- a/scaleway-async/scaleway_async/applesilicon/v1alpha1/content.py +++ b/scaleway-async/scaleway_async/applesilicon/v1alpha1/content.py @@ -2,11 +2,18 @@ # If you have any remark or suggestion do not hesitate to open an issue. from .types import ( + RunnerStatus, ServerPrivateNetworkServerStatus, ServerPrivateNetworkStatus, ServerStatus, ) +RUNNER_TRANSIENT_STATUSES: list[RunnerStatus] = [ + RunnerStatus.WAITING, +] +""" +Lists transient statutes of the enum :class:`RunnerStatus `. +""" SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES: list[ ServerPrivateNetworkServerStatus ] = [ diff --git a/scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py b/scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py index 6dd880c15..a984505f9 100644 --- a/scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py +++ b/scaleway-async/scaleway_async/applesilicon/v1alpha1/marshalling.py @@ -5,6 +5,10 @@ from dateutil import parser from scaleway_core.profile import ProfileDefaults +from scaleway_core.utils import ( + OneOfPossibility, + resolve_one_of, +) from .types import ( ConnectivityDiagnosticActionType, ServerPrivateNetworkServerStatus, @@ -16,6 +20,10 @@ Commitment, RunnerConfiguration, Server, + GithubRunnerConfiguration, + GitlabRunnerConfiguration, + RunnerConfigurationV2, + Runner, ServerPrivateNetwork, ServerTypeCPU, ServerTypeDisk, @@ -28,6 +36,7 @@ ConnectivityDiagnosticServerHealth, ConnectivityDiagnostic, ListOSResponse, + ListRunnersResponse, ListServerPrivateNetworksResponse, ListServerTypesResponse, ListServersResponse, @@ -35,11 +44,14 @@ StartConnectivityDiagnosticResponse, BatchCreateServersRequestBatchInnerCreateServerRequest, BatchCreateServersRequest, + CreateRunnerRequest, + AppliedRunnerConfigurations, CreateServerRequest, PrivateNetworkApiAddServerPrivateNetworkRequest, PrivateNetworkApiSetServerPrivateNetworksRequest, ReinstallServerRequest, StartConnectivityDiagnosticRequest, + UpdateRunnerRequest, CommitmentTypeValue, UpdateServerRequest, ) @@ -293,6 +305,24 @@ def unmarshal_Server(data: Any) -> Server: else: args["status"] = ServerStatus.UNKNOWN_STATUS + field = data.get("deletion_scheduled", None) + if field is not None: + args["deletion_scheduled"] = field + else: + args["deletion_scheduled"] = False + + field = data.get("zone", None) + if field is not None: + args["zone"] = field + else: + args["zone"] = None + + field = data.get("delivered", None) + if field is not None: + args["delivered"] = field + else: + args["delivered"] = False + field = data.get("os", None) if field is not None: args["os"] = unmarshal_OS(field) @@ -319,24 +349,6 @@ 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 - else: - args["deletion_scheduled"] = False - - field = data.get("zone", None) - if field is not None: - args["zone"] = field - else: - args["zone"] = None - - field = data.get("delivered", None) - if field is not None: - args["delivered"] = field - else: - args["delivered"] = False - field = data.get("vpc_status", None) if field is not None: args["vpc_status"] = field @@ -355,6 +367,12 @@ def unmarshal_Server(data: Any) -> Server: else: args["tags"] = [] + field = data.get("applied_runner_configuration_ids", None) + if field is not None: + args["applied_runner_configuration_ids"] = field + else: + args["applied_runner_configuration_ids"] = [] + field = data.get("commitment", None) if field is not None: args["commitment"] = unmarshal_Commitment(field) @@ -370,6 +388,128 @@ def unmarshal_Server(data: Any) -> Server: return Server(**args) +def unmarshal_GithubRunnerConfiguration(data: Any) -> GithubRunnerConfiguration: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'GithubRunnerConfiguration' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("url", None) + if field is not None: + args["url"] = field + else: + args["url"] = None + + field = data.get("token", None) + if field is not None: + args["token"] = field + else: + args["token"] = None + + field = data.get("labels", None) + if field is not None: + args["labels"] = field + else: + args["labels"] = None + + return GithubRunnerConfiguration(**args) + + +def unmarshal_GitlabRunnerConfiguration(data: Any) -> GitlabRunnerConfiguration: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'GitlabRunnerConfiguration' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("url", None) + if field is not None: + args["url"] = field + else: + args["url"] = None + + field = data.get("token", None) + if field is not None: + args["token"] = field + else: + args["token"] = None + + return GitlabRunnerConfiguration(**args) + + +def unmarshal_RunnerConfigurationV2(data: Any) -> RunnerConfigurationV2: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'RunnerConfigurationV2' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("provider", None) + if field is not None: + args["provider"] = field + else: + args["provider"] = None + + field = data.get("github_configuration", None) + if field is not None: + args["github_configuration"] = unmarshal_GithubRunnerConfiguration(field) + else: + args["github_configuration"] = None + + field = data.get("gitlab_configuration", None) + if field is not None: + args["gitlab_configuration"] = unmarshal_GitlabRunnerConfiguration(field) + else: + args["gitlab_configuration"] = None + + return RunnerConfigurationV2(**args) + + +def unmarshal_Runner(data: Any) -> Runner: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Runner' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("status", None) + if field is not None: + args["status"] = field + else: + args["status"] = None + + field = data.get("error_message", None) + if field is not None: + args["error_message"] = field + else: + args["error_message"] = None + + field = data.get("configuration", None) + if field is not None: + args["configuration"] = unmarshal_RunnerConfigurationV2(field) + else: + args["configuration"] = None + + return Runner(**args) + + def unmarshal_ServerPrivateNetwork(data: Any) -> ServerPrivateNetwork: if not isinstance(data, dict): raise TypeError( @@ -800,6 +940,31 @@ def unmarshal_ListOSResponse(data: Any) -> ListOSResponse: return ListOSResponse(**args) +def unmarshal_ListRunnersResponse(data: Any) -> ListRunnersResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListRunnersResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = None + + field = data.get("runners", None) + if field is not None: + args["runners"] = ( + [unmarshal_Runner(v) for v in field] if field is not None else None + ) + else: + args["runners"] = None + + return ListRunnersResponse(**args) + + def unmarshal_ListServerPrivateNetworksResponse( data: Any, ) -> ListServerPrivateNetworksResponse: @@ -964,6 +1129,101 @@ def marshal_BatchCreateServersRequest( return output +def marshal_GithubRunnerConfiguration( + request: GithubRunnerConfiguration, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.url is not None: + output["url"] = request.url + + if request.token is not None: + output["token"] = request.token + + if request.labels is not None: + output["labels"] = request.labels + + return output + + +def marshal_GitlabRunnerConfiguration( + request: GitlabRunnerConfiguration, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.url is not None: + output["url"] = request.url + + if request.token is not None: + output["token"] = request.token + + return output + + +def marshal_RunnerConfigurationV2( + request: RunnerConfigurationV2, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility( + param="github_configuration", + value=request.github_configuration, + marshal_func=marshal_GithubRunnerConfiguration, + ), + OneOfPossibility( + param="gitlab_configuration", + value=request.gitlab_configuration, + marshal_func=marshal_GitlabRunnerConfiguration, + ), + ] + ), + ) + + if request.name is not None: + output["name"] = request.name + + if request.provider is not None: + output["provider"] = request.provider + + return output + + +def marshal_CreateRunnerRequest( + request: CreateRunnerRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.runner_configuration is not None: + output["runner_configuration"] = marshal_RunnerConfigurationV2( + request.runner_configuration, defaults + ) + + if request.project_id is not None: + output["project_id"] = request.project_id + else: + output["project_id"] = defaults.default_project_id + + return output + + +def marshal_AppliedRunnerConfigurations( + request: AppliedRunnerConfigurations, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.runner_configuration_ids is not None: + output["runner_configuration_ids"] = request.runner_configuration_ids + + return output + + def marshal_RunnerConfiguration( request: RunnerConfiguration, defaults: ProfileDefaults, @@ -1019,6 +1279,11 @@ def marshal_CreateServerRequest( request.runner_configuration, defaults ) + if request.applied_runner_configurations is not None: + output["applied_runner_configurations"] = marshal_AppliedRunnerConfigurations( + request.applied_runner_configurations, defaults + ) + return output @@ -1075,6 +1340,20 @@ def marshal_StartConnectivityDiagnosticRequest( return output +def marshal_UpdateRunnerRequest( + request: UpdateRunnerRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.runner_configuration is not None: + output["runner_configuration"] = marshal_RunnerConfigurationV2( + request.runner_configuration, defaults + ) + + return output + + def marshal_CommitmentTypeValue( request: CommitmentTypeValue, defaults: ProfileDefaults, @@ -1110,4 +1389,9 @@ def marshal_UpdateServerRequest( if request.public_bandwidth_bps is not None: output["public_bandwidth_bps"] = request.public_bandwidth_bps + if request.applied_runner_configurations is not None: + output["applied_runner_configurations"] = marshal_AppliedRunnerConfigurations( + request.applied_runner_configurations, defaults + ) + return output diff --git a/scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py b/scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py index 6c99d7034..8243fd94a 100644 --- a/scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/applesilicon/v1alpha1/types.py @@ -69,6 +69,26 @@ def __str__(self) -> str: return str(self.value) +class RunnerConfigurationV2Provider(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_PROVIDER = "unknown_provider" + GITHUB = "github" + GITLAB = "gitlab" + + def __str__(self) -> str: + return str(self.value) + + +class RunnerStatus(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATUS = "unknown_status" + WAITING = "waiting" + ENABLED = "enabled" + DISABLED = "disabled" + ERROR = "error" + + def __str__(self) -> str: + return str(self.value) + + class ServerPrivateNetworkServerStatus(str, Enum, metaclass=StrEnumMeta): UNKNOWN_STATUS = "unknown_status" ATTACHING = "attaching" @@ -124,6 +144,19 @@ class OSSupportedServerType: fast_delivery_available: bool +@dataclass +class GithubRunnerConfiguration: + url: str + token: str + labels: list[str] + + +@dataclass +class GitlabRunnerConfiguration: + url: str + token: str + + @dataclass class Commitment: type_: CommitmentType @@ -206,6 +239,15 @@ class RunnerConfiguration: provider: RunnerConfigurationProvider +@dataclass +class RunnerConfigurationV2: + name: str + provider: RunnerConfigurationV2Provider + github_configuration: Optional[GithubRunnerConfiguration] = None + + gitlab_configuration: Optional[GitlabRunnerConfiguration] = None + + @dataclass class ServerTypeCPU: name: str @@ -336,6 +378,11 @@ class Server: A list of tags attached to the server. """ + applied_runner_configuration_ids: list[str] + """ + Runner configurations applied on the server, optional. + """ + os: Optional[OS] = None """ Initially installed OS, this does not necessarily reflect the current OS version. @@ -377,6 +424,19 @@ class ConnectivityDiagnosticServerHealth: last_checkin_date: Optional[datetime] = None +@dataclass +class AppliedRunnerConfigurations: + runner_configuration_ids: list[str] + + +@dataclass +class Runner: + id: str + status: RunnerStatus + error_message: str + configuration: Optional[RunnerConfigurationV2] = None + + @dataclass class ServerPrivateNetwork: id: str @@ -546,6 +606,24 @@ class ConnectivityDiagnostic: health_details: Optional[ConnectivityDiagnosticServerHealth] = None +@dataclass +class CreateRunnerRequest: + runner_configuration: RunnerConfigurationV2 + """ + Configuration details for the runner. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + project_id: Optional[str] = None + """ + Creates a runner in the given project_id. + """ + + @dataclass class CreateServerRequest: type_: str @@ -593,6 +671,24 @@ class CreateServerRequest: Specify the configuration to install an optional CICD runner on the server during installation. """ + applied_runner_configurations: Optional[AppliedRunnerConfigurations] = None + """ + Runner configurations to apply on the server, existing ones missing from the specified configuration will be removed from the server. + """ + + +@dataclass +class DeleteRunnerRequest: + runner_id: str + """ + ID of the runner configuration to delete. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + @dataclass class DeleteServerRequest: @@ -629,6 +725,19 @@ class GetOSRequest: """ +@dataclass +class GetRunnerRequest: + runner_id: str + """ + ID of the runner configuration to get. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + @dataclass class GetServerRequest: server_id: str @@ -696,6 +805,45 @@ class ListOSResponse: """ +@dataclass +class ListRunnersRequest: + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + server_id: Optional[str] = None + """ + ID of the server for which to list applied runner configurations. + """ + + project_id: Optional[str] = None + """ + Only list servers of this project ID. + """ + + organization_id: Optional[str] = None + """ + Only list servers of this Organization ID. + """ + + page: Optional[int] = 0 + """ + Positive integer to choose the page to return. + """ + + page_size: Optional[int] = 0 + """ + Positive integer lower or equal to 100 to select the number of items to return. + """ + + +@dataclass +class ListRunnersResponse: + total_count: int + runners: list[Runner] + + @dataclass class ListServerPrivateNetworksResponse: server_private_networks: list[ServerPrivateNetwork] @@ -935,6 +1083,24 @@ class StartConnectivityDiagnosticResponse: diagnostic_id: str +@dataclass +class UpdateRunnerRequest: + runner_id: str + """ + ID of the runner configuration to update. + """ + + runner_configuration: RunnerConfigurationV2 + """ + Configuration details for the runner. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + @dataclass class UpdateServerRequest: server_id: str @@ -971,3 +1137,8 @@ class UpdateServerRequest: """ 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. """ + + applied_runner_configurations: Optional[AppliedRunnerConfigurations] = None + """ + Runner configurations to apply on the server, existing ones missing from the specified configuration will be removed from the server. + """ diff --git a/scaleway/scaleway/applesilicon/v1alpha1/__init__.py b/scaleway/scaleway/applesilicon/v1alpha1/__init__.py index 228aec6ec..93f2c5ddc 100644 --- a/scaleway/scaleway/applesilicon/v1alpha1/__init__.py +++ b/scaleway/scaleway/applesilicon/v1alpha1/__init__.py @@ -6,6 +6,9 @@ from .types import ListServerPrivateNetworksRequestOrderBy from .types import ListServersRequestOrderBy from .types import RunnerConfigurationProvider +from .types import RunnerConfigurationV2Provider +from .types import RunnerStatus +from .content import RUNNER_TRANSIENT_STATUSES from .types import ServerPrivateNetworkServerStatus from .content import SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES from .types import ServerPrivateNetworkStatus @@ -14,9 +17,12 @@ from .content import SERVER_TRANSIENT_STATUSES from .types import ServerTypeStock from .types import OSSupportedServerType +from .types import GithubRunnerConfiguration +from .types import GitlabRunnerConfiguration from .types import Commitment from .types import OS from .types import RunnerConfiguration +from .types import RunnerConfigurationV2 from .types import ServerTypeCPU from .types import ServerTypeDisk from .types import ServerTypeGPU @@ -26,20 +32,27 @@ from .types import BatchCreateServersRequestBatchInnerCreateServerRequest from .types import Server from .types import ConnectivityDiagnosticServerHealth +from .types import AppliedRunnerConfigurations +from .types import Runner 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 CreateRunnerRequest from .types import CreateServerRequest +from .types import DeleteRunnerRequest from .types import DeleteServerRequest from .types import GetConnectivityDiagnosticRequest from .types import GetOSRequest +from .types import GetRunnerRequest from .types import GetServerRequest from .types import GetServerTypeRequest from .types import ListOSRequest from .types import ListOSResponse +from .types import ListRunnersRequest +from .types import ListRunnersResponse from .types import ListServerPrivateNetworksResponse from .types import ListServerTypesRequest from .types import ListServerTypesResponse @@ -55,6 +68,7 @@ from .types import SetServerPrivateNetworksResponse from .types import StartConnectivityDiagnosticRequest from .types import StartConnectivityDiagnosticResponse +from .types import UpdateRunnerRequest from .types import UpdateServerRequest from .api import ApplesiliconV1Alpha1API from .api import ApplesiliconV1Alpha1PrivateNetworkAPI @@ -66,6 +80,9 @@ "ListServerPrivateNetworksRequestOrderBy", "ListServersRequestOrderBy", "RunnerConfigurationProvider", + "RunnerConfigurationV2Provider", + "RunnerStatus", + "RUNNER_TRANSIENT_STATUSES", "ServerPrivateNetworkServerStatus", "SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES", "ServerPrivateNetworkStatus", @@ -74,9 +91,12 @@ "SERVER_TRANSIENT_STATUSES", "ServerTypeStock", "OSSupportedServerType", + "GithubRunnerConfiguration", + "GitlabRunnerConfiguration", "Commitment", "OS", "RunnerConfiguration", + "RunnerConfigurationV2", "ServerTypeCPU", "ServerTypeDisk", "ServerTypeGPU", @@ -86,20 +106,27 @@ "BatchCreateServersRequestBatchInnerCreateServerRequest", "Server", "ConnectivityDiagnosticServerHealth", + "AppliedRunnerConfigurations", + "Runner", "ServerPrivateNetwork", "ServerType", "CommitmentTypeValue", "BatchCreateServersRequest", "BatchCreateServersResponse", "ConnectivityDiagnostic", + "CreateRunnerRequest", "CreateServerRequest", + "DeleteRunnerRequest", "DeleteServerRequest", "GetConnectivityDiagnosticRequest", "GetOSRequest", + "GetRunnerRequest", "GetServerRequest", "GetServerTypeRequest", "ListOSRequest", "ListOSResponse", + "ListRunnersRequest", + "ListRunnersResponse", "ListServerPrivateNetworksResponse", "ListServerTypesRequest", "ListServerTypesResponse", @@ -115,6 +142,7 @@ "SetServerPrivateNetworksResponse", "StartConnectivityDiagnosticRequest", "StartConnectivityDiagnosticResponse", + "UpdateRunnerRequest", "UpdateServerRequest", "ApplesiliconV1Alpha1API", "ApplesiliconV1Alpha1PrivateNetworkAPI", diff --git a/scaleway/scaleway/applesilicon/v1alpha1/api.py b/scaleway/scaleway/applesilicon/v1alpha1/api.py index 60b1b1711..4b052078a 100644 --- a/scaleway/scaleway/applesilicon/v1alpha1/api.py +++ b/scaleway/scaleway/applesilicon/v1alpha1/api.py @@ -18,13 +18,16 @@ CommitmentType, ListServerPrivateNetworksRequestOrderBy, ListServersRequestOrderBy, + AppliedRunnerConfigurations, BatchCreateServersRequest, BatchCreateServersRequestBatchInnerCreateServerRequest, BatchCreateServersResponse, CommitmentTypeValue, ConnectivityDiagnostic, + CreateRunnerRequest, CreateServerRequest, ListOSResponse, + ListRunnersResponse, ListServerPrivateNetworksResponse, ListServerTypesResponse, ListServersResponse, @@ -32,38 +35,46 @@ 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, ) @@ -144,6 +155,7 @@ def create_server( 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. @@ -157,6 +169,7 @@ def create_server( :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 ` Usage: @@ -185,6 +198,7 @@ def create_server( os_id=os_id, commitment_type=commitment_type, runner_configuration=runner_configuration, + applied_runner_configurations=applied_runner_configurations, ), self.client, ), @@ -529,6 +543,7 @@ def update_server( 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. @@ -540,6 +555,7 @@ def update_server( :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 ` Usage: @@ -565,6 +581,7 @@ def update_server( enable_vpc=enable_vpc, commitment_type=commitment_type, public_bandwidth_bps=public_bandwidth_bps, + applied_runner_configurations=applied_runner_configurations, ), self.client, ), @@ -744,6 +761,268 @@ def get_connectivity_diagnostic( self._throw_on_error(res) return unmarshal_ConnectivityDiagnostic(res.json()) + 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 ` + + Usage: + :: + + result = 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()) + + 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 ` + + Usage: + :: + + result = 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()) + + def wait_for_runner( + self, + *, + runner_id: str, + zone: Optional[ScwZone] = None, + options: Optional[WaitForOptions[Runner, 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 ` + + Usage: + :: + + result = 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 wait_for_resource( + fetcher=self.get_runner, + options=options, + args={ + "runner_id": runner_id, + "zone": zone, + }, + ) + + 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 ` + + Usage: + :: + + result = 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()) + + 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] ` + + Usage: + :: + + result = api.list_runners_all() + """ + + return fetch_all_pages( + 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, + }, + ) + + 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 ` + + Usage: + :: + + result = 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, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Runner(res.json()) + + def delete_runner( + self, + *, + runner_id: str, + zone: Optional[ScwZone] = None, + ) -> None: + """ + Create a new runner configuration. + :param runner_id: ID of the runner configuration to delete. + :param zone: Zone to target. If none is passed will use default zone from the config. + + Usage: + :: + + result = api.delete_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( + "DELETE", + f"/apple-silicon/v1alpha1/zones/{param_zone}/runners/{param_runner_id}", + ) + + self._throw_on_error(res) + class ApplesiliconV1Alpha1PrivateNetworkAPI(API): """ diff --git a/scaleway/scaleway/applesilicon/v1alpha1/content.py b/scaleway/scaleway/applesilicon/v1alpha1/content.py index 67fc6b73e..4088a1714 100644 --- a/scaleway/scaleway/applesilicon/v1alpha1/content.py +++ b/scaleway/scaleway/applesilicon/v1alpha1/content.py @@ -2,11 +2,18 @@ # If you have any remark or suggestion do not hesitate to open an issue. from .types import ( + RunnerStatus, ServerPrivateNetworkServerStatus, ServerPrivateNetworkStatus, ServerStatus, ) +RUNNER_TRANSIENT_STATUSES: list[RunnerStatus] = [ + RunnerStatus.WAITING, +] +""" +Lists transient statutes of the enum :class:`RunnerStatus `. +""" SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES: list[ ServerPrivateNetworkServerStatus ] = [ diff --git a/scaleway/scaleway/applesilicon/v1alpha1/marshalling.py b/scaleway/scaleway/applesilicon/v1alpha1/marshalling.py index 6dd880c15..a984505f9 100644 --- a/scaleway/scaleway/applesilicon/v1alpha1/marshalling.py +++ b/scaleway/scaleway/applesilicon/v1alpha1/marshalling.py @@ -5,6 +5,10 @@ from dateutil import parser from scaleway_core.profile import ProfileDefaults +from scaleway_core.utils import ( + OneOfPossibility, + resolve_one_of, +) from .types import ( ConnectivityDiagnosticActionType, ServerPrivateNetworkServerStatus, @@ -16,6 +20,10 @@ Commitment, RunnerConfiguration, Server, + GithubRunnerConfiguration, + GitlabRunnerConfiguration, + RunnerConfigurationV2, + Runner, ServerPrivateNetwork, ServerTypeCPU, ServerTypeDisk, @@ -28,6 +36,7 @@ ConnectivityDiagnosticServerHealth, ConnectivityDiagnostic, ListOSResponse, + ListRunnersResponse, ListServerPrivateNetworksResponse, ListServerTypesResponse, ListServersResponse, @@ -35,11 +44,14 @@ StartConnectivityDiagnosticResponse, BatchCreateServersRequestBatchInnerCreateServerRequest, BatchCreateServersRequest, + CreateRunnerRequest, + AppliedRunnerConfigurations, CreateServerRequest, PrivateNetworkApiAddServerPrivateNetworkRequest, PrivateNetworkApiSetServerPrivateNetworksRequest, ReinstallServerRequest, StartConnectivityDiagnosticRequest, + UpdateRunnerRequest, CommitmentTypeValue, UpdateServerRequest, ) @@ -293,6 +305,24 @@ def unmarshal_Server(data: Any) -> Server: else: args["status"] = ServerStatus.UNKNOWN_STATUS + field = data.get("deletion_scheduled", None) + if field is not None: + args["deletion_scheduled"] = field + else: + args["deletion_scheduled"] = False + + field = data.get("zone", None) + if field is not None: + args["zone"] = field + else: + args["zone"] = None + + field = data.get("delivered", None) + if field is not None: + args["delivered"] = field + else: + args["delivered"] = False + field = data.get("os", None) if field is not None: args["os"] = unmarshal_OS(field) @@ -319,24 +349,6 @@ 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 - else: - args["deletion_scheduled"] = False - - field = data.get("zone", None) - if field is not None: - args["zone"] = field - else: - args["zone"] = None - - field = data.get("delivered", None) - if field is not None: - args["delivered"] = field - else: - args["delivered"] = False - field = data.get("vpc_status", None) if field is not None: args["vpc_status"] = field @@ -355,6 +367,12 @@ def unmarshal_Server(data: Any) -> Server: else: args["tags"] = [] + field = data.get("applied_runner_configuration_ids", None) + if field is not None: + args["applied_runner_configuration_ids"] = field + else: + args["applied_runner_configuration_ids"] = [] + field = data.get("commitment", None) if field is not None: args["commitment"] = unmarshal_Commitment(field) @@ -370,6 +388,128 @@ def unmarshal_Server(data: Any) -> Server: return Server(**args) +def unmarshal_GithubRunnerConfiguration(data: Any) -> GithubRunnerConfiguration: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'GithubRunnerConfiguration' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("url", None) + if field is not None: + args["url"] = field + else: + args["url"] = None + + field = data.get("token", None) + if field is not None: + args["token"] = field + else: + args["token"] = None + + field = data.get("labels", None) + if field is not None: + args["labels"] = field + else: + args["labels"] = None + + return GithubRunnerConfiguration(**args) + + +def unmarshal_GitlabRunnerConfiguration(data: Any) -> GitlabRunnerConfiguration: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'GitlabRunnerConfiguration' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("url", None) + if field is not None: + args["url"] = field + else: + args["url"] = None + + field = data.get("token", None) + if field is not None: + args["token"] = field + else: + args["token"] = None + + return GitlabRunnerConfiguration(**args) + + +def unmarshal_RunnerConfigurationV2(data: Any) -> RunnerConfigurationV2: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'RunnerConfigurationV2' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("provider", None) + if field is not None: + args["provider"] = field + else: + args["provider"] = None + + field = data.get("github_configuration", None) + if field is not None: + args["github_configuration"] = unmarshal_GithubRunnerConfiguration(field) + else: + args["github_configuration"] = None + + field = data.get("gitlab_configuration", None) + if field is not None: + args["gitlab_configuration"] = unmarshal_GitlabRunnerConfiguration(field) + else: + args["gitlab_configuration"] = None + + return RunnerConfigurationV2(**args) + + +def unmarshal_Runner(data: Any) -> Runner: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Runner' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("status", None) + if field is not None: + args["status"] = field + else: + args["status"] = None + + field = data.get("error_message", None) + if field is not None: + args["error_message"] = field + else: + args["error_message"] = None + + field = data.get("configuration", None) + if field is not None: + args["configuration"] = unmarshal_RunnerConfigurationV2(field) + else: + args["configuration"] = None + + return Runner(**args) + + def unmarshal_ServerPrivateNetwork(data: Any) -> ServerPrivateNetwork: if not isinstance(data, dict): raise TypeError( @@ -800,6 +940,31 @@ def unmarshal_ListOSResponse(data: Any) -> ListOSResponse: return ListOSResponse(**args) +def unmarshal_ListRunnersResponse(data: Any) -> ListRunnersResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListRunnersResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = None + + field = data.get("runners", None) + if field is not None: + args["runners"] = ( + [unmarshal_Runner(v) for v in field] if field is not None else None + ) + else: + args["runners"] = None + + return ListRunnersResponse(**args) + + def unmarshal_ListServerPrivateNetworksResponse( data: Any, ) -> ListServerPrivateNetworksResponse: @@ -964,6 +1129,101 @@ def marshal_BatchCreateServersRequest( return output +def marshal_GithubRunnerConfiguration( + request: GithubRunnerConfiguration, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.url is not None: + output["url"] = request.url + + if request.token is not None: + output["token"] = request.token + + if request.labels is not None: + output["labels"] = request.labels + + return output + + +def marshal_GitlabRunnerConfiguration( + request: GitlabRunnerConfiguration, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.url is not None: + output["url"] = request.url + + if request.token is not None: + output["token"] = request.token + + return output + + +def marshal_RunnerConfigurationV2( + request: RunnerConfigurationV2, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility( + param="github_configuration", + value=request.github_configuration, + marshal_func=marshal_GithubRunnerConfiguration, + ), + OneOfPossibility( + param="gitlab_configuration", + value=request.gitlab_configuration, + marshal_func=marshal_GitlabRunnerConfiguration, + ), + ] + ), + ) + + if request.name is not None: + output["name"] = request.name + + if request.provider is not None: + output["provider"] = request.provider + + return output + + +def marshal_CreateRunnerRequest( + request: CreateRunnerRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.runner_configuration is not None: + output["runner_configuration"] = marshal_RunnerConfigurationV2( + request.runner_configuration, defaults + ) + + if request.project_id is not None: + output["project_id"] = request.project_id + else: + output["project_id"] = defaults.default_project_id + + return output + + +def marshal_AppliedRunnerConfigurations( + request: AppliedRunnerConfigurations, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.runner_configuration_ids is not None: + output["runner_configuration_ids"] = request.runner_configuration_ids + + return output + + def marshal_RunnerConfiguration( request: RunnerConfiguration, defaults: ProfileDefaults, @@ -1019,6 +1279,11 @@ def marshal_CreateServerRequest( request.runner_configuration, defaults ) + if request.applied_runner_configurations is not None: + output["applied_runner_configurations"] = marshal_AppliedRunnerConfigurations( + request.applied_runner_configurations, defaults + ) + return output @@ -1075,6 +1340,20 @@ def marshal_StartConnectivityDiagnosticRequest( return output +def marshal_UpdateRunnerRequest( + request: UpdateRunnerRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.runner_configuration is not None: + output["runner_configuration"] = marshal_RunnerConfigurationV2( + request.runner_configuration, defaults + ) + + return output + + def marshal_CommitmentTypeValue( request: CommitmentTypeValue, defaults: ProfileDefaults, @@ -1110,4 +1389,9 @@ def marshal_UpdateServerRequest( if request.public_bandwidth_bps is not None: output["public_bandwidth_bps"] = request.public_bandwidth_bps + if request.applied_runner_configurations is not None: + output["applied_runner_configurations"] = marshal_AppliedRunnerConfigurations( + request.applied_runner_configurations, defaults + ) + return output diff --git a/scaleway/scaleway/applesilicon/v1alpha1/types.py b/scaleway/scaleway/applesilicon/v1alpha1/types.py index 6c99d7034..8243fd94a 100644 --- a/scaleway/scaleway/applesilicon/v1alpha1/types.py +++ b/scaleway/scaleway/applesilicon/v1alpha1/types.py @@ -69,6 +69,26 @@ def __str__(self) -> str: return str(self.value) +class RunnerConfigurationV2Provider(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_PROVIDER = "unknown_provider" + GITHUB = "github" + GITLAB = "gitlab" + + def __str__(self) -> str: + return str(self.value) + + +class RunnerStatus(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATUS = "unknown_status" + WAITING = "waiting" + ENABLED = "enabled" + DISABLED = "disabled" + ERROR = "error" + + def __str__(self) -> str: + return str(self.value) + + class ServerPrivateNetworkServerStatus(str, Enum, metaclass=StrEnumMeta): UNKNOWN_STATUS = "unknown_status" ATTACHING = "attaching" @@ -124,6 +144,19 @@ class OSSupportedServerType: fast_delivery_available: bool +@dataclass +class GithubRunnerConfiguration: + url: str + token: str + labels: list[str] + + +@dataclass +class GitlabRunnerConfiguration: + url: str + token: str + + @dataclass class Commitment: type_: CommitmentType @@ -206,6 +239,15 @@ class RunnerConfiguration: provider: RunnerConfigurationProvider +@dataclass +class RunnerConfigurationV2: + name: str + provider: RunnerConfigurationV2Provider + github_configuration: Optional[GithubRunnerConfiguration] = None + + gitlab_configuration: Optional[GitlabRunnerConfiguration] = None + + @dataclass class ServerTypeCPU: name: str @@ -336,6 +378,11 @@ class Server: A list of tags attached to the server. """ + applied_runner_configuration_ids: list[str] + """ + Runner configurations applied on the server, optional. + """ + os: Optional[OS] = None """ Initially installed OS, this does not necessarily reflect the current OS version. @@ -377,6 +424,19 @@ class ConnectivityDiagnosticServerHealth: last_checkin_date: Optional[datetime] = None +@dataclass +class AppliedRunnerConfigurations: + runner_configuration_ids: list[str] + + +@dataclass +class Runner: + id: str + status: RunnerStatus + error_message: str + configuration: Optional[RunnerConfigurationV2] = None + + @dataclass class ServerPrivateNetwork: id: str @@ -546,6 +606,24 @@ class ConnectivityDiagnostic: health_details: Optional[ConnectivityDiagnosticServerHealth] = None +@dataclass +class CreateRunnerRequest: + runner_configuration: RunnerConfigurationV2 + """ + Configuration details for the runner. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + project_id: Optional[str] = None + """ + Creates a runner in the given project_id. + """ + + @dataclass class CreateServerRequest: type_: str @@ -593,6 +671,24 @@ class CreateServerRequest: Specify the configuration to install an optional CICD runner on the server during installation. """ + applied_runner_configurations: Optional[AppliedRunnerConfigurations] = None + """ + Runner configurations to apply on the server, existing ones missing from the specified configuration will be removed from the server. + """ + + +@dataclass +class DeleteRunnerRequest: + runner_id: str + """ + ID of the runner configuration to delete. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + @dataclass class DeleteServerRequest: @@ -629,6 +725,19 @@ class GetOSRequest: """ +@dataclass +class GetRunnerRequest: + runner_id: str + """ + ID of the runner configuration to get. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + @dataclass class GetServerRequest: server_id: str @@ -696,6 +805,45 @@ class ListOSResponse: """ +@dataclass +class ListRunnersRequest: + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + server_id: Optional[str] = None + """ + ID of the server for which to list applied runner configurations. + """ + + project_id: Optional[str] = None + """ + Only list servers of this project ID. + """ + + organization_id: Optional[str] = None + """ + Only list servers of this Organization ID. + """ + + page: Optional[int] = 0 + """ + Positive integer to choose the page to return. + """ + + page_size: Optional[int] = 0 + """ + Positive integer lower or equal to 100 to select the number of items to return. + """ + + +@dataclass +class ListRunnersResponse: + total_count: int + runners: list[Runner] + + @dataclass class ListServerPrivateNetworksResponse: server_private_networks: list[ServerPrivateNetwork] @@ -935,6 +1083,24 @@ class StartConnectivityDiagnosticResponse: diagnostic_id: str +@dataclass +class UpdateRunnerRequest: + runner_id: str + """ + ID of the runner configuration to update. + """ + + runner_configuration: RunnerConfigurationV2 + """ + Configuration details for the runner. + """ + + zone: Optional[ScwZone] = None + """ + Zone to target. If none is passed will use default zone from the config. + """ + + @dataclass class UpdateServerRequest: server_id: str @@ -971,3 +1137,8 @@ class UpdateServerRequest: """ 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. """ + + applied_runner_configurations: Optional[AppliedRunnerConfigurations] = None + """ + Runner configurations to apply on the server, existing ones missing from the specified configuration will be removed from the server. + """