Merge pull request #267 from mslacken/nfs-mount-fstab
moved fstab creation for nodes to template
This commit is contained in:
@@ -3,9 +3,7 @@ package nfs
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
@@ -36,20 +34,6 @@ func Configure(show bool) error {
|
||||
}
|
||||
|
||||
if !SetShow {
|
||||
fstab, err := os.OpenFile(path.Join(overlay.OverlaySourceDir("wwinit"), "etc/fstab"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer fstab.Close()
|
||||
|
||||
fmt.Fprintf(fstab, "# This file was written by Warewulf (wwctl configure nfs)\n")
|
||||
|
||||
fmt.Fprintf(fstab, "rootfs / tmpfs defaults 0 0\n")
|
||||
fmt.Fprintf(fstab, "devpts /dev/pts devpts gid=5,mode=620 0 0\n")
|
||||
fmt.Fprintf(fstab, "tmpfs /run/shm tmpfs defaults 0 0\n")
|
||||
fmt.Fprintf(fstab, "sysfs /sys sysfs defaults 0 0\n")
|
||||
fmt.Fprintf(fstab, "proc /proc proc defaults 0 0\n")
|
||||
|
||||
if controller.Nfs.Enabled {
|
||||
exports, err := os.OpenFile("/etc/exports", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
@@ -63,15 +47,6 @@ func Configure(show bool) error {
|
||||
|
||||
for _, export := range controller.Nfs.ExportsExtended {
|
||||
fmt.Fprintf(exports, "%s %s/%s(%s)\n", export.Path, controller.Network, controller.Netmask, export.ExportOptions)
|
||||
if export.Mount {
|
||||
var mountOpts string
|
||||
if export.MountOptions == "" {
|
||||
mountOpts = "defaults"
|
||||
} else {
|
||||
mountOpts = export.MountOptions
|
||||
}
|
||||
fmt.Fprintf(fstab, "%s:%s %s nfs %s 0 0\n", controller.Ipaddr, export.Path, export.Path, mountOpts)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Enabling and restarting the NFS services\n")
|
||||
@@ -89,17 +64,11 @@ func Configure(show bool) error {
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("/etc/exports:\n")
|
||||
for _, export := range controller.Nfs.Exports {
|
||||
fmt.Printf("%s %s/%s\n", export, controller.Network, controller.Netmask)
|
||||
}
|
||||
|
||||
for _, export := range controller.Nfs.ExportsExtended {
|
||||
fmt.Printf("%s %s/%s\n", export.Path, controller.Network, controller.Netmask)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("SYSTEM OVERLAY: wwinit/etc/fstab:\n")
|
||||
for _, export := range controller.Nfs.ExportsExtended {
|
||||
fmt.Printf("%s:%s %s nfs defaults 0 0\n", controller.Ipaddr, export.Path, export.Path)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"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"
|
||||
)
|
||||
@@ -39,6 +40,7 @@ type TemplateStruct struct {
|
||||
NetDevs map[string]*node.NetDevs
|
||||
Keys map[string]string
|
||||
AllNodes []node.NodeInfo
|
||||
NFSMounts []string
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -127,6 +129,12 @@ func OverlayInit(overlayName string) error {
|
||||
}
|
||||
|
||||
func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error {
|
||||
controller, err := warewulfconf.New()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nodeDB, _ := node.New()
|
||||
allNodes, _ := nodeDB.FindAllNodes()
|
||||
var tstruct TemplateStruct
|
||||
@@ -143,7 +151,7 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error {
|
||||
return errors.New("overlay does not exist: " + overlayName)
|
||||
}
|
||||
|
||||
err := os.MkdirAll(OverlayImageDir, 0755)
|
||||
err = os.MkdirAll(OverlayImageDir, 0755)
|
||||
if err == nil {
|
||||
wwlog.Printf(wwlog.DEBUG, "Created parent directory for Overlay Images: %s\n", OverlayImageDir)
|
||||
} else {
|
||||
@@ -204,6 +212,17 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error {
|
||||
tstruct.Keys[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))
|
||||
}
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlaySourceDir)
|
||||
err = os.Chdir(OverlaySourceDir)
|
||||
|
||||
8
overlays/wwinit/etc/fstab.ww
Normal file
8
overlays/wwinit/etc/fstab.ww
Normal file
@@ -0,0 +1,8 @@
|
||||
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}}
|
||||
Reference in New Issue
Block a user