Skip to content

Commit

Permalink
feat(block): publish endpoint ImportSnapshotFromS3 (#2066)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Apr 29, 2024
1 parent 84e93b7 commit 30a12e8
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions api/block/v1alpha1/block_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,30 @@ type GetVolumeRequest struct {
VolumeID string `json:"-"`
}

// ImportSnapshotFromS3Request: import snapshot from s3 request.
type ImportSnapshotFromS3Request struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Zone scw.Zone `json:"-"`

// Bucket: scaleway Object Storage bucket where the object is stored.
Bucket string `json:"bucket"`

// Key: the object key inside the given bucket.
Key string `json:"key"`

// Name: name of the snapshot.
Name string `json:"name"`

// ProjectID: UUID of the Project to which the volume and the snapshot belong.
ProjectID string `json:"project_id"`

// Tags: list of tags assigned to the snapshot.
Tags []string `json:"tags"`

// Size: size of the snapshot.
Size *scw.Size `json:"size,omitempty"`
}

// ListSnapshotsRequest: list snapshots request.
type ListSnapshotsRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Expand Down Expand Up @@ -1091,6 +1115,44 @@ func (s *API) CreateSnapshot(req *CreateSnapshotRequest, opts ...scw.RequestOpti
return &resp, nil
}

// ImportSnapshotFromS3: 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.
func (s *API) ImportSnapshotFromS3(req *ImportSnapshotFromS3Request, opts ...scw.RequestOption) (*Snapshot, error) {
var err error

if req.Zone == "" {
defaultZone, _ := s.client.GetDefaultZone()
req.Zone = defaultZone
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

if fmt.Sprint(req.Zone) == "" {
return nil, errors.New("field Zone cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/block/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/snapshots/import-from-s3",
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp Snapshot

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// DeleteSnapshot: You must specify the `snapshot_id` of the snapshot you want to delete. The snapshot must not be in use.
func (s *API) DeleteSnapshot(req *DeleteSnapshotRequest, opts ...scw.RequestOption) error {
var err error
Expand Down

0 comments on commit 30a12e8

Please sign in to comment.