@@ -6,6 +6,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
return configure.Configure("DHCP", setShow)
|
return configure.Dhcp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ var (
|
|||||||
"in the warewulf.conf file.",
|
"in the warewulf.conf file.",
|
||||||
RunE: CobraRunE,
|
RunE: CobraRunE,
|
||||||
}
|
}
|
||||||
setShow bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
|
|||||||
43
internal/app/wwctl/configure/main.go
Normal file
43
internal/app/wwctl/configure/main.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package configure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/configure"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
if allFunctions {
|
||||||
|
err = configure.Dhcp()
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = configure.NFS()
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = configure.SSH()
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = configure.TFTP()
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_ = cmd.Help()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -6,5 +6,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
return configure.Configure("NFS", setShow)
|
return configure.NFS()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,9 @@ var (
|
|||||||
"configure NFS as per the configuration in the warewulf.conf file.",
|
"configure NFS as per the configuration in the warewulf.conf file.",
|
||||||
RunE: CobraRunE,
|
RunE: CobraRunE,
|
||||||
}
|
}
|
||||||
setShow bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package configure
|
package configure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/hpcng/warewulf/internal/app/wwctl/configure/dhcp"
|
"github.com/hpcng/warewulf/internal/app/wwctl/configure/dhcp"
|
||||||
"github.com/hpcng/warewulf/internal/app/wwctl/configure/nfs"
|
"github.com/hpcng/warewulf/internal/app/wwctl/configure/nfs"
|
||||||
"github.com/hpcng/warewulf/internal/app/wwctl/configure/ssh"
|
"github.com/hpcng/warewulf/internal/app/wwctl/configure/ssh"
|
||||||
"github.com/hpcng/warewulf/internal/app/wwctl/configure/tftp"
|
"github.com/hpcng/warewulf/internal/app/wwctl/configure/tftp"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/configure"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,20 +32,3 @@ func init() {
|
|||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return baseCmd
|
return baseCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
|
||||||
var err error
|
|
||||||
if allFunctions {
|
|
||||||
for _, s := range [5]string{"DHPC", "NFS", "SSH", "TFTP"} {
|
|
||||||
err = configure.Configure(s, false)
|
|
||||||
if err != nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_ = cmd.Help()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
return configure.Configure("SSH", setShow)
|
return configure.SSH()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ var (
|
|||||||
"keys.",
|
"keys.",
|
||||||
RunE: CobraRunE,
|
RunE: CobraRunE,
|
||||||
}
|
}
|
||||||
setShow bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRootCommand returns the root cobra.Command for the application.
|
// GetRootCommand returns the root cobra.Command for the application.
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
return configure.Configure("TFTP", setShow)
|
return configure.TFTP()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package configure
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Configure(serv string, show bool) error {
|
|
||||||
if !show {
|
|
||||||
fmt.Printf("################################################################################\n")
|
|
||||||
fmt.Printf("Configuring: %s\n", serv)
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
switch serv {
|
|
||||||
case "DHCP":
|
|
||||||
err = configureDHCP(show)
|
|
||||||
case "hosts":
|
|
||||||
err = configureHosts(show)
|
|
||||||
case "NFS":
|
|
||||||
if !show {
|
|
||||||
err = configureNFS()
|
|
||||||
} else {
|
|
||||||
showNFS()
|
|
||||||
}
|
|
||||||
case "SSH":
|
|
||||||
if !show {
|
|
||||||
err = configureSSH()
|
|
||||||
} else {
|
|
||||||
fmt.Printf("'ssh -s' is not yet implemented.\n")
|
|
||||||
}
|
|
||||||
case "TFTP":
|
|
||||||
if !show {
|
|
||||||
err = configureTFTP()
|
|
||||||
} else {
|
|
||||||
fmt.Printf("'tftp -s' is not yet implemented.\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Failed to execute configure on "+serv)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -4,18 +4,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Configures the dhcpd server, when show is set to false, else the
|
Configures the dhcpd server, when show is set to false, else the
|
||||||
dhcp configuration is checked.
|
dhcp configuration is checked.
|
||||||
*/
|
*/
|
||||||
func configureDHCP(show bool) error {
|
func Dhcp() error {
|
||||||
|
|
||||||
|
|
||||||
controller, err := warewulfconf.New()
|
controller, err := warewulfconf.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -37,18 +37,16 @@ func configureDHCP(show bool) error {
|
|||||||
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range end`\n")
|
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range end`\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if !show {
|
|
||||||
|
|
||||||
err = overlay.BuildHostOverlay()
|
err = overlay.BuildHostOverlay()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.WARN, "host overlay could not be built: %s\n", err)
|
wwlog.Printf(wwlog.WARN, "host overlay could not be built: %s\n", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Enabling and restarting the DHCP services\n")
|
fmt.Printf("Enabling and restarting the DHCP services\n")
|
||||||
err := util.SystemdStart(controller.Dhcp.SystemdName)
|
err = util.SystemdStart(controller.Dhcp.SystemdName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to start")
|
return errors.Wrap(err, "failed to start")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
package configure
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
|
||||||
"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"
|
|
||||||
)
|
|
||||||
|
|
||||||
type hostsTemplate struct {
|
|
||||||
PrevHostFile string
|
|
||||||
Ipaddr string
|
|
||||||
Fqdn string
|
|
||||||
AllNodes []node.NodeInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func configureHosts(show bool) error {
|
|
||||||
var replace hostsTemplate
|
|
||||||
|
|
||||||
if !util.IsFile(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl")) {
|
|
||||||
wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
controller, err := warewulfconf.New()
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err := node.New()
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl"))
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "Could not parse hosts template: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
replace.PrevHostFile = ""
|
|
||||||
w, err := os.Open("/etc/hosts")
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.WARN, "%s\n", err)
|
|
||||||
} else {
|
|
||||||
// if /etc/hosts.ww does not exist, backup /etc/hosts to /etc/hosts.wwbackup
|
|
||||||
if !util.IsFile("/etc/hosts.wwbackup") {
|
|
||||||
err = util.CopyFile("/etc/hosts", "/etc/hosts.wwbackup")
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// read all lines before the # warewulf comment and put into PrevHostFile template variable
|
|
||||||
lines, _ := util.ReadFile("/etc/hosts")
|
|
||||||
if lines != nil {
|
|
||||||
var buffer bytes.Buffer
|
|
||||||
for _, line := range lines {
|
|
||||||
//wwlog.Printf(wwlog.INFO, "Reading line: %s\n", line)
|
|
||||||
if util.ValidString(line, "^#.*maintained by warewulf") {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
buffer.WriteString(line)
|
|
||||||
buffer.WriteString("\n")
|
|
||||||
}
|
|
||||||
replace.PrevHostFile = buffer.String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Close()
|
|
||||||
|
|
||||||
nodes, _ := n.FindAllNodes()
|
|
||||||
|
|
||||||
replace.AllNodes = nodes
|
|
||||||
replace.Ipaddr = controller.Ipaddr
|
|
||||||
replace.Fqdn = controller.Fqdn
|
|
||||||
|
|
||||||
if !show {
|
|
||||||
// only open "/etc/hosts" when intended to write, as 'os.O_TRUNC' will empty the file otherwise.
|
|
||||||
w, err = os.OpenFile("/etc/hosts", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
defer w.Close()
|
|
||||||
|
|
||||||
err = tmpl.Execute(w, replace)
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = tmpl.Execute(os.Stdout, replace)
|
|
||||||
if err != nil {
|
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -12,10 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Creates '/etc/exports' from the host template, enables and start the
|
Creates '/etc/exports' from the host template, enables and start the
|
||||||
nfs server.
|
nfs server.
|
||||||
*/
|
*/
|
||||||
func configureNFS() error {
|
func NFS() error {
|
||||||
|
|
||||||
controller, err := warewulfconf.New()
|
controller, err := warewulfconf.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -28,7 +28,7 @@ func configureNFS() error {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
err = overlay.BuildHostOverlay()
|
err = overlay.BuildHostOverlay()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.WARN, "host overlay could not be built: %s\n", err)
|
wwlog.Printf(wwlog.WARN, "host overlay could not be built: %s\n", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Enabling and restarting the NFS services\n")
|
fmt.Printf("Enabling and restarting the NFS services\n")
|
||||||
@@ -49,7 +49,7 @@ func configureNFS() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Prints the configured nfs exports in formated style, needs not to be
|
Prints the configured nfs exports in formated style, needs not to be
|
||||||
the content of '/etc/exports'
|
the content of '/etc/exports'
|
||||||
*/
|
*/
|
||||||
func showNFS() {
|
func showNFS() {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func configureSSH() error {
|
func SSH() error {
|
||||||
if os.Getuid() == 0 {
|
if os.Getuid() == 0 {
|
||||||
fmt.Printf("Updating system keys\n")
|
fmt.Printf("Updating system keys\n")
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
var tftpdir string = path.Join(buildconfig.TFTPDIR(), "warewulf")
|
var tftpdir string = path.Join(buildconfig.TFTPDIR(), "warewulf")
|
||||||
|
|
||||||
func configureTFTP() error {
|
func TFTP() error {
|
||||||
controller, err := warewulfconf.New()
|
controller, err := warewulfconf.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user