extended tstruct for templating
- tstruct is in new datastructure.go - updated fstab.ww to new syntax
This commit is contained in:
38
internal/pkg/overlay/datastructure.go
Normal file
38
internal/pkg/overlay/datastructure.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
)
|
||||
|
||||
type TemplateStruct struct {
|
||||
Id string
|
||||
Hostname string
|
||||
ClusterName string
|
||||
Container string
|
||||
KernelVersion string
|
||||
KernelArgs string
|
||||
Init string
|
||||
Root string
|
||||
IpmiIpaddr string
|
||||
IpmiNetmask string
|
||||
IpmiPort string
|
||||
IpmiGateway string
|
||||
IpmiUserName string
|
||||
IpmiPassword string
|
||||
IpmiInterface string
|
||||
RuntimeOverlay string
|
||||
SystemOverlay string
|
||||
NetDevs map[string]*node.NetDevs
|
||||
Tags map[string]string
|
||||
Keys map[string]string
|
||||
AllNodes []node.NodeInfo
|
||||
BuildHost string
|
||||
BuildTime string
|
||||
BuildSource string
|
||||
Ipaddr string
|
||||
Netmask string
|
||||
Network string
|
||||
Dhcp warewulfconf.DhcpConf
|
||||
Nfs warewulfconf.NfsConf
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
@@ -19,31 +20,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type TemplateStruct struct {
|
||||
Id string
|
||||
Hostname string
|
||||
ClusterName string
|
||||
Container string
|
||||
KernelVersion string
|
||||
KernelArgs string
|
||||
Init string
|
||||
Root string
|
||||
IpmiIpaddr string
|
||||
IpmiNetmask string
|
||||
IpmiPort string
|
||||
IpmiGateway string
|
||||
IpmiUserName string
|
||||
IpmiPassword string
|
||||
IpmiInterface string
|
||||
RuntimeOverlay string
|
||||
SystemOverlay string
|
||||
NetDevs map[string]*node.NetDevs
|
||||
Tags map[string]string
|
||||
Keys map[string]string
|
||||
AllNodes []node.NodeInfo
|
||||
NFSMounts []string
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func BuildSystemOverlay(nodeList []node.NodeInfo) error {
|
||||
@@ -234,18 +210,15 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error {
|
||||
tstruct.Tags[keyname] = key.Get()
|
||||
}
|
||||
tstruct.AllNodes = allNodes
|
||||
for _, export := range controller.Nfs.ExportsExtended {
|
||||
if export.Mount {
|
||||
var mountOpts string
|
||||
if export.MountOptions == "" {
|
||||
mountOpts = "defaults"
|
||||
} else {
|
||||
mountOpts = export.MountOptions
|
||||
}
|
||||
tstruct.NFSMounts = append(tstruct.NFSMounts, fmt.Sprintf("%s:%s %s nfs %s 0 0\n", controller.Ipaddr, export.Path, export.Path, mountOpts))
|
||||
}
|
||||
}
|
||||
|
||||
tstruct.Nfs = *controller.Nfs
|
||||
tstruct.Dhcp = *controller.Dhcp
|
||||
tstruct.Ipaddr = controller.Ipaddr
|
||||
tstruct.Netmask = controller.Netmask
|
||||
tstruct.Network = controller.Network
|
||||
hostname, _ := os.Hostname()
|
||||
tstruct.BuildHost = hostname
|
||||
dt := time.Now()
|
||||
tstruct.BuildTime = dt.Format("01-02-2006 15:04:05 MST")
|
||||
wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlaySourceDir)
|
||||
err = os.Chdir(OverlaySourceDir)
|
||||
if err != nil {
|
||||
@@ -275,6 +248,7 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error {
|
||||
wwlog.Printf(wwlog.DEBUG, "Created directory in overlay: %s\n", location)
|
||||
|
||||
} else if filepath.Ext(location) == ".ww" {
|
||||
tstruct.BuildSource = path.Join(OverlaySourceDir, location)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Evaluating overlay template file: %s\n", location)
|
||||
|
||||
destFile := strings.TrimSuffix(location, ".ww")
|
||||
|
||||
@@ -52,9 +52,9 @@ type NfsConf struct {
|
||||
|
||||
type NfsExportConf struct {
|
||||
Path string `yaml:"path"`
|
||||
ExportOptions string `yaml:"export options"`
|
||||
MountOptions string `yaml:"mount options"`
|
||||
Mount bool `yaml:"mount"`
|
||||
ExportOptions string `default:"rw,sync" yaml:"export options"`
|
||||
MountOptions string `default:"defaults" yaml:"mount options"`
|
||||
Mount bool `default:"true" yaml:"mount"`
|
||||
}
|
||||
|
||||
func (s *NfsConf) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
@@ -70,7 +70,6 @@ func (s *NfsConf) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func init() {
|
||||
if !util.IsFile(ConfigFile) {
|
||||
wwlog.Printf(wwlog.ERROR, "Configuration file not found: %s\n", ConfigFile)
|
||||
@@ -86,4 +85,4 @@ func init() {
|
||||
|
||||
func DataStore() string {
|
||||
return cachedConf.Warewulf.DataStore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
# This file is autogenerated by warewulf
|
||||
# Host: {{.BuildHost}}
|
||||
# Time: {{.BuildTime}}
|
||||
# Source: {{.BuildSource}}
|
||||
rootfs / tmpfs defaults 0 0
|
||||
devpts /dev/pts devpts gid=5,mode=620 0 0
|
||||
tmpfs /run/shm tmpfs defaults 0 0
|
||||
sysfs /sys sysfs defaults 0 0
|
||||
proc /proc proc defaults 0 0
|
||||
{{range .NFSMounts}}
|
||||
{{.}}
|
||||
{{end}}
|
||||
{{- $IP:=.Ipaddr }}
|
||||
{{- if .Nfs.Enabled }}
|
||||
{{- range .Nfs.ExportsExtended }}
|
||||
{{- if .Mount }}
|
||||
{{ $IP }}:{{ .Path }} {{ .Path }} nfs {{ .MountOptions }} 0 0
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- range .Nfs.Exports }}
|
||||
{{ $IP }}:{{ . }} {{ . }} nfs defaults 0 0
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user