Added a package for Warewulf config
This commit is contained in:
33
internal/pkg/warewulfconf/constructors.go
Normal file
33
internal/pkg/warewulfconf/constructors.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package warewulfconf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func New() (ControllerConf, error) {
|
||||
var ret ControllerConf
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Opening Warewulf configuration file: %s\n", ConfigFile)
|
||||
data, err := ioutil.ReadFile(ConfigFile)
|
||||
if err != nil {
|
||||
fmt.Printf("error reading node configuration file\n")
|
||||
return ret, err
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Unmarshaling the Warewulf configuration\n")
|
||||
err = yaml.Unmarshal(data, &ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
if ret.Warewulf.Port == 0 {
|
||||
ret.Warewulf.Port = 9873
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Returning node object\n")
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
59
internal/pkg/warewulfconf/datastructure.go
Normal file
59
internal/pkg/warewulfconf/datastructure.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package warewulfconf
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"os"
|
||||
)
|
||||
|
||||
const ConfigFile = "/etc/warewulf/warewulf.conf"
|
||||
|
||||
type ControllerConf struct {
|
||||
Comment string `yaml:"comment"`
|
||||
Ipaddr string `yaml:"ipaddr"`
|
||||
Netmask string `yaml:"netmask,omitempty"`
|
||||
Fqdn string `yaml:"fqdn,omitempty"`
|
||||
Warewulf *WarewulfConf `yaml:"warewulf"`
|
||||
Dhcp *DhcpConf `yaml:"dhcp"`
|
||||
Tftp *TftpConf `yaml:"tftp"`
|
||||
Nfs *NfsConf `yaml:"nfs"`
|
||||
}
|
||||
|
||||
type WarewulfConf struct {
|
||||
Port int `yaml:"port,omitempty"`
|
||||
Secure bool `yaml:"secure,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
}
|
||||
|
||||
type DhcpConf struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Template string `yaml:"template,omitempty"`
|
||||
RangeStart string `yaml:"range start,omitempty"`
|
||||
RangeEnd string `yaml:"range end,omitempty"`
|
||||
ConfigFile string `yaml:"config file,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
}
|
||||
|
||||
type TftpConf struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Root string `yaml:"root,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
}
|
||||
|
||||
type NfsConf struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Exports []string `yaml:"exports,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
//TODO: Check to make sure nodes.conf is found
|
||||
if util.IsFile(ConfigFile) == false {
|
||||
wwlog.Printf(wwlog.ERROR, "Configuration file not found: %s\n", ConfigFile)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
30
internal/pkg/warewulfconf/modifiers.go
Normal file
30
internal/pkg/warewulfconf/modifiers.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package warewulfconf
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"gopkg.in/yaml.v2"
|
||||
"os"
|
||||
)
|
||||
|
||||
func (self *ControllerConf) Persist() error {
|
||||
|
||||
out, err := yaml.Marshal(self)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
_, err = file.WriteString(string(out))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user