Skip to content

feat(block): publish endpoint ImportSnapshotFromS3 #506

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
Apr 29, 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/block/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .types import DeleteVolumeRequest
from .types import GetSnapshotRequest
from .types import GetVolumeRequest
from .types import ImportSnapshotFromS3Request
from .types import ListSnapshotsRequest
from .types import ListSnapshotsResponse
from .types import ListVolumeTypesRequest
Expand Down Expand Up @@ -59,6 +60,7 @@
"DeleteVolumeRequest",
"GetSnapshotRequest",
"GetVolumeRequest",
"ImportSnapshotFromS3Request",
"ListSnapshotsRequest",
"ListSnapshotsResponse",
"ListVolumeTypesRequest",
Expand Down
58 changes: 58 additions & 0 deletions scaleway-async/scaleway_async/block/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CreateVolumeRequest,
CreateVolumeRequestFromEmpty,
CreateVolumeRequestFromSnapshot,
ImportSnapshotFromS3Request,
ListSnapshotsResponse,
ListVolumeTypesResponse,
ListVolumesResponse,
Expand All @@ -41,6 +42,7 @@
unmarshal_ListVolumesResponse,
marshal_CreateSnapshotRequest,
marshal_CreateVolumeRequest,
marshal_ImportSnapshotFromS3Request,
marshal_UpdateSnapshotRequest,
marshal_UpdateVolumeRequest,
)
Expand Down Expand Up @@ -643,6 +645,62 @@ async def create_snapshot(
self._throw_on_error(res)
return unmarshal_Snapshot(res.json())

async def import_snapshot_from_s3(
self,
*,
bucket: str,
key: str,
name: str,
zone: Optional[Zone] = None,
project_id: Optional[str] = None,
tags: Optional[List[str]] = None,
size: Optional[int] = None,
) -> Snapshot:
"""
Import a snapshot from a Scaleway Object Storage bucket.
The bucket must contain a QCOW2 image.
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
:param bucket: Scaleway Object Storage bucket where the object is stored.
:param key: The object key inside the given bucket.
:param name: Name of the snapshot.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param project_id: UUID of the Project to which the volume and the snapshot belong.
:param tags: List of tags assigned to the snapshot.
:param size: Size of the snapshot.
:return: :class:`Snapshot <Snapshot>`

Usage:
::

result = await api.import_snapshot_from_s3(
bucket="example",
key="example",
name="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)

res = self._request(
"POST",
f"/block/v1alpha1/zones/{param_zone}/snapshots/import-from-s3",
body=marshal_ImportSnapshotFromS3Request(
ImportSnapshotFromS3Request(
bucket=bucket,
key=key,
name=name,
zone=zone,
project_id=project_id,
tags=tags,
size=size,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Snapshot(res.json())

async def delete_snapshot(
self,
*,
Expand Down
28 changes: 28 additions & 0 deletions scaleway-async/scaleway_async/block/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CreateVolumeRequestFromEmpty,
CreateVolumeRequestFromSnapshot,
CreateVolumeRequest,
ImportSnapshotFromS3Request,
UpdateSnapshotRequest,
UpdateVolumeRequest,
)
Expand Down Expand Up @@ -441,6 +442,33 @@ def marshal_CreateVolumeRequest(
return output


def marshal_ImportSnapshotFromS3Request(
request: ImportSnapshotFromS3Request,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.bucket is not None:
output["bucket"] = request.bucket

if request.key is not None:
output["key"] = request.key

if request.name is not None:
output["name"] = request.name

if request.project_id is not None:
output["project_id"] = request.project_id or defaults.default_project_id

if request.tags is not None:
output["tags"] = request.tags

if request.size is not None:
output["size"] = request.size

return output


def marshal_UpdateSnapshotRequest(
request: UpdateSnapshotRequest,
defaults: ProfileDefaults,
Expand Down
38 changes: 38 additions & 0 deletions scaleway-async/scaleway_async/block/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,44 @@ class GetVolumeRequest:
"""


@dataclass
class ImportSnapshotFromS3Request:
bucket: str
"""
Scaleway Object Storage bucket where the object is stored.
"""

key: str
"""
The object key inside the given bucket.
"""

name: str
"""
Name of the snapshot.
"""

zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config.
"""

project_id: Optional[str]
"""
UUID of the Project to which the volume and the snapshot belong.
"""

tags: Optional[List[str]]
"""
List of tags assigned to the snapshot.
"""

size: Optional[int]
"""
Size of the snapshot.
"""


@dataclass
class ListSnapshotsRequest:
zone: Optional[Zone]
Expand Down
2 changes: 2 additions & 0 deletions scaleway/scaleway/block/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .types import DeleteVolumeRequest
from .types import GetSnapshotRequest
from .types import GetVolumeRequest
from .types import ImportSnapshotFromS3Request
from .types import ListSnapshotsRequest
from .types import ListSnapshotsResponse
from .types import ListVolumeTypesRequest
Expand Down Expand Up @@ -59,6 +60,7 @@
"DeleteVolumeRequest",
"GetSnapshotRequest",
"GetVolumeRequest",
"ImportSnapshotFromS3Request",
"ListSnapshotsRequest",
"ListSnapshotsResponse",
"ListVolumeTypesRequest",
Expand Down
58 changes: 58 additions & 0 deletions scaleway/scaleway/block/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CreateVolumeRequest,
CreateVolumeRequestFromEmpty,
CreateVolumeRequestFromSnapshot,
ImportSnapshotFromS3Request,
ListSnapshotsResponse,
ListVolumeTypesResponse,
ListVolumesResponse,
Expand All @@ -41,6 +42,7 @@
unmarshal_ListVolumesResponse,
marshal_CreateSnapshotRequest,
marshal_CreateVolumeRequest,
marshal_ImportSnapshotFromS3Request,
marshal_UpdateSnapshotRequest,
marshal_UpdateVolumeRequest,
)
Expand Down Expand Up @@ -641,6 +643,62 @@ def create_snapshot(
self._throw_on_error(res)
return unmarshal_Snapshot(res.json())

def import_snapshot_from_s3(
self,
*,
bucket: str,
key: str,
name: str,
zone: Optional[Zone] = None,
project_id: Optional[str] = None,
tags: Optional[List[str]] = None,
size: Optional[int] = None,
) -> Snapshot:
"""
Import a snapshot from a Scaleway Object Storage bucket.
The bucket must contain a QCOW2 image.
The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
:param bucket: Scaleway Object Storage bucket where the object is stored.
:param key: The object key inside the given bucket.
:param name: Name of the snapshot.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param project_id: UUID of the Project to which the volume and the snapshot belong.
:param tags: List of tags assigned to the snapshot.
:param size: Size of the snapshot.
:return: :class:`Snapshot <Snapshot>`

Usage:
::

result = api.import_snapshot_from_s3(
bucket="example",
key="example",
name="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)

res = self._request(
"POST",
f"/block/v1alpha1/zones/{param_zone}/snapshots/import-from-s3",
body=marshal_ImportSnapshotFromS3Request(
ImportSnapshotFromS3Request(
bucket=bucket,
key=key,
name=name,
zone=zone,
project_id=project_id,
tags=tags,
size=size,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Snapshot(res.json())

def delete_snapshot(
self,
*,
Expand Down
28 changes: 28 additions & 0 deletions scaleway/scaleway/block/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CreateVolumeRequestFromEmpty,
CreateVolumeRequestFromSnapshot,
CreateVolumeRequest,
ImportSnapshotFromS3Request,
UpdateSnapshotRequest,
UpdateVolumeRequest,
)
Expand Down Expand Up @@ -441,6 +442,33 @@ def marshal_CreateVolumeRequest(
return output


def marshal_ImportSnapshotFromS3Request(
request: ImportSnapshotFromS3Request,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.bucket is not None:
output["bucket"] = request.bucket

if request.key is not None:
output["key"] = request.key

if request.name is not None:
output["name"] = request.name

if request.project_id is not None:
output["project_id"] = request.project_id or defaults.default_project_id

if request.tags is not None:
output["tags"] = request.tags

if request.size is not None:
output["size"] = request.size

return output


def marshal_UpdateSnapshotRequest(
request: UpdateSnapshotRequest,
defaults: ProfileDefaults,
Expand Down
38 changes: 38 additions & 0 deletions scaleway/scaleway/block/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,44 @@ class GetVolumeRequest:
"""


@dataclass
class ImportSnapshotFromS3Request:
bucket: str
"""
Scaleway Object Storage bucket where the object is stored.
"""

key: str
"""
The object key inside the given bucket.
"""

name: str
"""
Name of the snapshot.
"""

zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config.
"""

project_id: Optional[str]
"""
UUID of the Project to which the volume and the snapshot belong.
"""

tags: Optional[List[str]]
"""
List of tags assigned to the snapshot.
"""

size: Optional[int]
"""
Size of the snapshot.
"""


@dataclass
class ListSnapshotsRequest:
zone: Optional[Zone]
Expand Down