Skip to content

Commit a5589d9

Browse files
authored
feat(instance): add RPC for volume/snapshot migration to SBS (#1830)
1 parent 4eb2292 commit a5589d9

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

api/instance/v1/instance_sdk.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,16 @@ type ListVolumesTypesResponse struct {
12011201
Volumes map[string]*VolumeType `json:"volumes"`
12021202
}
12031203

1204+
// MigrationPlan: migration plan.
1205+
type MigrationPlan struct {
1206+
// Volume: a volume which will be migrated to SBS together with the snapshots, if present.
1207+
Volume *Volume `json:"volume"`
1208+
// Snapshots: a list of snapshots which will be migrated to SBS together and with the volume, if present.
1209+
Snapshots []*Snapshot `json:"snapshots"`
1210+
// ValidationKey: a value to be passed to ApplyBlockMigrationRequest, to confirm that the execution of the plan is being requested.
1211+
ValidationKey string `json:"validation_key"`
1212+
}
1213+
12041214
type NullableStringValue struct {
12051215
Null bool `json:"null,omitempty"`
12061216

@@ -5305,6 +5315,96 @@ func (s *API) GetDashboard(req *GetDashboardRequest, opts ...scw.RequestOption)
53055315
return &resp, nil
53065316
}
53075317

5318+
type PlanBlockMigrationRequest struct {
5319+
// Zone: zone to target. If none is passed will use default zone from the config.
5320+
Zone scw.Zone `json:"-"`
5321+
// VolumeID: the volume for which the migration plan will be generated.
5322+
// Precisely one of SnapshotID, VolumeID must be set.
5323+
VolumeID *string `json:"volume_id,omitempty"`
5324+
// SnapshotID: the snapshot for which the migration plan will be generated.
5325+
// Precisely one of SnapshotID, VolumeID must be set.
5326+
SnapshotID *string `json:"snapshot_id,omitempty"`
5327+
}
5328+
5329+
// PlanBlockMigration: get a volume or snapshot's migration plan.
5330+
// Given a volume or snapshot, returns the migration plan for a call to the RPC ApplyBlockMigration. This plan will include zero or one volume, and zero or more snapshots, which will need to be migrated together. This RPC does not perform the actual migration itself, ApplyBlockMigration must be used. The validation_key value returned by this call must be provided to the ApplyBlockMigration call to confirm that all resources listed in the plan should be migrated.
5331+
func (s *API) PlanBlockMigration(req *PlanBlockMigrationRequest, opts ...scw.RequestOption) (*MigrationPlan, error) {
5332+
var err error
5333+
5334+
if req.Zone == "" {
5335+
defaultZone, _ := s.client.GetDefaultZone()
5336+
req.Zone = defaultZone
5337+
}
5338+
5339+
if fmt.Sprint(req.Zone) == "" {
5340+
return nil, errors.New("field Zone cannot be empty in request")
5341+
}
5342+
5343+
scwReq := &scw.ScalewayRequest{
5344+
Method: "POST",
5345+
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/block-migration/plan",
5346+
Headers: http.Header{},
5347+
}
5348+
5349+
err = scwReq.SetBody(req)
5350+
if err != nil {
5351+
return nil, err
5352+
}
5353+
5354+
var resp MigrationPlan
5355+
5356+
err = s.client.Do(scwReq, &resp, opts...)
5357+
if err != nil {
5358+
return nil, err
5359+
}
5360+
return &resp, nil
5361+
}
5362+
5363+
type ApplyBlockMigrationRequest struct {
5364+
// Zone: zone to target. If none is passed will use default zone from the config.
5365+
Zone scw.Zone `json:"-"`
5366+
// VolumeID: the volume to migrate, along with potentially other resources, according to the migration plan generated with a call to PlanBlockMigration.
5367+
// Precisely one of SnapshotID, VolumeID must be set.
5368+
VolumeID *string `json:"volume_id,omitempty"`
5369+
// SnapshotID: the snapshot to migrate, along with potentially other resources, according to the migration plan generated with a call to PlanBlockMigration.
5370+
// Precisely one of SnapshotID, VolumeID must be set.
5371+
SnapshotID *string `json:"snapshot_id,omitempty"`
5372+
// ValidationKey: a value to be retrieved from a call to PlanBlockMigration, to confirm that the volume and/or snapshots specified in said plan should be migrated.
5373+
ValidationKey string `json:"validation_key,omitempty"`
5374+
}
5375+
5376+
// ApplyBlockMigration: migrate a volume and/or snapshots to SBS (Scaleway Block Storage).
5377+
// To be used, this RPC must be preceded by a call to PlanBlockMigration. To migrate all resources mentioned in the MigrationPlan, the validation_key returned in the MigrationPlan must be provided.
5378+
func (s *API) ApplyBlockMigration(req *ApplyBlockMigrationRequest, opts ...scw.RequestOption) error {
5379+
var err error
5380+
5381+
if req.Zone == "" {
5382+
defaultZone, _ := s.client.GetDefaultZone()
5383+
req.Zone = defaultZone
5384+
}
5385+
5386+
if fmt.Sprint(req.Zone) == "" {
5387+
return errors.New("field Zone cannot be empty in request")
5388+
}
5389+
5390+
scwReq := &scw.ScalewayRequest{
5391+
Method: "POST",
5392+
Path: "/instance/v1/zones/" + fmt.Sprint(req.Zone) + "/block-migration/apply",
5393+
Headers: http.Header{},
5394+
}
5395+
5396+
err = scwReq.SetBody(req)
5397+
if err != nil {
5398+
return err
5399+
}
5400+
5401+
err = s.client.Do(scwReq, nil, opts...)
5402+
if err != nil {
5403+
return err
5404+
}
5405+
return nil
5406+
}
5407+
53085408
// UnsafeGetTotalCount should not be used
53095409
// Internal usage only
53105410
func (r *ListServersResponse) UnsafeGetTotalCount() uint32 {

0 commit comments

Comments
 (0)