Read the defaults for anode from defaults.conf
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,6 +16,7 @@
|
||||
/wwapic
|
||||
/wwapid
|
||||
/wwapird
|
||||
/print_defaults
|
||||
|
||||
# other created files
|
||||
/man_pages
|
||||
|
||||
7
Makefile
7
Makefile
@@ -95,7 +95,7 @@ export GOPROXY
|
||||
# built tags needed for wwbuild binary
|
||||
WW_GO_BUILD_TAGS := containers_image_openpgp containers_image_ostree
|
||||
|
||||
all: config vendor wwctl wwclient bash_completion.d man_pages config_defaults wwapid wwapic wwapird
|
||||
all: config vendor wwctl wwclient bash_completion.d man_pages config_defaults print_defaults wwapid wwapic wwapird
|
||||
|
||||
build: lint test-it vet all
|
||||
|
||||
@@ -174,6 +174,7 @@ files: all
|
||||
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/wwapic.conf || install -m 644 etc/wwapic.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
|
||||
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/wwapid.conf || install -m 644 etc/wwapid.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
|
||||
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/wwapird.conf || install -m 644 etc/wwapird.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
|
||||
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/defaults.conf || ./print_defaults > $(DESTDIR)$(SYSCONFDIR)/warewulf/defaults.conf
|
||||
cp -r etc/examples $(DESTDIR)$(WWCONFIGDIR)/
|
||||
cp -r etc/ipxe $(DESTDIR)$(WWCONFIGDIR)/
|
||||
cp -r overlays/* $(DESTDIR)$(WWOVERLAYDIR)/
|
||||
@@ -237,6 +238,9 @@ config_defaults: vendor cmd/config_defaults/config_defaults.go
|
||||
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
|
||||
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../config_defaults
|
||||
|
||||
print_defaults: vendor cmd/print_defaults/print_defaults.go
|
||||
cd cmd/print_defaults && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'" -o ../../print_defaults
|
||||
|
||||
update_configuration: vendor cmd/update_configuration/update_configuration.go
|
||||
cd cmd/update_configuration && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
|
||||
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
|
||||
@@ -297,6 +301,7 @@ clean:
|
||||
rm -rf $(TOOLS_DIR)
|
||||
rm -f config_defaults
|
||||
rm -f update_configuration
|
||||
rm -f print_defaults
|
||||
|
||||
install: files install_wwclient
|
||||
|
||||
|
||||
17
cmd/print_defaults/print_defaults.go
Normal file
17
cmd/print_defaults/print_defaults.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
)
|
||||
|
||||
/*
|
||||
Print the build in defaults for the nodes.
|
||||
Called via Makefile so that there is single upstream
|
||||
source of the defaults which is FallBackConf
|
||||
*/
|
||||
|
||||
func main() {
|
||||
fmt.Println(node.FallBackConf)
|
||||
}
|
||||
@@ -14,11 +14,28 @@ import (
|
||||
)
|
||||
|
||||
var ConfigFile string
|
||||
var DefaultConfig string
|
||||
|
||||
// used as fallback if DefaultConfig can't be read
|
||||
var FallBackConf = `
|
||||
runtime overlay:
|
||||
- generic
|
||||
system overlay:
|
||||
- wwinit
|
||||
kernel:
|
||||
args: quiet crashkernel=no vga=791
|
||||
init: /sbin/init
|
||||
root: initramfs
|
||||
profiles:
|
||||
- default`
|
||||
|
||||
func init() {
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/nodes.conf")
|
||||
}
|
||||
if DefaultConfig == "" {
|
||||
DefaultConfig = path.Join(buildconfig.SYSCONFDIR(), "warewulf/defaults.conf")
|
||||
}
|
||||
}
|
||||
|
||||
func New() (NodeYaml, error) {
|
||||
@@ -54,6 +71,27 @@ func (config *NodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
return ret, err
|
||||
}
|
||||
*/
|
||||
var defConf NodeConf
|
||||
readBuildin := false
|
||||
wwlog.Verbose("Opening defaults failed %s\n", DefaultConfig)
|
||||
defData, err := ioutil.ReadFile(DefaultConfig)
|
||||
if err != nil {
|
||||
wwlog.Verbose("Couldn't read DefaultConfig :%s\n", err)
|
||||
}
|
||||
wwlog.Debug("Unmarshalling default config\n")
|
||||
err = yaml.Unmarshal(defData, &defConf)
|
||||
if err != nil {
|
||||
readBuildin = true
|
||||
wwlog.Verbose("Couldn't unmarshall defaults from file :%s\n", err)
|
||||
}
|
||||
if readBuildin {
|
||||
wwlog.Verbose("Using building defaults")
|
||||
err = yaml.Unmarshal([]byte(FallBackConf), &defConf)
|
||||
if err != nil {
|
||||
wwlog.Warn("Could not get any defaults")
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Debug("Finding all nodes...\n")
|
||||
for nodename, node := range config.Nodes {
|
||||
var n NodeInfo
|
||||
@@ -63,13 +101,7 @@ func (config *NodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.Tags = make(map[string]*Entry)
|
||||
n.Kernel = new(KernelEntry)
|
||||
n.Ipmi = new(IpmiEntry)
|
||||
n.SystemOverlay.SetDefault("wwinit")
|
||||
n.RuntimeOverlay.SetDefault("generic")
|
||||
n.Ipxe.SetDefault("default")
|
||||
n.Init.SetDefault("/sbin/init")
|
||||
n.Root.SetDefault("initramfs")
|
||||
n.Kernel.Args.SetDefault("quiet crashkernel=no vga=791")
|
||||
|
||||
n.SetDefFrom(&defConf)
|
||||
fullname := strings.SplitN(nodename, ".", 2)
|
||||
if len(fullname) > 1 {
|
||||
n.ClusterName.SetDefault(fullname[1])
|
||||
@@ -80,9 +112,9 @@ func (config *NodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
} else {
|
||||
n.Profiles.SetSlice(node.Profiles)
|
||||
}
|
||||
// node explciti nodename field in NodeConf
|
||||
// node explicitly nodename field in NodeConf
|
||||
n.Id.Set(nodename)
|
||||
// backward compatibilty
|
||||
// backward compatibility
|
||||
for keyname, key := range node.Keys {
|
||||
node.Tags[keyname] = key
|
||||
delete(node.Keys, keyname)
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
/******
|
||||
* YAML data representations
|
||||
******/
|
||||
@@ -163,6 +158,8 @@ type NetDevEntry struct {
|
||||
// string which is printed if no value is set
|
||||
const NoValue = "--"
|
||||
|
||||
/*
|
||||
Has no real purpose as only New() needs it
|
||||
func init() {
|
||||
// Check that nodes.conf is found
|
||||
if !util.IsFile(ConfigFile) {
|
||||
@@ -171,3 +168,4 @@ func init() {
|
||||
return
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -303,6 +303,20 @@ func (node *NodeInfo) SetAltFrom(n *NodeConf, profileName string) {
|
||||
node.setterFrom(n, profileName, (*Entry).SetAlt, (*Entry).SetAltSlice)
|
||||
}
|
||||
|
||||
/*
|
||||
Populates all fields of NodeInfo with SetDefault from the
|
||||
values of NodeConf.
|
||||
*/
|
||||
func (node *NodeInfo) SetDefFrom(n *NodeConf) {
|
||||
setWrap := func(entr *Entry, val string, nameArg string) {
|
||||
entr.SetDefault(val)
|
||||
}
|
||||
setSliceWrap := func(entr *Entry, val []string, nameArg string) {
|
||||
entr.SetDefaultSlice(val)
|
||||
}
|
||||
node.setterFrom(n, "", setWrap, setSliceWrap)
|
||||
}
|
||||
|
||||
/*
|
||||
Abstract function which populates a NodeInfo from a NodeConf via
|
||||
setter functionns.
|
||||
|
||||
Reference in New Issue
Block a user