Initial wwctl upgrade command

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-11-05 12:03:03 -07:00
parent 336577c221
commit 981d11a012
5 changed files with 68 additions and 7 deletions

View File

@@ -18,14 +18,17 @@ var (
ConfigFile string
)
/*
Creates a new nodeDb object from the on-disk configuration
*/
func New() (NodesYaml, error) {
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)
if err != nil {

View File

@@ -109,12 +109,19 @@ func (config *NodesYaml) DelProfile(nodeID string) error {
Write the the NodeYaml to disk.
*/
func (config *NodesYaml) Persist() error {
return config.PersistToFile(ConfigFile)
}
func (config *NodesYaml) PersistToFile(configFile string) error {
if configFile == "" {
configFile = ConfigFile
}
out, dumpErr := config.Dump()
if dumpErr != nil {
wwlog.Error("%s", dumpErr)
return dumpErr
}
file, err := os.OpenFile(ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
file, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
wwlog.Error("%s", err)
return err
@@ -124,7 +131,7 @@ func (config *NodesYaml) Persist() error {
if err != nil {
return err
}
wwlog.Debug("persisted: %s", ConfigFile)
wwlog.Debug("persisted: %s", configFile)
return nil
}