diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py index 849bdf68c..0fd1e118d 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py @@ -34,6 +34,7 @@ from .types import DeleteSnapshotRequest from .types import GetInstanceCertificateRequest from .types import GetInstanceRequest +from .types import GetSnapshotRequest from .types import ListInstancesRequest from .types import ListInstancesResponse from .types import ListNodeTypesRequest @@ -86,6 +87,7 @@ "DeleteSnapshotRequest", "GetInstanceCertificateRequest", "GetInstanceRequest", + "GetSnapshotRequest", "ListInstancesRequest", "ListInstancesResponse", "ListNodeTypesRequest", diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py index 0dfbb8231..e81ca3884 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/api.py @@ -43,6 +43,7 @@ ) from .content import ( INSTANCE_TRANSIENT_STATUSES, + SNAPSHOT_TRANSIENT_STATUSES, ) from .marshalling import ( unmarshal_Instance, @@ -667,6 +668,79 @@ async def create_snapshot( self._throw_on_error(res) return unmarshal_Snapshot(res.json()) + async def get_snapshot( + self, + *, + snapshot_id: str, + region: Optional[Region] = 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/v1alpha1/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[Region] = 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, *, diff --git a/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py b/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py index 825aa81f0..547b27cf8 100644 --- a/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/mongodb/v1alpha1/types.py @@ -644,6 +644,19 @@ class GetInstanceRequest: """ +@dataclass +class GetSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + @dataclass class ListInstancesRequest: region: Optional[Region] diff --git a/scaleway/scaleway/mongodb/v1alpha1/__init__.py b/scaleway/scaleway/mongodb/v1alpha1/__init__.py index 849bdf68c..0fd1e118d 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/__init__.py +++ b/scaleway/scaleway/mongodb/v1alpha1/__init__.py @@ -34,6 +34,7 @@ from .types import DeleteSnapshotRequest from .types import GetInstanceCertificateRequest from .types import GetInstanceRequest +from .types import GetSnapshotRequest from .types import ListInstancesRequest from .types import ListInstancesResponse from .types import ListNodeTypesRequest @@ -86,6 +87,7 @@ "DeleteSnapshotRequest", "GetInstanceCertificateRequest", "GetInstanceRequest", + "GetSnapshotRequest", "ListInstancesRequest", "ListInstancesResponse", "ListNodeTypesRequest", diff --git a/scaleway/scaleway/mongodb/v1alpha1/api.py b/scaleway/scaleway/mongodb/v1alpha1/api.py index efd6b88c0..80bdc6415 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/api.py +++ b/scaleway/scaleway/mongodb/v1alpha1/api.py @@ -43,6 +43,7 @@ ) from .content import ( INSTANCE_TRANSIENT_STATUSES, + SNAPSHOT_TRANSIENT_STATUSES, ) from .marshalling import ( unmarshal_Instance, @@ -665,6 +666,77 @@ def create_snapshot( self._throw_on_error(res) return unmarshal_Snapshot(res.json()) + def get_snapshot( + self, + *, + snapshot_id: str, + region: Optional[Region] = 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/v1alpha1/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[Region] = 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, *, diff --git a/scaleway/scaleway/mongodb/v1alpha1/types.py b/scaleway/scaleway/mongodb/v1alpha1/types.py index 825aa81f0..547b27cf8 100644 --- a/scaleway/scaleway/mongodb/v1alpha1/types.py +++ b/scaleway/scaleway/mongodb/v1alpha1/types.py @@ -644,6 +644,19 @@ class GetInstanceRequest: """ +@dataclass +class GetSnapshotRequest: + snapshot_id: str + """ + UUID of the snapshot. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + @dataclass class ListInstancesRequest: region: Optional[Region]