Merge pull request #1595 from anderbubble/removeInit
Configure nodes.conf dynamically from config
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -31,17 +30,10 @@ Simple check if the config can be written in case wwctl isn't run as root
|
||||
*/
|
||||
func CanWriteConfig() (canwrite *wwapiv1.CanWriteConfig, err error) {
|
||||
canwrite = new(wwapiv1.CanWriteConfig)
|
||||
// node is not initialized yet
|
||||
if node.ConfigFile == "" {
|
||||
_, err := node.New()
|
||||
if err != nil {
|
||||
canwrite.CanWriteConfig = false
|
||||
return canwrite, fmt.Errorf("unable to initialize the node %w", err)
|
||||
}
|
||||
}
|
||||
err = syscall.Access(node.ConfigFile, syscall.O_RDWR)
|
||||
nodesConf := config.Get().Paths.NodesConf()
|
||||
err = syscall.Access(nodesConf, syscall.O_RDWR)
|
||||
if err != nil {
|
||||
wwlog.Warn("Couldn't open %s:%s", node.ConfigFile, err)
|
||||
wwlog.Warn("Couldn't open %s:%s", nodesConf, err)
|
||||
canwrite.CanWriteConfig = false
|
||||
} else {
|
||||
canwrite.CanWriteConfig = true
|
||||
|
||||
@@ -71,6 +71,10 @@ func (this WarewulfConf) GrubBoot() bool {
|
||||
return util.BoolP(this.GrubBootP)
|
||||
}
|
||||
|
||||
func (paths BuildConfig) NodesConf() string {
|
||||
return path.Join(paths.Sysconfdir, "warewulf", "nodes.conf")
|
||||
}
|
||||
|
||||
func (paths BuildConfig) OciBlobCachedir() string {
|
||||
return path.Join(paths.Cachedir, "warewulf")
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
"dario.cat/mergo"
|
||||
@@ -14,23 +13,13 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigFile string
|
||||
)
|
||||
|
||||
func init() {
|
||||
conf := warewulfconf.Get()
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(conf.Paths.Sysconfdir, "warewulf/nodes.conf")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Creates a new nodeDb object from the on-disk configuration
|
||||
*/
|
||||
func New() (NodesYaml, error) {
|
||||
wwlog.Verbose("Opening node configuration file: %s", ConfigFile)
|
||||
data, err := os.ReadFile(ConfigFile)
|
||||
nodesConf := warewulfconf.Get().Paths.NodesConf()
|
||||
wwlog.Verbose("Opening node configuration file: %s", nodesConf)
|
||||
data, err := os.ReadFile(nodesConf)
|
||||
if err != nil {
|
||||
return NodesYaml{}, err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -109,12 +110,12 @@ func (config *NodesYaml) DelProfile(nodeID string) error {
|
||||
Write the the NodeYaml to disk.
|
||||
*/
|
||||
func (config *NodesYaml) Persist() error {
|
||||
return config.PersistToFile(ConfigFile)
|
||||
return config.PersistToFile(warewulfconf.Get().Paths.NodesConf())
|
||||
}
|
||||
|
||||
func (config *NodesYaml) PersistToFile(configFile string) error {
|
||||
if configFile == "" {
|
||||
configFile = ConfigFile
|
||||
configFile = warewulfconf.Get().Paths.NodesConf()
|
||||
}
|
||||
out, dumpErr := config.Dump()
|
||||
if dumpErr != nil {
|
||||
|
||||
@@ -12,10 +12,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
)
|
||||
|
||||
const initWarewulfConf = ``
|
||||
@@ -61,7 +60,7 @@ func New(t *testing.T) (env *TestEnv) {
|
||||
env.WriteFile(t, path.Join(Sysconfdir, "warewulf/warewulf.conf"), initWarewulfConf)
|
||||
|
||||
// re-read warewulf.conf
|
||||
conf := warewulfconf.New()
|
||||
conf := config.New()
|
||||
err = conf.Read(env.GetPath(path.Join(Sysconfdir, "warewulf/warewulf.conf")))
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -95,9 +94,6 @@ func New(t *testing.T) (env *TestEnv) {
|
||||
env.MkdirAll(t, confPath)
|
||||
}
|
||||
|
||||
// node.init() has already run, so set the config path again
|
||||
node.ConfigFile = env.GetPath(path.Join(Sysconfdir, "warewulf/nodes.conf"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
nodepkg "github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
@@ -51,7 +51,7 @@ func getOverlayFile(n node.Node, context string, stage_overlays []string, autobu
|
||||
build := !util.IsFile(stage_file)
|
||||
wwlog.Verbose("stage file: %s", stage_file)
|
||||
if !build && autobuild {
|
||||
build = util.PathIsNewer(stage_file, nodepkg.ConfigFile)
|
||||
build = util.PathIsNewer(stage_file, config.Get().Paths.NodesConf())
|
||||
|
||||
for _, overlayname := range stage_overlays {
|
||||
build = build || util.PathIsNewer(stage_file, overlay.OverlaySourceDir(overlayname))
|
||||
|
||||
Reference in New Issue
Block a user