Skip to content

Commit b822287

Browse files
authored
feat(instance): add RPC for volume/snapshot migration to SBS (#853)
1 parent 4612c3a commit b822287

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

packages/clients/src/api/instance/v1/api.gen.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '../../../bridge'
99
import type { Zone } from '../../../bridge'
1010
import {
11+
marshalApplyBlockMigrationRequest,
1112
marshalCreateImageRequest,
1213
marshalCreateIpRequest,
1314
marshalCreatePlacementGroupRequest,
@@ -18,6 +19,7 @@ import {
1819
marshalCreateSnapshotRequest,
1920
marshalCreateVolumeRequest,
2021
marshalExportSnapshotRequest,
22+
marshalPlanBlockMigrationRequest,
2123
marshalServerActionRequest,
2224
marshalSetImageRequest,
2325
marshalSetPlacementGroupRequest,
@@ -70,6 +72,7 @@ import {
7072
unmarshalListSnapshotsResponse,
7173
unmarshalListVolumesResponse,
7274
unmarshalListVolumesTypesResponse,
75+
unmarshalMigrationPlan,
7376
unmarshalPrivateNIC,
7477
unmarshalServerActionResponse,
7578
unmarshalSetImageResponse,
@@ -87,6 +90,7 @@ import {
8790
unmarshalUpdateVolumeResponse,
8891
} from './marshalling.gen'
8992
import type {
93+
ApplyBlockMigrationRequest,
9094
CreateImageRequest,
9195
CreateImageResponse,
9296
CreateIpRequest,
@@ -171,6 +175,8 @@ import type {
171175
ListVolumesResponse,
172176
ListVolumesTypesRequest,
173177
ListVolumesTypesResponse,
178+
MigrationPlan,
179+
PlanBlockMigrationRequest,
174180
PrivateNIC,
175181
ServerActionRequest,
176182
ServerActionResponse,
@@ -1708,4 +1714,53 @@ export class API extends ParentAPI {
17081714
},
17091715
unmarshalGetDashboardResponse,
17101716
)
1717+
1718+
/**
1719+
* Get a volume or snapshot's migration plan. Given a volume or snapshot,
1720+
* returns the migration plan for a call to the RPC ApplyBlockMigration. This
1721+
* plan will include zero or one volume, and zero or more snapshots, which
1722+
* will need to be migrated together. This RPC does not perform the actual
1723+
* migration itself, ApplyBlockMigration must be used. The validation_key
1724+
* value returned by this call must be provided to the ApplyBlockMigration
1725+
* call to confirm that all resources listed in the plan should be migrated.
1726+
*
1727+
* @param request - The request {@link PlanBlockMigrationRequest}
1728+
* @returns A Promise of MigrationPlan
1729+
*/
1730+
planBlockMigration = (request: Readonly<PlanBlockMigrationRequest> = {}) =>
1731+
this.client.fetch<MigrationPlan>(
1732+
{
1733+
body: JSON.stringify(
1734+
marshalPlanBlockMigrationRequest(request, this.client.settings),
1735+
),
1736+
headers: jsonContentHeaders,
1737+
method: 'POST',
1738+
path: `/instance/v1/zones/${validatePathParam(
1739+
'zone',
1740+
request.zone ?? this.client.settings.defaultZone,
1741+
)}/block-migration/plan`,
1742+
},
1743+
unmarshalMigrationPlan,
1744+
)
1745+
1746+
/**
1747+
* Migrate a volume and/or snapshots to SBS (Scaleway Block Storage). To be
1748+
* used, this RPC must be preceded by a call to PlanBlockMigration. To migrate
1749+
* all resources mentioned in the MigrationPlan, the validation_key returned
1750+
* in the MigrationPlan must be provided.
1751+
*
1752+
* @param request - The request {@link ApplyBlockMigrationRequest}
1753+
*/
1754+
applyBlockMigration = (request: Readonly<ApplyBlockMigrationRequest>) =>
1755+
this.client.fetch<void>({
1756+
body: JSON.stringify(
1757+
marshalApplyBlockMigrationRequest(request, this.client.settings),
1758+
),
1759+
headers: jsonContentHeaders,
1760+
method: 'POST',
1761+
path: `/instance/v1/zones/${validatePathParam(
1762+
'zone',
1763+
request.zone ?? this.client.settings.defaultZone,
1764+
)}/block-migration/apply`,
1765+
})
17111766
}

packages/clients/src/api/instance/v1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export { API } from './api.gen'
44
export * from './content.gen'
55
export type {
6+
ApplyBlockMigrationRequest,
67
Arch,
78
BootType,
89
Bootscript,
@@ -98,10 +99,12 @@ export type {
9899
ListVolumesResponse,
99100
ListVolumesTypesRequest,
100101
ListVolumesTypesResponse,
102+
MigrationPlan,
101103
PlacementGroup,
102104
PlacementGroupPolicyMode,
103105
PlacementGroupPolicyType,
104106
PlacementGroupServer,
107+
PlanBlockMigrationRequest,
105108
PrivateNIC,
106109
PrivateNICState,
107110
SecurityGroup,

packages/clients/src/api/instance/v1/marshalling.gen.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '../../../bridge'
1111
import type { DefaultValues } from '../../../bridge'
1212
import type {
13+
ApplyBlockMigrationRequest,
1314
Bootscript,
1415
CreateImageRequest,
1516
CreateImageResponse,
@@ -61,8 +62,10 @@ import type {
6162
ListSnapshotsResponse,
6263
ListVolumesResponse,
6364
ListVolumesTypesResponse,
65+
MigrationPlan,
6466
PlacementGroup,
6567
PlacementGroupServer,
68+
PlanBlockMigrationRequest,
6669
PrivateNIC,
6770
SecurityGroup,
6871
SecurityGroupRule,
@@ -1210,6 +1213,20 @@ export const unmarshalListVolumesTypesResponse = (data: unknown) => {
12101213
} as ListVolumesTypesResponse
12111214
}
12121215

1216+
export const unmarshalMigrationPlan = (data: unknown) => {
1217+
if (!isJSONObject(data)) {
1218+
throw new TypeError(
1219+
`Unmarshalling the type 'MigrationPlan' failed as data isn't a dictionary.`,
1220+
)
1221+
}
1222+
1223+
return {
1224+
snapshots: unmarshalArrayOfObject(data.snapshots, unmarshalSnapshot),
1225+
validationKey: data.validation_key,
1226+
volume: data.volume ? unmarshalVolume(data.volume) : undefined,
1227+
} as MigrationPlan
1228+
}
1229+
12131230
export const unmarshalServerActionResponse = (data: unknown) => {
12141231
if (!isJSONObject(data)) {
12151232
throw new TypeError(
@@ -1624,6 +1641,23 @@ const marshalVolumeTemplate = (
16241641
]),
16251642
})
16261643

1644+
export const marshalApplyBlockMigrationRequest = (
1645+
request: ApplyBlockMigrationRequest,
1646+
defaults: DefaultValues,
1647+
): Record<string, unknown> => ({
1648+
validation_key: request.validationKey,
1649+
...resolveOneOf([
1650+
{
1651+
param: 'volume_id',
1652+
value: request.volumeId,
1653+
},
1654+
{
1655+
param: 'snapshot_id',
1656+
value: request.snapshotId,
1657+
},
1658+
]),
1659+
})
1660+
16271661
export const marshalCreateImageRequest = (
16281662
request: CreateImageRequest,
16291663
defaults: DefaultValues,
@@ -1866,6 +1900,22 @@ export const marshalExportSnapshotRequest = (
18661900
key: request.key,
18671901
})
18681902

1903+
export const marshalPlanBlockMigrationRequest = (
1904+
request: PlanBlockMigrationRequest,
1905+
defaults: DefaultValues,
1906+
): Record<string, unknown> => ({
1907+
...resolveOneOf([
1908+
{
1909+
param: 'volume_id',
1910+
value: request.volumeId,
1911+
},
1912+
{
1913+
param: 'snapshot_id',
1914+
value: request.snapshotId,
1915+
},
1916+
]),
1917+
})
1918+
18691919
export const marshalServerActionRequest = (
18701920
request: ServerActionRequest,
18711921
defaults: DefaultValues,

packages/clients/src/api/instance/v1/types.gen.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,25 @@ export interface ListVolumesTypesResponse {
388388
volumes: Record<string, VolumeType>
389389
}
390390

391+
/** Migration plan. */
392+
export interface MigrationPlan {
393+
/**
394+
* A volume which will be migrated to SBS together with the snapshots, if
395+
* present.
396+
*/
397+
volume?: Volume
398+
/**
399+
* A list of snapshots which will be migrated to SBS together and with the
400+
* volume, if present.
401+
*/
402+
snapshots: Snapshot[]
403+
/**
404+
* A value to be passed to ApplyBlockMigrationRequest, to confirm that the
405+
* execution of the plan is being requested.
406+
*/
407+
validationKey: string
408+
}
409+
391410
/** Placement group. */
392411
export interface PlacementGroup {
393412
/** Placement group unique ID. */
@@ -1742,3 +1761,44 @@ export type GetDashboardRequest = {
17421761
organization?: string
17431762
project?: string
17441763
}
1764+
1765+
export type PlanBlockMigrationRequest = {
1766+
/** Zone to target. If none is passed will use default zone from the config. */
1767+
zone?: Zone
1768+
/**
1769+
* The volume for which the migration plan will be generated.
1770+
*
1771+
* One-of ('resource'): at most one of 'volumeId', 'snapshotId' could be set.
1772+
*/
1773+
volumeId?: string
1774+
/**
1775+
* The snapshot for which the migration plan will be generated.
1776+
*
1777+
* One-of ('resource'): at most one of 'volumeId', 'snapshotId' could be set.
1778+
*/
1779+
snapshotId?: string
1780+
}
1781+
1782+
export type ApplyBlockMigrationRequest = {
1783+
/** Zone to target. If none is passed will use default zone from the config. */
1784+
zone?: Zone
1785+
/**
1786+
* The volume to migrate, along with potentially other resources, according to
1787+
* the migration plan generated with a call to PlanBlockMigration.
1788+
*
1789+
* One-of ('resource'): at most one of 'volumeId', 'snapshotId' could be set.
1790+
*/
1791+
volumeId?: string
1792+
/**
1793+
* The snapshot to migrate, along with potentially other resources, according
1794+
* to the migration plan generated with a call to PlanBlockMigration.
1795+
*
1796+
* One-of ('resource'): at most one of 'volumeId', 'snapshotId' could be set.
1797+
*/
1798+
snapshotId?: string
1799+
/**
1800+
* A value to be retrieved from a call to PlanBlockMigration, to confirm that
1801+
* the volume and/or snapshots specified in said plan should be migrated.
1802+
*/
1803+
validationKey: string
1804+
}

0 commit comments

Comments
 (0)