More updates including #WW... declarations in overlay configs
This commit is contained in:
5
Makefile
5
Makefile
@@ -6,8 +6,9 @@ files: all
|
|||||||
install -d -m 0755 /var/warewulf/
|
install -d -m 0755 /var/warewulf/
|
||||||
install -d -m 0755 /etc/warewulf/
|
install -d -m 0755 /etc/warewulf/
|
||||||
install -d -m 0755 /var/lib/tftpboot/warewulf/ipxe/
|
install -d -m 0755 /var/lib/tftpboot/warewulf/ipxe/
|
||||||
install -m 0644 dhcpd.conf /etc/dhcp/dhcpd.conf
|
install -m 0640 etc/dhcpd.conf /etc/dhcp/dhcpd.conf
|
||||||
install -m 0644 nodes.yaml /etc/warewulf/nodes.yaml
|
install -m 0640 etc/nodes.conf /etc/warewulf/nodes.conf
|
||||||
|
install -m 0640 etc/warewulf.conf /etc/warewulf/warewulf.conf
|
||||||
cp -r tftpboot/* /var/lib/tftpboot/warewulf/ipxe/
|
cp -r tftpboot/* /var/lib/tftpboot/warewulf/ipxe/
|
||||||
cp -r overlays /var/warewulf/
|
cp -r overlays /var/warewulf/
|
||||||
chmod +x /var/warewulf/overlays/system/default/init
|
chmod +x /var/warewulf/overlays/system/default/init
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -29,6 +30,7 @@ func BuildOverlayDir(sourceDir string, destDir string, replace map[string]string
|
|||||||
} else {
|
} else {
|
||||||
if filepath.Ext(path) == ".in" {
|
if filepath.Ext(path) == ".in" {
|
||||||
destFile := strings.TrimSuffix(path, ".in")
|
destFile := strings.TrimSuffix(path, ".in")
|
||||||
|
skip := false
|
||||||
|
|
||||||
sourceFD, err := os.Open(sourceDir + "/" + path)
|
sourceFD, err := os.Open(sourceDir + "/" + path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -45,18 +47,49 @@ func BuildOverlayDir(sourceDir string, destDir string, replace map[string]string
|
|||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
newLine := scanner.Text()
|
newLine := scanner.Text()
|
||||||
|
|
||||||
for k, v := range replace {
|
for k, v := range replace {
|
||||||
replaceString := fmt.Sprintf("@%s@", strings.ToUpper(k))
|
replaceString := fmt.Sprintf("@%s@", strings.ToUpper(k))
|
||||||
newLine = strings.ReplaceAll(newLine, replaceString, v)
|
newLine = strings.ReplaceAll(newLine, replaceString, v)
|
||||||
}
|
}
|
||||||
//TODO: Support directives like '#include <filename>' and
|
//TODO: Support directives like '#INCLUDE <filename>' and
|
||||||
// conditionals like '#IFDEF ....`
|
// conditionals like '#IFDEF ....`
|
||||||
|
|
||||||
_, err := w.WriteString(newLine + "\n")
|
if strings.HasPrefix(newLine, "#WWENDIF") {
|
||||||
if err != nil {
|
skip = false
|
||||||
return err
|
} else if skip == true {
|
||||||
}
|
|
||||||
|
|
||||||
|
} else if strings.HasPrefix(newLine, "#WWIFDEF") {
|
||||||
|
line := strings.Split(newLine, " ")
|
||||||
|
if len(line) > 0 && line[1] != "false" {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(newLine, "#WWIF ") {
|
||||||
|
line := strings.Split(newLine, " ")
|
||||||
|
if len(line) == 2 && line[1] != "false" {
|
||||||
|
skip = true
|
||||||
|
} else if len(line) > 3 {
|
||||||
|
|
||||||
|
if line[2] == "==" {
|
||||||
|
if line[1] != line[3] {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(newLine, "#WWINCLUDE ") {
|
||||||
|
line := strings.Split(newLine, " ")
|
||||||
|
includeFD, err := os.Open(line[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
io.Copy(w, includeFD)
|
||||||
|
includeFD.Close()
|
||||||
|
} else {
|
||||||
|
_, err := w.WriteString(newLine + "\n")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
sourceFD.Close()
|
sourceFD.Close()
|
||||||
|
|||||||
4
etc/warewulf.conf
Normal file
4
etc/warewulf.conf
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Port: 9873
|
||||||
|
Ipaddr: 192.168.1.1
|
||||||
|
Secure: true
|
||||||
|
Debug: false
|
||||||
5
go.mod
5
go.mod
@@ -2,4 +2,7 @@ module github.com/hpcng/warewulf
|
|||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require gopkg.in/yaml.v2 v2.3.0
|
require (
|
||||||
|
github.com/kelseyhightower/envconfig v1.4.0
|
||||||
|
gopkg.in/yaml.v2 v2.3.0
|
||||||
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1,3 +1,5 @@
|
|||||||
|
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||||
|
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/hpcng/warewulf/internal/pkg/errors"
|
"github.com/hpcng/warewulf/internal/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ConfigFile = "/etc/warewulf/nodes.yaml"
|
const ConfigFile = "/etc/warewulf/nodes.conf"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//TODO: Check to make sure nodes.yaml is found
|
//TODO: Check to make sure nodes.yaml is found
|
||||||
@@ -22,21 +22,21 @@ type nodeYaml struct {
|
|||||||
type nodeGroup struct {
|
type nodeGroup struct {
|
||||||
Comment string
|
Comment string
|
||||||
Vnfs string
|
Vnfs string
|
||||||
SystemOverlay string `yaml:"system overlay""`
|
SystemOverlay string `yaml:"system overlay""`
|
||||||
RuntimeOverlay string `yaml:"runtime overlay""`
|
RuntimeOverlay string `yaml:"runtime overlay""`
|
||||||
DomainSuffix string `yaml:"domain suffix"`
|
DomainSuffix string `yaml:"domain suffix"`
|
||||||
KernelVersion string `yaml:"kernel version"`
|
KernelVersion string `yaml:"kernel version"`
|
||||||
Nodes map[string]nodeEntry
|
Nodes map[string]nodeEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
type nodeEntry struct {
|
type nodeEntry struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
Vnfs string
|
Vnfs string
|
||||||
SystemOverlay string `yaml:"system overlay"`
|
SystemOverlay string `yaml:"system overlay"`
|
||||||
RuntimeOverlay string `yaml:"runtime overlay"`
|
RuntimeOverlay string `yaml:"runtime overlay"`
|
||||||
DomainSuffix string `yaml:"domain suffix"`
|
DomainSuffix string `yaml:"domain suffix"`
|
||||||
KernelVersion string `yaml:"kernel version"`
|
KernelVersion string `yaml:"kernel version"`
|
||||||
IpmiIpaddr string `yaml:"ipmi ipaddr"`
|
IpmiIpaddr string `yaml:"ipmi ipaddr"`
|
||||||
NetDevs map[string]netDevs
|
NetDevs map[string]netDevs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
internal/pkg/config/config.go
Normal file
35
internal/pkg/config/config.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
"github.com/kelseyhightower/envconfig"
|
||||||
|
"io/ioutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Port int `yaml:"port", envconfig:"WAREWULFD_PORT"`
|
||||||
|
Ipaddr string `yaml:"ipaddr", envconfig:"WAREWULFD_IPADDR"`
|
||||||
|
Secure bool `yaml:"secure port"`
|
||||||
|
Debug bool `yaml:"debug"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() (Config, error) {
|
||||||
|
var c Config
|
||||||
|
|
||||||
|
fd, err := ioutil.ReadFile("/etc/warewulf/warewulf.conf")
|
||||||
|
if err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(fd, &c)
|
||||||
|
if err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = envconfig.Process("", &c)
|
||||||
|
if err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user