Skip to content

Commit 30a12e8

Browse files
authored
feat(block): publish endpoint ImportSnapshotFromS3 (#2066)
1 parent 84e93b7 commit 30a12e8

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

api/block/v1alpha1/block_sdk.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,30 @@ type GetVolumeRequest struct {
562562
VolumeID string `json:"-"`
563563
}
564564

565+
// ImportSnapshotFromS3Request: import snapshot from s3 request.
566+
type ImportSnapshotFromS3Request struct {
567+
// Zone: zone to target. If none is passed will use default zone from the config.
568+
Zone scw.Zone `json:"-"`
569+
570+
// Bucket: scaleway Object Storage bucket where the object is stored.
571+
Bucket string `json:"bucket"`
572+
573+
// Key: the object key inside the given bucket.
574+
Key string `json:"key"`
575+
576+
// Name: name of the snapshot.
577+
Name string `json:"name"`
578+
579+
// ProjectID: UUID of the Project to which the volume and the snapshot belong.
580+
ProjectID string `json:"project_id"`
581+
582+
// Tags: list of tags assigned to the snapshot.
583+
Tags []string `json:"tags"`
584+
585+
// Size: size of the snapshot.
586+
Size *scw.Size `json:"size,omitempty"`
587+
}
588+
565589
// ListSnapshotsRequest: list snapshots request.
566590
type ListSnapshotsRequest struct {
567591
// Zone: zone to target. If none is passed will use default zone from the config.
@@ -1091,6 +1115,44 @@ func (s *API) CreateSnapshot(req *CreateSnapshotRequest, opts ...scw.RequestOpti
10911115
return &resp, nil
10921116
}
10931117

1118+
// ImportSnapshotFromS3: The bucket must contain a QCOW2 image.
1119+
// The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
1120+
func (s *API) ImportSnapshotFromS3(req *ImportSnapshotFromS3Request, opts ...scw.RequestOption) (*Snapshot, error) {
1121+
var err error
1122+
1123+
if req.Zone == "" {
1124+
defaultZone, _ := s.client.GetDefaultZone()
1125+
req.Zone = defaultZone
1126+
}
1127+
1128+
if req.ProjectID == "" {
1129+
defaultProjectID, _ := s.client.GetDefaultProjectID()
1130+
req.ProjectID = defaultProjectID
1131+
}
1132+
1133+
if fmt.Sprint(req.Zone) == "" {
1134+
return nil, errors.New("field Zone cannot be empty in request")
1135+
}
1136+
1137+
scwReq := &scw.ScalewayRequest{
1138+
Method: "POST",
1139+
Path: "/block/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/snapshots/import-from-s3",
1140+
}
1141+
1142+
err = scwReq.SetBody(req)
1143+
if err != nil {
1144+
return nil, err
1145+
}
1146+
1147+
var resp Snapshot
1148+
1149+
err = s.client.Do(scwReq, &resp, opts...)
1150+
if err != nil {
1151+
return nil, err
1152+
}
1153+
return &resp, nil
1154+
}
1155+
10941156
// DeleteSnapshot: You must specify the `snapshot_id` of the snapshot you want to delete. The snapshot must not be in use.
10951157
func (s *API) DeleteSnapshot(req *DeleteSnapshotRequest, opts ...scw.RequestOption) error {
10961158
var err error

0 commit comments

Comments
 (0)