Skip to content

Commit f59d6a7

Browse files
authored
feat(instance): add endpoints to attach/detach server volumes (#370)
1 parent 4ee2f66 commit f59d6a7

File tree

8 files changed

+470
-0
lines changed

8 files changed

+470
-0
lines changed

scaleway-async/scaleway_async/instance/v1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
33
from .types import Arch
4+
from .types import AttachServerVolumeRequestVolumeType
45
from .types import BootType
56
from .types import ImageState
67
from .types import IpState
@@ -27,6 +28,7 @@
2728
from .types import VolumeServerVolumeType
2829
from .types import VolumeState
2930
from .types import VolumeVolumeType
31+
from .types import AttachServerVolumeResponse
3032
from .types import Bootscript
3133
from .types import CreateImageResponse
3234
from .types import CreateIpResponse
@@ -38,6 +40,7 @@
3840
from .types import CreateSnapshotResponse
3941
from .types import CreateVolumeResponse
4042
from .types import Dashboard
43+
from .types import DetachServerVolumeResponse
4144
from .types import ExportSnapshotResponse
4245
from .types import GetBootscriptResponse
4346
from .types import GetDashboardResponse
@@ -125,6 +128,7 @@
125128

126129
__all__ = [
127130
"Arch",
131+
"AttachServerVolumeRequestVolumeType",
128132
"BootType",
129133
"ImageState",
130134
"IpState",
@@ -151,6 +155,7 @@
151155
"VolumeServerVolumeType",
152156
"VolumeState",
153157
"VolumeVolumeType",
158+
"AttachServerVolumeResponse",
154159
"Bootscript",
155160
"CreateImageResponse",
156161
"CreateIpResponse",
@@ -162,6 +167,7 @@
162167
"CreateSnapshotResponse",
163168
"CreateVolumeResponse",
164169
"Dashboard",
170+
"DetachServerVolumeResponse",
165171
"ExportSnapshotResponse",
166172
"GetBootscriptResponse",
167173
"GetDashboardResponse",

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from .types import (
1717
Arch,
18+
AttachServerVolumeRequestVolumeType,
1819
BootType,
1920
ImageState,
2021
IpType,
@@ -30,6 +31,7 @@
3031
SnapshotState,
3132
SnapshotVolumeType,
3233
VolumeVolumeType,
34+
AttachServerVolumeResponse,
3335
Bootscript,
3436
CreateImageResponse,
3537
CreateIpResponse,
@@ -40,6 +42,7 @@
4042
CreateServerResponse,
4143
CreateSnapshotResponse,
4244
CreateVolumeResponse,
45+
DetachServerVolumeResponse,
4346
ExportSnapshotResponse,
4447
GetBootscriptResponse,
4548
GetDashboardResponse,
@@ -101,6 +104,8 @@
101104
VolumeSummary,
102105
VolumeTemplate,
103106
ServerActionRequest,
107+
AttachServerVolumeRequest,
108+
DetachServerVolumeRequest,
104109
CreateImageRequest,
105110
CreateSnapshotRequest,
106111
ExportSnapshotRequest,
@@ -137,6 +142,7 @@
137142
)
138143
from .marshalling import (
139144
marshal_ApplyBlockMigrationRequest,
145+
marshal_AttachServerVolumeRequest,
140146
marshal_CreateImageRequest,
141147
marshal_CreateIpRequest,
142148
marshal_CreatePlacementGroupRequest,
@@ -145,6 +151,7 @@
145151
marshal_CreateSecurityGroupRuleRequest,
146152
marshal_CreateSnapshotRequest,
147153
marshal_CreateVolumeRequest,
154+
marshal_DetachServerVolumeRequest,
148155
marshal_ExportSnapshotRequest,
149156
marshal_PlanBlockMigrationRequest,
150157
marshal_ServerActionRequest,
@@ -164,6 +171,7 @@
164171
marshal__SetSnapshotRequest,
165172
marshal__UpdateServerRequest,
166173
unmarshal_PrivateNIC,
174+
unmarshal_AttachServerVolumeResponse,
167175
unmarshal_CreateImageResponse,
168176
unmarshal_CreateIpResponse,
169177
unmarshal_CreatePlacementGroupResponse,
@@ -173,6 +181,7 @@
173181
unmarshal_CreateServerResponse,
174182
unmarshal_CreateSnapshotResponse,
175183
unmarshal_CreateVolumeResponse,
184+
unmarshal_DetachServerVolumeResponse,
176185
unmarshal_ExportSnapshotResponse,
177186
unmarshal_GetBootscriptResponse,
178187
unmarshal_GetDashboardResponse,
@@ -972,6 +981,97 @@ async def delete_server_user_data(
972981
self._throw_on_error(res)
973982
return None
974983

984+
async def attach_server_volume(
985+
self,
986+
*,
987+
server_id: str,
988+
volume_id: str,
989+
volume_type: AttachServerVolumeRequestVolumeType,
990+
zone: Optional[Zone] = None,
991+
boot: Optional[bool] = None,
992+
) -> AttachServerVolumeResponse:
993+
"""
994+
Attach a volume to a server.
995+
:param zone: Zone to target. If none is passed will use default zone from the config.
996+
:param server_id: UUID of the Instance.
997+
:param volume_id: UUID of the Volume to attach.
998+
:param volume_type: Type of the volume to attach.
999+
:param boot: Force the Instance to boot on this volume.
1000+
:return: :class:`AttachServerVolumeResponse <AttachServerVolumeResponse>`
1001+
1002+
Usage:
1003+
::
1004+
1005+
result = await api.attach_server_volume(
1006+
server_id="example",
1007+
volume_id="example",
1008+
volume_type=unknown_volume_type,
1009+
)
1010+
"""
1011+
1012+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
1013+
param_server_id = validate_path_param("server_id", server_id)
1014+
1015+
res = self._request(
1016+
"POST",
1017+
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/attach-volume",
1018+
body=marshal_AttachServerVolumeRequest(
1019+
AttachServerVolumeRequest(
1020+
server_id=server_id,
1021+
volume_id=volume_id,
1022+
volume_type=volume_type,
1023+
zone=zone,
1024+
boot=boot,
1025+
),
1026+
self.client,
1027+
),
1028+
)
1029+
1030+
self._throw_on_error(res)
1031+
return unmarshal_AttachServerVolumeResponse(res.json())
1032+
1033+
async def detach_server_volume(
1034+
self,
1035+
*,
1036+
server_id: str,
1037+
volume_id: str,
1038+
zone: Optional[Zone] = None,
1039+
) -> DetachServerVolumeResponse:
1040+
"""
1041+
Detach a volume from a server.
1042+
:param zone: Zone to target. If none is passed will use default zone from the config.
1043+
:param server_id: UUID of the Instance.
1044+
:param volume_id: UUID of the Volume to detach.
1045+
:return: :class:`DetachServerVolumeResponse <DetachServerVolumeResponse>`
1046+
1047+
Usage:
1048+
::
1049+
1050+
result = await api.detach_server_volume(
1051+
server_id="example",
1052+
volume_id="example",
1053+
)
1054+
"""
1055+
1056+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
1057+
param_server_id = validate_path_param("server_id", server_id)
1058+
1059+
res = self._request(
1060+
"POST",
1061+
f"/instance/v1/zones/{param_zone}/servers/{param_server_id}/detach-volume",
1062+
body=marshal_DetachServerVolumeRequest(
1063+
DetachServerVolumeRequest(
1064+
server_id=server_id,
1065+
volume_id=volume_id,
1066+
zone=zone,
1067+
),
1068+
self.client,
1069+
),
1070+
)
1071+
1072+
self._throw_on_error(res)
1073+
return unmarshal_DetachServerVolumeResponse(res.json())
1074+
9751075
async def list_images(
9761076
self,
9771077
*,

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from dateutil import parser
1212
from .types import (
1313
Arch,
14+
AttachServerVolumeRequestVolumeType,
1415
BootType,
1516
ImageState,
1617
IpType,
@@ -30,6 +31,7 @@
3031
SnapshotVolumeType,
3132
VolumeState,
3233
VolumeVolumeType,
34+
AttachServerVolumeResponse,
3335
Bootscript,
3436
CreateImageResponse,
3537
CreateIpResponse,
@@ -41,6 +43,7 @@
4143
CreateSnapshotResponse,
4244
CreateVolumeResponse,
4345
Dashboard,
46+
DetachServerVolumeResponse,
4447
ExportSnapshotResponse,
4548
GetBootscriptResponse,
4649
GetDashboardResponse,
@@ -115,6 +118,8 @@
115118
VolumeTypeCapabilities,
116119
VolumeTypeConstraints,
117120
ServerActionRequest,
121+
AttachServerVolumeRequest,
122+
DetachServerVolumeRequest,
118123
CreateImageRequest,
119124
CreateSnapshotRequest,
120125
ExportSnapshotRequest,
@@ -1262,6 +1267,20 @@ def unmarshal_VolumeType(data: Any) -> VolumeType:
12621267
return VolumeType(**args)
12631268

12641269

1270+
def unmarshal_AttachServerVolumeResponse(data: Any) -> AttachServerVolumeResponse:
1271+
if type(data) is not dict:
1272+
raise TypeError(
1273+
f"Unmarshalling the type 'AttachServerVolumeResponse' failed as data isn't a dictionary."
1274+
)
1275+
1276+
args: Dict[str, Any] = {}
1277+
1278+
field = data.get("server", None)
1279+
args["server"] = unmarshal_Server(field) if field is not None else None
1280+
1281+
return AttachServerVolumeResponse(**args)
1282+
1283+
12651284
def unmarshal_CreateImageResponse(data: Any) -> CreateImageResponse:
12661285
if type(data) is not dict:
12671286
raise TypeError(
@@ -1397,6 +1416,20 @@ def unmarshal_CreateVolumeResponse(data: Any) -> CreateVolumeResponse:
13971416
return CreateVolumeResponse(**args)
13981417

13991418

1419+
def unmarshal_DetachServerVolumeResponse(data: Any) -> DetachServerVolumeResponse:
1420+
if type(data) is not dict:
1421+
raise TypeError(
1422+
f"Unmarshalling the type 'DetachServerVolumeResponse' failed as data isn't a dictionary."
1423+
)
1424+
1425+
args: Dict[str, Any] = {}
1426+
1427+
field = data.get("server", None)
1428+
args["server"] = unmarshal_Server(field) if field is not None else None
1429+
1430+
return DetachServerVolumeResponse(**args)
1431+
1432+
14001433
def unmarshal_ExportSnapshotResponse(data: Any) -> ExportSnapshotResponse:
14011434
if type(data) is not dict:
14021435
raise TypeError(
@@ -2645,6 +2678,24 @@ def marshal_ApplyBlockMigrationRequest(
26452678
return output
26462679

26472680

2681+
def marshal_AttachServerVolumeRequest(
2682+
request: AttachServerVolumeRequest,
2683+
defaults: ProfileDefaults,
2684+
) -> Dict[str, Any]:
2685+
output: Dict[str, Any] = {}
2686+
2687+
if request.boot is not None:
2688+
output["boot"] = request.boot
2689+
2690+
if request.volume_id is not None:
2691+
output["volume_id"] = request.volume_id
2692+
2693+
if request.volume_type is not None:
2694+
output["volume_type"] = AttachServerVolumeRequestVolumeType(request.volume_type)
2695+
2696+
return output
2697+
2698+
26482699
def marshal_CreateImageRequest(
26492700
request: CreateImageRequest,
26502701
defaults: ProfileDefaults,
@@ -3007,6 +3058,18 @@ def marshal_CreateVolumeRequest(
30073058
return output
30083059

30093060

3061+
def marshal_DetachServerVolumeRequest(
3062+
request: DetachServerVolumeRequest,
3063+
defaults: ProfileDefaults,
3064+
) -> Dict[str, Any]:
3065+
output: Dict[str, Any] = {}
3066+
3067+
if request.volume_id is not None:
3068+
output["volume_id"] = request.volume_id
3069+
3070+
return output
3071+
3072+
30103073
def marshal_ExportSnapshotRequest(
30113074
request: ExportSnapshotRequest,
30123075
defaults: ProfileDefaults,

0 commit comments

Comments
 (0)