Skip to content

Commit

Permalink
incus/profile: Add support for creating from YAML
Browse files Browse the repository at this point in the history
Part of #741

Signed-off-by: Vishesh Agrawal <agrawal.vishesh.178@gmail.com>
  • Loading branch information
awalvie authored and stgraber committed Apr 16, 2024
1 parent b6bce39 commit 7c84b4b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/incus/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ func (c *cmdProfileCreate) Command() *cobra.Command {
cmd.Short = i18n.G("Create profiles")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Create profiles`))
cmd.Example = cli.FormatSection("", i18n.G(`incus profile create p1
incus profile create p1 < config.yaml
Create profile with configuration from config.yaml`))

cmd.RunE = c.Run

Expand All @@ -366,12 +370,27 @@ func (c *cmdProfileCreate) Command() *cobra.Command {
}

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

// Quick checks.
exit, err := c.global.CheckArgs(cmd, args, 1, 1)
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 All @@ -387,6 +406,7 @@ func (c *cmdProfileCreate) Run(cmd *cobra.Command, args []string) error {
// Create the profile
profile := api.ProfilesPost{}
profile.Name = resource.name
profile.ProfilePut = stdinData

err = resource.server.CreateProfile(profile)
if err != nil {
Expand Down

0 comments on commit 7c84b4b

Please sign in to comment.