Skip to content

Commit 4572061

Browse files
authored
feat(instance): add AttachServerVolume and DetachServerVolume (#4937)
1 parent 9fa4389 commit 4572061

File tree

6 files changed

+173
-21
lines changed

6 files changed

+173
-21
lines changed

cmd/scw/testdata/test-all-usage-instance-server-attach-volume-usage.golden

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
Attach a volume to a server
3+
Attach a volume to an Instance.
44

55
USAGE:
66
scw instance server attach-volume [arg=value ...]
77

8-
EXAMPLES:
9-
Attach a volume to a server
10-
scw instance server attach-volume server-id=11111111-1111-1111-1111-111111111111 volume-id=22222222-1111-5555-2222-666666111111
11-
128
ARGS:
13-
server-id ID of the server
14-
volume-id ID of the volume to attach
9+
server-id
10+
[volume-id]
11+
[volume-type] (unknown_volume_type | l_ssd | b_ssd | sbs_volume)
12+
[boot]
1513
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3)
1614

1715
FLAGS:

cmd/scw/testdata/test-all-usage-instance-server-detach-filesystem-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
Detach a filesystem volume to an Instance.
3+
Detach a filesystem volume from an Instance.
44

55
USAGE:
66
scw instance server detach-filesystem [arg=value ...]

cmd/scw/testdata/test-all-usage-instance-server-detach-volume-usage.golden

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
Detach a volume from its server
3+
Detach a volume from an Instance.
44

55
USAGE:
66
scw instance server detach-volume [arg=value ...]
77

8-
EXAMPLES:
9-
Detach a volume from its server
10-
scw instance server detach-volume volume-id=22222222-1111-5555-2222-666666111111
11-
128
ARGS:
13-
volume-id ID of the volume to detach
14-
server-id ID of the server
9+
server-id
10+
[volume-id]
1511
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3)
1612

1713
FLAGS:

cmd/scw/testdata/test-all-usage-instance-server-usage.golden

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ AVAILABLE COMMANDS:
1111
action Perform a raw API action on a server
1212
attach-filesystem Attach a filesystem volume to an Instance
1313
attach-ip Attach an IP to a server
14+
attach-volume Attach a volume to an Instance
1415
backup Backup server
1516
console Connect to the serial console of an instance
1617
create Create server
1718
delete Delete server
18-
detach-filesystem Detach a filesystem volume to an Instance
19+
detach-filesystem Detach a filesystem volume from an Instance
1920
detach-ip Detach an IP from a server
21+
detach-volume Detach a volume from an Instance
2022
enable-routed-ip Migrate server to IP mobility
2123
get Get an Instance
2224
get-compatible-types Get Instance compatible types

docs/commands/instance.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ This API allows you to manage your CPU and GPU Instances.
5252
- [Perform a raw API action on a server](#perform-a-raw-api-action-on-a-server)
5353
- [Attach a filesystem volume to an Instance](#attach-a-filesystem-volume-to-an-instance)
5454
- [Attach an IP to a server](#attach-an-ip-to-a-server)
55+
- [Attach a volume to an Instance](#attach-a-volume-to-an-instance)
5556
- [Backup server](#backup-server)
5657
- [Connect to the serial console of an instance](#connect-to-the-serial-console-of-an-instance)
5758
- [Create server](#create-server)
5859
- [Delete server](#delete-server)
59-
- [Detach a filesystem volume to an Instance](#detach-a-filesystem-volume-to-an-instance)
60+
- [Detach a filesystem volume from an Instance](#detach-a-filesystem-volume-from-an-instance)
6061
- [Detach an IP from a server](#detach-an-ip-from-a-server)
62+
- [Detach a volume from an Instance](#detach-a-volume-from-an-instance)
6163
- [Migrate server to IP mobility](#migrate-server-to-ip-mobility)
6264
- [Get an Instance](#get-an-instance)
6365
- [Get Instance compatible types](#get-instance-compatible-types)
@@ -1626,6 +1628,29 @@ scw instance server attach-ip 11111111-1111-1111-1111-111111111111 ip=1.2.3.4
16261628

16271629

16281630

1631+
### Attach a volume to an Instance
1632+
1633+
Attach a volume to an Instance.
1634+
1635+
**Usage:**
1636+
1637+
```
1638+
scw instance server attach-volume [arg=value ...]
1639+
```
1640+
1641+
1642+
**Args:**
1643+
1644+
| Name | | Description |
1645+
|------|---|-------------|
1646+
| server-id | Required | |
1647+
| volume-id | | |
1648+
| volume-type | One of: `unknown_volume_type`, `l_ssd`, `b_ssd`, `sbs_volume` | |
1649+
| boot | | |
1650+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |
1651+
1652+
1653+
16291654
### Backup server
16301655

16311656
Create a new image based on the server.
@@ -1810,9 +1835,9 @@ scw instance server delete 11111111-1111-1111-1111-111111111111 zone=fr-par-1
18101835

18111836

18121837

1813-
### Detach a filesystem volume to an Instance
1838+
### Detach a filesystem volume from an Instance
18141839

1815-
Detach a filesystem volume to an Instance.
1840+
Detach a filesystem volume from an Instance.
18161841

18171842
**Usage:**
18181843

@@ -1861,6 +1886,27 @@ scw instance server detach-ip 11111111-1111-1111-1111-111111111111
18611886

18621887

18631888

1889+
### Detach a volume from an Instance
1890+
1891+
Detach a volume from an Instance.
1892+
1893+
**Usage:**
1894+
1895+
```
1896+
scw instance server detach-volume [arg=value ...]
1897+
```
1898+
1899+
1900+
**Args:**
1901+
1902+
| Name | | Description |
1903+
|------|---|-------------|
1904+
| server-id | Required | |
1905+
| volume-id | | |
1906+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |
1907+
1908+
1909+
18641910
### Migrate server to IP mobility
18651911

18661912
Enable routed IP for this server and migrate the nat public IP to routed

internal/namespaces/instance/v1/instance_cli.go

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func GetGeneratedCommands() *core.Commands {
4343
instanceUserDataSet(),
4444
instanceUserDataGet(),
4545
instanceServerGetCompatibleTypes(),
46+
instanceServerAttachVolume(),
47+
instanceServerDetachVolume(),
4648
instanceServerAttachFilesystem(),
4749
instanceServerDetachFilesystem(),
4850
instanceImageList(),
@@ -1135,6 +1137,114 @@ If the specified Instance offer is flagged as end of service, the best compatibl
11351137
}
11361138
}
11371139

1140+
func instanceServerAttachVolume() *core.Command {
1141+
return &core.Command{
1142+
Short: `Attach a volume to an Instance`,
1143+
Long: `Attach a volume to an Instance.`,
1144+
Namespace: "instance",
1145+
Resource: "server",
1146+
Verb: "attach-volume",
1147+
// Deprecated: false,
1148+
ArgsType: reflect.TypeOf(instance.AttachServerVolumeRequest{}),
1149+
ArgSpecs: core.ArgSpecs{
1150+
{
1151+
Name: "server-id",
1152+
Required: true,
1153+
Deprecated: false,
1154+
Positional: false,
1155+
},
1156+
{
1157+
Name: "volume-id",
1158+
Required: false,
1159+
Deprecated: false,
1160+
Positional: false,
1161+
},
1162+
{
1163+
Name: "volume-type",
1164+
Required: false,
1165+
Deprecated: false,
1166+
Positional: false,
1167+
EnumValues: []string{
1168+
"unknown_volume_type",
1169+
"l_ssd",
1170+
"b_ssd",
1171+
"sbs_volume",
1172+
},
1173+
},
1174+
{
1175+
Name: "boot",
1176+
Required: false,
1177+
Deprecated: false,
1178+
Positional: false,
1179+
},
1180+
core.ZoneArgSpec(
1181+
scw.ZoneFrPar1,
1182+
scw.ZoneFrPar2,
1183+
scw.ZoneFrPar3,
1184+
scw.ZoneNlAms1,
1185+
scw.ZoneNlAms2,
1186+
scw.ZoneNlAms3,
1187+
scw.ZonePlWaw1,
1188+
scw.ZonePlWaw2,
1189+
scw.ZonePlWaw3,
1190+
),
1191+
},
1192+
Run: func(ctx context.Context, args any) (i any, e error) {
1193+
request := args.(*instance.AttachServerVolumeRequest)
1194+
1195+
client := core.ExtractClient(ctx)
1196+
api := instance.NewAPI(client)
1197+
1198+
return api.AttachServerVolume(request)
1199+
},
1200+
}
1201+
}
1202+
1203+
func instanceServerDetachVolume() *core.Command {
1204+
return &core.Command{
1205+
Short: `Detach a volume from an Instance`,
1206+
Long: `Detach a volume from an Instance.`,
1207+
Namespace: "instance",
1208+
Resource: "server",
1209+
Verb: "detach-volume",
1210+
// Deprecated: false,
1211+
ArgsType: reflect.TypeOf(instance.DetachServerVolumeRequest{}),
1212+
ArgSpecs: core.ArgSpecs{
1213+
{
1214+
Name: "server-id",
1215+
Required: true,
1216+
Deprecated: false,
1217+
Positional: false,
1218+
},
1219+
{
1220+
Name: "volume-id",
1221+
Required: false,
1222+
Deprecated: false,
1223+
Positional: false,
1224+
},
1225+
core.ZoneArgSpec(
1226+
scw.ZoneFrPar1,
1227+
scw.ZoneFrPar2,
1228+
scw.ZoneFrPar3,
1229+
scw.ZoneNlAms1,
1230+
scw.ZoneNlAms2,
1231+
scw.ZoneNlAms3,
1232+
scw.ZonePlWaw1,
1233+
scw.ZonePlWaw2,
1234+
scw.ZonePlWaw3,
1235+
),
1236+
},
1237+
Run: func(ctx context.Context, args any) (i any, e error) {
1238+
request := args.(*instance.DetachServerVolumeRequest)
1239+
1240+
client := core.ExtractClient(ctx)
1241+
api := instance.NewAPI(client)
1242+
1243+
return api.DetachServerVolume(request)
1244+
},
1245+
}
1246+
}
1247+
11381248
func instanceServerAttachFilesystem() *core.Command {
11391249
return &core.Command{
11401250
Short: `Attach a filesystem volume to an Instance`,
@@ -1182,8 +1292,8 @@ func instanceServerAttachFilesystem() *core.Command {
11821292

11831293
func instanceServerDetachFilesystem() *core.Command {
11841294
return &core.Command{
1185-
Short: `Detach a filesystem volume to an Instance`,
1186-
Long: `Detach a filesystem volume to an Instance.`,
1295+
Short: `Detach a filesystem volume from an Instance`,
1296+
Long: `Detach a filesystem volume from an Instance.`,
11871297
Namespace: "instance",
11881298
Resource: "server",
11891299
Verb: "detach-filesystem",

0 commit comments

Comments
 (0)