Updates for text/template subsystem integration
This commit is contained in:
@@ -16,6 +16,15 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func fileInclude(path string) string {
|
||||
wwlog.Printf(wwlog.DEBUG, "Including file into template: %s\n", path)
|
||||
content, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Template include: %s\n", err)
|
||||
}
|
||||
return strings.TrimSuffix(string(content), "\n")
|
||||
}
|
||||
|
||||
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
wwlog.Printf(wwlog.INFO, "Building Runtime Overlays:\n")
|
||||
wwlog.SetIndent(4)
|
||||
@@ -78,7 +87,7 @@ func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
|
||||
destFile := strings.TrimSuffix(location, ".ww")
|
||||
|
||||
tmpl, err := template.ParseGlob(path.Join(OverlayDir, destFile) + ".ww*")
|
||||
tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": fileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
return err
|
||||
|
||||
@@ -16,6 +16,15 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func fileInclude(path string) string {
|
||||
wwlog.Printf(wwlog.DEBUG, "Including file into template: %s\n", path)
|
||||
content, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Template include: %s\n", err)
|
||||
}
|
||||
return strings.TrimSuffix(string(content), "\n")
|
||||
}
|
||||
|
||||
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
wwlog.Printf(wwlog.INFO, "Building System Overlays:\n")
|
||||
wwlog.SetIndent(4)
|
||||
@@ -78,7 +87,7 @@ func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
|
||||
destFile := strings.TrimSuffix(location, ".ww")
|
||||
|
||||
tmpl, err := template.ParseGlob(path.Join(OverlayDir, destFile) + ".ww*")
|
||||
tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"include": fileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
return err
|
||||
|
||||
@@ -12,7 +12,7 @@ var buildForce bool
|
||||
func Build(nodeList []assets.NodeInfo, force bool) (error) {
|
||||
set := make(map[string]int)
|
||||
|
||||
wwlog.Printf(wwlog.INFO, "Importing VNFS Images:\n")
|
||||
wwlog.Printf(wwlog.INFO, "Building and Importing VNFS Images:\n")
|
||||
wwlog.SetIndent(4)
|
||||
|
||||
buildForce = force
|
||||
|
||||
@@ -2,9 +2,9 @@ package assets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
// "os"
|
||||
@@ -140,7 +140,8 @@ func FindAllNodes() ([]NodeInfo, error) {
|
||||
if strings.HasPrefix(n.Vnfs, "docker://") {
|
||||
//TODO: This is a kludge and shouldn't be done here. We need to go back
|
||||
// and do this from a "vnfs" interface or package
|
||||
n.VnfsDir = LocalStateDir + "/oci/vnfs/name/" + path.Base(n.Vnfs)
|
||||
v := vnfs.New(n.Vnfs)
|
||||
n.VnfsDir = v.Root()
|
||||
} else {
|
||||
n.VnfsDir = n.Vnfs
|
||||
}
|
||||
|
||||
21
internal/pkg/assets/template.go
Normal file
21
internal/pkg/assets/template.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package assets
|
||||
|
||||
|
||||
|
||||
type WWTemplate struct {
|
||||
GroupName string
|
||||
HostName string
|
||||
DomainName string
|
||||
Fqdn string
|
||||
Vnfs string
|
||||
VnfsDir string
|
||||
Ipxe string
|
||||
SystemOverlay string
|
||||
RuntimeOverlay string
|
||||
KernelVersion string
|
||||
NetDevs map[string]netDevs
|
||||
}
|
||||
|
||||
func (t WWTemplate) Import(file string) {
|
||||
|
||||
}
|
||||
@@ -41,7 +41,6 @@ func (self *VnfsObject) NameClean() string {
|
||||
if strings.HasPrefix(self.SourcePath, "/") {
|
||||
return path.Base(self.SourcePath)
|
||||
}
|
||||
|
||||
uri := strings.Split(self.SourcePath, "://")
|
||||
|
||||
return strings.ReplaceAll(uri[1], "/", "_")
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#WWINCLUDE @VNFSDIR@/etc/group
|
||||
#WWINCLUDE /etc/group
|
||||
2
overlays/runtime/default/etc/group.ww
Normal file
2
overlays/runtime/default/etc/group.ww
Normal file
@@ -0,0 +1,2 @@
|
||||
{{Include (printf "%s%s" .VnfsDir "/etc/group")}}
|
||||
{{Include "/etc/passwd"}}
|
||||
@@ -1,3 +0,0 @@
|
||||
root::0:0:root:/root:/bin/bash
|
||||
#WWINCLUDE @VNFSDIR@/etc/passwd
|
||||
#WWINCLUDE /etc/passwd
|
||||
3
overlays/runtime/default/etc/passwd.ww
Normal file
3
overlays/runtime/default/etc/passwd.ww
Normal file
@@ -0,0 +1,3 @@
|
||||
root::0:0:root:/root:/bin/bash
|
||||
{{Include (printf "%s%s" .VnfsDir "/etc/passwd")}}
|
||||
{{Include "/etc/passwd"}}
|
||||
@@ -1 +0,0 @@
|
||||
Hello from Warewulf
|
||||
@@ -1 +0,0 @@
|
||||
#WWINCLUDE /root/.ssh/authorized_keys
|
||||
1
overlays/runtime/default/root/.ssh/authorized_keys.ww
Normal file
1
overlays/runtime/default/root/.ssh/authorized_keys.ww
Normal file
@@ -0,0 +1 @@
|
||||
{{Include "/root/.ssh/authorized_keys")}}
|
||||
@@ -1 +0,0 @@
|
||||
@HOSTNAME@
|
||||
1
overlays/system/default/etc/hostname.ww
Normal file
1
overlays/system/default/etc/hostname.ww
Normal file
@@ -0,0 +1 @@
|
||||
{{.Fqdn}}
|
||||
@@ -1,8 +1,8 @@
|
||||
DEVICE=@ETH0:NAME@
|
||||
NAME=@ETH0:NAME@
|
||||
IPADDR=@ETH0:IPADDR@
|
||||
NETMASK=@ETH0:NETMASK@
|
||||
GATEWAY=@ETH0:GATEWAY@
|
||||
HWADDR=@ETH0:HWADDR@
|
||||
DEVICE=eth0
|
||||
NAME=eth0
|
||||
IPADDR={{.NetDevs.eth0.Ipaddr}}
|
||||
NETMASK={{.NetDevs.eth0.Netmask}}
|
||||
GATEWAY={{.NetDevs.eth0.Gateway}}
|
||||
HWADDR={{.NetDevs.eth0.Hwaddr}}
|
||||
BOOTPROTO=static
|
||||
ONBOOT=yes
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
NETWORKING=yes
|
||||
HOSTNAME=@FQDN@
|
||||
2
overlays/system/default/etc/sysconfig/network.ww
Normal file
2
overlays/system/default/etc/sysconfig/network.ww
Normal file
@@ -0,0 +1,2 @@
|
||||
NETWORKING=yes
|
||||
HOSTNAME={{.Fqdn}}
|
||||
@@ -1 +0,0 @@
|
||||
#WWINCLUDE /etc/warewulf/warewulf.conf
|
||||
1
overlays/system/default/etc/warewulf/warewulf.conf.ww
Normal file
1
overlays/system/default/etc/warewulf/warewulf.conf.ww
Normal file
@@ -0,0 +1 @@
|
||||
{{Include "/etc/warewulf/warewulf.conf"}}
|
||||
Reference in New Issue
Block a user