Optimizing pull to automatically build the VNFS and set default if requested

This commit is contained in:
Gregory Kurtzer
2020-12-13 20:35:47 -08:00
parent 5c23ef9f94
commit 487f45f7a9
2 changed files with 29 additions and 6 deletions

View File

@@ -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)
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

View File

@@ -13,12 +13,14 @@ var (
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")
}