created exports with template
This commit is contained in:
@@ -4,12 +4,17 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"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"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
/*
|
||||
Creates '/etc/exports' from the host template, enables and start the
|
||||
nfs server.
|
||||
*/
|
||||
func configureNFS() error {
|
||||
|
||||
controller, err := warewulfconf.New()
|
||||
@@ -19,19 +24,13 @@ func configureNFS() error {
|
||||
}
|
||||
|
||||
if controller.Nfs.Enabled {
|
||||
exports, err := os.OpenFile("/etc/exports", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer exports.Close()
|
||||
|
||||
fmt.Fprintf(exports, "# This file was written by Warewulf (wwctl configure nfs)\n")
|
||||
|
||||
for _, export := range controller.Nfs.ExportsExtended {
|
||||
fmt.Fprintf(exports, "%s %s/%s(%s)\n", export.Path, controller.Network, controller.Netmask, export.ExportOptions)
|
||||
err = overlay.BuildHostOverlay()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.WARN, "host overlay could not be built: %s\n", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Enabling and restarting the NFS services\n")
|
||||
if controller.Nfs.SystemdName == "" {
|
||||
err := util.SystemdStart("nfs-server")
|
||||
@@ -49,6 +48,10 @@ func configureNFS() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
Prints the configured nfs exports in formated style, needs not to be
|
||||
the content of '/etc/exports'
|
||||
*/
|
||||
func showNFS() {
|
||||
controller, err := warewulfconf.New()
|
||||
if err != nil {
|
||||
|
||||
@@ -52,7 +52,7 @@ type NfsConf struct {
|
||||
|
||||
type NfsExportConf struct {
|
||||
Path string `yaml:"path"`
|
||||
ExportOptions string `default:"rw,sync" yaml:"export options"`
|
||||
ExportOptions string `default:"rw,sync,no_subtree_check" yaml:"export options"`
|
||||
MountOptions string `default:"defaults" yaml:"mount options"`
|
||||
Mount bool `default:"true" yaml:"mount"`
|
||||
}
|
||||
|
||||
14
overlays/host/etc/exports.ww
Normal file
14
overlays/host/etc/exports.ww
Normal file
@@ -0,0 +1,14 @@
|
||||
{{- if .Nfs.Enabled }}
|
||||
# This file is autogenerated by warewulf
|
||||
# Host: {{.BuildHost}}
|
||||
# Time: {{.BuildTime}}
|
||||
# Source: {{.BuildSource}}
|
||||
{{- $network := .Network }}
|
||||
{{- $netmask := .Netmask }}
|
||||
{{- range .Nfs.ExportsExtended }}
|
||||
{{ .Path }} {{ $network }}/{{ $netmask }}({{ .ExportOptions }})
|
||||
{{- end }}
|
||||
{{range .Nfs.Exports }}
|
||||
{{ . }} {{ $network }}/{{ $netmask }}(rw,sync,no_subtree_check)
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
Reference in New Issue
Block a user