Skip to content

Commit d9779d7

Browse files
authored
feat(rdb): migrate endpoint from one instance to another (#66)
1 parent 85b2d92 commit d9779d7

File tree

6 files changed

+148
-0
lines changed

6 files changed

+148
-0
lines changed

scaleway-async/scaleway_async/rdb/v1/api.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
UpdateSnapshotRequest,
8989
CreateInstanceFromSnapshotRequest,
9090
CreateEndpointRequest,
91+
MigrateEndpointRequest,
9192
)
9293
from .content import (
9394
DATABASE_BACKUP_TRANSIENT_STATUSES,
@@ -111,6 +112,7 @@
111112
marshal_CreateUserRequest,
112113
marshal_DeleteInstanceACLRulesRequest,
113114
marshal_DeleteInstanceSettingsRequest,
115+
marshal_MigrateEndpointRequest,
114116
marshal_PrepareInstanceLogsRequest,
115117
marshal_PurgeInstanceLogsRequest,
116118
marshal_RestoreDatabaseBackupRequest,
@@ -3040,3 +3042,47 @@ async def get_endpoint(
30403042

30413043
self._throw_on_error(res)
30423044
return unmarshal_Endpoint(res.json())
3045+
3046+
async def migrate_endpoint(
3047+
self,
3048+
*,
3049+
endpoint_id: str,
3050+
instance_id: str,
3051+
region: Optional[Region] = None,
3052+
) -> Endpoint:
3053+
"""
3054+
Migrate an existing instance endpoint to another instance
3055+
:param region: Region to target. If none is passed will use default region from the config
3056+
:param endpoint_id: UUID of the endpoint you want to migrate
3057+
:param instance_id: UUID of the instance you want to attach the endpoint to
3058+
:return: :class:`Endpoint <Endpoint>`
3059+
3060+
Usage:
3061+
::
3062+
3063+
result = await api.migrate_endpoint(
3064+
endpoint_id="example",
3065+
instance_id="example",
3066+
)
3067+
"""
3068+
3069+
param_region = validate_path_param(
3070+
"region", region or self.client.default_region
3071+
)
3072+
param_endpoint_id = validate_path_param("endpoint_id", endpoint_id)
3073+
3074+
res = self._request(
3075+
"POST",
3076+
f"/rdb/v1/regions/{param_region}/endpoints/{param_endpoint_id}/migrate",
3077+
body=marshal_MigrateEndpointRequest(
3078+
MigrateEndpointRequest(
3079+
endpoint_id=endpoint_id,
3080+
instance_id=instance_id,
3081+
region=region,
3082+
),
3083+
self.client,
3084+
),
3085+
)
3086+
3087+
self._throw_on_error(res)
3088+
return unmarshal_Endpoint(res.json())

scaleway-async/scaleway_async/rdb/v1/marshalling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
UpdateSnapshotRequest,
9393
CreateInstanceFromSnapshotRequest,
9494
CreateEndpointRequest,
95+
MigrateEndpointRequest,
9596
)
9697

9798

@@ -1415,6 +1416,15 @@ def marshal_DeleteInstanceSettingsRequest(
14151416
}
14161417

14171418

1419+
def marshal_MigrateEndpointRequest(
1420+
request: MigrateEndpointRequest,
1421+
defaults: ProfileDefaults,
1422+
) -> Dict[str, Any]:
1423+
return {
1424+
"instance_id": request.instance_id,
1425+
}
1426+
1427+
14181428
def marshal_PrepareInstanceLogsRequest(
14191429
request: PrepareInstanceLogsRequest,
14201430
defaults: ProfileDefaults,

scaleway-async/scaleway_async/rdb/v1/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,3 +2679,21 @@ class GetEndpointRequest:
26792679
"""
26802680
UUID of the endpoint you want to get
26812681
"""
2682+
2683+
2684+
@dataclass
2685+
class MigrateEndpointRequest:
2686+
region: Optional[Region]
2687+
"""
2688+
Region to target. If none is passed will use default region from the config
2689+
"""
2690+
2691+
endpoint_id: str
2692+
"""
2693+
UUID of the endpoint you want to migrate
2694+
"""
2695+
2696+
instance_id: str
2697+
"""
2698+
UUID of the instance you want to attach the endpoint to
2699+
"""

scaleway/scaleway/rdb/v1/api.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
UpdateSnapshotRequest,
8989
CreateInstanceFromSnapshotRequest,
9090
CreateEndpointRequest,
91+
MigrateEndpointRequest,
9192
)
9293
from .content import (
9394
DATABASE_BACKUP_TRANSIENT_STATUSES,
@@ -111,6 +112,7 @@
111112
marshal_CreateUserRequest,
112113
marshal_DeleteInstanceACLRulesRequest,
113114
marshal_DeleteInstanceSettingsRequest,
115+
marshal_MigrateEndpointRequest,
114116
marshal_PrepareInstanceLogsRequest,
115117
marshal_PurgeInstanceLogsRequest,
116118
marshal_RestoreDatabaseBackupRequest,
@@ -3030,3 +3032,47 @@ def get_endpoint(
30303032

30313033
self._throw_on_error(res)
30323034
return unmarshal_Endpoint(res.json())
3035+
3036+
def migrate_endpoint(
3037+
self,
3038+
*,
3039+
endpoint_id: str,
3040+
instance_id: str,
3041+
region: Optional[Region] = None,
3042+
) -> Endpoint:
3043+
"""
3044+
Migrate an existing instance endpoint to another instance
3045+
:param region: Region to target. If none is passed will use default region from the config
3046+
:param endpoint_id: UUID of the endpoint you want to migrate
3047+
:param instance_id: UUID of the instance you want to attach the endpoint to
3048+
:return: :class:`Endpoint <Endpoint>`
3049+
3050+
Usage:
3051+
::
3052+
3053+
result = api.migrate_endpoint(
3054+
endpoint_id="example",
3055+
instance_id="example",
3056+
)
3057+
"""
3058+
3059+
param_region = validate_path_param(
3060+
"region", region or self.client.default_region
3061+
)
3062+
param_endpoint_id = validate_path_param("endpoint_id", endpoint_id)
3063+
3064+
res = self._request(
3065+
"POST",
3066+
f"/rdb/v1/regions/{param_region}/endpoints/{param_endpoint_id}/migrate",
3067+
body=marshal_MigrateEndpointRequest(
3068+
MigrateEndpointRequest(
3069+
endpoint_id=endpoint_id,
3070+
instance_id=instance_id,
3071+
region=region,
3072+
),
3073+
self.client,
3074+
),
3075+
)
3076+
3077+
self._throw_on_error(res)
3078+
return unmarshal_Endpoint(res.json())

scaleway/scaleway/rdb/v1/marshalling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
UpdateSnapshotRequest,
9393
CreateInstanceFromSnapshotRequest,
9494
CreateEndpointRequest,
95+
MigrateEndpointRequest,
9596
)
9697

9798

@@ -1415,6 +1416,15 @@ def marshal_DeleteInstanceSettingsRequest(
14151416
}
14161417

14171418

1419+
def marshal_MigrateEndpointRequest(
1420+
request: MigrateEndpointRequest,
1421+
defaults: ProfileDefaults,
1422+
) -> Dict[str, Any]:
1423+
return {
1424+
"instance_id": request.instance_id,
1425+
}
1426+
1427+
14181428
def marshal_PrepareInstanceLogsRequest(
14191429
request: PrepareInstanceLogsRequest,
14201430
defaults: ProfileDefaults,

scaleway/scaleway/rdb/v1/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,3 +2679,21 @@ class GetEndpointRequest:
26792679
"""
26802680
UUID of the endpoint you want to get
26812681
"""
2682+
2683+
2684+
@dataclass
2685+
class MigrateEndpointRequest:
2686+
region: Optional[Region]
2687+
"""
2688+
Region to target. If none is passed will use default region from the config
2689+
"""
2690+
2691+
endpoint_id: str
2692+
"""
2693+
UUID of the endpoint you want to migrate
2694+
"""
2695+
2696+
instance_id: str
2697+
"""
2698+
UUID of the instance you want to attach the endpoint to
2699+
"""

0 commit comments

Comments
 (0)