make the configuration to be based in warewulf.conf
defaults will be se by the Makefile Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
package buildconfig
|
||||
|
||||
import "github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
|
||||
const WWVer = 43
|
||||
|
||||
var (
|
||||
bindir string = "UNDEF"
|
||||
sysconfdir string = "UNDEF"
|
||||
localstatedir string = "UNDEF"
|
||||
srvdir string = "UNDEF"
|
||||
tftpdir string = "UNDEF"
|
||||
firewallddir string = "UNDEF"
|
||||
systemddir string = "UNDEF"
|
||||
wwoverlaydir string = "UNDEF"
|
||||
wwchrootdir string = "UNDEF"
|
||||
wwprovisiondir string = "UNDEF"
|
||||
version string = "UNDEF"
|
||||
release string = "UNDEF"
|
||||
wwclientdir string = "UNDEF"
|
||||
datadir string = "UNDEF"
|
||||
tmpdir string = "UNDEF"
|
||||
)
|
||||
|
||||
func BINDIR() string {
|
||||
wwlog.Debug("BINDIR = '%s'", bindir)
|
||||
return bindir
|
||||
}
|
||||
|
||||
func DATADIR() string {
|
||||
wwlog.Debug("DATADIR = '%s'", datadir)
|
||||
return datadir
|
||||
}
|
||||
|
||||
func SYSCONFDIR() string {
|
||||
wwlog.Debug("SYSCONFDIR = '%s'", sysconfdir)
|
||||
return sysconfdir
|
||||
}
|
||||
|
||||
func LOCALSTATEDIR() string {
|
||||
wwlog.Debug("LOCALSTATEDIR = '%s'", localstatedir)
|
||||
return localstatedir
|
||||
}
|
||||
|
||||
func SRVDIR() string {
|
||||
wwlog.Debug("SRVDIR = '%s'", srvdir)
|
||||
return srvdir
|
||||
}
|
||||
|
||||
func TFTPDIR() string {
|
||||
wwlog.Debug("TFTPDIR = '%s'", tftpdir)
|
||||
return tftpdir
|
||||
}
|
||||
|
||||
func FIREWALLDDIR() string {
|
||||
wwlog.Debug("FIREWALLDDIR = '%s'", firewallddir)
|
||||
return firewallddir
|
||||
}
|
||||
|
||||
func SYSTEMDDIR() string {
|
||||
wwlog.Debug("SYSTEMDDIR = '%s'", systemddir)
|
||||
return systemddir
|
||||
}
|
||||
|
||||
func WWOVERLAYDIR() string {
|
||||
wwlog.Debug("WWOVERLAYDIR = '%s'", wwoverlaydir)
|
||||
return wwoverlaydir
|
||||
}
|
||||
|
||||
func WWCHROOTDIR() string {
|
||||
wwlog.Debug("WWCHROOTDIR = '%s'", wwchrootdir)
|
||||
return wwchrootdir
|
||||
}
|
||||
|
||||
func WWPROVISIONDIR() string {
|
||||
wwlog.Debug("WWPROVISIONDIR = '%s'", wwprovisiondir)
|
||||
return wwprovisiondir
|
||||
}
|
||||
|
||||
func VERSION() string {
|
||||
wwlog.Debug("VERSION = '%s'", version)
|
||||
return version
|
||||
}
|
||||
|
||||
func RELEASE() string {
|
||||
wwlog.Debug("RELEASE = '%s'", release)
|
||||
return release
|
||||
}
|
||||
|
||||
func WWCLIENTDIR() string {
|
||||
wwlog.Debug("WWCLIENTDIR = '%s'", wwclientdir)
|
||||
return wwclientdir
|
||||
}
|
||||
|
||||
func TMPDIR() string {
|
||||
wwlog.Debug("TMPDIR = '%s'", tmpdir)
|
||||
return tmpdir
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package buildconfig
|
||||
|
||||
func init() {
|
||||
bindir = "@BINDIR@"
|
||||
sysconfdir = "@SYSCONFDIR@"
|
||||
datadir = "@DATADIR@"
|
||||
localstatedir = "@LOCALSTATEDIR@"
|
||||
srvdir = "@SRVDIR@"
|
||||
tftpdir = "@TFTPDIR@"
|
||||
firewallddir = "@FIREWALLDDIR@"
|
||||
systemddir = "@SYSTEMDDIR@"
|
||||
wwoverlaydir = "@WWOVERLAYDIR@"
|
||||
wwchrootdir = "@WWCHROOTDIR@"
|
||||
wwprovisiondir = "@WWPROVISIONDIR@"
|
||||
version = "@VERSION@"
|
||||
release = "@RELEASE@"
|
||||
wwclientdir = "@WWCLIENTDIR@"
|
||||
tmpdir = "@TMPDIR@"
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
func SSH() error {
|
||||
if os.Getuid() == 0 {
|
||||
fmt.Printf("Updating system keys\n")
|
||||
conf := warewulfconf.New()
|
||||
wwkeydir := path.Join(conf.SYSCONFDIR(), "warewulf/keys") + "/"
|
||||
|
||||
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys") + "/"
|
||||
|
||||
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys"), 0755)
|
||||
err := os.MkdirAll(path.Join(conf.SYSCONFDIR(), "warewulf/keys"), 0755)
|
||||
if err != nil {
|
||||
wwlog.Error("Could not create base directory: %s", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -5,15 +5,14 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func TFTP() error {
|
||||
var tftpdir string = path.Join(buildconfig.TFTPDIR(), "warewulf")
|
||||
controller := warewulfconf.New()
|
||||
var tftpdir string = path.Join(controller.TFTPDIR(), "warewulf")
|
||||
|
||||
err := os.MkdirAll(tftpdir, 0755)
|
||||
if err != nil {
|
||||
@@ -28,7 +27,7 @@ func TFTP() error {
|
||||
continue
|
||||
}
|
||||
copyCheck[f] = true
|
||||
err = util.SafeCopyFile(path.Join(buildconfig.DATADIR(), f), path.Join(tftpdir, f))
|
||||
err = util.SafeCopyFile(path.Join(controller.DATADIR(), f), path.Join(tftpdir, f))
|
||||
if err != nil {
|
||||
wwlog.Warn("ipxe binary could not be copied, booting may not work: %s", err)
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@ package container
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
)
|
||||
|
||||
func SourceParentDir() string {
|
||||
return buildconfig.WWCHROOTDIR()
|
||||
conf := warewulfconf.New()
|
||||
return conf.WWCHROOTDIR()
|
||||
}
|
||||
|
||||
func SourceDir(name string) string {
|
||||
@@ -19,7 +20,8 @@ func RootFsDir(name string) string {
|
||||
}
|
||||
|
||||
func ImageParentDir() string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR(), "container/")
|
||||
conf := warewulfconf.New()
|
||||
return path.Join(conf.WWPROVISIONDIR(), "container/")
|
||||
}
|
||||
|
||||
func ImageFile(name string) string {
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,8 @@ var (
|
||||
)
|
||||
|
||||
func KernelImageTopDir() string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR(), "kernel")
|
||||
conf := warewulfconf.New()
|
||||
return path.Join(conf.WWPROVISIONDIR(), "kernel")
|
||||
}
|
||||
|
||||
func KernelImage(kernelName string) string {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -37,11 +37,12 @@ defaultnode:
|
||||
netmask: 255.255.255.0`
|
||||
|
||||
func init() {
|
||||
conf := warewulfconf.New()
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/nodes.conf")
|
||||
ConfigFile = path.Join(conf.SYSCONFDIR(), "warewulf/nodes.conf")
|
||||
}
|
||||
if DefaultConfig == "" {
|
||||
DefaultConfig = path.Join(buildconfig.SYSCONFDIR(), "warewulf/defaults.conf")
|
||||
DefaultConfig = path.Join(conf.SYSCONFDIR(), "warewulf/defaults.conf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
)
|
||||
|
||||
func OverlaySourceTopDir() string {
|
||||
return buildconfig.WWOVERLAYDIR()
|
||||
conf := warewulfconf.New()
|
||||
return conf.WWOVERLAYDIR()
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -30,5 +31,6 @@ func OverlaySourceDir(overlayName string) string {
|
||||
Returns the overlay name of the image for a given node
|
||||
*/
|
||||
func OverlayImage(nodeName string, overlayName []string) string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR(), "overlays/", nodeName, strings.Join(overlayName, "-")+".img")
|
||||
conf := warewulfconf.New()
|
||||
return path.Join(conf.WWPROVISIONDIR(), "overlays/", nodeName, strings.Join(overlayName, "-")+".img")
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -18,8 +18,9 @@ the path is relative to SYSCONFDIR.
|
||||
Templates in the file are no evaluated.
|
||||
*/
|
||||
func templateFileInclude(inc string) string {
|
||||
conf := warewulfconf.New()
|
||||
if !strings.HasPrefix(inc, "/") {
|
||||
inc = path.Join(buildconfig.SYSCONFDIR(), "warewulf", inc)
|
||||
inc = path.Join(conf.SYSCONFDIR(), "warewulf", inc)
|
||||
}
|
||||
wwlog.Debug("Including file into template: %s", inc)
|
||||
content, err := os.ReadFile(inc)
|
||||
@@ -35,8 +36,9 @@ is the file to read, the second the abort string
|
||||
Templates in the file are no evaluated.
|
||||
*/
|
||||
func templateFileBlock(inc string, abortStr string) (string, error) {
|
||||
conf := warewulfconf.New()
|
||||
if !strings.HasPrefix(inc, "/") {
|
||||
inc = path.Join(buildconfig.SYSCONFDIR(), "warewulf", inc)
|
||||
inc = path.Join(conf.SYSCONFDIR(), "warewulf", inc)
|
||||
}
|
||||
wwlog.Debug("Including file block into template: %s", inc)
|
||||
readFile, err := os.Open(inc)
|
||||
|
||||
@@ -4,14 +4,15 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
)
|
||||
|
||||
/*
|
||||
Return the version of wwctl
|
||||
*/
|
||||
func GetVersion() string {
|
||||
return fmt.Sprintf("%s-%s", buildconfig.VERSION(), buildconfig.RELEASE())
|
||||
conf := warewulfconf.New()
|
||||
return fmt.Sprintf("%s-%s", conf.VERSION(), conf.RELEASE())
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
18
internal/pkg/warewulfconf/buildconfig.go.in
Normal file
18
internal/pkg/warewulfconf/buildconfig.go.in
Normal file
@@ -0,0 +1,18 @@
|
||||
package warewulfconf
|
||||
|
||||
type BuildConfig struct {
|
||||
bindir string `default:"@BINDIR@"`
|
||||
sysconfdir string `default:"@SYSCONFDIR@"`
|
||||
datadir string `default:"@DATADIR@"`
|
||||
localstatedir string `default:"@LOCALSTATEDIR@"`
|
||||
srvdir string `default:"@SRVDIR@"`
|
||||
tftpdir string `default:"@TFTPDIR@"`
|
||||
firewallddir string `default:"@FIREWALLDDIR@"`
|
||||
systemddir string `default:"@SYSTEMDDIR@"`
|
||||
wwoverlaydir string `default:"@WWOVERLAYDIR@"`
|
||||
wwchrootdir string `default:"@WWCHROOTDIR@"`
|
||||
wwprovisiondir string `default:"@WWPROVISIONDIR@"`
|
||||
version string `default:"@VERSION@"`
|
||||
release string `default:"@RELEASE@"`
|
||||
wwclientdir string `default:"@WWCLIENTDIR@"`
|
||||
}
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/brotherpowers/ipsubnet"
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
@@ -18,18 +16,6 @@ var cachedConf ControllerConf
|
||||
|
||||
var ConfigFile string
|
||||
|
||||
/*
|
||||
Get the configFile location from the os.ev if set
|
||||
*/
|
||||
func init() {
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = os.Getenv("WARWULFCONF")
|
||||
}
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/warewulf.conf")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Creates a new empty ControllerConf object, returns a cached
|
||||
one if called in a nother context.
|
||||
@@ -42,10 +28,9 @@ func New() (ret ControllerConf) {
|
||||
ret.Dhcp = new(DhcpConf)
|
||||
ret.Tftp = new(TftpConf)
|
||||
ret.Nfs = new(NfsConf)
|
||||
err := defaults.Set(&ret)
|
||||
if err != nil {
|
||||
ret.setDynamicDefaults()
|
||||
}
|
||||
ret.Paths = new(BuildConfig)
|
||||
_ = defaults.Set(&ret)
|
||||
ret.setDynamicDefaults()
|
||||
|
||||
cachedConf = ret
|
||||
cachedConf.current = true
|
||||
|
||||
@@ -18,6 +18,7 @@ type ControllerConf struct {
|
||||
Tftp *TftpConf `yaml:"tftp"`
|
||||
Nfs *NfsConf `yaml:"nfs"`
|
||||
MountsContainer []*MountEntry `yaml:"container mounts" default:"[{\"source\": \"/etc/resolv.conf\", \"dest\": \"/etc/resolv.conf\"}]"`
|
||||
Paths *BuildConfig `yaml:"mypaths"`
|
||||
current bool
|
||||
}
|
||||
|
||||
|
||||
73
internal/pkg/warewulfconf/getter.go
Normal file
73
internal/pkg/warewulfconf/getter.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package warewulfconf
|
||||
|
||||
import "github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
|
||||
func (conf *ControllerConf) BINDIR() string {
|
||||
wwlog.Debug("BINDIR = '%s'", conf.Paths.bindir)
|
||||
return conf.Paths.bindir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) DATADIR() string {
|
||||
wwlog.Debug("DATADIR = '%s'", conf.Paths.datadir)
|
||||
return conf.Paths.datadir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) SYSCONFDIR() string {
|
||||
wwlog.Debug("SYSCONFDIR = '%s'", conf.Paths.sysconfdir)
|
||||
return conf.Paths.sysconfdir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) LOCALSTATEDIR() string {
|
||||
wwlog.Debug("LOCALSTATEDIR = '%s'", conf.Paths.localstatedir)
|
||||
return conf.Paths.localstatedir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) SRVDIR() string {
|
||||
wwlog.Debug("SRVDIR = '%s'", conf.Paths.srvdir)
|
||||
return conf.Paths.srvdir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) TFTPDIR() string {
|
||||
wwlog.Debug("TFTPDIR = '%s'", conf.Paths.tftpdir)
|
||||
return conf.Paths.tftpdir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) FIREWALLDDIR() string {
|
||||
wwlog.Debug("FIREWALLDDIR = '%s'", conf.Paths.firewallddir)
|
||||
return conf.Paths.firewallddir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) SYSTEMDDIR() string {
|
||||
wwlog.Debug("SYSTEMDDIR = '%s'", conf.Paths.systemddir)
|
||||
return conf.Paths.systemddir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) WWOVERLAYDIR() string {
|
||||
wwlog.Debug("WWOVERLAYDIR = '%s'", conf.Paths.wwoverlaydir)
|
||||
return conf.Paths.wwoverlaydir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) WWCHROOTDIR() string {
|
||||
wwlog.Debug("WWCHROOTDIR = '%s'", conf.Paths.wwchrootdir)
|
||||
return conf.Paths.wwchrootdir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) WWPROVISIONDIR() string {
|
||||
wwlog.Debug("WWPROVISIONDIR = '%s'", conf.Paths.wwprovisiondir)
|
||||
return conf.Paths.wwprovisiondir
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) VERSION() string {
|
||||
wwlog.Debug("VERSION = '%s'", conf.Paths.version)
|
||||
return conf.Paths.version
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) RELEASE() string {
|
||||
wwlog.Debug("RELEASE = '%s'", conf.Paths.release)
|
||||
return conf.Paths.release
|
||||
}
|
||||
|
||||
func (conf *ControllerConf) WWCLIENTDIR() string {
|
||||
wwlog.Debug("WWCLIENTDIR = '%s'", conf.Paths.wwclientdir)
|
||||
return conf.Paths.wwclientdir
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
"text/template"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
@@ -80,13 +79,13 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
|
||||
if !node.Id.Defined() {
|
||||
wwlog.Error("%s (unknown/unconfigured node)", rinfo.hwaddr)
|
||||
if rinfo.stage == "ipxe" {
|
||||
stage_file = path.Join(buildconfig.SYSCONFDIR(), "/warewulf/ipxe/unconfigured.ipxe")
|
||||
stage_file = path.Join(conf.SYSCONFDIR(), "/warewulf/ipxe/unconfigured.ipxe")
|
||||
tmpl_data = iPxeTemplate{
|
||||
Hwaddr: rinfo.hwaddr}
|
||||
}
|
||||
|
||||
} else if rinfo.stage == "ipxe" {
|
||||
stage_file = path.Join(buildconfig.SYSCONFDIR(), "warewulf/ipxe/"+node.Ipxe.Get()+".ipxe")
|
||||
stage_file = path.Join(conf.SYSCONFDIR(), "warewulf/ipxe/"+node.Ipxe.Get()+".ipxe")
|
||||
tmpl_data = iPxeTemplate{
|
||||
Id: node.Id.Get(),
|
||||
Cluster: node.ClusterName.Get(),
|
||||
|
||||
Reference in New Issue
Block a user