Skip to content
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ ucloud-sandbox-cli sandbox create base \
--mount <volume-name-2>:/cache
```

开启自动暂停/自动恢复后,沙箱在超时被暂停后,下次访问时会自动恢复运行:

```bash
ucloud-sandbox-cli sandbox create base --auto-pause --auto-resume --detach
```

> 创建成功后,CLI 会自动连接终端,您可以像操作本地 Shell 一样执行命令。按`Ctrl+D`或输入`exit`退出连接(沙箱继续运行)。

### 连接现有沙箱
Expand Down
10 changes: 10 additions & 0 deletions cmd/sandbox/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
func newCreateCmd() *cobra.Command {
var timeout int
var detach bool
var autoPause bool
var autoResume bool
var mountSpecs []string

cmd := &cobra.Command{
Expand Down Expand Up @@ -40,6 +42,12 @@ func newCreateCmd() *cobra.Command {
if timeout > 0 {
opts = append(opts, sdk.WithTimeout(timeout))
}
if autoPause {
opts = append(opts, sdk.WithAutoPause(true))
}
if autoResume {
opts = append(opts, sdk.WithAutoResume(sdk.AutoResumePolicyOn))
}
if len(mountSpecs) > 0 {
mounts, err := parseVolumeMounts(mountSpecs)
if err != nil {
Expand All @@ -64,6 +72,8 @@ func newCreateCmd() *cobra.Command {

cmd.Flags().IntVar(&timeout, "timeout", 0, "Sandbox timeout in seconds")
cmd.Flags().BoolVar(&detach, "detach", false, "Do not connect to the sandbox after creation")
cmd.Flags().BoolVar(&autoPause, "auto-pause", false, "Automatically pause the sandbox when the timeout is reached")
cmd.Flags().BoolVar(&autoResume, "auto-resume", false, "Automatically resume the sandbox when it is paused")
cmd.Flags().StringArrayVar(&mountSpecs, "mount", nil, "Mount volume as <volume-name>:<path> (repeatable)")
return cmd
}
Expand Down
18 changes: 16 additions & 2 deletions cmd/snapshot/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (

"github.com/spf13/cobra"
"github.com/ucloud/ucloud-sandbox-cli/internal/config"
sdk "github.com/ucloud/ucloud-sandbox-sdk-go"
)

func newCreateCmd() *cobra.Command {
var name string

cmd := &cobra.Command{
Use: "create <sandbox-id>",
Aliases: []string{"cr"},
Expand All @@ -34,16 +37,27 @@ func newCreateCmd() *cobra.Command {
return fmt.Errorf("failed to connect to sandbox %s: %w", sandboxID, err)
}

var opts []sdk.SnapshotOption
if name != "" {
opts = append(opts, sdk.WithSnapshotName(name))
}

// Create snapshot from the sandbox
snapshot, err := sbx.CreateSnapshot(ctx)
snapshot, err := sbx.CreateSnapshot(ctx, opts...)
if err != nil {
return fmt.Errorf("failed to create snapshot: %w", err)
}

fmt.Printf("Snapshot created: %s\n", snapshot.SnapshotID)
if name != "" {
fmt.Printf("Snapshot created: %s (%s)\n", snapshot.SnapshotID, name)
} else {
fmt.Printf("Snapshot created: %s\n", snapshot.SnapshotID)
}
return nil
},
}

cmd.Flags().StringVarP(&name, "name", "n", "", "Snapshot name")

return cmd
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/schollz/progressbar/v3 v3.19.1
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260918080929-c96bfe4b7c62
golang.org/x/mod v0.40.0
golang.org/x/term v0.44.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2 h1:hW
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8=
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2 h1:m9JyzdCMKqQh05bphya4OZLZUb1DIsWDmmqlZeFRtyg=
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8=
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260918080929-c96bfe4b7c62 h1:Bd6kEbBmOoF5qP1kaKjnKnWMhGKvlmOtBn1Co/xY9N4=
github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260918080929-c96bfe4b7c62/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
Expand Down
Loading