From afc94ebd42855059a94ddf38863fee5febe45237 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 15 Feb 2022 11:47:10 +0100 Subject: [PATCH] created exports with template --- internal/pkg/configure/nfs.go | 23 ++++++++++++---------- internal/pkg/warewulfconf/datastructure.go | 2 +- overlays/host/etc/exports.ww | 14 +++++++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 overlays/host/etc/exports.ww diff --git a/internal/pkg/configure/nfs.go b/internal/pkg/configure/nfs.go index 6bdc7123..dd29c86b 100644 --- a/internal/pkg/configure/nfs.go +++ b/internal/pkg/configure/nfs.go @@ -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 { diff --git a/internal/pkg/warewulfconf/datastructure.go b/internal/pkg/warewulfconf/datastructure.go index 0b721204..4e9cb44f 100644 --- a/internal/pkg/warewulfconf/datastructure.go +++ b/internal/pkg/warewulfconf/datastructure.go @@ -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"` } diff --git a/overlays/host/etc/exports.ww b/overlays/host/etc/exports.ww new file mode 100644 index 00000000..82d3f491 --- /dev/null +++ b/overlays/host/etc/exports.ww @@ -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 }}