Optimizing pull to automatically build the VNFS and set default if requested
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user