Skip to content
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

incus/profile: Add support for creating profile from yaml #756

Merged
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
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
Loading
Loading