Skip to content

Commit ee25959

Browse files
authored
feat(block): publish endpoint ImportSnapshotFromS3 (#506)
1 parent f015c2d commit ee25959

File tree

8 files changed

+252
-0
lines changed

8 files changed

+252
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .types import DeleteVolumeRequest
2525
from .types import GetSnapshotRequest
2626
from .types import GetVolumeRequest
27+
from .types import ImportSnapshotFromS3Request
2728
from .types import ListSnapshotsRequest
2829
from .types import ListSnapshotsResponse
2930
from .types import ListVolumeTypesRequest
@@ -59,6 +60,7 @@
5960
"DeleteVolumeRequest",
6061
"GetSnapshotRequest",
6162
"GetVolumeRequest",
63+
"ImportSnapshotFromS3Request",
6264
"ListSnapshotsRequest",
6365
"ListSnapshotsResponse",
6466
"ListVolumeTypesRequest",

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
CreateVolumeRequest,
2121
CreateVolumeRequestFromEmpty,
2222
CreateVolumeRequestFromSnapshot,
23+
ImportSnapshotFromS3Request,
2324
ListSnapshotsResponse,
2425
ListVolumeTypesResponse,
2526
ListVolumesResponse,
@@ -41,6 +42,7 @@
4142
unmarshal_ListVolumesResponse,
4243
marshal_CreateSnapshotRequest,
4344
marshal_CreateVolumeRequest,
45+
marshal_ImportSnapshotFromS3Request,
4446
marshal_UpdateSnapshotRequest,
4547
marshal_UpdateVolumeRequest,
4648
)
@@ -643,6 +645,62 @@ async def create_snapshot(
643645
self._throw_on_error(res)
644646
return unmarshal_Snapshot(res.json())
645647

648+
async def import_snapshot_from_s3(
649+
self,
650+
*,
651+
bucket: str,
652+
key: str,
653+
name: str,
654+
zone: Optional[Zone] = None,
655+
project_id: Optional[str] = None,
656+
tags: Optional[List[str]] = None,
657+
size: Optional[int] = None,
658+
) -> Snapshot:
659+
"""
660+
Import a snapshot from a Scaleway Object Storage bucket.
661+
The bucket must contain a QCOW2 image.
662+
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
663+
:param bucket: Scaleway Object Storage bucket where the object is stored.
664+
:param key: The object key inside the given bucket.
665+
:param name: Name of the snapshot.
666+
:param zone: Zone to target. If none is passed will use default zone from the config.
667+
:param project_id: UUID of the Project to which the volume and the snapshot belong.
668+
:param tags: List of tags assigned to the snapshot.
669+
:param size: Size of the snapshot.
670+
:return: :class:`Snapshot <Snapshot>`
671+
672+
Usage:
673+
::
674+
675+
result = await api.import_snapshot_from_s3(
676+
bucket="example",
677+
key="example",
678+
name="example",
679+
)
680+
"""
681+
682+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
683+
684+
res = self._request(
685+
"POST",
686+
f"/block/v1alpha1/zones/{param_zone}/snapshots/import-from-s3",
687+
body=marshal_ImportSnapshotFromS3Request(
688+
ImportSnapshotFromS3Request(
689+
bucket=bucket,
690+
key=key,
691+
name=name,
692+
zone=zone,
693+
project_id=project_id,
694+
tags=tags,
695+
size=size,
696+
),
697+
self.client,
698+
),
699+
)
700+
701+
self._throw_on_error(res)
702+
return unmarshal_Snapshot(res.json())
703+
646704
async def delete_snapshot(
647705
self,
648706
*,

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
CreateVolumeRequestFromEmpty,
2727
CreateVolumeRequestFromSnapshot,
2828
CreateVolumeRequest,
29+
ImportSnapshotFromS3Request,
2930
UpdateSnapshotRequest,
3031
UpdateVolumeRequest,
3132
)
@@ -441,6 +442,33 @@ def marshal_CreateVolumeRequest(
441442
return output
442443

443444

445+
def marshal_ImportSnapshotFromS3Request(
446+
request: ImportSnapshotFromS3Request,
447+
defaults: ProfileDefaults,
448+
) -> Dict[str, Any]:
449+
output: Dict[str, Any] = {}
450+
451+
if request.bucket is not None:
452+
output["bucket"] = request.bucket
453+
454+
if request.key is not None:
455+
output["key"] = request.key
456+
457+
if request.name is not None:
458+
output["name"] = request.name
459+
460+
if request.project_id is not None:
461+
output["project_id"] = request.project_id or defaults.default_project_id
462+
463+
if request.tags is not None:
464+
output["tags"] = request.tags
465+
466+
if request.size is not None:
467+
output["size"] = request.size
468+
469+
return output
470+
471+
444472
def marshal_UpdateSnapshotRequest(
445473
request: UpdateSnapshotRequest,
446474
defaults: ProfileDefaults,

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,44 @@ class GetVolumeRequest:
458458
"""
459459

460460

461+
@dataclass
462+
class ImportSnapshotFromS3Request:
463+
bucket: str
464+
"""
465+
Scaleway Object Storage bucket where the object is stored.
466+
"""
467+
468+
key: str
469+
"""
470+
The object key inside the given bucket.
471+
"""
472+
473+
name: str
474+
"""
475+
Name of the snapshot.
476+
"""
477+
478+
zone: Optional[Zone]
479+
"""
480+
Zone to target. If none is passed will use default zone from the config.
481+
"""
482+
483+
project_id: Optional[str]
484+
"""
485+
UUID of the Project to which the volume and the snapshot belong.
486+
"""
487+
488+
tags: Optional[List[str]]
489+
"""
490+
List of tags assigned to the snapshot.
491+
"""
492+
493+
size: Optional[int]
494+
"""
495+
Size of the snapshot.
496+
"""
497+
498+
461499
@dataclass
462500
class ListSnapshotsRequest:
463501
zone: Optional[Zone]

scaleway/scaleway/block/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .types import DeleteVolumeRequest
2525
from .types import GetSnapshotRequest
2626
from .types import GetVolumeRequest
27+
from .types import ImportSnapshotFromS3Request
2728
from .types import ListSnapshotsRequest
2829
from .types import ListSnapshotsResponse
2930
from .types import ListVolumeTypesRequest
@@ -59,6 +60,7 @@
5960
"DeleteVolumeRequest",
6061
"GetSnapshotRequest",
6162
"GetVolumeRequest",
63+
"ImportSnapshotFromS3Request",
6264
"ListSnapshotsRequest",
6365
"ListSnapshotsResponse",
6466
"ListVolumeTypesRequest",

scaleway/scaleway/block/v1alpha1/api.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
CreateVolumeRequest,
2121
CreateVolumeRequestFromEmpty,
2222
CreateVolumeRequestFromSnapshot,
23+
ImportSnapshotFromS3Request,
2324
ListSnapshotsResponse,
2425
ListVolumeTypesResponse,
2526
ListVolumesResponse,
@@ -41,6 +42,7 @@
4142
unmarshal_ListVolumesResponse,
4243
marshal_CreateSnapshotRequest,
4344
marshal_CreateVolumeRequest,
45+
marshal_ImportSnapshotFromS3Request,
4446
marshal_UpdateSnapshotRequest,
4547
marshal_UpdateVolumeRequest,
4648
)
@@ -641,6 +643,62 @@ def create_snapshot(
641643
self._throw_on_error(res)
642644
return unmarshal_Snapshot(res.json())
643645

646+
def import_snapshot_from_s3(
647+
self,
648+
*,
649+
bucket: str,
650+
key: str,
651+
name: str,
652+
zone: Optional[Zone] = None,
653+
project_id: Optional[str] = None,
654+
tags: Optional[List[str]] = None,
655+
size: Optional[int] = None,
656+
) -> Snapshot:
657+
"""
658+
Import a snapshot from a Scaleway Object Storage bucket.
659+
The bucket must contain a QCOW2 image.
660+
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
661+
:param bucket: Scaleway Object Storage bucket where the object is stored.
662+
:param key: The object key inside the given bucket.
663+
:param name: Name of the snapshot.
664+
:param zone: Zone to target. If none is passed will use default zone from the config.
665+
:param project_id: UUID of the Project to which the volume and the snapshot belong.
666+
:param tags: List of tags assigned to the snapshot.
667+
:param size: Size of the snapshot.
668+
:return: :class:`Snapshot <Snapshot>`
669+
670+
Usage:
671+
::
672+
673+
result = api.import_snapshot_from_s3(
674+
bucket="example",
675+
key="example",
676+
name="example",
677+
)
678+
"""
679+
680+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
681+
682+
res = self._request(
683+
"POST",
684+
f"/block/v1alpha1/zones/{param_zone}/snapshots/import-from-s3",
685+
body=marshal_ImportSnapshotFromS3Request(
686+
ImportSnapshotFromS3Request(
687+
bucket=bucket,
688+
key=key,
689+
name=name,
690+
zone=zone,
691+
project_id=project_id,
692+
tags=tags,
693+
size=size,
694+
),
695+
self.client,
696+
),
697+
)
698+
699+
self._throw_on_error(res)
700+
return unmarshal_Snapshot(res.json())
701+
644702
def delete_snapshot(
645703
self,
646704
*,

scaleway/scaleway/block/v1alpha1/marshalling.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
CreateVolumeRequestFromEmpty,
2727
CreateVolumeRequestFromSnapshot,
2828
CreateVolumeRequest,
29+
ImportSnapshotFromS3Request,
2930
UpdateSnapshotRequest,
3031
UpdateVolumeRequest,
3132
)
@@ -441,6 +442,33 @@ def marshal_CreateVolumeRequest(
441442
return output
442443

443444

445+
def marshal_ImportSnapshotFromS3Request(
446+
request: ImportSnapshotFromS3Request,
447+
defaults: ProfileDefaults,
448+
) -> Dict[str, Any]:
449+
output: Dict[str, Any] = {}
450+
451+
if request.bucket is not None:
452+
output["bucket"] = request.bucket
453+
454+
if request.key is not None:
455+
output["key"] = request.key
456+
457+
if request.name is not None:
458+
output["name"] = request.name
459+
460+
if request.project_id is not None:
461+
output["project_id"] = request.project_id or defaults.default_project_id
462+
463+
if request.tags is not None:
464+
output["tags"] = request.tags
465+
466+
if request.size is not None:
467+
output["size"] = request.size
468+
469+
return output
470+
471+
444472
def marshal_UpdateSnapshotRequest(
445473
request: UpdateSnapshotRequest,
446474
defaults: ProfileDefaults,

scaleway/scaleway/block/v1alpha1/types.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,44 @@ class GetVolumeRequest:
458458
"""
459459

460460

461+
@dataclass
462+
class ImportSnapshotFromS3Request:
463+
bucket: str
464+
"""
465+
Scaleway Object Storage bucket where the object is stored.
466+
"""
467+
468+
key: str
469+
"""
470+
The object key inside the given bucket.
471+
"""
472+
473+
name: str
474+
"""
475+
Name of the snapshot.
476+
"""
477+
478+
zone: Optional[Zone]
479+
"""
480+
Zone to target. If none is passed will use default zone from the config.
481+
"""
482+
483+
project_id: Optional[str]
484+
"""
485+
UUID of the Project to which the volume and the snapshot belong.
486+
"""
487+
488+
tags: Optional[List[str]]
489+
"""
490+
List of tags assigned to the snapshot.
491+
"""
492+
493+
size: Optional[int]
494+
"""
495+
Size of the snapshot.
496+
"""
497+
498+
461499
@dataclass
462500
class ListSnapshotsRequest:
463501
zone: Optional[Zone]

0 commit comments

Comments
 (0)