Skip to content

feat(mongodb): add Get Snapshot Endpoint #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +87,7 @@
"DeleteSnapshotRequest",
"GetInstanceCertificateRequest",
"GetInstanceRequest",
"GetSnapshotRequest",
"ListInstancesRequest",
"ListInstancesResponse",
"ListNodeTypesRequest",
Expand Down
74 changes: 74 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
)
from .content import (
INSTANCE_TRANSIENT_STATUSES,
SNAPSHOT_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Instance,
Expand Down Expand Up @@ -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 <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 <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,
*,
Expand Down
13 changes: 13 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +87,7 @@
"DeleteSnapshotRequest",
"GetInstanceCertificateRequest",
"GetInstanceRequest",
"GetSnapshotRequest",
"ListInstancesRequest",
"ListInstancesResponse",
"ListNodeTypesRequest",
Expand Down
72 changes: 72 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
)
from .content import (
INSTANCE_TRANSIENT_STATUSES,
SNAPSHOT_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Instance,
Expand Down Expand Up @@ -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 <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 <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,
*,
Expand Down
13 changes: 13 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down