Skip to content

feat(instance): add support detach and attach filesystem #4797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
List all existing attachments in a specified region.
By default, the attachments listed are ordered by creation date in ascending order. This can be modified using the `order_by` field.

USAGE:
scw file attachment list [arg=value ...]

ARGS:
[filesystem-id] UUID of the File Storage volume
[resource-id] Filter by resource ID
[resource-type] Filter by resource type (unknown_resource_type | instance_server)
[zone] Filter by resource zone
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | all)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
20 changes: 20 additions & 0 deletions cmd/scw/testdata/test-all-usage-file-attachment-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Attachment management.

USAGE:
scw file attachment <command>

AVAILABLE COMMANDS:
list List filesystems attachments

FLAGS:
-h, --help help for attachment

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw file attachment [command] --help" for more information about a command.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
To create a new filesystem, you must specify a name, a size, and a project ID.

USAGE:
scw file filesystem create [arg=value ...]

ARGS:
name Name of the filesystem
[project-id] Project ID to use. If none is passed the default project ID will be used
size Filesystem size in bytes, with a granularity of 100 GB (10^11 bytes).
[tags.{index}] List of tags assigned to the filesystem
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for create

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
You must specify the `filesystem_id` of the filesystem you want to delete.

USAGE:
scw file filesystem delete <filesystem-id ...> [arg=value ...]

ARGS:
filesystem-id UUID of the filesystem
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for delete

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve all properties and current status of a specific filesystem identified by its ID.

USAGE:
scw file filesystem get <filesystem-id ...> [arg=value ...]

ARGS:
filesystem-id UUID of the filesystem
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for get

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve all filesystems in the specified region. By default, the filesystems listed are ordered by creation date in ascending order. This can be modified using the `order_by` field.

USAGE:
scw file filesystem list [arg=value ...]

ARGS:
[order-by] Criteria to use when ordering the list (created_at_asc | created_at_desc | name_asc | name_desc)
[project-id] Filter by project ID
[name] Filter the returned filesystems by their names
[tags.{index}] Filter by tags. Only filesystems with one or more matching tags will be returned
[organization-id] Filter by organization ID
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | all)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Update the technical details of a filesystem, such as its name, tags or its new size.

USAGE:
scw file filesystem update [arg=value ...]

ARGS:
filesystem-id UUID of the filesystem
[name] When defined, is the new name of the filesystem
[size] Optional field for increasing the size of the filesystem (must be larger than the current size)
[tags.{index}] List of tags assigned to the filesystem
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for update

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
24 changes: 24 additions & 0 deletions cmd/scw/testdata/test-all-usage-file-filesystem-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Filesystem management.

USAGE:
scw file filesystem <command>

AVAILABLE COMMANDS:
create Create a new filesystem
delete Delete a detached filesystem
get Get filesystem details
list List all filesystems
update Update filesystem properties

FLAGS:
-h, --help help for filesystem

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw file filesystem [command] --help" for more information about a command.
21 changes: 21 additions & 0 deletions cmd/scw/testdata/test-all-usage-file-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This API allows you to manage your File Storage resources.

USAGE:
scw file <command>

AVAILABLE COMMANDS:
attachment Attachment management
filesystem Filesystem management

FLAGS:
-h, --help help for file

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw file [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-main-usage-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SERVERLESS COMMANDS:

STORAGE COMMANDS:
block This API allows you to manage your Block Storage volumes
file This API allows you to manage your File Storage resources
object Object-storage utils
registry This API allows you to manage your Container Registry resources

Expand Down
4 changes: 2 additions & 2 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func GetCommands() *core.Commands {
domain.GetCommands(),
applesilicon.GetCommands(),
flexibleip.GetCommands(),
file.GetCommands(),
container.GetCommands(),
function.GetCommands(),
vpcgw.GetCommands(),
Expand All @@ -116,9 +117,8 @@ func GetCommands() *core.Commands {
)

if beta {
commands.MergeAll(
commands.Merge(
dedibox.GetCommands(),
file.GetCommands(),
)
}

Expand Down
12 changes: 5 additions & 7 deletions docs/commands/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Attachment management.
### List filesystems attachments

List all existing attachments in a specified region.
By default, the attachments listed are ordered by creation date in ascending order.
This can be modified using the `order_by` field.
By default, the attachments listed are ordered by creation date in ascending order. This can be modified using the `order_by` field.

**Usage:**

Expand Down Expand Up @@ -49,7 +48,7 @@ Filesystem management.

### Create a new filesystem

To create a new filesystem, you need to provide a name, a size, and a project ID.
To create a new filesystem, you must specify a name, a size, and a project ID.

**Usage:**

Expand Down Expand Up @@ -112,8 +111,7 @@ scw file filesystem get <filesystem-id ...> [arg=value ...]

### List all filesystems

Retrieve all filesystems in the specified region. Results are ordered by creation date in ascending order by default.
Use the order_by parameter to modify the sorting behavior.
Retrieve all filesystems in the specified region. By default, the filesystems listed are ordered by creation date in ascending order. This can be modified using the `order_by` field.

**Usage:**

Expand All @@ -128,16 +126,16 @@ scw file filesystem list [arg=value ...]
|------|---|-------------|
| order-by | One of: `created_at_asc`, `created_at_desc`, `name_asc`, `name_desc` | Criteria to use when ordering the list |
| project-id | | Filter by project ID |
| name | | Filter the return filesystems by their names |
| name | | Filter the returned filesystems by their names |
| tags.{index} | | Filter by tags. Only filesystems with one or more matching tags will be returned |
| organization-id | | Filter by organization ID |
| region | Default: `fr-par`<br />One of: `fr-par`, `all` | Region to target. If none is passed will use default region from the config |



### Update filesystem properties

Update the technical details of a filesystem, such as its name, tags or its new size.
You can only resize a filesystem to a larger size.

**Usage:**

Expand Down
4 changes: 4 additions & 0 deletions internal/namespaces/instance/v1/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ func serverGetBuilder(c *core.Command) *core.Command {
Title: "Warnings",
HideIfEmpty: true,
},
{
FieldName: "Filesystems",
Title: "Server Filesystems",
},
},
}

Expand Down
35 changes: 35 additions & 0 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/scaleway/scaleway-cli/v2/core"
block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1"
file "github.com/scaleway/scaleway-cli/v2/internal/namespaces/file/v1alpha1"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1"
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
blockSDK "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
Expand Down Expand Up @@ -907,3 +908,37 @@ func Test_CreateServerScratchStorage(t *testing.T) {
DisableParallel: true,
}))
}

func Test_AttachFilesystem(t *testing.T) {
t.Run("attach filesystem", core.Test(&core.TestConfig{
Commands: core.NewCommandsMerge(
instance.GetCommands(),
file.GetCommands(),
),
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd(
"FileSystem",
"scw file filesystem create name=instance-fs-cli size=100000000000",
),
core.ExecStoreBeforeCmd(
"Server",
testServerCommand("stopped=true image=ubuntu-jammy type=POP2-2C-8G"),
),
),
Cmd: "scw instance server attach-filesystem server-id={{ .Server.ID }} filesystem-id={{ .FileSystem.ID }}",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
AfterFunc: core.AfterFuncCombine(
core.ExecAfterCmd(
"scw instance server detach-filesystem server-id={{ .Server.ID }} filesystem-id={{ .FileSystem.ID }}",
),
deleteServer("Server"),
core.ExecAfterCmd(
"scw file filesystem delete {{ .FileSystem.ID }}",
),
),
DisableParallel: true,
}))
}
5 changes: 4 additions & 1 deletion internal/namespaces/instance/v1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ func createServer(metaKey string) core.BeforeFunc {

// testServerCommand creates returns a create server command with the instance type and the given arguments
func testServerCommand(params string) string {
baseCommand := "scw instance server create type=DEV1-S "
baseCommand := "scw instance server create "
if !strings.Contains(params, "ip=") {
baseCommand += "ip=none "
}
if !strings.Contains(params, "image=") {
baseCommand += "image=ubuntu_jammy "
}
if !strings.Contains(params, "type=") {
baseCommand += "type=DEV1-S "
}

return baseCommand + params
}
Expand Down
Loading
Loading