Skip to content

Commit dda2dcb

Browse files
authored
feat(mongodb): add Get Snapshot Endpoint (scaleway#703)
1 parent be3dfa6 commit dda2dcb

File tree

6 files changed

+176
-0
lines changed

6 files changed

+176
-0
lines changed

scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .types import DeleteSnapshotRequest
3535
from .types import GetInstanceCertificateRequest
3636
from .types import GetInstanceRequest
37+
from .types import GetSnapshotRequest
3738
from .types import ListInstancesRequest
3839
from .types import ListInstancesResponse
3940
from .types import ListNodeTypesRequest
@@ -86,6 +87,7 @@
8687
"DeleteSnapshotRequest",
8788
"GetInstanceCertificateRequest",
8889
"GetInstanceRequest",
90+
"GetSnapshotRequest",
8991
"ListInstancesRequest",
9092
"ListInstancesResponse",
9193
"ListNodeTypesRequest",

scaleway-async/scaleway_async/mongodb/v1alpha1/api.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
)
4444
from .content import (
4545
INSTANCE_TRANSIENT_STATUSES,
46+
SNAPSHOT_TRANSIENT_STATUSES,
4647
)
4748
from .marshalling import (
4849
unmarshal_Instance,
@@ -667,6 +668,79 @@ async def create_snapshot(
667668
self._throw_on_error(res)
668669
return unmarshal_Snapshot(res.json())
669670

671+
async def get_snapshot(
672+
self,
673+
*,
674+
snapshot_id: str,
675+
region: Optional[Region] = None,
676+
) -> Snapshot:
677+
"""
678+
Get a Database Instance snapshot.
679+
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.
680+
:param snapshot_id: UUID of the snapshot.
681+
:param region: Region to target. If none is passed will use default region from the config.
682+
:return: :class:`Snapshot <Snapshot>`
683+
684+
Usage:
685+
::
686+
687+
result = await api.get_snapshot(
688+
snapshot_id="example",
689+
)
690+
"""
691+
692+
param_region = validate_path_param(
693+
"region", region or self.client.default_region
694+
)
695+
param_snapshot_id = validate_path_param("snapshot_id", snapshot_id)
696+
697+
res = self._request(
698+
"GET",
699+
f"/mongodb/v1alpha1/regions/{param_region}/snapshots/{param_snapshot_id}",
700+
)
701+
702+
self._throw_on_error(res)
703+
return unmarshal_Snapshot(res.json())
704+
705+
async def wait_for_snapshot(
706+
self,
707+
*,
708+
snapshot_id: str,
709+
region: Optional[Region] = None,
710+
options: Optional[
711+
WaitForOptions[Snapshot, Union[bool, Awaitable[bool]]]
712+
] = None,
713+
) -> Snapshot:
714+
"""
715+
Get a Database Instance snapshot.
716+
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.
717+
:param snapshot_id: UUID of the snapshot.
718+
:param region: Region to target. If none is passed will use default region from the config.
719+
:return: :class:`Snapshot <Snapshot>`
720+
721+
Usage:
722+
::
723+
724+
result = await api.get_snapshot(
725+
snapshot_id="example",
726+
)
727+
"""
728+
729+
if not options:
730+
options = WaitForOptions()
731+
732+
if not options.stop:
733+
options.stop = lambda res: res.status not in SNAPSHOT_TRANSIENT_STATUSES
734+
735+
return await wait_for_resource_async(
736+
fetcher=self.get_snapshot,
737+
options=options,
738+
args={
739+
"snapshot_id": snapshot_id,
740+
"region": region,
741+
},
742+
)
743+
670744
async def update_snapshot(
671745
self,
672746
*,

scaleway-async/scaleway_async/mongodb/v1alpha1/types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ class GetInstanceRequest:
644644
"""
645645

646646

647+
@dataclass
648+
class GetSnapshotRequest:
649+
snapshot_id: str
650+
"""
651+
UUID of the snapshot.
652+
"""
653+
654+
region: Optional[Region]
655+
"""
656+
Region to target. If none is passed will use default region from the config.
657+
"""
658+
659+
647660
@dataclass
648661
class ListInstancesRequest:
649662
region: Optional[Region]

scaleway/scaleway/mongodb/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .types import DeleteSnapshotRequest
3535
from .types import GetInstanceCertificateRequest
3636
from .types import GetInstanceRequest
37+
from .types import GetSnapshotRequest
3738
from .types import ListInstancesRequest
3839
from .types import ListInstancesResponse
3940
from .types import ListNodeTypesRequest
@@ -86,6 +87,7 @@
8687
"DeleteSnapshotRequest",
8788
"GetInstanceCertificateRequest",
8889
"GetInstanceRequest",
90+
"GetSnapshotRequest",
8991
"ListInstancesRequest",
9092
"ListInstancesResponse",
9193
"ListNodeTypesRequest",

scaleway/scaleway/mongodb/v1alpha1/api.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
)
4444
from .content import (
4545
INSTANCE_TRANSIENT_STATUSES,
46+
SNAPSHOT_TRANSIENT_STATUSES,
4647
)
4748
from .marshalling import (
4849
unmarshal_Instance,
@@ -665,6 +666,77 @@ def create_snapshot(
665666
self._throw_on_error(res)
666667
return unmarshal_Snapshot(res.json())
667668

669+
def get_snapshot(
670+
self,
671+
*,
672+
snapshot_id: str,
673+
region: Optional[Region] = None,
674+
) -> Snapshot:
675+
"""
676+
Get a Database Instance snapshot.
677+
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.
678+
:param snapshot_id: UUID of the snapshot.
679+
:param region: Region to target. If none is passed will use default region from the config.
680+
:return: :class:`Snapshot <Snapshot>`
681+
682+
Usage:
683+
::
684+
685+
result = api.get_snapshot(
686+
snapshot_id="example",
687+
)
688+
"""
689+
690+
param_region = validate_path_param(
691+
"region", region or self.client.default_region
692+
)
693+
param_snapshot_id = validate_path_param("snapshot_id", snapshot_id)
694+
695+
res = self._request(
696+
"GET",
697+
f"/mongodb/v1alpha1/regions/{param_region}/snapshots/{param_snapshot_id}",
698+
)
699+
700+
self._throw_on_error(res)
701+
return unmarshal_Snapshot(res.json())
702+
703+
def wait_for_snapshot(
704+
self,
705+
*,
706+
snapshot_id: str,
707+
region: Optional[Region] = None,
708+
options: Optional[WaitForOptions[Snapshot, bool]] = None,
709+
) -> Snapshot:
710+
"""
711+
Get a Database Instance snapshot.
712+
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.
713+
:param snapshot_id: UUID of the snapshot.
714+
:param region: Region to target. If none is passed will use default region from the config.
715+
:return: :class:`Snapshot <Snapshot>`
716+
717+
Usage:
718+
::
719+
720+
result = api.get_snapshot(
721+
snapshot_id="example",
722+
)
723+
"""
724+
725+
if not options:
726+
options = WaitForOptions()
727+
728+
if not options.stop:
729+
options.stop = lambda res: res.status not in SNAPSHOT_TRANSIENT_STATUSES
730+
731+
return wait_for_resource(
732+
fetcher=self.get_snapshot,
733+
options=options,
734+
args={
735+
"snapshot_id": snapshot_id,
736+
"region": region,
737+
},
738+
)
739+
668740
def update_snapshot(
669741
self,
670742
*,

scaleway/scaleway/mongodb/v1alpha1/types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ class GetInstanceRequest:
644644
"""
645645

646646

647+
@dataclass
648+
class GetSnapshotRequest:
649+
snapshot_id: str
650+
"""
651+
UUID of the snapshot.
652+
"""
653+
654+
region: Optional[Region]
655+
"""
656+
Region to target. If none is passed will use default region from the config.
657+
"""
658+
659+
647660
@dataclass
648661
class ListInstancesRequest:
649662
region: Optional[Region]

0 commit comments

Comments
 (0)