Skip to content

Commit

Permalink
feat(instance): add snapshot export (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Aug 24, 2022
1 parent e3c7e25 commit aa98606
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
66 changes: 65 additions & 1 deletion api/instance/v1/instance_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ type Dashboard struct {
IPsUnused uint32 `json:"ips_unused"`
}

type ExportSnapshotResponse struct {
Task *Task `json:"task"`
}

type GetBootscriptResponse struct {
Bootscript *Bootscript `json:"bootscript"`
}
Expand Down Expand Up @@ -1528,6 +1532,8 @@ type Snapshot struct {
ModificationDate *time.Time `json:"modification_date"`
// Zone: the snapshot zone
Zone scw.Zone `json:"zone"`
// ErrorReason: the reason for the failed snapshot import
ErrorReason *string `json:"error_reason"`
}

// SnapshotBaseVolume: snapshot. base volume
Expand Down Expand Up @@ -2963,9 +2969,15 @@ type CreateSnapshotRequest struct {
//
// Default value: unknown_volume_type
VolumeType SnapshotVolumeType `json:"volume_type"`
// Bucket: bucket name for snapshot imports
Bucket *string `json:"bucket,omitempty"`
// Key: object key for snapshot imports
Key *string `json:"key,omitempty"`
// Size: imported snapshot size, must be a multiple of 512
Size *scw.Size `json:"size,omitempty"`
}

// CreateSnapshot: create a snapshot from a given volume
// CreateSnapshot: create a snapshot from a given volume or from a QCOW2 file
func (s *API) CreateSnapshot(req *CreateSnapshotRequest, opts ...scw.RequestOption) (*CreateSnapshotResponse, error) {
var err error

Expand Down Expand Up @@ -3180,6 +3192,58 @@ func (s *API) DeleteSnapshot(req *DeleteSnapshotRequest, opts ...scw.RequestOpti
return nil
}

type ExportSnapshotRequest struct {
// Zone:
//
// Zone to target. If none is passed will use default zone from the config
Zone scw.Zone `json:"-"`
// SnapshotID: the snapshot ID
SnapshotID string `json:"-"`
// Bucket: s3 bucket name
Bucket string `json:"bucket,omitempty"`
// Key: s3 object key
Key string `json:"key,omitempty"`
}

// ExportSnapshot: export a snapshot
//
// Export a snapshot to a given S3 bucket in the same region.
func (s *API) ExportSnapshot(req *ExportSnapshotRequest, opts ...scw.RequestOption) (*ExportSnapshotResponse, error) {
var err error

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

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

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

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/snapshots/" + fmt.Sprint(req.SnapshotID) + "/export",
Headers: http.Header{},
}

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

var resp ExportSnapshotResponse

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

type ListVolumesRequest struct {
// Zone:
//
Expand Down
10 changes: 10 additions & 0 deletions api/rdb/v1/rdb_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,8 @@ type CreateReadReplicaRequest struct {
}

// CreateReadReplica: create a read replica
//
// You can only create a maximum of 3 read replicas for one instance.
func (s *API) CreateReadReplica(req *CreateReadReplicaRequest, opts ...scw.RequestOption) (*ReadReplica, error) {
var err error

Expand Down Expand Up @@ -2568,6 +2570,10 @@ type ResetReadReplicaRequest struct {
}

// ResetReadReplica: reset a read replica
//
// Resetting a read replica resyncs data from the leader node. This operation can take some time, depending on the database's size.
// During this operation, the read replica will not be available. Endpoints will not change.
//
func (s *API) ResetReadReplica(req *ResetReadReplicaRequest, opts ...scw.RequestOption) (*ReadReplica, error) {
var err error

Expand Down Expand Up @@ -2616,6 +2622,8 @@ type CreateReadReplicaEndpointRequest struct {
}

// CreateReadReplicaEndpoint: create a new endpoint for a given read replica
//
// A read replica can have at most one direct access and one private network endpoint.
func (s *API) CreateReadReplicaEndpoint(req *CreateReadReplicaEndpointRequest, opts ...scw.RequestOption) (*ReadReplica, error) {
var err error

Expand Down Expand Up @@ -4084,6 +4092,8 @@ type DeleteEndpointRequest struct {
// Region to target. If none is passed will use default region from the config
Region scw.Region `json:"-"`
// EndpointID: UUID of the endpoint you want to delete
//
// This endpoint can also be used to delete a read replica endpoint.
EndpointID string `json:"-"`
}

Expand Down

0 comments on commit aa98606

Please sign in to comment.