Skip to content

Commit

Permalink
Merge pull request #891 from stgraber/cli
Browse files Browse the repository at this point in the history
incus/storage_volume/snapshot: Support YAML for creation
  • Loading branch information
hallyn authored May 23, 2024
2 parents 1315976 + b2f8b44 commit 9d02f1c
Show file tree
Hide file tree
Showing 12 changed files with 763 additions and 628 deletions.
22 changes: 22 additions & 0 deletions cmd/incus/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,11 @@ func (c *cmdStorageVolumeSnapshotCreate) Command() *cobra.Command {
cmd.Short = i18n.G("Snapshot storage volumes")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Snapshot storage volumes`))
cmd.Example = cli.FormatSection("", i18n.G(`incus storage volume snapshot create default v1 snap0
Create a snapshot of "v1" in pool "default" called "snap0".
incus storage volume snapshot create default v1 snap0 < config.yaml
Create a snapshot of "v1" in pool "default" called "snap0" with the configuration from "config.yaml".`))

cmd.Flags().BoolVar(&c.flagNoExpiry, "no-expiry", false, i18n.G("Ignore any configured auto-expiry for the storage volume"))
cmd.Flags().BoolVar(&c.flagReuse, "reuse", false, i18n.G("If the snapshot name already exists, delete and create a new one"))
Expand All @@ -2335,12 +2340,27 @@ func (c *cmdStorageVolumeSnapshotCreate) Command() *cobra.Command {
}

func (c *cmdStorageVolumeSnapshotCreate) Run(cmd *cobra.Command, args []string) error {
var stdinData api.StorageVolumeSnapshotPut

// Quick checks.
exit, err := c.global.CheckArgs(cmd, args, 2, 3)
if exit {
return err
}

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}

err = yaml.Unmarshal(contents, &stdinData)
if err != nil {
return err
}
}

// Parse remote
resources, err := c.global.ParseServers(args[0])
if err != nil {
Expand Down Expand Up @@ -2384,6 +2404,8 @@ func (c *cmdStorageVolumeSnapshotCreate) Run(cmd *cobra.Command, args []string)

if c.flagNoExpiry {
req.ExpiresAt = &time.Time{}
} else if stdinData.ExpiresAt != nil && !stdinData.ExpiresAt.IsZero() {
req.ExpiresAt = stdinData.ExpiresAt
}

if c.flagReuse && snapname != "" {
Expand Down
Loading

0 comments on commit 9d02f1c

Please sign in to comment.