Extend and optimize relocatable build config infrastructure
This commit is contained in:
16
internal/pkg/buildconfig/buildconfig.go.in
Normal file
16
internal/pkg/buildconfig/buildconfig.go.in
Normal file
@@ -0,0 +1,16 @@
|
||||
package buildconfig
|
||||
|
||||
const (
|
||||
BINDIR = "@BINDIR@"
|
||||
SYSCONFDIR = "@SYSCONFDIR@"
|
||||
LOCALSTATEDIR = "@LOCALSTATEDIR@"
|
||||
SRVDIR = "@SRVDIR@"
|
||||
TFTPDIR = "@TFTPDIR@"
|
||||
FIREWALLDDIR = "@FIREWALLDDIR@"
|
||||
SYSTEMDDIR = "@SYSTEMDDIR@"
|
||||
WWOVERLAYDIR = "@WWOVERLAYDIR@"
|
||||
WWCHROOTDIR = "@WWCHROOTDIR@"
|
||||
WWPROVISIONDIR = "@WWPROVISIONDIR@"
|
||||
VERSION = "@VERSION@"
|
||||
RELEASE = "@RELEASE@"
|
||||
)
|
||||
27
internal/pkg/container/config.go
Normal file
27
internal/pkg/container/config.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
)
|
||||
|
||||
func SourceParentDir() string {
|
||||
return buildconfig.WWCHROOTDIR
|
||||
}
|
||||
|
||||
func SourceDir(name string) string {
|
||||
return path.Join(SourceParentDir(), name)
|
||||
}
|
||||
|
||||
func RootFsDir(name string) string {
|
||||
return path.Join(SourceDir(name), "rootfs")
|
||||
}
|
||||
|
||||
func ImageParentDir() string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR, "container/")
|
||||
}
|
||||
|
||||
func ImageFile(name string) string {
|
||||
return path.Join(ImageParentDir(), name+".img.gz")
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package container
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
@@ -20,26 +18,6 @@ func ValidName(name string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func SourceParentDir() string {
|
||||
return path.Join(warewulfconf.DataStore(), "chroots")
|
||||
}
|
||||
|
||||
func SourceDir(name string) string {
|
||||
return path.Join(SourceParentDir(), name)
|
||||
}
|
||||
|
||||
func RootFsDir(name string) string {
|
||||
return path.Join(SourceDir(name), "rootfs")
|
||||
}
|
||||
|
||||
func ImageParentDir() string {
|
||||
return path.Join(warewulfconf.DataStore(), "provision/container/")
|
||||
}
|
||||
|
||||
func ImageFile(name string) string {
|
||||
return path.Join(ImageParentDir(), name+".img.gz")
|
||||
}
|
||||
|
||||
func ListSources() ([]string, error) {
|
||||
var ret []string
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func ParentDir() string {
|
||||
return path.Join(warewulfconf.DataStore(), "provision/kernel")
|
||||
func KernelImageTopDir() string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR, "kernel")
|
||||
}
|
||||
|
||||
func KernelImage(kernelName string) string {
|
||||
@@ -41,7 +41,7 @@ func KernelImage(kernelName string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(ParentDir(), kernelName, "vmlinuz")
|
||||
return path.Join(KernelImageTopDir(), kernelName, "vmlinuz")
|
||||
}
|
||||
|
||||
func GetKernelVersion(kernelName string) string {
|
||||
@@ -49,7 +49,7 @@ func GetKernelVersion(kernelName string) string {
|
||||
wwlog.Printf(wwlog.ERROR, "Kernel Name is not defined\n")
|
||||
return ""
|
||||
}
|
||||
kernelVersion, err := ioutil.ReadFile(path.Join(ParentDir(), kernelName, "version"))
|
||||
kernelVersion, err := ioutil.ReadFile(KernelVersionFile(kernelName))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
@@ -67,10 +67,10 @@ func KmodsImage(kernelName string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(ParentDir(), kernelName, "kmods.img")
|
||||
return path.Join(KernelImageTopDir(), kernelName, "kmods.img")
|
||||
}
|
||||
|
||||
func KernelVersion(kernelName string) string {
|
||||
func KernelVersionFile(kernelName string) string {
|
||||
if kernelName == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Kernel Name is not defined\n")
|
||||
return ""
|
||||
@@ -81,20 +81,20 @@ func KernelVersion(kernelName string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(ParentDir(), kernelName, "version")
|
||||
return path.Join(KernelImageTopDir(), kernelName, "version")
|
||||
}
|
||||
|
||||
func ListKernels() ([]string, error) {
|
||||
var ret []string
|
||||
|
||||
err := os.MkdirAll(ParentDir(), 0755)
|
||||
err := os.MkdirAll(KernelImageTopDir(), 0755)
|
||||
if err != nil {
|
||||
return ret, errors.New("Could not create Kernel parent directory: " + ParentDir())
|
||||
return ret, errors.New("Could not create Kernel parent directory: " + KernelImageTopDir())
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Searching for Kernel image directories: %s\n", ParentDir())
|
||||
wwlog.Printf(wwlog.DEBUG, "Searching for Kernel image directories: %s\n", KernelImageTopDir())
|
||||
|
||||
kernels, err := ioutil.ReadDir(ParentDir())
|
||||
kernels, err := ioutil.ReadDir(KernelImageTopDir())
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
@@ -109,12 +109,12 @@ func ListKernels() ([]string, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func Build(kernelVersion string, kernelName string, root string) (string, error) {
|
||||
func Build(kernelVersion, kernelName, root string) (string, error) {
|
||||
kernelDrivers := path.Join(root, "/lib/modules/"+kernelVersion)
|
||||
kernelDriversRelative := path.Join("/lib/modules/"+kernelVersion)
|
||||
kernelDriversRelative := path.Join("/lib/modules/" + kernelVersion)
|
||||
kernelDestination := KernelImage(kernelName)
|
||||
driversDestination := KmodsImage(kernelName)
|
||||
versionDestination := KernelVersion(kernelName)
|
||||
versionDestination := KernelVersionFile(kernelName)
|
||||
var kernelSource string
|
||||
|
||||
// Create the destination paths just in case it doesn't exist
|
||||
@@ -223,7 +223,7 @@ func Build(kernelVersion string, kernelName string, root string) (string, error)
|
||||
}
|
||||
|
||||
func DeleteKernel(name string) error {
|
||||
fullPath := path.Join(ParentDir(), name)
|
||||
fullPath := path.Join(KernelImageTopDir(), name)
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Removing path: %s\n", fullPath)
|
||||
return os.RemoveAll(fullPath)
|
||||
|
||||
@@ -3,14 +3,23 @@ package node
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var ConfigFile = "/etc/warewulf/nodes.conf"
|
||||
var ConfigFile string
|
||||
|
||||
func init() {
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/nodes.conf")
|
||||
}
|
||||
}
|
||||
|
||||
func New() (nodeYaml, error) {
|
||||
var ret nodeYaml
|
||||
|
||||
@@ -3,13 +3,11 @@ package overlay
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
)
|
||||
|
||||
func OverlaySourceTopDir() string {
|
||||
return path.Join(warewulfconf.DataStore(), "overlays/")
|
||||
return buildconfig.WWOVERLAYDIR
|
||||
}
|
||||
|
||||
func OverlaySourceDir(overlayName string) string {
|
||||
@@ -17,68 +15,5 @@ func OverlaySourceDir(overlayName string) string {
|
||||
}
|
||||
|
||||
func OverlayImage(nodeName string, overlayName string) string {
|
||||
return path.Join(warewulfconf.DataStore(), "/provision/overlays/", nodeName, overlayName + ".img")
|
||||
}
|
||||
func SystemOverlayDir() string {
|
||||
return path.Join(OverlaySourceTopDir(), "/system")
|
||||
}
|
||||
|
||||
func RuntimeOverlayDir() string {
|
||||
return path.Join(OverlaySourceTopDir(), "/runtime")
|
||||
}
|
||||
|
||||
func SystemOverlaySource(overlayName string) string {
|
||||
if overlayName == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "System overlay name is not defined\n")
|
||||
return ""
|
||||
}
|
||||
|
||||
if !util.ValidString(overlayName, "^[a-zA-Z0-9-._]+$") {
|
||||
wwlog.Printf(wwlog.ERROR, "System overlay name contains illegal characters: %s\n", overlayName)
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(SystemOverlayDir(), overlayName)
|
||||
}
|
||||
|
||||
func RuntimeOverlaySource(overlayName string) string {
|
||||
if overlayName == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Runtime overlay name is not defined\n")
|
||||
return ""
|
||||
}
|
||||
|
||||
if !util.ValidString(overlayName, "^[a-zA-Z0-9-._]+$") {
|
||||
wwlog.Printf(wwlog.ERROR, "Runtime overlay name contains illegal characters: %s\n", overlayName)
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(RuntimeOverlayDir(), overlayName)
|
||||
}
|
||||
|
||||
func SystemOverlayImage(nodeName string) string {
|
||||
if nodeName == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Node name is not defined\n")
|
||||
return ""
|
||||
}
|
||||
|
||||
if !util.ValidString(nodeName, "^[a-zA-Z0-9-._:]+$") {
|
||||
wwlog.Printf(wwlog.ERROR, "System overlay name contains illegal characters: %s\n", nodeName)
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(warewulfconf.DataStore(), "/provision/overlays/runtime/", nodeName + ".img")
|
||||
}
|
||||
|
||||
func RuntimeOverlayImage(nodeName string) string {
|
||||
if nodeName == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Node name is not defined\n")
|
||||
return ""
|
||||
}
|
||||
|
||||
if !util.ValidString(nodeName, "^[a-zA-Z0-9-._:]+$") {
|
||||
wwlog.Printf(wwlog.ERROR, "System overlay name contains illegal characters: %s\n", nodeName)
|
||||
return ""
|
||||
}
|
||||
|
||||
return path.Join(warewulfconf.DataStore(), "/provision/overlays/system/", nodeName + ".img")
|
||||
return path.Join(buildconfig.WWPROVISIONDIR, "overlays/", nodeName, overlayName+".img")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package version
|
||||
|
||||
var Version string = "development"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
)
|
||||
|
||||
func GetVersion() string {
|
||||
return Version
|
||||
return fmt.Sprintf("%s-%s", buildconfig.VERSION, buildconfig.RELEASE)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package warewulfconf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"errors"
|
||||
"path"
|
||||
|
||||
"github.com/brotherpowers/ipsubnet"
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -14,6 +16,14 @@ import (
|
||||
|
||||
var cachedConf ControllerConf
|
||||
|
||||
var ConfigFile string
|
||||
|
||||
func init() {
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/warewulf.conf")
|
||||
}
|
||||
}
|
||||
|
||||
func New() (ControllerConf, error) {
|
||||
var ret ControllerConf = *defaultConfig()
|
||||
|
||||
@@ -32,8 +42,8 @@ func New() (ControllerConf, error) {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// TODO: Need to add comprehensive config file validator
|
||||
// TODO: Change function to guess default IP address and/or mask from local system
|
||||
// TODO: Need to add comprehensive config file validator
|
||||
// TODO: Change function to guess default IP address and/or mask from local system
|
||||
if ret.Ipaddr == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "IP address is not configured in warewulfd.conf\n")
|
||||
return ret, errors.New("no IP Address")
|
||||
@@ -63,7 +73,7 @@ func New() (ControllerConf, error) {
|
||||
|
||||
} else {
|
||||
wwlog.Printf(wwlog.DEBUG, "Returning cached warewulf config object\n")
|
||||
// If cached struct isn't empty, use it as the return value
|
||||
// If cached struct isn't empty, use it as the return value
|
||||
ret = cachedConf
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package warewulfconf
|
||||
|
||||
const defaultPort int = 9983
|
||||
const defaultPort int = 9983
|
||||
|
||||
var (
|
||||
ConfigFile string = "/etc/warewulf/warewulf.conf"
|
||||
defaultDataStore string = "/var/lib/warewulf"
|
||||
)
|
||||
var defaultDataStore string = "/var/lib/warewulf"
|
||||
|
||||
func defaultConfig() *ControllerConf {
|
||||
Warewulf := &WarewulfConf{
|
||||
@@ -30,8 +27,8 @@ func defaultConfig() *ControllerConf {
|
||||
SystemdName: "tftp",
|
||||
}
|
||||
Nfs := &NfsConf{
|
||||
Enabled: true,
|
||||
Exports: []string{"/home",},
|
||||
Enabled: true,
|
||||
Exports: []string{"/home"},
|
||||
SystemdName: "nfs-server",
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package warewulfd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
@@ -100,7 +101,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
if unconfiguredNode {
|
||||
daemonLogf("IPXEREQ: %s (unknown/unconfigured node)\n", hwaddr)
|
||||
|
||||
tmpl, err := template.ParseFiles("/etc/warewulf/ipxe/unconfigured.ipxe")
|
||||
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR, "/warewulf/ipxe/unconfigured.ipxe"))
|
||||
if err != nil {
|
||||
daemonLogf("ERROR: Could not parse unconfigured node IPXE template: %s\n", err)
|
||||
return
|
||||
@@ -120,7 +121,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
} else {
|
||||
|
||||
ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/%s.ipxe", nodeobj.Ipxe.Get())
|
||||
ipxeTemplate := path.Join(buildconfig.SYSCONFDIR, "warewulf/ipxe/"+nodeobj.Ipxe.Get()+".ipxe")
|
||||
|
||||
tmpl, err := template.ParseFiles(ipxeTemplate)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user