Skip to content

Commit 13e0451

Browse files
authored
feat(block): add exporting snapshot to s3 (#537)
1 parent 13c4f93 commit 13e0451

File tree

10 files changed

+440
-0
lines changed

10 files changed

+440
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
from .types import CreateVolumeRequest
2323
from .types import DeleteSnapshotRequest
2424
from .types import DeleteVolumeRequest
25+
from .types import ExportSnapshotToObjectStorageRequest
2526
from .types import GetSnapshotRequest
2627
from .types import GetVolumeRequest
28+
from .types import ImportSnapshotFromObjectStorageRequest
2729
from .types import ImportSnapshotFromS3Request
2830
from .types import ListSnapshotsRequest
2931
from .types import ListSnapshotsResponse
@@ -58,8 +60,10 @@
5860
"CreateVolumeRequest",
5961
"DeleteSnapshotRequest",
6062
"DeleteVolumeRequest",
63+
"ExportSnapshotToObjectStorageRequest",
6164
"GetSnapshotRequest",
6265
"GetVolumeRequest",
66+
"ImportSnapshotFromObjectStorageRequest",
6367
"ImportSnapshotFromS3Request",
6468
"ListSnapshotsRequest",
6569
"ListSnapshotsResponse",

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
CreateVolumeRequest,
2121
CreateVolumeRequestFromEmpty,
2222
CreateVolumeRequestFromSnapshot,
23+
ExportSnapshotToObjectStorageRequest,
24+
ImportSnapshotFromObjectStorageRequest,
2325
ImportSnapshotFromS3Request,
2426
ListSnapshotsResponse,
2527
ListVolumeTypesResponse,
@@ -42,6 +44,8 @@
4244
unmarshal_ListVolumesResponse,
4345
marshal_CreateSnapshotRequest,
4446
marshal_CreateVolumeRequest,
47+
marshal_ExportSnapshotToObjectStorageRequest,
48+
marshal_ImportSnapshotFromObjectStorageRequest,
4549
marshal_ImportSnapshotFromS3Request,
4650
marshal_UpdateSnapshotRequest,
4751
marshal_UpdateVolumeRequest,
@@ -668,6 +672,7 @@ async def import_snapshot_from_s3(
668672
:param tags: List of tags assigned to the snapshot.
669673
:param size: Size of the snapshot.
670674
:return: :class:`Snapshot <Snapshot>`
675+
:deprecated
671676
672677
Usage:
673678
::
@@ -701,6 +706,110 @@ async def import_snapshot_from_s3(
701706
self._throw_on_error(res)
702707
return unmarshal_Snapshot(res.json())
703708

709+
async def import_snapshot_from_object_storage(
710+
self,
711+
*,
712+
bucket: str,
713+
key: str,
714+
name: str,
715+
zone: Optional[Zone] = None,
716+
project_id: Optional[str] = None,
717+
tags: Optional[List[str]] = None,
718+
size: Optional[int] = None,
719+
) -> Snapshot:
720+
"""
721+
Import a snapshot from a Scaleway Object Storage bucket.
722+
The bucket must contain a QCOW2 image.
723+
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
724+
:param bucket: Scaleway Object Storage bucket where the object is stored.
725+
:param key: The object key inside the given bucket.
726+
:param name: Name of the snapshot.
727+
:param zone: Zone to target. If none is passed will use default zone from the config.
728+
:param project_id: UUID of the Project to which the volume and the snapshot belong.
729+
:param tags: List of tags assigned to the snapshot.
730+
:param size: Size of the snapshot.
731+
:return: :class:`Snapshot <Snapshot>`
732+
733+
Usage:
734+
::
735+
736+
result = await api.import_snapshot_from_object_storage(
737+
bucket="example",
738+
key="example",
739+
name="example",
740+
)
741+
"""
742+
743+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
744+
745+
res = self._request(
746+
"POST",
747+
f"/block/v1alpha1/zones/{param_zone}/snapshots/import-from-object-storage",
748+
body=marshal_ImportSnapshotFromObjectStorageRequest(
749+
ImportSnapshotFromObjectStorageRequest(
750+
bucket=bucket,
751+
key=key,
752+
name=name,
753+
zone=zone,
754+
project_id=project_id,
755+
tags=tags,
756+
size=size,
757+
),
758+
self.client,
759+
),
760+
)
761+
762+
self._throw_on_error(res)
763+
return unmarshal_Snapshot(res.json())
764+
765+
async def export_snapshot_to_object_storage(
766+
self,
767+
*,
768+
snapshot_id: str,
769+
bucket: str,
770+
key: str,
771+
zone: Optional[Zone] = None,
772+
) -> Snapshot:
773+
"""
774+
Export a snapshot to a Scaleway Object Storage bucket.
775+
The snapshot is exported in QCOW2 format.
776+
The snapshot must not be in transient state.
777+
:param snapshot_id: UUID of the snapshot.
778+
:param bucket: Scaleway Object Storage bucket where the object is stored.
779+
:param key: The object key inside the given bucket.
780+
:param zone: Zone to target. If none is passed will use default zone from the config.
781+
:return: :class:`Snapshot <Snapshot>`
782+
783+
Usage:
784+
::
785+
786+
result = await api.export_snapshot_to_object_storage(
787+
snapshot_id="example",
788+
bucket="example",
789+
key="example",
790+
)
791+
"""
792+
793+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
794+
param_snapshot_id = validate_path_param("snapshot_id", snapshot_id)
795+
796+
res = self._request(
797+
"POST",
798+
f"/block/v1alpha1/zones/{param_zone}/snapshots/{param_snapshot_id}/export-to-object-storage",
799+
body=marshal_ExportSnapshotToObjectStorageRequest(
800+
ExportSnapshotToObjectStorageRequest(
801+
snapshot_id=snapshot_id,
802+
bucket=bucket,
803+
key=key,
804+
zone=zone,
805+
),
806+
self.client,
807+
),
808+
)
809+
810+
self._throw_on_error(res)
811+
return unmarshal_Snapshot(res.json())
812+
704813
async def delete_snapshot(
705814
self,
706815
*,

scaleway-async/scaleway_async/block/v1alpha1/content.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SNAPSHOT_TRANSIENT_STATUSES: List[SnapshotStatus] = [
2020
SnapshotStatus.CREATING,
2121
SnapshotStatus.DELETING,
22+
SnapshotStatus.EXPORTING,
2223
]
2324
"""
2425
Lists transient statutes of the enum :class:`SnapshotStatus <SnapshotStatus>`.

scaleway-async/scaleway_async/block/v1alpha1/marshalling.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
CreateVolumeRequestFromEmpty,
2727
CreateVolumeRequestFromSnapshot,
2828
CreateVolumeRequest,
29+
ExportSnapshotToObjectStorageRequest,
30+
ImportSnapshotFromObjectStorageRequest,
2931
ImportSnapshotFromS3Request,
3032
UpdateSnapshotRequest,
3133
UpdateVolumeRequest,
@@ -442,6 +444,48 @@ def marshal_CreateVolumeRequest(
442444
return output
443445

444446

447+
def marshal_ExportSnapshotToObjectStorageRequest(
448+
request: ExportSnapshotToObjectStorageRequest,
449+
defaults: ProfileDefaults,
450+
) -> Dict[str, Any]:
451+
output: Dict[str, Any] = {}
452+
453+
if request.bucket is not None:
454+
output["bucket"] = request.bucket
455+
456+
if request.key is not None:
457+
output["key"] = request.key
458+
459+
return output
460+
461+
462+
def marshal_ImportSnapshotFromObjectStorageRequest(
463+
request: ImportSnapshotFromObjectStorageRequest,
464+
defaults: ProfileDefaults,
465+
) -> Dict[str, Any]:
466+
output: Dict[str, Any] = {}
467+
468+
if request.bucket is not None:
469+
output["bucket"] = request.bucket
470+
471+
if request.key is not None:
472+
output["key"] = request.key
473+
474+
if request.name is not None:
475+
output["name"] = request.name
476+
477+
if request.project_id is not None:
478+
output["project_id"] = request.project_id or defaults.default_project_id
479+
480+
if request.tags is not None:
481+
output["tags"] = request.tags
482+
483+
if request.size is not None:
484+
output["size"] = request.size
485+
486+
return output
487+
488+
445489
def marshal_ImportSnapshotFromS3Request(
446490
request: ImportSnapshotFromS3Request,
447491
defaults: ProfileDefaults,

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SnapshotStatus(str, Enum, metaclass=StrEnumMeta):
6868
DELETED = "deleted"
6969
IN_USE = "in_use"
7070
LOCKED = "locked"
71+
EXPORTING = "exporting"
7172

7273
def __str__(self) -> str:
7374
return str(self.value)
@@ -433,6 +434,29 @@ class DeleteVolumeRequest:
433434
"""
434435

435436

437+
@dataclass
438+
class ExportSnapshotToObjectStorageRequest:
439+
snapshot_id: str
440+
"""
441+
UUID of the snapshot.
442+
"""
443+
444+
bucket: str
445+
"""
446+
Scaleway Object Storage bucket where the object is stored.
447+
"""
448+
449+
key: str
450+
"""
451+
The object key inside the given bucket.
452+
"""
453+
454+
zone: Optional[Zone]
455+
"""
456+
Zone to target. If none is passed will use default zone from the config.
457+
"""
458+
459+
436460
@dataclass
437461
class GetSnapshotRequest:
438462
snapshot_id: str
@@ -459,6 +483,44 @@ class GetVolumeRequest:
459483
"""
460484

461485

486+
@dataclass
487+
class ImportSnapshotFromObjectStorageRequest:
488+
bucket: str
489+
"""
490+
Scaleway Object Storage bucket where the object is stored.
491+
"""
492+
493+
key: str
494+
"""
495+
The object key inside the given bucket.
496+
"""
497+
498+
name: str
499+
"""
500+
Name of the snapshot.
501+
"""
502+
503+
zone: Optional[Zone]
504+
"""
505+
Zone to target. If none is passed will use default zone from the config.
506+
"""
507+
508+
project_id: Optional[str]
509+
"""
510+
UUID of the Project to which the volume and the snapshot belong.
511+
"""
512+
513+
tags: Optional[List[str]]
514+
"""
515+
List of tags assigned to the snapshot.
516+
"""
517+
518+
size: Optional[int]
519+
"""
520+
Size of the snapshot.
521+
"""
522+
523+
462524
@dataclass
463525
class ImportSnapshotFromS3Request:
464526
bucket: str

scaleway/scaleway/block/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
from .types import CreateVolumeRequest
2323
from .types import DeleteSnapshotRequest
2424
from .types import DeleteVolumeRequest
25+
from .types import ExportSnapshotToObjectStorageRequest
2526
from .types import GetSnapshotRequest
2627
from .types import GetVolumeRequest
28+
from .types import ImportSnapshotFromObjectStorageRequest
2729
from .types import ImportSnapshotFromS3Request
2830
from .types import ListSnapshotsRequest
2931
from .types import ListSnapshotsResponse
@@ -58,8 +60,10 @@
5860
"CreateVolumeRequest",
5961
"DeleteSnapshotRequest",
6062
"DeleteVolumeRequest",
63+
"ExportSnapshotToObjectStorageRequest",
6164
"GetSnapshotRequest",
6265
"GetVolumeRequest",
66+
"ImportSnapshotFromObjectStorageRequest",
6367
"ImportSnapshotFromS3Request",
6468
"ListSnapshotsRequest",
6569
"ListSnapshotsResponse",

0 commit comments

Comments
 (0)