diff --git a/internal/app/wwctl/container/pull/main.go b/internal/app/wwctl/container/pull/main.go index f9a9919d..2acd199d 100644 --- a/internal/app/wwctl/container/pull/main.go +++ b/internal/app/wwctl/container/pull/main.go @@ -3,6 +3,7 @@ package pull import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" @@ -50,9 +51,29 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if SetBuild == true { - fmt.Printf("Building container: %s\n", name) - container.Build(name, false) + fmt.Printf("Building container: %s\n", name) + container.Build(name, true) + + if SetDefault == true { + nodeDB, err := node.New() + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) + os.Exit(1) + } + + //TODO: Don't loop through profiles, instead have a nodeDB function that goes directly to the map + profiles, _ := nodeDB.FindAllProfiles() + for _, profile := range profiles { + wwlog.Printf(wwlog.DEBUG, "Looking for profile default: %s\n", profile.Id.Get()) + if profile.Id.Get() == "default" { + wwlog.Printf(wwlog.DEBUG, "Found profile default, setting container name to: %s\n", name) + profile.ContainerName.Set(name) + nodeDB.ProfileUpdate(profile) + } + } + nodeDB.Persist() + fmt.Printf("Set default profile to container: %s\n", name) + } return nil diff --git a/internal/app/wwctl/container/pull/root.go b/internal/app/wwctl/container/pull/root.go index 84ed3d04..882a18f0 100644 --- a/internal/app/wwctl/container/pull/root.go +++ b/internal/app/wwctl/container/pull/root.go @@ -10,15 +10,17 @@ var ( RunE: CobraRunE, Args: cobra.MinimumNArgs(1), } - SetForce bool - SetUpdate bool - SetBuild bool + SetForce bool + SetUpdate bool + SetBuild bool + SetDefault bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&SetForce, "force", "f", false, "Force overwrite of an existing container") baseCmd.PersistentFlags().BoolVarP(&SetUpdate, "update", "u", false, "Update and overwrite an existing container") baseCmd.PersistentFlags().BoolVarP(&SetBuild, "build", "b", false, "Build container when after pulling") + baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this container for the default profile") }