diff --git a/scaleway-async/scaleway_async/mongodb/v1/__init__.py b/scaleway-async/scaleway_async/mongodb/v1/__init__.py new file mode 100644 index 000000000..8dc097d17 --- /dev/null +++ b/scaleway-async/scaleway_async/mongodb/v1/__init__.py @@ -0,0 +1,111 @@ +# 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 InstanceStatus +from .content import INSTANCE_TRANSIENT_STATUSES +from .types import ListInstancesRequestOrderBy +from .types import ListSnapshotsRequestOrderBy +from .types import ListUsersRequestOrderBy +from .types import NodeTypeStock +from .types import SnapshotStatus +from .content import SNAPSHOT_TRANSIENT_STATUSES +from .types import UserRoleRole +from .types import VolumeType +from .types import EndpointPrivateNetworkDetails +from .types import EndpointPublicNetworkDetails +from .types import EndpointSpecPrivateNetworkDetails +from .types import EndpointSpecPublicNetworkDetails +from .types import Endpoint +from .types import InstanceSnapshotSchedule +from .types import Volume +from .types import NodeTypeVolumeType +from .types import UserRole +from .types import EndpointSpec +from .types import Instance +from .types import NodeType +from .types import Snapshot +from .types import User +from .types import Version +from .types import CreateEndpointRequest +from .types import CreateInstanceRequest +from .types import CreateSnapshotRequest +from .types import CreateUserRequest +from .types import DeleteEndpointRequest +from .types import DeleteInstanceRequest +from .types import DeleteSnapshotRequest +from .types import DeleteUserRequest +from .types import GetInstanceCertificateRequest +from .types import GetInstanceRequest +from .types import GetSnapshotRequest +from .types import ListInstancesRequest +from .types import ListInstancesResponse +from .types import ListNodeTypesRequest +from .types import ListNodeTypesResponse +from .types import ListSnapshotsRequest +from .types import ListSnapshotsResponse +from .types import ListUsersRequest +from .types import ListUsersResponse +from .types import ListVersionsRequest +from .types import ListVersionsResponse +from .types import RestoreSnapshotRequest +from .types import SetUserRoleRequest +from .types import UpdateInstanceRequest +from .types import UpdateSnapshotRequest +from .types import UpdateUserRequest +from .types import UpgradeInstanceRequest +from .api import MongodbV1API + +__all__ = [ + "InstanceStatus", + "INSTANCE_TRANSIENT_STATUSES", + "ListInstancesRequestOrderBy", + "ListSnapshotsRequestOrderBy", + "ListUsersRequestOrderBy", + "NodeTypeStock", + "SnapshotStatus", + "SNAPSHOT_TRANSIENT_STATUSES", + "UserRoleRole", + "VolumeType", + "EndpointPrivateNetworkDetails", + "EndpointPublicNetworkDetails", + "EndpointSpecPrivateNetworkDetails", + "EndpointSpecPublicNetworkDetails", + "Endpoint", + "InstanceSnapshotSchedule", + "Volume", + "NodeTypeVolumeType", + "UserRole", + "EndpointSpec", + "Instance", + "NodeType", + "Snapshot", + "User", + "Version", + "CreateEndpointRequest", + "CreateInstanceRequest", + "CreateSnapshotRequest", + "CreateUserRequest", + "DeleteEndpointRequest", + "DeleteInstanceRequest", + "DeleteSnapshotRequest", + "DeleteUserRequest", + "GetInstanceCertificateRequest", + "GetInstanceRequest", + "GetSnapshotRequest", + "ListInstancesRequest", + "ListInstancesResponse", + "ListNodeTypesRequest", + "ListNodeTypesResponse", + "ListSnapshotsRequest", + "ListSnapshotsResponse", + "ListUsersRequest", + "ListUsersResponse", + "ListVersionsRequest", + "ListVersionsResponse", + "RestoreSnapshotRequest", + "SetUserRoleRequest", + "UpdateInstanceRequest", + "UpdateSnapshotRequest", + "UpdateUserRequest", + "UpgradeInstanceRequest", + "MongodbV1API", +] diff --git a/scaleway-async/scaleway_async/mongodb/v1/api.py b/scaleway-async/scaleway_async/mongodb/v1/api.py new file mode 100644 index 000000000..381d12b4e --- /dev/null +++ b/scaleway-async/scaleway_async/mongodb/v1/api.py @@ -0,0 +1,1346 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from datetime import datetime +from typing import Awaitable, List, Optional, Union + +from scaleway_core.api import API +from scaleway_core.bridge import ( + Region as ScwRegion, + ScwFile, + unmarshal_ScwFile, +) +from scaleway_core.utils import ( + WaitForOptions, + random_name, + validate_path_param, + fetch_all_pages_async, + wait_for_resource_async, +) +from .types import ( + ListInstancesRequestOrderBy, + ListSnapshotsRequestOrderBy, + ListUsersRequestOrderBy, + VolumeType, + CreateEndpointRequest, + CreateInstanceRequest, + CreateSnapshotRequest, + CreateUserRequest, + Endpoint, + EndpointSpec, + Instance, + ListInstancesResponse, + ListNodeTypesResponse, + ListSnapshotsResponse, + ListUsersResponse, + ListVersionsResponse, + NodeType, + RestoreSnapshotRequest, + SetUserRoleRequest, + Snapshot, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, + User, + UserRole, + Version, + Volume, +) +from .content import ( + INSTANCE_TRANSIENT_STATUSES, + SNAPSHOT_TRANSIENT_STATUSES, +) +from .marshalling import ( + unmarshal_Endpoint, + unmarshal_Instance, + unmarshal_Snapshot, + unmarshal_User, + unmarshal_ListInstancesResponse, + unmarshal_ListNodeTypesResponse, + unmarshal_ListSnapshotsResponse, + unmarshal_ListUsersResponse, + unmarshal_ListVersionsResponse, + marshal_CreateEndpointRequest, + marshal_CreateInstanceRequest, + marshal_CreateSnapshotRequest, + marshal_CreateUserRequest, + marshal_RestoreSnapshotRequest, + marshal_SetUserRoleRequest, + marshal_UpdateInstanceRequest, + marshal_UpdateSnapshotRequest, + marshal_UpdateUserRequest, + marshal_UpgradeInstanceRequest, +) + + +class MongodbV1API(API): + """ + This API allows you to manage your Managed Databases for MongoDB®. + """ + + async def list_node_types( + self, + *, + region: Optional[ScwRegion] = None, + include_disabled: Optional[bool] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListNodeTypesResponse: + """ + List available node types. + :param region: Region to target. If none is passed will use default region from the config. + :param include_disabled: Defines whether or not to include disabled types. + :param page: + :param page_size: + :return: :class:`ListNodeTypesResponse ` + + Usage: + :: + + result = await api.list_node_types() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/node-types", + params={ + "include_disabled": include_disabled, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListNodeTypesResponse(res.json()) + + async def list_node_types_all( + self, + *, + region: Optional[ScwRegion] = None, + include_disabled: Optional[bool] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[NodeType]: + """ + List available node types. + :param region: Region to target. If none is passed will use default region from the config. + :param include_disabled: Defines whether or not to include disabled types. + :param page: + :param page_size: + :return: :class:`List[NodeType] ` + + Usage: + :: + + result = await api.list_node_types_all() + """ + + return await fetch_all_pages_async( + type=ListNodeTypesResponse, + key="node_types", + fetcher=self.list_node_types, + args={ + "region": region, + "include_disabled": include_disabled, + "page": page, + "page_size": page_size, + }, + ) + + async def list_versions( + self, + *, + region: Optional[ScwRegion] = None, + version: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListVersionsResponse: + """ + List available MongoDB® major versions. + :param region: Region to target. If none is passed will use default region from the config. + :param version: + :param page: + :param page_size: + :return: :class:`ListVersionsResponse ` + + Usage: + :: + + result = await api.list_versions() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/versions", + params={ + "page": page, + "page_size": page_size or self.client.default_page_size, + "version": version, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListVersionsResponse(res.json()) + + async def list_versions_all( + self, + *, + region: Optional[ScwRegion] = None, + version: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[Version]: + """ + List available MongoDB® major versions. + :param region: Region to target. If none is passed will use default region from the config. + :param version: + :param page: + :param page_size: + :return: :class:`List[Version] ` + + Usage: + :: + + result = await api.list_versions_all() + """ + + return await fetch_all_pages_async( + type=ListVersionsResponse, + key="versions", + fetcher=self.list_versions, + args={ + "region": region, + "version": version, + "page": page, + "page_size": page_size, + }, + ) + + async def list_instances( + self, + *, + region: Optional[ScwRegion] = None, + tags: Optional[List[str]] = None, + name: Optional[str] = None, + order_by: Optional[ListInstancesRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListInstancesResponse: + """ + List MongoDB® Database Instances. + List all MongoDB® Database Instances in the specified region. By default, the MongoDB® Database Instances returned in the list are ordered by creation date in ascending order, though this can be modified via the order_by field. You can define additional parameters for your query, such as `tags` and `name`. For the `name` parameter, the value you include will be checked against the whole name string to see if it includes the string you put in the parameter. + :param region: Region to target. If none is passed will use default region from the config. + :param tags: List Database Instances that have a given tag. + :param name: Lists Database Instances that match a name pattern. + :param order_by: Criteria to use when ordering Database Instance listings. + :param organization_id: Organization ID of the Database Instance. + :param project_id: Project ID to list the instances of. + :param page: + :param page_size: + :return: :class:`ListInstancesResponse ` + + Usage: + :: + + result = await api.list_instances() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances", + params={ + "name": name, + "order_by": order_by, + "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, + "tags": tags, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListInstancesResponse(res.json()) + + async def list_instances_all( + self, + *, + region: Optional[ScwRegion] = None, + tags: Optional[List[str]] = None, + name: Optional[str] = None, + order_by: Optional[ListInstancesRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[Instance]: + """ + List MongoDB® Database Instances. + List all MongoDB® Database Instances in the specified region. By default, the MongoDB® Database Instances returned in the list are ordered by creation date in ascending order, though this can be modified via the order_by field. You can define additional parameters for your query, such as `tags` and `name`. For the `name` parameter, the value you include will be checked against the whole name string to see if it includes the string you put in the parameter. + :param region: Region to target. If none is passed will use default region from the config. + :param tags: List Database Instances that have a given tag. + :param name: Lists Database Instances that match a name pattern. + :param order_by: Criteria to use when ordering Database Instance listings. + :param organization_id: Organization ID of the Database Instance. + :param project_id: Project ID to list the instances of. + :param page: + :param page_size: + :return: :class:`List[Instance] ` + + Usage: + :: + + result = await api.list_instances_all() + """ + + return await fetch_all_pages_async( + type=ListInstancesResponse, + key="instances", + fetcher=self.list_instances, + args={ + "region": region, + "tags": tags, + "name": name, + "order_by": order_by, + "organization_id": organization_id, + "project_id": project_id, + "page": page, + "page_size": page_size, + }, + ) + + async def get_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + ) -> Instance: + """ + Get a MongoDB® Database Instance. + Retrieve information about a given MongoDB® Database Instance, specified by the `region` and `instance_id` parameters. Its full details, including name, status, IP address and port, are returned in the response object. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.get_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}", + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + async def wait_for_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + options: Optional[ + WaitForOptions[Instance, Union[bool, Awaitable[bool]]] + ] = None, + ) -> Instance: + """ + Get a MongoDB® Database Instance. + Retrieve information about a given MongoDB® Database Instance, specified by the `region` and `instance_id` parameters. Its full details, including name, status, IP address and port, are returned in the response object. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.get_instance( + instance_id="example", + ) + """ + + if not options: + options = WaitForOptions() + + if not options.stop: + options.stop = lambda res: res.status not in INSTANCE_TRANSIENT_STATUSES + + return await wait_for_resource_async( + fetcher=self.get_instance, + options=options, + args={ + "instance_id": instance_id, + "region": region, + }, + ) + + async def create_instance( + self, + *, + version: str, + node_amount: int, + node_type: str, + user_name: str, + password: str, + region: Optional[ScwRegion] = None, + project_id: Optional[str] = None, + name: Optional[str] = None, + tags: Optional[List[str]] = None, + volume: Optional[Volume] = None, + endpoints: Optional[List[EndpointSpec]] = None, + ) -> Instance: + """ + Create a MongoDB® Database Instance. + Create a new MongoDB® Database Instance. + :param version: Major version of the MongoDB® engine. + :param node_amount: Number of node to use for the Database Instance. + :param node_type: Type of node to use for the Database Instance. + :param user_name: Username created when the Database Instance is created. + :param password: Password of the initial user. + :param region: Region to target. If none is passed will use default region from the config. + :param project_id: The Project ID on which the Database Instance will be created. + :param name: Name of the Database Instance. + :param tags: Tags to apply to the Database Instance. + :param volume: Instance volume information. + :param endpoints: One or multiple EndpointSpec used to expose your Database Instance. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.create_instance( + version="example", + node_amount=1, + node_type="example", + user_name="example", + password="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/instances", + body=marshal_CreateInstanceRequest( + CreateInstanceRequest( + version=version, + node_amount=node_amount, + node_type=node_type, + user_name=user_name, + password=password, + region=region, + project_id=project_id, + name=name or random_name(prefix="mgdb"), + tags=tags, + volume=volume, + endpoints=endpoints, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + async def update_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + tags: Optional[List[str]] = None, + snapshot_schedule_frequency_hours: Optional[int] = None, + snapshot_schedule_retention_days: Optional[int] = None, + is_snapshot_schedule_enabled: Optional[bool] = None, + ) -> Instance: + """ + Update a MongoDB® Database Instance. + Update the parameters of a MongoDB® Database Instance. + :param instance_id: UUID of the Database Instance to update. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the Database Instance. + :param tags: Tags of a Database Instance. + :param snapshot_schedule_frequency_hours: In hours. + :param snapshot_schedule_retention_days: In days. + :param is_snapshot_schedule_enabled: Defines whether or not the snapshot schedule is enabled. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.update_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "PATCH", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}", + body=marshal_UpdateInstanceRequest( + UpdateInstanceRequest( + instance_id=instance_id, + region=region, + name=name, + tags=tags, + snapshot_schedule_frequency_hours=snapshot_schedule_frequency_hours, + snapshot_schedule_retention_days=snapshot_schedule_retention_days, + is_snapshot_schedule_enabled=is_snapshot_schedule_enabled, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + async def delete_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + ) -> Instance: + """ + Delete a MongoDB® Database Instance. + Delete a given MongoDB® Database Instance, specified by the `region` and `instance_id` parameters. Deleting a MongoDB® Database Instance is permanent, and cannot be undone. Note that upon deletion all your data will be lost. + :param instance_id: UUID of the Database Instance to delete. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.delete_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}", + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + async def upgrade_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + volume_size_bytes: Optional[int] = None, + ) -> Instance: + """ + Upgrade a Database Instance. + Upgrade your current Database Instance specifications like volume size. + :param instance_id: UUID of the Database Instance you want to upgrade. + :param region: Region to target. If none is passed will use default region from the config. + :param volume_size_bytes: Increase your Block Storage volume size. + One-Of ('upgrade_target'): at most one of 'volume_size_bytes' could be set. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.upgrade_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/upgrade", + body=marshal_UpgradeInstanceRequest( + UpgradeInstanceRequest( + instance_id=instance_id, + region=region, + volume_size_bytes=volume_size_bytes, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + async def get_instance_certificate( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + ) -> ScwFile: + """ + Get the certificate of a Database Instance. + Retrieve the certificate of a given Database Instance, specified by the `instance_id` parameter. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`ScwFile ` + + Usage: + :: + + result = await api.get_instance_certificate( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/certificate", + ) + + self._throw_on_error(res) + return unmarshal_ScwFile(res.json()) + + async def create_snapshot( + self, + *, + instance_id: str, + name: str, + region: Optional[ScwRegion] = None, + expires_at: Optional[datetime] = None, + ) -> Snapshot: + """ + Create a Database Instance snapshot. + Create a new snapshot of a Database Instance. You must define the `name` and `instance_id` parameters in the request. + :param instance_id: UUID of the Database Instance to snapshot. + :param name: Name of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :param expires_at: Expiration date of the snapshot (must follow the ISO 8601 format). + :return: :class:`Snapshot ` + + Usage: + :: + + result = await api.create_snapshot( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/snapshots", + body=marshal_CreateSnapshotRequest( + CreateSnapshotRequest( + instance_id=instance_id, + name=name, + region=region, + expires_at=expires_at, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + async def get_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + ) -> Snapshot: + """ + Get a Database Instance snapshot. + Retrieve information about a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to retrieve. + :param snapshot_id: UUID of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Snapshot ` + + Usage: + :: + + result = await api.get_snapshot( + snapshot_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}", + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + async def wait_for_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + options: Optional[ + WaitForOptions[Snapshot, Union[bool, Awaitable[bool]]] + ] = None, + ) -> Snapshot: + """ + Get a Database Instance snapshot. + Retrieve information about a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to retrieve. + :param snapshot_id: UUID of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Snapshot ` + + Usage: + :: + + result = await api.get_snapshot( + snapshot_id="example", + ) + """ + + if not options: + options = WaitForOptions() + + if not options.stop: + options.stop = lambda res: res.status not in SNAPSHOT_TRANSIENT_STATUSES + + return await wait_for_resource_async( + fetcher=self.get_snapshot, + options=options, + args={ + "snapshot_id": snapshot_id, + "region": region, + }, + ) + + async def update_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + expires_at: Optional[datetime] = None, + ) -> Snapshot: + """ + Update a Database Instance snapshot. + Update the parameters of a snapshot of a Database Instance. You can update the `name` and `expires_at` parameters. + :param snapshot_id: UUID of the Snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the snapshot. + :param expires_at: Expiration date of the snapshot (must follow the ISO 8601 format). + :return: :class:`Snapshot ` + + Usage: + :: + + result = await api.update_snapshot( + snapshot_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "PATCH", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}", + body=marshal_UpdateSnapshotRequest( + UpdateSnapshotRequest( + snapshot_id=snapshot_id, + region=region, + name=name, + expires_at=expires_at, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + async def restore_snapshot( + self, + *, + snapshot_id: str, + instance_name: str, + node_type: str, + node_amount: int, + volume_type: VolumeType, + region: Optional[ScwRegion] = None, + ) -> Instance: + """ + Restore a Database Instance snapshot. + Restore a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to restore, the `instance_name` of the new Database Instance, `node_type` of the new Database Instance and `node_amount` of the new Database Instance. + :param snapshot_id: UUID of the snapshot. + :param instance_name: Name of the new Database Instance. + :param node_type: Node type to use for the new Database Instance. + :param node_amount: Number of nodes to use for the new Database Instance. + :param volume_type: Instance volume type. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = await api.restore_snapshot( + snapshot_id="example", + instance_name="example", + node_type="example", + node_amount=1, + volume_type=VolumeType.unknown_type, + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}/restore", + body=marshal_RestoreSnapshotRequest( + RestoreSnapshotRequest( + snapshot_id=snapshot_id, + instance_name=instance_name, + node_type=node_type, + node_amount=node_amount, + volume_type=volume_type, + region=region, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + async def list_snapshots( + self, + *, + region: Optional[ScwRegion] = None, + instance_id: Optional[str] = None, + name: Optional[str] = None, + order_by: Optional[ListSnapshotsRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListSnapshotsResponse: + """ + List snapshots. + List snapshots. You can include the `instance_id` or `project_id` in your query to get the list of snapshots for specific Database Instances and/or Projects. By default, the details returned in the list are ordered by creation date in ascending order, though this can be modified via the `order_by` field. + :param region: Region to target. If none is passed will use default region from the config. + :param instance_id: Instance ID the snapshots belongs to. + :param name: Lists database snapshots that match a name pattern. + :param order_by: Criteria to use when ordering snapshot listings. + :param organization_id: Organization ID the snapshots belongs to. + :param project_id: Project ID to list the snapshots of. + :param page: + :param page_size: + :return: :class:`ListSnapshotsResponse ` + + Usage: + :: + + result = await api.list_snapshots() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/snapshots", + params={ + "instance_id": instance_id, + "name": name, + "order_by": order_by, + "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, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListSnapshotsResponse(res.json()) + + async def list_snapshots_all( + self, + *, + region: Optional[ScwRegion] = None, + instance_id: Optional[str] = None, + name: Optional[str] = None, + order_by: Optional[ListSnapshotsRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[Snapshot]: + """ + List snapshots. + List snapshots. You can include the `instance_id` or `project_id` in your query to get the list of snapshots for specific Database Instances and/or Projects. By default, the details returned in the list are ordered by creation date in ascending order, though this can be modified via the `order_by` field. + :param region: Region to target. If none is passed will use default region from the config. + :param instance_id: Instance ID the snapshots belongs to. + :param name: Lists database snapshots that match a name pattern. + :param order_by: Criteria to use when ordering snapshot listings. + :param organization_id: Organization ID the snapshots belongs to. + :param project_id: Project ID to list the snapshots of. + :param page: + :param page_size: + :return: :class:`List[Snapshot] ` + + Usage: + :: + + result = await api.list_snapshots_all() + """ + + return await fetch_all_pages_async( + type=ListSnapshotsResponse, + key="snapshots", + fetcher=self.list_snapshots, + args={ + "region": region, + "instance_id": instance_id, + "name": name, + "order_by": order_by, + "organization_id": organization_id, + "project_id": project_id, + "page": page, + "page_size": page_size, + }, + ) + + async def delete_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + ) -> Snapshot: + """ + Delete a Database Instance snapshot. + Delete a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to delete. + :param snapshot_id: UUID of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Snapshot ` + + Usage: + :: + + result = await api.delete_snapshot( + snapshot_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}", + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + async def list_users( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + order_by: Optional[ListUsersRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListUsersResponse: + """ + List users of a Database Instance. + List all users of a given Database Instance. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the user. + :param order_by: Criteria to use when requesting user listing. + :param page: + :param page_size: + :return: :class:`ListUsersResponse ` + + Usage: + :: + + result = await api.list_users( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users", + params={ + "name": name, + "order_by": order_by, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListUsersResponse(res.json()) + + async def list_users_all( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + order_by: Optional[ListUsersRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[User]: + """ + List users of a Database Instance. + List all users of a given Database Instance. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the user. + :param order_by: Criteria to use when requesting user listing. + :param page: + :param page_size: + :return: :class:`List[User] ` + + Usage: + :: + + result = await api.list_users_all( + instance_id="example", + ) + """ + + return await fetch_all_pages_async( + type=ListUsersResponse, + key="users", + fetcher=self.list_users, + args={ + "instance_id": instance_id, + "region": region, + "name": name, + "order_by": order_by, + "page": page, + "page_size": page_size, + }, + ) + + async def create_user( + self, + *, + instance_id: str, + name: str, + password: str, + region: Optional[ScwRegion] = None, + ) -> User: + """ + Create an user on a Database Instance. + Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param password: Password of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`User ` + + Usage: + :: + + result = await api.create_user( + instance_id="example", + name="example", + password="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users", + body=marshal_CreateUserRequest( + CreateUserRequest( + instance_id=instance_id, + name=name, + password=password, + region=region, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + + async def update_user( + self, + *, + instance_id: str, + name: str, + region: Optional[ScwRegion] = None, + password: Optional[str] = None, + ) -> User: + """ + Update a user on a Database Instance. + Update the parameters of a user on a Database Instance. You can update the `password` parameter, but you cannot change the name of the user. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param password: Password of the database user. + :return: :class:`User ` + + Usage: + :: + + result = await api.update_user( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + param_name = validate_path_param("name", name) + + res = self._request( + "PATCH", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}", + body=marshal_UpdateUserRequest( + UpdateUserRequest( + instance_id=instance_id, + name=name, + region=region, + password=password, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + + async def delete_user( + self, + *, + instance_id: str, + name: str, + region: Optional[ScwRegion] = None, + ) -> None: + """ + Delete a user on a Database Instance. + Delete an existing user on a Database Instance. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + + Usage: + :: + + result = await api.delete_user( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + param_name = validate_path_param("name", name) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}", + ) + + self._throw_on_error(res) + + async def set_user_role( + self, + *, + instance_id: str, + user_name: str, + region: Optional[ScwRegion] = None, + roles: Optional[List[UserRole]] = None, + ) -> User: + """ + Apply user roles. + Apply preset roles for a user in a Database Instance. + :param instance_id: UUID of the Database Instance the user belongs to. + :param user_name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param roles: List of roles assigned to the user, along with the corresponding database where each role is granted. + :return: :class:`User ` + + Usage: + :: + + result = await api.set_user_role( + instance_id="example", + user_name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "PUT", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/set-user-roles", + body=marshal_SetUserRoleRequest( + SetUserRoleRequest( + instance_id=instance_id, + user_name=user_name, + region=region, + roles=roles, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + + async def delete_endpoint( + self, + *, + endpoint_id: str, + region: Optional[ScwRegion] = None, + ) -> None: + """ + Delete a Database Instance endpoint. + Delete the endpoint of a Database Instance. You must specify the `endpoint_id` parameter of the endpoint you want to delete. Note that you might need to update any environment configurations that point to the deleted endpoint. + :param endpoint_id: UUID of the Endpoint to delete. + :param region: Region to target. If none is passed will use default region from the config. + + Usage: + :: + + result = await api.delete_endpoint( + endpoint_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_endpoint_id = validate_path_param("endpoint_id", endpoint_id) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/endpoints/{param_endpoint_id}", + ) + + self._throw_on_error(res) + + async def create_endpoint( + self, + *, + instance_id: str, + endpoint: EndpointSpec, + region: Optional[ScwRegion] = None, + ) -> Endpoint: + """ + Create a new Instance endpoint. + Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request. + :param instance_id: UUID of the Database Instance. + :param endpoint: EndpointSpec used to expose your Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Endpoint ` + + Usage: + :: + + result = await api.create_endpoint( + instance_id="example", + endpoint=EndpointSpec(), + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/endpoints", + body=marshal_CreateEndpointRequest( + CreateEndpointRequest( + instance_id=instance_id, + endpoint=endpoint, + region=region, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Endpoint(res.json()) diff --git a/scaleway-async/scaleway_async/mongodb/v1/content.py b/scaleway-async/scaleway_async/mongodb/v1/content.py new file mode 100644 index 000000000..8e0092203 --- /dev/null +++ b/scaleway-async/scaleway_async/mongodb/v1/content.py @@ -0,0 +1,27 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from typing import List + +from .types import ( + InstanceStatus, + SnapshotStatus, +) + +INSTANCE_TRANSIENT_STATUSES: List[InstanceStatus] = [ + InstanceStatus.PROVISIONING, + InstanceStatus.CONFIGURING, + InstanceStatus.DELETING, + InstanceStatus.INITIALIZING, + InstanceStatus.SNAPSHOTTING, +] +""" +Lists transient statutes of the enum :class:`InstanceStatus `. +""" +SNAPSHOT_TRANSIENT_STATUSES: List[SnapshotStatus] = [ + SnapshotStatus.CREATING, + SnapshotStatus.RESTORING, + SnapshotStatus.DELETING, +] +""" +Lists transient statutes of the enum :class:`SnapshotStatus `. +""" diff --git a/scaleway-async/scaleway_async/mongodb/v1/marshalling.py b/scaleway-async/scaleway_async/mongodb/v1/marshalling.py new file mode 100644 index 000000000..ecef2c1e8 --- /dev/null +++ b/scaleway-async/scaleway_async/mongodb/v1/marshalling.py @@ -0,0 +1,829 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from typing import Any, Dict +from dateutil import parser + +from scaleway_core.profile import ProfileDefaults +from scaleway_core.utils import ( + OneOfPossibility, + resolve_one_of, +) +from .types import ( + EndpointPrivateNetworkDetails, + EndpointPublicNetworkDetails, + Endpoint, + InstanceSnapshotSchedule, + Volume, + Instance, + Snapshot, + UserRole, + User, + ListInstancesResponse, + NodeTypeVolumeType, + NodeType, + ListNodeTypesResponse, + ListSnapshotsResponse, + ListUsersResponse, + Version, + ListVersionsResponse, + EndpointSpecPrivateNetworkDetails, + EndpointSpecPublicNetworkDetails, + EndpointSpec, + CreateEndpointRequest, + CreateInstanceRequest, + CreateSnapshotRequest, + CreateUserRequest, + RestoreSnapshotRequest, + SetUserRoleRequest, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, +) + + +def unmarshal_EndpointPrivateNetworkDetails(data: Any) -> EndpointPrivateNetworkDetails: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'EndpointPrivateNetworkDetails' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("private_network_id", None) + if field is not None: + args["private_network_id"] = field + + return EndpointPrivateNetworkDetails(**args) + + +def unmarshal_EndpointPublicNetworkDetails(data: Any) -> EndpointPublicNetworkDetails: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'EndpointPublicNetworkDetails' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + return EndpointPublicNetworkDetails(**args) + + +def unmarshal_Endpoint(data: Any) -> Endpoint: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Endpoint' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("dns_record", None) + if field is not None: + args["dns_record"] = field + + field = data.get("port", None) + if field is not None: + args["port"] = field + + field = data.get("private_network", None) + if field is not None: + args["private_network"] = unmarshal_EndpointPrivateNetworkDetails(field) + else: + args["private_network"] = None + + field = data.get("public_network", None) + if field is not None: + args["public_network"] = unmarshal_EndpointPublicNetworkDetails(field) + else: + args["public_network"] = None + + return Endpoint(**args) + + +def unmarshal_InstanceSnapshotSchedule(data: Any) -> InstanceSnapshotSchedule: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'InstanceSnapshotSchedule' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("frequency_hours", None) + if field is not None: + args["frequency_hours"] = field + + field = data.get("retention_days", None) + if field is not None: + args["retention_days"] = field + + field = data.get("enabled", None) + if field is not None: + args["enabled"] = field + + field = data.get("next_update", None) + if field is not None: + args["next_update"] = ( + parser.isoparse(field) if isinstance(field, str) else field + ) + else: + args["next_update"] = None + + field = data.get("last_run", None) + if field is not None: + args["last_run"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["last_run"] = None + + return InstanceSnapshotSchedule(**args) + + +def unmarshal_Volume(data: Any) -> Volume: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Volume' 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("size_bytes", None) + if field is not None: + args["size_bytes"] = field + + return Volume(**args) + + +def unmarshal_Instance(data: Any) -> Instance: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Instance' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("project_id", None) + if field is not None: + args["project_id"] = field + + field = data.get("organization_id", None) + if field is not None: + args["organization_id"] = field + + field = data.get("status", None) + if field is not None: + args["status"] = field + + field = data.get("version", None) + if field is not None: + args["version"] = field + + field = data.get("tags", None) + if field is not None: + args["tags"] = field + + field = data.get("node_amount", None) + if field is not None: + args["node_amount"] = field + + field = data.get("node_type", None) + if field is not None: + args["node_type"] = field + + field = data.get("endpoints", None) + if field is not None: + args["endpoints"] = ( + [unmarshal_Endpoint(v) for v in field] if field is not None else None + ) + + field = data.get("region", None) + if field is not None: + args["region"] = field + + field = data.get("volume", None) + if field is not None: + args["volume"] = unmarshal_Volume(field) + else: + args["volume"] = None + + field = data.get("created_at", None) + if field is not None: + args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["created_at"] = None + + field = data.get("snapshot_schedule", None) + if field is not None: + args["snapshot_schedule"] = unmarshal_InstanceSnapshotSchedule(field) + else: + args["snapshot_schedule"] = None + + return Instance(**args) + + +def unmarshal_Snapshot(data: Any) -> Snapshot: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Snapshot' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("status", None) + if field is not None: + args["status"] = field + + field = data.get("size_bytes", None) + if field is not None: + args["size_bytes"] = field + + field = data.get("instance_name", None) + if field is not None: + args["instance_name"] = field + + field = data.get("node_type", None) + if field is not None: + args["node_type"] = field + + field = data.get("volume_type", None) + if field is not None: + args["volume_type"] = field + + field = data.get("region", None) + if field is not None: + args["region"] = field + + field = data.get("instance_id", None) + if field is not None: + args["instance_id"] = field + else: + args["instance_id"] = None + + field = data.get("expires_at", None) + if field is not None: + args["expires_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["expires_at"] = None + + field = data.get("created_at", None) + if field is not None: + args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["created_at"] = None + + field = data.get("updated_at", None) + if field is not None: + args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["updated_at"] = None + + return Snapshot(**args) + + +def unmarshal_UserRole(data: Any) -> UserRole: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'UserRole' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("role", None) + if field is not None: + args["role"] = field + + field = data.get("database_name", None) + if field is not None: + args["database_name"] = field + else: + args["database_name"] = None + + field = data.get("any_database", None) + if field is not None: + args["any_database"] = field + else: + args["any_database"] = None + + return UserRole(**args) + + +def unmarshal_User(data: Any) -> User: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'User' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("roles", None) + if field is not None: + args["roles"] = ( + [unmarshal_UserRole(v) for v in field] if field is not None else None + ) + + return User(**args) + + +def unmarshal_ListInstancesResponse(data: Any) -> ListInstancesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListInstancesResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("instances", None) + if field is not None: + args["instances"] = ( + [unmarshal_Instance(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListInstancesResponse(**args) + + +def unmarshal_NodeTypeVolumeType(data: Any) -> NodeTypeVolumeType: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'NodeTypeVolumeType' 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("description", None) + if field is not None: + args["description"] = field + + field = data.get("min_size_bytes", None) + if field is not None: + args["min_size_bytes"] = field + + field = data.get("max_size_bytes", None) + if field is not None: + args["max_size_bytes"] = field + + field = data.get("chunk_size_bytes", None) + if field is not None: + args["chunk_size_bytes"] = field + + return NodeTypeVolumeType(**args) + + +def unmarshal_NodeType(data: Any) -> NodeType: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'NodeType' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("stock_status", None) + if field is not None: + args["stock_status"] = field + + field = data.get("description", None) + if field is not None: + args["description"] = field + + field = data.get("vcpus", None) + if field is not None: + args["vcpus"] = field + + field = data.get("memory_bytes", None) + if field is not None: + args["memory_bytes"] = field + + field = data.get("available_volume_types", None) + if field is not None: + args["available_volume_types"] = ( + [unmarshal_NodeTypeVolumeType(v) for v in field] + if field is not None + else None + ) + + field = data.get("disabled", None) + if field is not None: + args["disabled"] = field + + field = data.get("beta", None) + if field is not None: + args["beta"] = field + + field = data.get("instance_range", None) + if field is not None: + args["instance_range"] = field + + return NodeType(**args) + + +def unmarshal_ListNodeTypesResponse(data: Any) -> ListNodeTypesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListNodeTypesResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("node_types", None) + if field is not None: + args["node_types"] = ( + [unmarshal_NodeType(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListNodeTypesResponse(**args) + + +def unmarshal_ListSnapshotsResponse(data: Any) -> ListSnapshotsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListSnapshotsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("snapshots", None) + if field is not None: + args["snapshots"] = ( + [unmarshal_Snapshot(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListSnapshotsResponse(**args) + + +def unmarshal_ListUsersResponse(data: Any) -> ListUsersResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListUsersResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("users", None) + if field is not None: + args["users"] = ( + [unmarshal_User(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListUsersResponse(**args) + + +def unmarshal_Version(data: Any) -> Version: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Version' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("version", None) + if field is not None: + args["version"] = field + + field = data.get("end_of_life_at", None) + if field is not None: + args["end_of_life_at"] = ( + parser.isoparse(field) if isinstance(field, str) else field + ) + else: + args["end_of_life_at"] = None + + return Version(**args) + + +def unmarshal_ListVersionsResponse(data: Any) -> ListVersionsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListVersionsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("versions", None) + if field is not None: + args["versions"] = ( + [unmarshal_Version(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListVersionsResponse(**args) + + +def marshal_EndpointSpecPrivateNetworkDetails( + request: EndpointSpecPrivateNetworkDetails, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.private_network_id is not None: + output["private_network_id"] = request.private_network_id + + return output + + +def marshal_EndpointSpecPublicNetworkDetails( + request: EndpointSpecPublicNetworkDetails, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + return output + + +def marshal_EndpointSpec( + request: EndpointSpec, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("public_network", request.public_network), + OneOfPossibility("private_network", request.private_network), + ] + ), + ) + + return output + + +def marshal_CreateEndpointRequest( + request: CreateEndpointRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.instance_id is not None: + output["instance_id"] = request.instance_id + + if request.endpoint is not None: + output["endpoint"] = marshal_EndpointSpec(request.endpoint, defaults) + + return output + + +def marshal_Volume( + request: Volume, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.type_ is not None: + output["type"] = str(request.type_) + + if request.size_bytes is not None: + output["size_bytes"] = request.size_bytes + + return output + + +def marshal_CreateInstanceRequest( + request: CreateInstanceRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.version is not None: + output["version"] = request.version + + if request.node_amount is not None: + output["node_amount"] = request.node_amount + + if request.node_type is not None: + output["node_type"] = request.node_type + + if request.user_name is not None: + output["user_name"] = request.user_name + + if request.password is not None: + output["password"] = request.password + + if request.project_id is not None: + output["project_id"] = request.project_id or defaults.default_project_id + + if request.name is not None: + output["name"] = request.name + + if request.tags is not None: + output["tags"] = request.tags + + if request.volume is not None: + output["volume"] = marshal_Volume(request.volume, defaults) + + if request.endpoints is not None: + output["endpoints"] = [ + marshal_EndpointSpec(item, defaults) for item in request.endpoints + ] + + return output + + +def marshal_CreateSnapshotRequest( + request: CreateSnapshotRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.instance_id is not None: + output["instance_id"] = request.instance_id + + if request.name is not None: + output["name"] = request.name + + if request.expires_at is not None: + output["expires_at"] = request.expires_at.isoformat() + + return output + + +def marshal_CreateUserRequest( + request: CreateUserRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.password is not None: + output["password"] = request.password + + return output + + +def marshal_RestoreSnapshotRequest( + request: RestoreSnapshotRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.instance_name is not None: + output["instance_name"] = request.instance_name + + if request.node_type is not None: + output["node_type"] = request.node_type + + if request.node_amount is not None: + output["node_amount"] = request.node_amount + + if request.volume_type is not None: + output["volume_type"] = str(request.volume_type) + + return output + + +def marshal_UserRole( + request: UserRole, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("database_name", request.database_name), + OneOfPossibility("any_database", request.any_database), + ] + ), + ) + + if request.role is not None: + output["role"] = str(request.role) + + return output + + +def marshal_SetUserRoleRequest( + request: SetUserRoleRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.user_name is not None: + output["user_name"] = request.user_name + + if request.roles is not None: + output["roles"] = [marshal_UserRole(item, defaults) for item in request.roles] + + return output + + +def marshal_UpdateInstanceRequest( + request: UpdateInstanceRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.tags is not None: + output["tags"] = request.tags + + if request.snapshot_schedule_frequency_hours is not None: + output["snapshot_schedule_frequency_hours"] = ( + request.snapshot_schedule_frequency_hours + ) + + if request.snapshot_schedule_retention_days is not None: + output["snapshot_schedule_retention_days"] = ( + request.snapshot_schedule_retention_days + ) + + if request.is_snapshot_schedule_enabled is not None: + output["is_snapshot_schedule_enabled"] = request.is_snapshot_schedule_enabled + + return output + + +def marshal_UpdateSnapshotRequest( + request: UpdateSnapshotRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.expires_at is not None: + output["expires_at"] = request.expires_at.isoformat() + + return output + + +def marshal_UpdateUserRequest( + request: UpdateUserRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.password is not None: + output["password"] = request.password + + return output + + +def marshal_UpgradeInstanceRequest( + request: UpgradeInstanceRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("volume_size_bytes", request.volume_size_bytes), + ] + ), + ) + + return output diff --git a/scaleway-async/scaleway_async/mongodb/v1/types.py b/scaleway-async/scaleway_async/mongodb/v1/types.py new file mode 100644 index 000000000..f8aa2c08e --- /dev/null +++ b/scaleway-async/scaleway_async/mongodb/v1/types.py @@ -0,0 +1,1014 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from __future__ import annotations + +from dataclasses import dataclass +from datetime import datetime +from enum import Enum +from typing import List, Optional + +from scaleway_core.bridge import ( + Region as ScwRegion, +) +from scaleway_core.utils import ( + StrEnumMeta, +) + + +class InstanceStatus(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATUS = "unknown_status" + READY = "ready" + PROVISIONING = "provisioning" + CONFIGURING = "configuring" + DELETING = "deleting" + ERROR = "error" + INITIALIZING = "initializing" + LOCKED = "locked" + SNAPSHOTTING = "snapshotting" + + def __str__(self) -> str: + return str(self.value) + + +class ListInstancesRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + CREATED_AT_ASC = "created_at_asc" + CREATED_AT_DESC = "created_at_desc" + NAME_ASC = "name_asc" + NAME_DESC = "name_desc" + STATUS_ASC = "status_asc" + STATUS_DESC = "status_desc" + + def __str__(self) -> str: + return str(self.value) + + +class ListSnapshotsRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + CREATED_AT_ASC = "created_at_asc" + CREATED_AT_DESC = "created_at_desc" + NAME_ASC = "name_asc" + NAME_DESC = "name_desc" + EXPIRES_AT_ASC = "expires_at_asc" + EXPIRES_AT_DESC = "expires_at_desc" + + def __str__(self) -> str: + return str(self.value) + + +class ListUsersRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + NAME_ASC = "name_asc" + NAME_DESC = "name_desc" + + def __str__(self) -> str: + return str(self.value) + + +class NodeTypeStock(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STOCK = "unknown_stock" + LOW_STOCK = "low_stock" + OUT_OF_STOCK = "out_of_stock" + AVAILABLE = "available" + + def __str__(self) -> str: + return str(self.value) + + +class SnapshotStatus(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATUS = "unknown_status" + CREATING = "creating" + READY = "ready" + RESTORING = "restoring" + DELETING = "deleting" + ERROR = "error" + LOCKED = "locked" + + def __str__(self) -> str: + return str(self.value) + + +class UserRoleRole(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_ROLE = "unknown_role" + READ = "read" + READ_WRITE = "read_write" + DB_ADMIN = "db_admin" + SYNC = "sync" + + def __str__(self) -> str: + return str(self.value) + + +class VolumeType(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_TYPE = "unknown_type" + SBS_5K = "sbs_5k" + SBS_15K = "sbs_15k" + + def __str__(self) -> str: + return str(self.value) + + +@dataclass +class EndpointPrivateNetworkDetails: + """ + Private Network details. + """ + + private_network_id: str + """ + UUID of the Private Network. + """ + + +@dataclass +class EndpointPublicNetworkDetails: + """ + Public Access details. + """ + + pass + + +@dataclass +class EndpointSpecPrivateNetworkDetails: + private_network_id: str + """ + UUID of the Private Network. + """ + + +@dataclass +class EndpointSpecPublicNetworkDetails: + pass + + +@dataclass +class Endpoint: + id: str + """ + UUID of the endpoint. + """ + + dns_record: str + """ + List of DNS records of the endpoint. + """ + + port: int + """ + TCP port of the endpoint. + """ + + private_network: Optional[EndpointPrivateNetworkDetails] + + public_network: Optional[EndpointPublicNetworkDetails] + + +@dataclass +class InstanceSnapshotSchedule: + frequency_hours: int + + retention_days: int + + enabled: bool + + next_update: Optional[datetime] + + last_run: Optional[datetime] + + +@dataclass +class Volume: + type_: VolumeType + """ + Type of volume where data is stored. + """ + + size_bytes: int + """ + Volume size. + """ + + +@dataclass +class NodeTypeVolumeType: + type_: VolumeType + """ + Volume Type. + """ + + description: str + """ + The description of the volume. + """ + + min_size_bytes: int + """ + Minimum size required for the volume. + """ + + max_size_bytes: int + """ + Maximum size required for the volume. + """ + + chunk_size_bytes: int + """ + Minimum increment level for a Block Storage volume size. + """ + + +@dataclass +class UserRole: + role: UserRoleRole + """ + Name of the preset role. + """ + + database_name: Optional[str] + + any_database: Optional[bool] + + +@dataclass +class EndpointSpec: + public_network: Optional[EndpointSpecPublicNetworkDetails] + + private_network: Optional[EndpointSpecPrivateNetworkDetails] + + +@dataclass +class Instance: + id: str + """ + UUID of the Database Instance. + """ + + name: str + """ + Name of the Database Instance. + """ + + project_id: str + """ + Project ID the Database Instance belongs to. + """ + + organization_id: str + """ + Organization ID the Database Instance belongs to. + """ + + status: InstanceStatus + """ + Status of the Database Instance. + """ + + version: str + """ + MongoDB® major engine version of the Database Instance. + """ + + tags: List[str] + """ + List of tags applied to the Database Instance. + """ + + node_amount: int + """ + Number of node in the Database Instance. + """ + + node_type: str + """ + Node type of the Database Instance. + """ + + endpoints: List[Endpoint] + """ + List of Database Instance endpoints. + """ + + region: ScwRegion + """ + Region the Database Instance is in. + """ + + volume: Optional[Volume] + """ + Volumes of the Database Instance. + """ + + created_at: Optional[datetime] + """ + Creation date (must follow the ISO 8601 format). + """ + + snapshot_schedule: Optional[InstanceSnapshotSchedule] + """ + Snapshot schedule configuration of the Database Instance. + """ + + +@dataclass +class NodeType: + name: str + """ + Node type name identifier. + """ + + stock_status: NodeTypeStock + """ + Current stock status for the node type. + """ + + description: str + """ + Current specs of the offer. + """ + + vcpus: int + """ + Number of virtual CPUs. + """ + + memory_bytes: int + """ + Quantity of RAM. + """ + + available_volume_types: List[NodeTypeVolumeType] + """ + Available storage options for the node type. + """ + + disabled: bool + """ + The node type is currently disabled. + """ + + beta: bool + """ + The node type is currently in beta. + """ + + instance_range: str + """ + Instance range associated with the node type offer. + """ + + +@dataclass +class Snapshot: + id: str + """ + UUID of the snapshot. + """ + + name: str + """ + Name of the snapshot. + """ + + status: SnapshotStatus + """ + Status of the snapshot. + """ + + size_bytes: int + """ + Size of the snapshot. + """ + + instance_name: str + """ + Name of the Database Instance of the snapshot. + """ + + node_type: str + """ + Source node type. + """ + + volume_type: VolumeType + """ + Type of volume where data is stored - sbs_5k or sbs_15k. + """ + + region: ScwRegion + """ + Region of the snapshot. + """ + + instance_id: Optional[str] + """ + UUID of the Database Instance. + """ + + expires_at: Optional[datetime] + """ + Expiration date (must follow the ISO 8601 format). + """ + + created_at: Optional[datetime] + """ + Creation date (must follow the ISO 8601 format). + """ + + updated_at: Optional[datetime] + """ + Updated date (must follow the ISO 8601 format). + """ + + +@dataclass +class User: + name: str + """ + Name of the user (Length must be between 1 and 63 characters. First character must be an alphabet character (a-zA-Z). Only a-zA-Z0-9_$- characters are accepted). + """ + + roles: List[UserRole] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + + +@dataclass +class Version: + version: str + """ + MongoDB® major engine version. + """ + + end_of_life_at: Optional[datetime] + """ + Date of End of Life. + """ + + +@dataclass +class CreateEndpointRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + endpoint: EndpointSpec + """ + EndpointSpec used to expose your Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class CreateInstanceRequest: + version: str + """ + Major version of the MongoDB® engine. + """ + + node_amount: int + """ + Number of node to use for the Database Instance. + """ + + node_type: str + """ + Type of node to use for the Database Instance. + """ + + user_name: str + """ + Username created when the Database Instance is created. + """ + + password: str + """ + Password of the initial user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + project_id: Optional[str] + """ + The Project ID on which the Database Instance will be created. + """ + + name: Optional[str] + """ + Name of the Database Instance. + """ + + tags: Optional[List[str]] + """ + Tags to apply to the Database Instance. + """ + + volume: Optional[Volume] + """ + Instance volume information. + """ + + endpoints: Optional[List[EndpointSpec]] + """ + One or multiple EndpointSpec used to expose your Database Instance. + """ + + +@dataclass +class CreateSnapshotRequest: + instance_id: str + """ + UUID of the Database Instance to snapshot. + """ + + name: str + """ + Name of the snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + expires_at: Optional[datetime] + """ + Expiration date of the snapshot (must follow the ISO 8601 format). + """ + + +@dataclass +class CreateUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + password: str + """ + Password of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteEndpointRequest: + endpoint_id: str + """ + UUID of the Endpoint to delete. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteInstanceRequest: + instance_id: str + """ + UUID of the Database Instance to delete. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class GetInstanceCertificateRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class GetInstanceRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class GetSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class ListInstancesRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + tags: Optional[List[str]] + """ + List Database Instances that have a given tag. + """ + + name: Optional[str] + """ + Lists Database Instances that match a name pattern. + """ + + order_by: Optional[ListInstancesRequestOrderBy] + """ + Criteria to use when ordering Database Instance listings. + """ + + organization_id: Optional[str] + """ + Organization ID of the Database Instance. + """ + + project_id: Optional[str] + """ + Project ID to list the instances of. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListInstancesResponse: + instances: List[Instance] + """ + List of all Database Instances available in an Organization or Project. + """ + + total_count: int + """ + Total count of Database Instances available in an Organization or Project. + """ + + +@dataclass +class ListNodeTypesRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + include_disabled: Optional[bool] + """ + Defines whether or not to include disabled types. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListNodeTypesResponse: + node_types: List[NodeType] + """ + Types of the node. + """ + + total_count: int + """ + Total count of node-types available. + """ + + +@dataclass +class ListSnapshotsRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + instance_id: Optional[str] + """ + Instance ID the snapshots belongs to. + """ + + name: Optional[str] + """ + Lists database snapshots that match a name pattern. + """ + + order_by: Optional[ListSnapshotsRequestOrderBy] + """ + Criteria to use when ordering snapshot listings. + """ + + organization_id: Optional[str] + """ + Organization ID the snapshots belongs to. + """ + + project_id: Optional[str] + """ + Project ID to list the snapshots of. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListSnapshotsResponse: + snapshots: List[Snapshot] + """ + List of all database snapshots available in an Organization or Project. + """ + + total_count: int + """ + Total count of database snapshots available in a Organization or Project. + """ + + +@dataclass +class ListUsersRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + name: Optional[str] + """ + Name of the user. + """ + + order_by: Optional[ListUsersRequestOrderBy] + """ + Criteria to use when requesting user listing. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListUsersResponse: + users: List[User] + """ + List of users in a Database Instance. + """ + + total_count: int + """ + Total count of users present on a Database Instance. + """ + + +@dataclass +class ListVersionsRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + version: Optional[str] + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListVersionsResponse: + versions: List[Version] + """ + Available MongoDB® major engine version. + """ + + total_count: int + """ + Total count of MongoDB® major engine version available. + """ + + +@dataclass +class RestoreSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + instance_name: str + """ + Name of the new Database Instance. + """ + + node_type: str + """ + Node type to use for the new Database Instance. + """ + + node_amount: int + """ + Number of nodes to use for the new Database Instance. + """ + + volume_type: VolumeType + """ + Instance volume type. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class SetUserRoleRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + user_name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + roles: Optional[List[UserRole]] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + + +@dataclass +class UpdateInstanceRequest: + instance_id: str + """ + UUID of the Database Instance to update. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + name: Optional[str] + """ + Name of the Database Instance. + """ + + tags: Optional[List[str]] + """ + Tags of a Database Instance. + """ + + snapshot_schedule_frequency_hours: Optional[int] + """ + In hours. + """ + + snapshot_schedule_retention_days: Optional[int] + """ + In days. + """ + + is_snapshot_schedule_enabled: Optional[bool] + """ + Defines whether or not the snapshot schedule is enabled. + """ + + +@dataclass +class UpdateSnapshotRequest: + snapshot_id: str + """ + UUID of the Snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + name: Optional[str] + """ + Name of the snapshot. + """ + + expires_at: Optional[datetime] + """ + Expiration date of the snapshot (must follow the ISO 8601 format). + """ + + +@dataclass +class UpdateUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + password: Optional[str] + """ + Password of the database user. + """ + + +@dataclass +class UpgradeInstanceRequest: + instance_id: str + """ + UUID of the Database Instance you want to upgrade. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + volume_size_bytes: Optional[int] diff --git a/scaleway/scaleway/mongodb/v1/__init__.py b/scaleway/scaleway/mongodb/v1/__init__.py new file mode 100644 index 000000000..8dc097d17 --- /dev/null +++ b/scaleway/scaleway/mongodb/v1/__init__.py @@ -0,0 +1,111 @@ +# 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 InstanceStatus +from .content import INSTANCE_TRANSIENT_STATUSES +from .types import ListInstancesRequestOrderBy +from .types import ListSnapshotsRequestOrderBy +from .types import ListUsersRequestOrderBy +from .types import NodeTypeStock +from .types import SnapshotStatus +from .content import SNAPSHOT_TRANSIENT_STATUSES +from .types import UserRoleRole +from .types import VolumeType +from .types import EndpointPrivateNetworkDetails +from .types import EndpointPublicNetworkDetails +from .types import EndpointSpecPrivateNetworkDetails +from .types import EndpointSpecPublicNetworkDetails +from .types import Endpoint +from .types import InstanceSnapshotSchedule +from .types import Volume +from .types import NodeTypeVolumeType +from .types import UserRole +from .types import EndpointSpec +from .types import Instance +from .types import NodeType +from .types import Snapshot +from .types import User +from .types import Version +from .types import CreateEndpointRequest +from .types import CreateInstanceRequest +from .types import CreateSnapshotRequest +from .types import CreateUserRequest +from .types import DeleteEndpointRequest +from .types import DeleteInstanceRequest +from .types import DeleteSnapshotRequest +from .types import DeleteUserRequest +from .types import GetInstanceCertificateRequest +from .types import GetInstanceRequest +from .types import GetSnapshotRequest +from .types import ListInstancesRequest +from .types import ListInstancesResponse +from .types import ListNodeTypesRequest +from .types import ListNodeTypesResponse +from .types import ListSnapshotsRequest +from .types import ListSnapshotsResponse +from .types import ListUsersRequest +from .types import ListUsersResponse +from .types import ListVersionsRequest +from .types import ListVersionsResponse +from .types import RestoreSnapshotRequest +from .types import SetUserRoleRequest +from .types import UpdateInstanceRequest +from .types import UpdateSnapshotRequest +from .types import UpdateUserRequest +from .types import UpgradeInstanceRequest +from .api import MongodbV1API + +__all__ = [ + "InstanceStatus", + "INSTANCE_TRANSIENT_STATUSES", + "ListInstancesRequestOrderBy", + "ListSnapshotsRequestOrderBy", + "ListUsersRequestOrderBy", + "NodeTypeStock", + "SnapshotStatus", + "SNAPSHOT_TRANSIENT_STATUSES", + "UserRoleRole", + "VolumeType", + "EndpointPrivateNetworkDetails", + "EndpointPublicNetworkDetails", + "EndpointSpecPrivateNetworkDetails", + "EndpointSpecPublicNetworkDetails", + "Endpoint", + "InstanceSnapshotSchedule", + "Volume", + "NodeTypeVolumeType", + "UserRole", + "EndpointSpec", + "Instance", + "NodeType", + "Snapshot", + "User", + "Version", + "CreateEndpointRequest", + "CreateInstanceRequest", + "CreateSnapshotRequest", + "CreateUserRequest", + "DeleteEndpointRequest", + "DeleteInstanceRequest", + "DeleteSnapshotRequest", + "DeleteUserRequest", + "GetInstanceCertificateRequest", + "GetInstanceRequest", + "GetSnapshotRequest", + "ListInstancesRequest", + "ListInstancesResponse", + "ListNodeTypesRequest", + "ListNodeTypesResponse", + "ListSnapshotsRequest", + "ListSnapshotsResponse", + "ListUsersRequest", + "ListUsersResponse", + "ListVersionsRequest", + "ListVersionsResponse", + "RestoreSnapshotRequest", + "SetUserRoleRequest", + "UpdateInstanceRequest", + "UpdateSnapshotRequest", + "UpdateUserRequest", + "UpgradeInstanceRequest", + "MongodbV1API", +] diff --git a/scaleway/scaleway/mongodb/v1/api.py b/scaleway/scaleway/mongodb/v1/api.py new file mode 100644 index 000000000..8c6798a41 --- /dev/null +++ b/scaleway/scaleway/mongodb/v1/api.py @@ -0,0 +1,1342 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from datetime import datetime +from typing import List, Optional + +from scaleway_core.api import API +from scaleway_core.bridge import ( + Region as ScwRegion, + ScwFile, + unmarshal_ScwFile, +) +from scaleway_core.utils import ( + WaitForOptions, + random_name, + validate_path_param, + fetch_all_pages, + wait_for_resource, +) +from .types import ( + ListInstancesRequestOrderBy, + ListSnapshotsRequestOrderBy, + ListUsersRequestOrderBy, + VolumeType, + CreateEndpointRequest, + CreateInstanceRequest, + CreateSnapshotRequest, + CreateUserRequest, + Endpoint, + EndpointSpec, + Instance, + ListInstancesResponse, + ListNodeTypesResponse, + ListSnapshotsResponse, + ListUsersResponse, + ListVersionsResponse, + NodeType, + RestoreSnapshotRequest, + SetUserRoleRequest, + Snapshot, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, + User, + UserRole, + Version, + Volume, +) +from .content import ( + INSTANCE_TRANSIENT_STATUSES, + SNAPSHOT_TRANSIENT_STATUSES, +) +from .marshalling import ( + unmarshal_Endpoint, + unmarshal_Instance, + unmarshal_Snapshot, + unmarshal_User, + unmarshal_ListInstancesResponse, + unmarshal_ListNodeTypesResponse, + unmarshal_ListSnapshotsResponse, + unmarshal_ListUsersResponse, + unmarshal_ListVersionsResponse, + marshal_CreateEndpointRequest, + marshal_CreateInstanceRequest, + marshal_CreateSnapshotRequest, + marshal_CreateUserRequest, + marshal_RestoreSnapshotRequest, + marshal_SetUserRoleRequest, + marshal_UpdateInstanceRequest, + marshal_UpdateSnapshotRequest, + marshal_UpdateUserRequest, + marshal_UpgradeInstanceRequest, +) + + +class MongodbV1API(API): + """ + This API allows you to manage your Managed Databases for MongoDB®. + """ + + def list_node_types( + self, + *, + region: Optional[ScwRegion] = None, + include_disabled: Optional[bool] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListNodeTypesResponse: + """ + List available node types. + :param region: Region to target. If none is passed will use default region from the config. + :param include_disabled: Defines whether or not to include disabled types. + :param page: + :param page_size: + :return: :class:`ListNodeTypesResponse ` + + Usage: + :: + + result = api.list_node_types() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/node-types", + params={ + "include_disabled": include_disabled, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListNodeTypesResponse(res.json()) + + def list_node_types_all( + self, + *, + region: Optional[ScwRegion] = None, + include_disabled: Optional[bool] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[NodeType]: + """ + List available node types. + :param region: Region to target. If none is passed will use default region from the config. + :param include_disabled: Defines whether or not to include disabled types. + :param page: + :param page_size: + :return: :class:`List[NodeType] ` + + Usage: + :: + + result = api.list_node_types_all() + """ + + return fetch_all_pages( + type=ListNodeTypesResponse, + key="node_types", + fetcher=self.list_node_types, + args={ + "region": region, + "include_disabled": include_disabled, + "page": page, + "page_size": page_size, + }, + ) + + def list_versions( + self, + *, + region: Optional[ScwRegion] = None, + version: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListVersionsResponse: + """ + List available MongoDB® major versions. + :param region: Region to target. If none is passed will use default region from the config. + :param version: + :param page: + :param page_size: + :return: :class:`ListVersionsResponse ` + + Usage: + :: + + result = api.list_versions() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/versions", + params={ + "page": page, + "page_size": page_size or self.client.default_page_size, + "version": version, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListVersionsResponse(res.json()) + + def list_versions_all( + self, + *, + region: Optional[ScwRegion] = None, + version: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[Version]: + """ + List available MongoDB® major versions. + :param region: Region to target. If none is passed will use default region from the config. + :param version: + :param page: + :param page_size: + :return: :class:`List[Version] ` + + Usage: + :: + + result = api.list_versions_all() + """ + + return fetch_all_pages( + type=ListVersionsResponse, + key="versions", + fetcher=self.list_versions, + args={ + "region": region, + "version": version, + "page": page, + "page_size": page_size, + }, + ) + + def list_instances( + self, + *, + region: Optional[ScwRegion] = None, + tags: Optional[List[str]] = None, + name: Optional[str] = None, + order_by: Optional[ListInstancesRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListInstancesResponse: + """ + List MongoDB® Database Instances. + List all MongoDB® Database Instances in the specified region. By default, the MongoDB® Database Instances returned in the list are ordered by creation date in ascending order, though this can be modified via the order_by field. You can define additional parameters for your query, such as `tags` and `name`. For the `name` parameter, the value you include will be checked against the whole name string to see if it includes the string you put in the parameter. + :param region: Region to target. If none is passed will use default region from the config. + :param tags: List Database Instances that have a given tag. + :param name: Lists Database Instances that match a name pattern. + :param order_by: Criteria to use when ordering Database Instance listings. + :param organization_id: Organization ID of the Database Instance. + :param project_id: Project ID to list the instances of. + :param page: + :param page_size: + :return: :class:`ListInstancesResponse ` + + Usage: + :: + + result = api.list_instances() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances", + params={ + "name": name, + "order_by": order_by, + "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, + "tags": tags, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListInstancesResponse(res.json()) + + def list_instances_all( + self, + *, + region: Optional[ScwRegion] = None, + tags: Optional[List[str]] = None, + name: Optional[str] = None, + order_by: Optional[ListInstancesRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[Instance]: + """ + List MongoDB® Database Instances. + List all MongoDB® Database Instances in the specified region. By default, the MongoDB® Database Instances returned in the list are ordered by creation date in ascending order, though this can be modified via the order_by field. You can define additional parameters for your query, such as `tags` and `name`. For the `name` parameter, the value you include will be checked against the whole name string to see if it includes the string you put in the parameter. + :param region: Region to target. If none is passed will use default region from the config. + :param tags: List Database Instances that have a given tag. + :param name: Lists Database Instances that match a name pattern. + :param order_by: Criteria to use when ordering Database Instance listings. + :param organization_id: Organization ID of the Database Instance. + :param project_id: Project ID to list the instances of. + :param page: + :param page_size: + :return: :class:`List[Instance] ` + + Usage: + :: + + result = api.list_instances_all() + """ + + return fetch_all_pages( + type=ListInstancesResponse, + key="instances", + fetcher=self.list_instances, + args={ + "region": region, + "tags": tags, + "name": name, + "order_by": order_by, + "organization_id": organization_id, + "project_id": project_id, + "page": page, + "page_size": page_size, + }, + ) + + def get_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + ) -> Instance: + """ + Get a MongoDB® Database Instance. + Retrieve information about a given MongoDB® Database Instance, specified by the `region` and `instance_id` parameters. Its full details, including name, status, IP address and port, are returned in the response object. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = api.get_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}", + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + def wait_for_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + options: Optional[WaitForOptions[Instance, bool]] = None, + ) -> Instance: + """ + Get a MongoDB® Database Instance. + Retrieve information about a given MongoDB® Database Instance, specified by the `region` and `instance_id` parameters. Its full details, including name, status, IP address and port, are returned in the response object. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = api.get_instance( + instance_id="example", + ) + """ + + if not options: + options = WaitForOptions() + + if not options.stop: + options.stop = lambda res: res.status not in INSTANCE_TRANSIENT_STATUSES + + return wait_for_resource( + fetcher=self.get_instance, + options=options, + args={ + "instance_id": instance_id, + "region": region, + }, + ) + + def create_instance( + self, + *, + version: str, + node_amount: int, + node_type: str, + user_name: str, + password: str, + region: Optional[ScwRegion] = None, + project_id: Optional[str] = None, + name: Optional[str] = None, + tags: Optional[List[str]] = None, + volume: Optional[Volume] = None, + endpoints: Optional[List[EndpointSpec]] = None, + ) -> Instance: + """ + Create a MongoDB® Database Instance. + Create a new MongoDB® Database Instance. + :param version: Major version of the MongoDB® engine. + :param node_amount: Number of node to use for the Database Instance. + :param node_type: Type of node to use for the Database Instance. + :param user_name: Username created when the Database Instance is created. + :param password: Password of the initial user. + :param region: Region to target. If none is passed will use default region from the config. + :param project_id: The Project ID on which the Database Instance will be created. + :param name: Name of the Database Instance. + :param tags: Tags to apply to the Database Instance. + :param volume: Instance volume information. + :param endpoints: One or multiple EndpointSpec used to expose your Database Instance. + :return: :class:`Instance ` + + Usage: + :: + + result = api.create_instance( + version="example", + node_amount=1, + node_type="example", + user_name="example", + password="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/instances", + body=marshal_CreateInstanceRequest( + CreateInstanceRequest( + version=version, + node_amount=node_amount, + node_type=node_type, + user_name=user_name, + password=password, + region=region, + project_id=project_id, + name=name or random_name(prefix="mgdb"), + tags=tags, + volume=volume, + endpoints=endpoints, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + def update_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + tags: Optional[List[str]] = None, + snapshot_schedule_frequency_hours: Optional[int] = None, + snapshot_schedule_retention_days: Optional[int] = None, + is_snapshot_schedule_enabled: Optional[bool] = None, + ) -> Instance: + """ + Update a MongoDB® Database Instance. + Update the parameters of a MongoDB® Database Instance. + :param instance_id: UUID of the Database Instance to update. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the Database Instance. + :param tags: Tags of a Database Instance. + :param snapshot_schedule_frequency_hours: In hours. + :param snapshot_schedule_retention_days: In days. + :param is_snapshot_schedule_enabled: Defines whether or not the snapshot schedule is enabled. + :return: :class:`Instance ` + + Usage: + :: + + result = api.update_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "PATCH", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}", + body=marshal_UpdateInstanceRequest( + UpdateInstanceRequest( + instance_id=instance_id, + region=region, + name=name, + tags=tags, + snapshot_schedule_frequency_hours=snapshot_schedule_frequency_hours, + snapshot_schedule_retention_days=snapshot_schedule_retention_days, + is_snapshot_schedule_enabled=is_snapshot_schedule_enabled, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + def delete_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + ) -> Instance: + """ + Delete a MongoDB® Database Instance. + Delete a given MongoDB® Database Instance, specified by the `region` and `instance_id` parameters. Deleting a MongoDB® Database Instance is permanent, and cannot be undone. Note that upon deletion all your data will be lost. + :param instance_id: UUID of the Database Instance to delete. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = api.delete_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}", + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + def upgrade_instance( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + volume_size_bytes: Optional[int] = None, + ) -> Instance: + """ + Upgrade a Database Instance. + Upgrade your current Database Instance specifications like volume size. + :param instance_id: UUID of the Database Instance you want to upgrade. + :param region: Region to target. If none is passed will use default region from the config. + :param volume_size_bytes: Increase your Block Storage volume size. + One-Of ('upgrade_target'): at most one of 'volume_size_bytes' could be set. + :return: :class:`Instance ` + + Usage: + :: + + result = api.upgrade_instance( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/upgrade", + body=marshal_UpgradeInstanceRequest( + UpgradeInstanceRequest( + instance_id=instance_id, + region=region, + volume_size_bytes=volume_size_bytes, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + def get_instance_certificate( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + ) -> ScwFile: + """ + Get the certificate of a Database Instance. + Retrieve the certificate of a given Database Instance, specified by the `instance_id` parameter. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`ScwFile ` + + Usage: + :: + + result = api.get_instance_certificate( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/certificate", + ) + + self._throw_on_error(res) + return unmarshal_ScwFile(res.json()) + + def create_snapshot( + self, + *, + instance_id: str, + name: str, + region: Optional[ScwRegion] = None, + expires_at: Optional[datetime] = None, + ) -> Snapshot: + """ + Create a Database Instance snapshot. + Create a new snapshot of a Database Instance. You must define the `name` and `instance_id` parameters in the request. + :param instance_id: UUID of the Database Instance to snapshot. + :param name: Name of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :param expires_at: Expiration date of the snapshot (must follow the ISO 8601 format). + :return: :class:`Snapshot ` + + Usage: + :: + + result = api.create_snapshot( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/snapshots", + body=marshal_CreateSnapshotRequest( + CreateSnapshotRequest( + instance_id=instance_id, + name=name, + region=region, + expires_at=expires_at, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + def get_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + ) -> Snapshot: + """ + Get a Database Instance snapshot. + Retrieve information about a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to retrieve. + :param snapshot_id: UUID of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Snapshot ` + + Usage: + :: + + result = api.get_snapshot( + snapshot_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}", + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + def wait_for_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + options: Optional[WaitForOptions[Snapshot, bool]] = None, + ) -> Snapshot: + """ + Get a Database Instance snapshot. + Retrieve information about a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to retrieve. + :param snapshot_id: UUID of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Snapshot ` + + Usage: + :: + + result = api.get_snapshot( + snapshot_id="example", + ) + """ + + if not options: + options = WaitForOptions() + + if not options.stop: + options.stop = lambda res: res.status not in SNAPSHOT_TRANSIENT_STATUSES + + return wait_for_resource( + fetcher=self.get_snapshot, + options=options, + args={ + "snapshot_id": snapshot_id, + "region": region, + }, + ) + + def update_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + expires_at: Optional[datetime] = None, + ) -> Snapshot: + """ + Update a Database Instance snapshot. + Update the parameters of a snapshot of a Database Instance. You can update the `name` and `expires_at` parameters. + :param snapshot_id: UUID of the Snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the snapshot. + :param expires_at: Expiration date of the snapshot (must follow the ISO 8601 format). + :return: :class:`Snapshot ` + + Usage: + :: + + result = api.update_snapshot( + snapshot_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "PATCH", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}", + body=marshal_UpdateSnapshotRequest( + UpdateSnapshotRequest( + snapshot_id=snapshot_id, + region=region, + name=name, + expires_at=expires_at, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + def restore_snapshot( + self, + *, + snapshot_id: str, + instance_name: str, + node_type: str, + node_amount: int, + volume_type: VolumeType, + region: Optional[ScwRegion] = None, + ) -> Instance: + """ + Restore a Database Instance snapshot. + Restore a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to restore, the `instance_name` of the new Database Instance, `node_type` of the new Database Instance and `node_amount` of the new Database Instance. + :param snapshot_id: UUID of the snapshot. + :param instance_name: Name of the new Database Instance. + :param node_type: Node type to use for the new Database Instance. + :param node_amount: Number of nodes to use for the new Database Instance. + :param volume_type: Instance volume type. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Instance ` + + Usage: + :: + + result = api.restore_snapshot( + snapshot_id="example", + instance_name="example", + node_type="example", + node_amount=1, + volume_type=VolumeType.unknown_type, + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}/restore", + body=marshal_RestoreSnapshotRequest( + RestoreSnapshotRequest( + snapshot_id=snapshot_id, + instance_name=instance_name, + node_type=node_type, + node_amount=node_amount, + volume_type=volume_type, + region=region, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Instance(res.json()) + + def list_snapshots( + self, + *, + region: Optional[ScwRegion] = None, + instance_id: Optional[str] = None, + name: Optional[str] = None, + order_by: Optional[ListSnapshotsRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListSnapshotsResponse: + """ + List snapshots. + List snapshots. You can include the `instance_id` or `project_id` in your query to get the list of snapshots for specific Database Instances and/or Projects. By default, the details returned in the list are ordered by creation date in ascending order, though this can be modified via the `order_by` field. + :param region: Region to target. If none is passed will use default region from the config. + :param instance_id: Instance ID the snapshots belongs to. + :param name: Lists database snapshots that match a name pattern. + :param order_by: Criteria to use when ordering snapshot listings. + :param organization_id: Organization ID the snapshots belongs to. + :param project_id: Project ID to list the snapshots of. + :param page: + :param page_size: + :return: :class:`ListSnapshotsResponse ` + + Usage: + :: + + result = api.list_snapshots() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/snapshots", + params={ + "instance_id": instance_id, + "name": name, + "order_by": order_by, + "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, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListSnapshotsResponse(res.json()) + + def list_snapshots_all( + self, + *, + region: Optional[ScwRegion] = None, + instance_id: Optional[str] = None, + name: Optional[str] = None, + order_by: Optional[ListSnapshotsRequestOrderBy] = None, + organization_id: Optional[str] = None, + project_id: Optional[str] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[Snapshot]: + """ + List snapshots. + List snapshots. You can include the `instance_id` or `project_id` in your query to get the list of snapshots for specific Database Instances and/or Projects. By default, the details returned in the list are ordered by creation date in ascending order, though this can be modified via the `order_by` field. + :param region: Region to target. If none is passed will use default region from the config. + :param instance_id: Instance ID the snapshots belongs to. + :param name: Lists database snapshots that match a name pattern. + :param order_by: Criteria to use when ordering snapshot listings. + :param organization_id: Organization ID the snapshots belongs to. + :param project_id: Project ID to list the snapshots of. + :param page: + :param page_size: + :return: :class:`List[Snapshot] ` + + Usage: + :: + + result = api.list_snapshots_all() + """ + + return fetch_all_pages( + type=ListSnapshotsResponse, + key="snapshots", + fetcher=self.list_snapshots, + args={ + "region": region, + "instance_id": instance_id, + "name": name, + "order_by": order_by, + "organization_id": organization_id, + "project_id": project_id, + "page": page, + "page_size": page_size, + }, + ) + + def delete_snapshot( + self, + *, + snapshot_id: str, + region: Optional[ScwRegion] = None, + ) -> Snapshot: + """ + Delete a Database Instance snapshot. + Delete a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to delete. + :param snapshot_id: UUID of the snapshot. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Snapshot ` + + Usage: + :: + + result = api.delete_snapshot( + snapshot_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_snapshot_id = validate_path_param("snapshot_id", snapshot_id) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/snapshots/{param_snapshot_id}", + ) + + self._throw_on_error(res) + return unmarshal_Snapshot(res.json()) + + def list_users( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + order_by: Optional[ListUsersRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> ListUsersResponse: + """ + List users of a Database Instance. + List all users of a given Database Instance. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the user. + :param order_by: Criteria to use when requesting user listing. + :param page: + :param page_size: + :return: :class:`ListUsersResponse ` + + Usage: + :: + + result = api.list_users( + instance_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "GET", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users", + params={ + "name": name, + "order_by": order_by, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListUsersResponse(res.json()) + + def list_users_all( + self, + *, + instance_id: str, + region: Optional[ScwRegion] = None, + name: Optional[str] = None, + order_by: Optional[ListUsersRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[User]: + """ + List users of a Database Instance. + List all users of a given Database Instance. + :param instance_id: UUID of the Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :param name: Name of the user. + :param order_by: Criteria to use when requesting user listing. + :param page: + :param page_size: + :return: :class:`List[User] ` + + Usage: + :: + + result = api.list_users_all( + instance_id="example", + ) + """ + + return fetch_all_pages( + type=ListUsersResponse, + key="users", + fetcher=self.list_users, + args={ + "instance_id": instance_id, + "region": region, + "name": name, + "order_by": order_by, + "page": page, + "page_size": page_size, + }, + ) + + def create_user( + self, + *, + instance_id: str, + name: str, + password: str, + region: Optional[ScwRegion] = None, + ) -> User: + """ + Create an user on a Database Instance. + Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param password: Password of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`User ` + + Usage: + :: + + result = api.create_user( + instance_id="example", + name="example", + password="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users", + body=marshal_CreateUserRequest( + CreateUserRequest( + instance_id=instance_id, + name=name, + password=password, + region=region, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + + def update_user( + self, + *, + instance_id: str, + name: str, + region: Optional[ScwRegion] = None, + password: Optional[str] = None, + ) -> User: + """ + Update a user on a Database Instance. + Update the parameters of a user on a Database Instance. You can update the `password` parameter, but you cannot change the name of the user. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param password: Password of the database user. + :return: :class:`User ` + + Usage: + :: + + result = api.update_user( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + param_name = validate_path_param("name", name) + + res = self._request( + "PATCH", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}", + body=marshal_UpdateUserRequest( + UpdateUserRequest( + instance_id=instance_id, + name=name, + region=region, + password=password, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + + def delete_user( + self, + *, + instance_id: str, + name: str, + region: Optional[ScwRegion] = None, + ) -> None: + """ + Delete a user on a Database Instance. + Delete an existing user on a Database Instance. + :param instance_id: UUID of the Database Instance the user belongs to. + :param name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + + Usage: + :: + + result = api.delete_user( + instance_id="example", + name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + param_name = validate_path_param("name", name) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/users/{param_name}", + ) + + self._throw_on_error(res) + + def set_user_role( + self, + *, + instance_id: str, + user_name: str, + region: Optional[ScwRegion] = None, + roles: Optional[List[UserRole]] = None, + ) -> User: + """ + Apply user roles. + Apply preset roles for a user in a Database Instance. + :param instance_id: UUID of the Database Instance the user belongs to. + :param user_name: Name of the database user. + :param region: Region to target. If none is passed will use default region from the config. + :param roles: List of roles assigned to the user, along with the corresponding database where each role is granted. + :return: :class:`User ` + + Usage: + :: + + result = api.set_user_role( + instance_id="example", + user_name="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_instance_id = validate_path_param("instance_id", instance_id) + + res = self._request( + "PUT", + f"/mongodb/v1/regions/{param_region}/instances/{param_instance_id}/set-user-roles", + body=marshal_SetUserRoleRequest( + SetUserRoleRequest( + instance_id=instance_id, + user_name=user_name, + region=region, + roles=roles, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_User(res.json()) + + def delete_endpoint( + self, + *, + endpoint_id: str, + region: Optional[ScwRegion] = None, + ) -> None: + """ + Delete a Database Instance endpoint. + Delete the endpoint of a Database Instance. You must specify the `endpoint_id` parameter of the endpoint you want to delete. Note that you might need to update any environment configurations that point to the deleted endpoint. + :param endpoint_id: UUID of the Endpoint to delete. + :param region: Region to target. If none is passed will use default region from the config. + + Usage: + :: + + result = api.delete_endpoint( + endpoint_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_endpoint_id = validate_path_param("endpoint_id", endpoint_id) + + res = self._request( + "DELETE", + f"/mongodb/v1/regions/{param_region}/endpoints/{param_endpoint_id}", + ) + + self._throw_on_error(res) + + def create_endpoint( + self, + *, + instance_id: str, + endpoint: EndpointSpec, + region: Optional[ScwRegion] = None, + ) -> Endpoint: + """ + Create a new Instance endpoint. + Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request. + :param instance_id: UUID of the Database Instance. + :param endpoint: EndpointSpec used to expose your Database Instance. + :param region: Region to target. If none is passed will use default region from the config. + :return: :class:`Endpoint ` + + Usage: + :: + + result = api.create_endpoint( + instance_id="example", + endpoint=EndpointSpec(), + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/mongodb/v1/regions/{param_region}/endpoints", + body=marshal_CreateEndpointRequest( + CreateEndpointRequest( + instance_id=instance_id, + endpoint=endpoint, + region=region, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Endpoint(res.json()) diff --git a/scaleway/scaleway/mongodb/v1/content.py b/scaleway/scaleway/mongodb/v1/content.py new file mode 100644 index 000000000..8e0092203 --- /dev/null +++ b/scaleway/scaleway/mongodb/v1/content.py @@ -0,0 +1,27 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from typing import List + +from .types import ( + InstanceStatus, + SnapshotStatus, +) + +INSTANCE_TRANSIENT_STATUSES: List[InstanceStatus] = [ + InstanceStatus.PROVISIONING, + InstanceStatus.CONFIGURING, + InstanceStatus.DELETING, + InstanceStatus.INITIALIZING, + InstanceStatus.SNAPSHOTTING, +] +""" +Lists transient statutes of the enum :class:`InstanceStatus `. +""" +SNAPSHOT_TRANSIENT_STATUSES: List[SnapshotStatus] = [ + SnapshotStatus.CREATING, + SnapshotStatus.RESTORING, + SnapshotStatus.DELETING, +] +""" +Lists transient statutes of the enum :class:`SnapshotStatus `. +""" diff --git a/scaleway/scaleway/mongodb/v1/marshalling.py b/scaleway/scaleway/mongodb/v1/marshalling.py new file mode 100644 index 000000000..ecef2c1e8 --- /dev/null +++ b/scaleway/scaleway/mongodb/v1/marshalling.py @@ -0,0 +1,829 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from typing import Any, Dict +from dateutil import parser + +from scaleway_core.profile import ProfileDefaults +from scaleway_core.utils import ( + OneOfPossibility, + resolve_one_of, +) +from .types import ( + EndpointPrivateNetworkDetails, + EndpointPublicNetworkDetails, + Endpoint, + InstanceSnapshotSchedule, + Volume, + Instance, + Snapshot, + UserRole, + User, + ListInstancesResponse, + NodeTypeVolumeType, + NodeType, + ListNodeTypesResponse, + ListSnapshotsResponse, + ListUsersResponse, + Version, + ListVersionsResponse, + EndpointSpecPrivateNetworkDetails, + EndpointSpecPublicNetworkDetails, + EndpointSpec, + CreateEndpointRequest, + CreateInstanceRequest, + CreateSnapshotRequest, + CreateUserRequest, + RestoreSnapshotRequest, + SetUserRoleRequest, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, +) + + +def unmarshal_EndpointPrivateNetworkDetails(data: Any) -> EndpointPrivateNetworkDetails: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'EndpointPrivateNetworkDetails' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("private_network_id", None) + if field is not None: + args["private_network_id"] = field + + return EndpointPrivateNetworkDetails(**args) + + +def unmarshal_EndpointPublicNetworkDetails(data: Any) -> EndpointPublicNetworkDetails: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'EndpointPublicNetworkDetails' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + return EndpointPublicNetworkDetails(**args) + + +def unmarshal_Endpoint(data: Any) -> Endpoint: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Endpoint' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("dns_record", None) + if field is not None: + args["dns_record"] = field + + field = data.get("port", None) + if field is not None: + args["port"] = field + + field = data.get("private_network", None) + if field is not None: + args["private_network"] = unmarshal_EndpointPrivateNetworkDetails(field) + else: + args["private_network"] = None + + field = data.get("public_network", None) + if field is not None: + args["public_network"] = unmarshal_EndpointPublicNetworkDetails(field) + else: + args["public_network"] = None + + return Endpoint(**args) + + +def unmarshal_InstanceSnapshotSchedule(data: Any) -> InstanceSnapshotSchedule: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'InstanceSnapshotSchedule' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("frequency_hours", None) + if field is not None: + args["frequency_hours"] = field + + field = data.get("retention_days", None) + if field is not None: + args["retention_days"] = field + + field = data.get("enabled", None) + if field is not None: + args["enabled"] = field + + field = data.get("next_update", None) + if field is not None: + args["next_update"] = ( + parser.isoparse(field) if isinstance(field, str) else field + ) + else: + args["next_update"] = None + + field = data.get("last_run", None) + if field is not None: + args["last_run"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["last_run"] = None + + return InstanceSnapshotSchedule(**args) + + +def unmarshal_Volume(data: Any) -> Volume: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Volume' 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("size_bytes", None) + if field is not None: + args["size_bytes"] = field + + return Volume(**args) + + +def unmarshal_Instance(data: Any) -> Instance: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Instance' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("project_id", None) + if field is not None: + args["project_id"] = field + + field = data.get("organization_id", None) + if field is not None: + args["organization_id"] = field + + field = data.get("status", None) + if field is not None: + args["status"] = field + + field = data.get("version", None) + if field is not None: + args["version"] = field + + field = data.get("tags", None) + if field is not None: + args["tags"] = field + + field = data.get("node_amount", None) + if field is not None: + args["node_amount"] = field + + field = data.get("node_type", None) + if field is not None: + args["node_type"] = field + + field = data.get("endpoints", None) + if field is not None: + args["endpoints"] = ( + [unmarshal_Endpoint(v) for v in field] if field is not None else None + ) + + field = data.get("region", None) + if field is not None: + args["region"] = field + + field = data.get("volume", None) + if field is not None: + args["volume"] = unmarshal_Volume(field) + else: + args["volume"] = None + + field = data.get("created_at", None) + if field is not None: + args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["created_at"] = None + + field = data.get("snapshot_schedule", None) + if field is not None: + args["snapshot_schedule"] = unmarshal_InstanceSnapshotSchedule(field) + else: + args["snapshot_schedule"] = None + + return Instance(**args) + + +def unmarshal_Snapshot(data: Any) -> Snapshot: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Snapshot' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("status", None) + if field is not None: + args["status"] = field + + field = data.get("size_bytes", None) + if field is not None: + args["size_bytes"] = field + + field = data.get("instance_name", None) + if field is not None: + args["instance_name"] = field + + field = data.get("node_type", None) + if field is not None: + args["node_type"] = field + + field = data.get("volume_type", None) + if field is not None: + args["volume_type"] = field + + field = data.get("region", None) + if field is not None: + args["region"] = field + + field = data.get("instance_id", None) + if field is not None: + args["instance_id"] = field + else: + args["instance_id"] = None + + field = data.get("expires_at", None) + if field is not None: + args["expires_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["expires_at"] = None + + field = data.get("created_at", None) + if field is not None: + args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["created_at"] = None + + field = data.get("updated_at", None) + if field is not None: + args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["updated_at"] = None + + return Snapshot(**args) + + +def unmarshal_UserRole(data: Any) -> UserRole: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'UserRole' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("role", None) + if field is not None: + args["role"] = field + + field = data.get("database_name", None) + if field is not None: + args["database_name"] = field + else: + args["database_name"] = None + + field = data.get("any_database", None) + if field is not None: + args["any_database"] = field + else: + args["any_database"] = None + + return UserRole(**args) + + +def unmarshal_User(data: Any) -> User: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'User' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("roles", None) + if field is not None: + args["roles"] = ( + [unmarshal_UserRole(v) for v in field] if field is not None else None + ) + + return User(**args) + + +def unmarshal_ListInstancesResponse(data: Any) -> ListInstancesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListInstancesResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("instances", None) + if field is not None: + args["instances"] = ( + [unmarshal_Instance(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListInstancesResponse(**args) + + +def unmarshal_NodeTypeVolumeType(data: Any) -> NodeTypeVolumeType: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'NodeTypeVolumeType' 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("description", None) + if field is not None: + args["description"] = field + + field = data.get("min_size_bytes", None) + if field is not None: + args["min_size_bytes"] = field + + field = data.get("max_size_bytes", None) + if field is not None: + args["max_size_bytes"] = field + + field = data.get("chunk_size_bytes", None) + if field is not None: + args["chunk_size_bytes"] = field + + return NodeTypeVolumeType(**args) + + +def unmarshal_NodeType(data: Any) -> NodeType: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'NodeType' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("stock_status", None) + if field is not None: + args["stock_status"] = field + + field = data.get("description", None) + if field is not None: + args["description"] = field + + field = data.get("vcpus", None) + if field is not None: + args["vcpus"] = field + + field = data.get("memory_bytes", None) + if field is not None: + args["memory_bytes"] = field + + field = data.get("available_volume_types", None) + if field is not None: + args["available_volume_types"] = ( + [unmarshal_NodeTypeVolumeType(v) for v in field] + if field is not None + else None + ) + + field = data.get("disabled", None) + if field is not None: + args["disabled"] = field + + field = data.get("beta", None) + if field is not None: + args["beta"] = field + + field = data.get("instance_range", None) + if field is not None: + args["instance_range"] = field + + return NodeType(**args) + + +def unmarshal_ListNodeTypesResponse(data: Any) -> ListNodeTypesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListNodeTypesResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("node_types", None) + if field is not None: + args["node_types"] = ( + [unmarshal_NodeType(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListNodeTypesResponse(**args) + + +def unmarshal_ListSnapshotsResponse(data: Any) -> ListSnapshotsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListSnapshotsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("snapshots", None) + if field is not None: + args["snapshots"] = ( + [unmarshal_Snapshot(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListSnapshotsResponse(**args) + + +def unmarshal_ListUsersResponse(data: Any) -> ListUsersResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListUsersResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("users", None) + if field is not None: + args["users"] = ( + [unmarshal_User(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListUsersResponse(**args) + + +def unmarshal_Version(data: Any) -> Version: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Version' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("version", None) + if field is not None: + args["version"] = field + + field = data.get("end_of_life_at", None) + if field is not None: + args["end_of_life_at"] = ( + parser.isoparse(field) if isinstance(field, str) else field + ) + else: + args["end_of_life_at"] = None + + return Version(**args) + + +def unmarshal_ListVersionsResponse(data: Any) -> ListVersionsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListVersionsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("versions", None) + if field is not None: + args["versions"] = ( + [unmarshal_Version(v) for v in field] if field is not None else None + ) + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + return ListVersionsResponse(**args) + + +def marshal_EndpointSpecPrivateNetworkDetails( + request: EndpointSpecPrivateNetworkDetails, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.private_network_id is not None: + output["private_network_id"] = request.private_network_id + + return output + + +def marshal_EndpointSpecPublicNetworkDetails( + request: EndpointSpecPublicNetworkDetails, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + return output + + +def marshal_EndpointSpec( + request: EndpointSpec, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("public_network", request.public_network), + OneOfPossibility("private_network", request.private_network), + ] + ), + ) + + return output + + +def marshal_CreateEndpointRequest( + request: CreateEndpointRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.instance_id is not None: + output["instance_id"] = request.instance_id + + if request.endpoint is not None: + output["endpoint"] = marshal_EndpointSpec(request.endpoint, defaults) + + return output + + +def marshal_Volume( + request: Volume, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.type_ is not None: + output["type"] = str(request.type_) + + if request.size_bytes is not None: + output["size_bytes"] = request.size_bytes + + return output + + +def marshal_CreateInstanceRequest( + request: CreateInstanceRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.version is not None: + output["version"] = request.version + + if request.node_amount is not None: + output["node_amount"] = request.node_amount + + if request.node_type is not None: + output["node_type"] = request.node_type + + if request.user_name is not None: + output["user_name"] = request.user_name + + if request.password is not None: + output["password"] = request.password + + if request.project_id is not None: + output["project_id"] = request.project_id or defaults.default_project_id + + if request.name is not None: + output["name"] = request.name + + if request.tags is not None: + output["tags"] = request.tags + + if request.volume is not None: + output["volume"] = marshal_Volume(request.volume, defaults) + + if request.endpoints is not None: + output["endpoints"] = [ + marshal_EndpointSpec(item, defaults) for item in request.endpoints + ] + + return output + + +def marshal_CreateSnapshotRequest( + request: CreateSnapshotRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.instance_id is not None: + output["instance_id"] = request.instance_id + + if request.name is not None: + output["name"] = request.name + + if request.expires_at is not None: + output["expires_at"] = request.expires_at.isoformat() + + return output + + +def marshal_CreateUserRequest( + request: CreateUserRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.password is not None: + output["password"] = request.password + + return output + + +def marshal_RestoreSnapshotRequest( + request: RestoreSnapshotRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.instance_name is not None: + output["instance_name"] = request.instance_name + + if request.node_type is not None: + output["node_type"] = request.node_type + + if request.node_amount is not None: + output["node_amount"] = request.node_amount + + if request.volume_type is not None: + output["volume_type"] = str(request.volume_type) + + return output + + +def marshal_UserRole( + request: UserRole, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("database_name", request.database_name), + OneOfPossibility("any_database", request.any_database), + ] + ), + ) + + if request.role is not None: + output["role"] = str(request.role) + + return output + + +def marshal_SetUserRoleRequest( + request: SetUserRoleRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.user_name is not None: + output["user_name"] = request.user_name + + if request.roles is not None: + output["roles"] = [marshal_UserRole(item, defaults) for item in request.roles] + + return output + + +def marshal_UpdateInstanceRequest( + request: UpdateInstanceRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.tags is not None: + output["tags"] = request.tags + + if request.snapshot_schedule_frequency_hours is not None: + output["snapshot_schedule_frequency_hours"] = ( + request.snapshot_schedule_frequency_hours + ) + + if request.snapshot_schedule_retention_days is not None: + output["snapshot_schedule_retention_days"] = ( + request.snapshot_schedule_retention_days + ) + + if request.is_snapshot_schedule_enabled is not None: + output["is_snapshot_schedule_enabled"] = request.is_snapshot_schedule_enabled + + return output + + +def marshal_UpdateSnapshotRequest( + request: UpdateSnapshotRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.expires_at is not None: + output["expires_at"] = request.expires_at.isoformat() + + return output + + +def marshal_UpdateUserRequest( + request: UpdateUserRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.password is not None: + output["password"] = request.password + + return output + + +def marshal_UpgradeInstanceRequest( + request: UpgradeInstanceRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + output.update( + resolve_one_of( + [ + OneOfPossibility("volume_size_bytes", request.volume_size_bytes), + ] + ), + ) + + return output diff --git a/scaleway/scaleway/mongodb/v1/types.py b/scaleway/scaleway/mongodb/v1/types.py new file mode 100644 index 000000000..f8aa2c08e --- /dev/null +++ b/scaleway/scaleway/mongodb/v1/types.py @@ -0,0 +1,1014 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from __future__ import annotations + +from dataclasses import dataclass +from datetime import datetime +from enum import Enum +from typing import List, Optional + +from scaleway_core.bridge import ( + Region as ScwRegion, +) +from scaleway_core.utils import ( + StrEnumMeta, +) + + +class InstanceStatus(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATUS = "unknown_status" + READY = "ready" + PROVISIONING = "provisioning" + CONFIGURING = "configuring" + DELETING = "deleting" + ERROR = "error" + INITIALIZING = "initializing" + LOCKED = "locked" + SNAPSHOTTING = "snapshotting" + + def __str__(self) -> str: + return str(self.value) + + +class ListInstancesRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + CREATED_AT_ASC = "created_at_asc" + CREATED_AT_DESC = "created_at_desc" + NAME_ASC = "name_asc" + NAME_DESC = "name_desc" + STATUS_ASC = "status_asc" + STATUS_DESC = "status_desc" + + def __str__(self) -> str: + return str(self.value) + + +class ListSnapshotsRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + CREATED_AT_ASC = "created_at_asc" + CREATED_AT_DESC = "created_at_desc" + NAME_ASC = "name_asc" + NAME_DESC = "name_desc" + EXPIRES_AT_ASC = "expires_at_asc" + EXPIRES_AT_DESC = "expires_at_desc" + + def __str__(self) -> str: + return str(self.value) + + +class ListUsersRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + NAME_ASC = "name_asc" + NAME_DESC = "name_desc" + + def __str__(self) -> str: + return str(self.value) + + +class NodeTypeStock(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STOCK = "unknown_stock" + LOW_STOCK = "low_stock" + OUT_OF_STOCK = "out_of_stock" + AVAILABLE = "available" + + def __str__(self) -> str: + return str(self.value) + + +class SnapshotStatus(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATUS = "unknown_status" + CREATING = "creating" + READY = "ready" + RESTORING = "restoring" + DELETING = "deleting" + ERROR = "error" + LOCKED = "locked" + + def __str__(self) -> str: + return str(self.value) + + +class UserRoleRole(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_ROLE = "unknown_role" + READ = "read" + READ_WRITE = "read_write" + DB_ADMIN = "db_admin" + SYNC = "sync" + + def __str__(self) -> str: + return str(self.value) + + +class VolumeType(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_TYPE = "unknown_type" + SBS_5K = "sbs_5k" + SBS_15K = "sbs_15k" + + def __str__(self) -> str: + return str(self.value) + + +@dataclass +class EndpointPrivateNetworkDetails: + """ + Private Network details. + """ + + private_network_id: str + """ + UUID of the Private Network. + """ + + +@dataclass +class EndpointPublicNetworkDetails: + """ + Public Access details. + """ + + pass + + +@dataclass +class EndpointSpecPrivateNetworkDetails: + private_network_id: str + """ + UUID of the Private Network. + """ + + +@dataclass +class EndpointSpecPublicNetworkDetails: + pass + + +@dataclass +class Endpoint: + id: str + """ + UUID of the endpoint. + """ + + dns_record: str + """ + List of DNS records of the endpoint. + """ + + port: int + """ + TCP port of the endpoint. + """ + + private_network: Optional[EndpointPrivateNetworkDetails] + + public_network: Optional[EndpointPublicNetworkDetails] + + +@dataclass +class InstanceSnapshotSchedule: + frequency_hours: int + + retention_days: int + + enabled: bool + + next_update: Optional[datetime] + + last_run: Optional[datetime] + + +@dataclass +class Volume: + type_: VolumeType + """ + Type of volume where data is stored. + """ + + size_bytes: int + """ + Volume size. + """ + + +@dataclass +class NodeTypeVolumeType: + type_: VolumeType + """ + Volume Type. + """ + + description: str + """ + The description of the volume. + """ + + min_size_bytes: int + """ + Minimum size required for the volume. + """ + + max_size_bytes: int + """ + Maximum size required for the volume. + """ + + chunk_size_bytes: int + """ + Minimum increment level for a Block Storage volume size. + """ + + +@dataclass +class UserRole: + role: UserRoleRole + """ + Name of the preset role. + """ + + database_name: Optional[str] + + any_database: Optional[bool] + + +@dataclass +class EndpointSpec: + public_network: Optional[EndpointSpecPublicNetworkDetails] + + private_network: Optional[EndpointSpecPrivateNetworkDetails] + + +@dataclass +class Instance: + id: str + """ + UUID of the Database Instance. + """ + + name: str + """ + Name of the Database Instance. + """ + + project_id: str + """ + Project ID the Database Instance belongs to. + """ + + organization_id: str + """ + Organization ID the Database Instance belongs to. + """ + + status: InstanceStatus + """ + Status of the Database Instance. + """ + + version: str + """ + MongoDB® major engine version of the Database Instance. + """ + + tags: List[str] + """ + List of tags applied to the Database Instance. + """ + + node_amount: int + """ + Number of node in the Database Instance. + """ + + node_type: str + """ + Node type of the Database Instance. + """ + + endpoints: List[Endpoint] + """ + List of Database Instance endpoints. + """ + + region: ScwRegion + """ + Region the Database Instance is in. + """ + + volume: Optional[Volume] + """ + Volumes of the Database Instance. + """ + + created_at: Optional[datetime] + """ + Creation date (must follow the ISO 8601 format). + """ + + snapshot_schedule: Optional[InstanceSnapshotSchedule] + """ + Snapshot schedule configuration of the Database Instance. + """ + + +@dataclass +class NodeType: + name: str + """ + Node type name identifier. + """ + + stock_status: NodeTypeStock + """ + Current stock status for the node type. + """ + + description: str + """ + Current specs of the offer. + """ + + vcpus: int + """ + Number of virtual CPUs. + """ + + memory_bytes: int + """ + Quantity of RAM. + """ + + available_volume_types: List[NodeTypeVolumeType] + """ + Available storage options for the node type. + """ + + disabled: bool + """ + The node type is currently disabled. + """ + + beta: bool + """ + The node type is currently in beta. + """ + + instance_range: str + """ + Instance range associated with the node type offer. + """ + + +@dataclass +class Snapshot: + id: str + """ + UUID of the snapshot. + """ + + name: str + """ + Name of the snapshot. + """ + + status: SnapshotStatus + """ + Status of the snapshot. + """ + + size_bytes: int + """ + Size of the snapshot. + """ + + instance_name: str + """ + Name of the Database Instance of the snapshot. + """ + + node_type: str + """ + Source node type. + """ + + volume_type: VolumeType + """ + Type of volume where data is stored - sbs_5k or sbs_15k. + """ + + region: ScwRegion + """ + Region of the snapshot. + """ + + instance_id: Optional[str] + """ + UUID of the Database Instance. + """ + + expires_at: Optional[datetime] + """ + Expiration date (must follow the ISO 8601 format). + """ + + created_at: Optional[datetime] + """ + Creation date (must follow the ISO 8601 format). + """ + + updated_at: Optional[datetime] + """ + Updated date (must follow the ISO 8601 format). + """ + + +@dataclass +class User: + name: str + """ + Name of the user (Length must be between 1 and 63 characters. First character must be an alphabet character (a-zA-Z). Only a-zA-Z0-9_$- characters are accepted). + """ + + roles: List[UserRole] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + + +@dataclass +class Version: + version: str + """ + MongoDB® major engine version. + """ + + end_of_life_at: Optional[datetime] + """ + Date of End of Life. + """ + + +@dataclass +class CreateEndpointRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + endpoint: EndpointSpec + """ + EndpointSpec used to expose your Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class CreateInstanceRequest: + version: str + """ + Major version of the MongoDB® engine. + """ + + node_amount: int + """ + Number of node to use for the Database Instance. + """ + + node_type: str + """ + Type of node to use for the Database Instance. + """ + + user_name: str + """ + Username created when the Database Instance is created. + """ + + password: str + """ + Password of the initial user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + project_id: Optional[str] + """ + The Project ID on which the Database Instance will be created. + """ + + name: Optional[str] + """ + Name of the Database Instance. + """ + + tags: Optional[List[str]] + """ + Tags to apply to the Database Instance. + """ + + volume: Optional[Volume] + """ + Instance volume information. + """ + + endpoints: Optional[List[EndpointSpec]] + """ + One or multiple EndpointSpec used to expose your Database Instance. + """ + + +@dataclass +class CreateSnapshotRequest: + instance_id: str + """ + UUID of the Database Instance to snapshot. + """ + + name: str + """ + Name of the snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + expires_at: Optional[datetime] + """ + Expiration date of the snapshot (must follow the ISO 8601 format). + """ + + +@dataclass +class CreateUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + password: str + """ + Password of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteEndpointRequest: + endpoint_id: str + """ + UUID of the Endpoint to delete. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteInstanceRequest: + instance_id: str + """ + UUID of the Database Instance to delete. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class DeleteUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class GetInstanceCertificateRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class GetInstanceRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class GetSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class ListInstancesRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + tags: Optional[List[str]] + """ + List Database Instances that have a given tag. + """ + + name: Optional[str] + """ + Lists Database Instances that match a name pattern. + """ + + order_by: Optional[ListInstancesRequestOrderBy] + """ + Criteria to use when ordering Database Instance listings. + """ + + organization_id: Optional[str] + """ + Organization ID of the Database Instance. + """ + + project_id: Optional[str] + """ + Project ID to list the instances of. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListInstancesResponse: + instances: List[Instance] + """ + List of all Database Instances available in an Organization or Project. + """ + + total_count: int + """ + Total count of Database Instances available in an Organization or Project. + """ + + +@dataclass +class ListNodeTypesRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + include_disabled: Optional[bool] + """ + Defines whether or not to include disabled types. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListNodeTypesResponse: + node_types: List[NodeType] + """ + Types of the node. + """ + + total_count: int + """ + Total count of node-types available. + """ + + +@dataclass +class ListSnapshotsRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + instance_id: Optional[str] + """ + Instance ID the snapshots belongs to. + """ + + name: Optional[str] + """ + Lists database snapshots that match a name pattern. + """ + + order_by: Optional[ListSnapshotsRequestOrderBy] + """ + Criteria to use when ordering snapshot listings. + """ + + organization_id: Optional[str] + """ + Organization ID the snapshots belongs to. + """ + + project_id: Optional[str] + """ + Project ID to list the snapshots of. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListSnapshotsResponse: + snapshots: List[Snapshot] + """ + List of all database snapshots available in an Organization or Project. + """ + + total_count: int + """ + Total count of database snapshots available in a Organization or Project. + """ + + +@dataclass +class ListUsersRequest: + instance_id: str + """ + UUID of the Database Instance. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + name: Optional[str] + """ + Name of the user. + """ + + order_by: Optional[ListUsersRequestOrderBy] + """ + Criteria to use when requesting user listing. + """ + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListUsersResponse: + users: List[User] + """ + List of users in a Database Instance. + """ + + total_count: int + """ + Total count of users present on a Database Instance. + """ + + +@dataclass +class ListVersionsRequest: + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + version: Optional[str] + + page: Optional[int] + + page_size: Optional[int] + + +@dataclass +class ListVersionsResponse: + versions: List[Version] + """ + Available MongoDB® major engine version. + """ + + total_count: int + """ + Total count of MongoDB® major engine version available. + """ + + +@dataclass +class RestoreSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + instance_name: str + """ + Name of the new Database Instance. + """ + + node_type: str + """ + Node type to use for the new Database Instance. + """ + + node_amount: int + """ + Number of nodes to use for the new Database Instance. + """ + + volume_type: VolumeType + """ + Instance volume type. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + +@dataclass +class SetUserRoleRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + user_name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + roles: Optional[List[UserRole]] + """ + List of roles assigned to the user, along with the corresponding database where each role is granted. + """ + + +@dataclass +class UpdateInstanceRequest: + instance_id: str + """ + UUID of the Database Instance to update. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + name: Optional[str] + """ + Name of the Database Instance. + """ + + tags: Optional[List[str]] + """ + Tags of a Database Instance. + """ + + snapshot_schedule_frequency_hours: Optional[int] + """ + In hours. + """ + + snapshot_schedule_retention_days: Optional[int] + """ + In days. + """ + + is_snapshot_schedule_enabled: Optional[bool] + """ + Defines whether or not the snapshot schedule is enabled. + """ + + +@dataclass +class UpdateSnapshotRequest: + snapshot_id: str + """ + UUID of the Snapshot. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + name: Optional[str] + """ + Name of the snapshot. + """ + + expires_at: Optional[datetime] + """ + Expiration date of the snapshot (must follow the ISO 8601 format). + """ + + +@dataclass +class UpdateUserRequest: + instance_id: str + """ + UUID of the Database Instance the user belongs to. + """ + + name: str + """ + Name of the database user. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + password: Optional[str] + """ + Password of the database user. + """ + + +@dataclass +class UpgradeInstanceRequest: + instance_id: str + """ + UUID of the Database Instance you want to upgrade. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + volume_size_bytes: Optional[int]