Skip to content

Commit

Permalink
Merge pull request #864 from awalvie/yaml-support-storage-volume-create
Browse files Browse the repository at this point in the history
incus/storage_volume: Add yaml support for create
  • Loading branch information
stgraber committed May 13, 2024
2 parents bcc3363 + 356b229 commit f149513
Show file tree
Hide file tree
Showing 12 changed files with 1,898 additions and 1,784 deletions.
32 changes: 27 additions & 5 deletions cmd/incus/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ func (c *cmdStorageVolumeCreate) Command() *cobra.Command {
cmd.Short = i18n.G("Create new custom storage volumes")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Create new custom storage volumes`))
cmd.Example = cli.FormatSection("", i18n.G(`incus storage volume create p1 v1
incus storage volume create p1 v1 < config.yaml
Create storage volume v1 for pool p1 with configuration from config.yaml.`))

cmd.Flags().StringVar(&c.storage.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVar(&c.flagContentType, "type", "filesystem", i18n.G("Content type, block or filesystem")+"``")
Expand Down Expand Up @@ -612,15 +616,33 @@ func (c *cmdStorageVolumeCreate) Run(cmd *cobra.Command, args []string) error {

client := resource.server

var volumePut api.StorageVolumePut
if !termios.IsTerminal(getStdinFd()) {
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}

err = yaml.UnmarshalStrict(contents, &volumePut)
if err != nil {
return err
}
}

// Parse the input
volName, volType := parseVolume("custom", args[1])

// Create the storage volume entry
vol := api.StorageVolumesPost{}
vol.Name = volName
vol.Type = volType
vol.ContentType = c.flagContentType
vol.Config = map[string]string{}
vol := api.StorageVolumesPost{
Name: volName,
Type: volType,
ContentType: c.flagContentType,
StorageVolumePut: volumePut,
}

if volumePut.Config == nil {
vol.Config = map[string]string{}
}

for i := 2; i < len(args); i++ {
entry := strings.SplitN(args[i], "=", 2)
Expand Down

0 comments on commit f149513

Please sign in to comment.