Added Init to datastructure, fixups to container interface, and --setdefault to kernel and container build
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
@@ -25,6 +27,31 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
container.Build(c, BuildForce)
|
||||
}
|
||||
|
||||
if SetDefault == true {
|
||||
if len(containers) != 1 {
|
||||
wwlog.Printf(wwlog.ERROR, "Can only set default for one container\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 container name to: %s\n", containers[0])
|
||||
profile.ContainerName.Set(containers[0])
|
||||
nodeDB.ProfileUpdate(profile)
|
||||
}
|
||||
}
|
||||
nodeDB.Persist()
|
||||
fmt.Printf("Set default profile to container: %s\n", containers[0])
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
var nodes []node.NodeInfo
|
||||
set := make(map[string]int)
|
||||
|
||||
@@ -12,11 +12,13 @@ var (
|
||||
}
|
||||
BuildForce bool
|
||||
BuildAll bool
|
||||
SetDefault bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "(re)Build all VNFS images for all nodes")
|
||||
baseCmd.PersistentFlags().BoolVarP(&BuildForce, "force", "f", false, "Force rebuild, even if it isn't necessary")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this container for the default profile")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// + build linux
|
||||
// +build linux
|
||||
|
||||
package child
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -56,6 +56,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "RuntimeOverlay", node.RuntimeOverlay.Source(), node.RuntimeOverlay.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "SystemOverlay", node.SystemOverlay.Source(), node.SystemOverlay.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Ipxe", node.Ipxe.Source(), node.Ipxe.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Init", node.Init.Source(), node.Init.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiIpaddr", node.IpmiIpaddr.Source(), node.IpmiIpaddr.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiNetmask", node.IpmiNetmask.Source(), node.IpmiNetmask.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.Print())
|
||||
|
||||
@@ -84,6 +84,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if SetInit != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting init command to: %s\n", n.Id.Get(), SetInit)
|
||||
|
||||
n.Init.Set(SetInit)
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if SetKernel != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Id.Get(), SetKernel)
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ var (
|
||||
SetAddProfile []string
|
||||
SetDelProfile []string
|
||||
SetForce bool
|
||||
SetInit string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -39,6 +40,7 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetClusterName, "cluster", "c", "", "Set the node's cluster group")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
|
||||
baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI IP address")
|
||||
|
||||
@@ -40,6 +40,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "ContainerName", profile.ContainerName.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "KernelVersion", profile.KernelVersion.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "KernelArgs", profile.KernelArgs.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Init", profile.Init.Print())
|
||||
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "RuntimeOverlay", profile.RuntimeOverlay.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "SystemOverlay", profile.SystemOverlay.Print())
|
||||
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), "Ipxe", profile.Ipxe.Print())
|
||||
|
||||
@@ -98,6 +98,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if SetInit != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting init command to: %s\n", p.Id, SetInit)
|
||||
|
||||
p.Init.Set(SetInit)
|
||||
err := nodeDB.ProfileUpdate(p)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if SetKernel != "" {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel version to: %s\n", p.Id, SetKernel)
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ var (
|
||||
SetGateway string
|
||||
SetHwaddr string
|
||||
SetNetDevDel bool
|
||||
SetInit string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -35,6 +36,8 @@ func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetClusterName, "cluster", "c", "", "Set the node's cluster group")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetInit, "init", "i", "", "Define the init process to boot the container")
|
||||
|
||||
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
|
||||
baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask")
|
||||
|
||||
@@ -77,12 +77,7 @@ func ValidSource(name string) bool {
|
||||
}
|
||||
|
||||
if util.IsDir(fullPath) == false {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Location is not a VNFS source directory: %s\n", name)
|
||||
return false
|
||||
}
|
||||
|
||||
if util.IsFile(path.Join(fullPath, "/sbin/init")) == false {
|
||||
wwlog.Printf(wwlog.VERBOSE, "VNFS Source does not have a valid /sbin/init: %s\n", name)
|
||||
wwlog.Printf(wwlog.WARN, "Location is not a VNFS source directory: %s\n", name)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.SystemOverlay.SetDefault("default")
|
||||
n.RuntimeOverlay.SetDefault("default")
|
||||
n.Ipxe.SetDefault("default")
|
||||
n.Init.SetDefault("/sbin/init")
|
||||
|
||||
fullname := strings.SplitN(nodename, ".", 2)
|
||||
if len(fullname) > 1 {
|
||||
@@ -64,6 +65,7 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.KernelArgs.Set(node.KernelArgs)
|
||||
n.ClusterName.Set(node.ClusterName)
|
||||
n.Ipxe.Set(node.Ipxe)
|
||||
n.Init.Set(node.Init)
|
||||
n.IpmiIpaddr.Set(node.IpmiIpaddr)
|
||||
n.IpmiNetmask.Set(node.IpmiNetmask)
|
||||
n.IpmiUserName.Set(node.IpmiUserName)
|
||||
@@ -101,6 +103,7 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.KernelVersion.SetAlt(self.NodeProfiles[p].KernelVersion, pstring)
|
||||
n.KernelArgs.SetAlt(self.NodeProfiles[p].KernelArgs, pstring)
|
||||
n.Ipxe.SetAlt(self.NodeProfiles[p].Ipxe, pstring)
|
||||
n.Init.SetAlt(self.NodeProfiles[p].Init, pstring)
|
||||
n.IpmiIpaddr.SetAlt(self.NodeProfiles[p].IpmiIpaddr, pstring)
|
||||
n.IpmiNetmask.SetAlt(self.NodeProfiles[p].IpmiNetmask, pstring)
|
||||
n.IpmiUserName.SetAlt(self.NodeProfiles[p].IpmiUserName, pstring)
|
||||
@@ -142,6 +145,7 @@ func (self *nodeYaml) FindAllProfiles() ([]NodeInfo, error) {
|
||||
p.Comment.Set(profile.Comment)
|
||||
p.ContainerName.Set(profile.ContainerName)
|
||||
p.Ipxe.Set(profile.Ipxe)
|
||||
p.Init.Set(profile.Init)
|
||||
p.KernelVersion.Set(profile.KernelVersion)
|
||||
p.KernelArgs.Set(profile.KernelArgs)
|
||||
p.IpmiNetmask.Set(profile.IpmiNetmask)
|
||||
|
||||
@@ -29,6 +29,7 @@ type NodeConf struct {
|
||||
IpmiNetmask string `yaml:"ipmi netmask,omitempty"`
|
||||
RuntimeOverlay string `yaml:"runtime overlay files,omitempty"`
|
||||
SystemOverlay string `yaml:"system overlay files,omitempty"`
|
||||
Init string `yaml:"init,omitempty"`
|
||||
Profiles []string `yaml:"profiles,omitempty"`
|
||||
NetDevs map[string]*NetDevs `yaml:"network devices,omitempty"`
|
||||
}
|
||||
@@ -70,6 +71,7 @@ type NodeInfo struct {
|
||||
IpmiPassword Entry
|
||||
RuntimeOverlay Entry
|
||||
SystemOverlay Entry
|
||||
Init Entry //TODO: Finish adding this...
|
||||
Profiles []string
|
||||
GroupProfiles []string
|
||||
NetDevs map[string]*NetDevEntry
|
||||
|
||||
@@ -57,6 +57,7 @@ func (self *nodeYaml) NodeUpdate(node NodeInfo) error {
|
||||
self.Nodes[nodeID].ContainerName = node.ContainerName.GetReal()
|
||||
self.Nodes[nodeID].ClusterName = node.ClusterName.GetReal()
|
||||
self.Nodes[nodeID].Ipxe = node.Ipxe.GetReal()
|
||||
self.Nodes[nodeID].Init = node.Init.GetReal()
|
||||
self.Nodes[nodeID].KernelVersion = node.KernelVersion.GetReal()
|
||||
self.Nodes[nodeID].KernelArgs = node.KernelArgs.GetReal()
|
||||
self.Nodes[nodeID].IpmiIpaddr = node.IpmiIpaddr.GetReal()
|
||||
@@ -127,6 +128,7 @@ func (self *nodeYaml) ProfileUpdate(profile NodeInfo) error {
|
||||
self.NodeProfiles[profileID].Comment = profile.Comment.GetReal()
|
||||
self.NodeProfiles[profileID].ContainerName = profile.ContainerName.GetReal()
|
||||
self.NodeProfiles[profileID].Ipxe = profile.Ipxe.GetReal()
|
||||
self.NodeProfiles[profileID].Init = profile.Init.GetReal()
|
||||
self.NodeProfiles[profileID].ClusterName = profile.ClusterName.GetReal()
|
||||
self.NodeProfiles[profileID].KernelVersion = profile.KernelVersion.GetReal()
|
||||
self.NodeProfiles[profileID].KernelArgs = profile.KernelArgs.GetReal()
|
||||
|
||||
@@ -22,6 +22,7 @@ type TemplateStruct struct {
|
||||
Hostname string
|
||||
GroupName string
|
||||
Container string
|
||||
Init string
|
||||
IpmiIpaddr string
|
||||
IpmiNetmask string
|
||||
IpmiUserName string
|
||||
@@ -132,6 +133,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
|
||||
t.Id = n.Id.Get()
|
||||
t.Hostname = n.Id.Get()
|
||||
t.Container = n.ContainerName.Get()
|
||||
t.Init = n.Init.Get()
|
||||
t.IpmiIpaddr = n.IpmiIpaddr.Get()
|
||||
t.IpmiNetmask = n.IpmiNetmask.Get()
|
||||
t.IpmiUserName = n.IpmiUserName.Get()
|
||||
|
||||
Reference in New Issue
Block a user