Added Init to datastructure, fixups to container interface, and --setdefault to kernel and container build

This commit is contained in:
Gregory Kurtzer
2020-12-06 22:29:25 -08:00
parent 9de9778648
commit 5c995f9d0f
18 changed files with 104 additions and 12 deletions

View File

@@ -1,7 +1,9 @@
package build
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/kernel"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
@@ -17,6 +19,31 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
if SetDefault == true {
if len(args) != 1 {
wwlog.Printf(wwlog.ERROR, "Can only set default for one kernel version\n")
} else {
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 kernel version to: %s\n", args[0])
profile.KernelVersion.Set(args[0])
nodeDB.ProfileUpdate(profile)
}
}
nodeDB.Persist()
fmt.Printf("Set default kernel version to: %s\n", args[0])
}
}
/*
var nodes []node.NodeInfo
set := make(map[string]int)

View File

@@ -12,13 +12,15 @@ var (
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
BuildAll bool
ByNode bool
BuildAll bool
ByNode bool
SetDefault bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)")
baseCmd.PersistentFlags().BoolVarP(&ByNode, "node", "n", false, "Build overlay for a particular node(s)")
baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this kernel for the default profile")
}
// GetRootCommand returns the root cobra.Command for the application.