Added support for tftp service and updated service interface and config
This commit is contained in:
@@ -25,10 +25,10 @@ type dhcpTemplate struct {
|
||||
}
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return ConfigureDHCP()
|
||||
return Configure(SetShow)
|
||||
}
|
||||
|
||||
func ConfigureDHCP() error {
|
||||
func Configure(show bool) error {
|
||||
var d dhcpTemplate
|
||||
var templateFile string
|
||||
|
||||
@@ -110,7 +110,7 @@ func ConfigureDHCP() error {
|
||||
d.RangeStart = controller.Dhcp.RangeStart
|
||||
d.RangeEnd = controller.Dhcp.RangeEnd
|
||||
|
||||
if DoConfig == true {
|
||||
if show == false {
|
||||
fmt.Printf("Writing the DHCP configuration file\n")
|
||||
configWriter, err := os.OpenFile(controller.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640)
|
||||
if err != nil {
|
||||
@@ -125,16 +125,7 @@ func ConfigureDHCP() error {
|
||||
}
|
||||
|
||||
fmt.Printf("Enabling and restarting the DHCP services\n")
|
||||
if controller.Dhcp.Enable != "" {
|
||||
util.ExecInteractive("/bin/sh", "-c", controller.Dhcp.Enable)
|
||||
} else {
|
||||
util.ExecInteractive("/bin/sh", "-c", "systemctl enable dhcpd")
|
||||
}
|
||||
if controller.Dhcp.Restart != "" {
|
||||
util.ExecInteractive("/bin/sh", "-c", controller.Dhcp.Restart)
|
||||
} else {
|
||||
util.ExecInteractive("/bin/sh", "-c", "systemctl restart dhcpd")
|
||||
}
|
||||
util.SystemdStart(controller.Dhcp.SystemdName)
|
||||
|
||||
} else {
|
||||
err = tmpl.Execute(os.Stdout, d)
|
||||
|
||||
@@ -11,11 +11,11 @@ var (
|
||||
Long: "DHCP Config",
|
||||
RunE: CobraRunE,
|
||||
}
|
||||
DoConfig bool
|
||||
SetShow bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&DoConfig, "configure", "c", false, "Do the DHCP Configuration")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/service/dhcp"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/service/tftp"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -10,14 +13,33 @@ var (
|
||||
Use: "service",
|
||||
Short: "Initialize Warewulf services",
|
||||
Long: "Warewulf Service Initialization",
|
||||
RunE: CobraRunE,
|
||||
}
|
||||
SetDoAll bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.AddCommand(dhcp.GetCommand())
|
||||
baseCmd.AddCommand(tftp.GetCommand())
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetDoAll, "all", "a", false, "Configure all services")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if SetDoAll == true {
|
||||
fmt.Printf("################################################################################\n")
|
||||
dhcp.Configure(false)
|
||||
|
||||
fmt.Printf("################################################################################\n")
|
||||
tftp.Configure(false)
|
||||
} else {
|
||||
cmd.Help()
|
||||
os.Exit(0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
68
internal/app/wwctl/service/tftp/main.go
Normal file
68
internal/app/wwctl/service/tftp/main.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package tftp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/staticfiles"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return Configure(SetShow)
|
||||
}
|
||||
|
||||
func Configure(show bool) error {
|
||||
controller, err := warewulfconf.New()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if controller.Tftp.TftpRoot == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Tftp root directory is not configured in warewulfd.conf\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if util.IsDir(controller.Tftp.TftpRoot) == false {
|
||||
wwlog.Printf(wwlog.ERROR, "Configured TFTP Root directory does not exist: %s\n", controller.Tftp.TftpRoot)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(path.Join(controller.Tftp.TftpRoot, "warewulf"), 0755)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if show == false {
|
||||
fmt.Printf("Writing PXE files to: %s\n", path.Join(controller.Tftp.TftpRoot, "warewulf"))
|
||||
err = staticfiles.WriteData("files/tftp/x86.efi", path.Join(controller.Tftp.TftpRoot, "warewulf/x86.efi"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = staticfiles.WriteData("files/tftp/i386.efi", path.Join(controller.Tftp.TftpRoot, "warewulf/i386.efi"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = staticfiles.WriteData("files/tftp/i386.kpxe", path.Join(controller.Tftp.TftpRoot, "warewulf/i386.kpxe"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Enabling and restarting the TFTP services\n")
|
||||
err = util.SystemdStart(controller.Tftp.SystemdName)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
22
internal/app/wwctl/service/tftp/root.go
Normal file
22
internal/app/wwctl/service/tftp/root.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package tftp
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "tftp",
|
||||
Short: "TFTP configuration",
|
||||
Long: "TFTP Config",
|
||||
RunE: CobraRunE,
|
||||
}
|
||||
SetShow bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
@@ -224,3 +224,14 @@ func SliceAddUniqueElement(array []string, add string) []string {
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func SystemdStart(systemdName string) error {
|
||||
startCmd := fmt.Sprintf("systemctl restart %s", systemdName)
|
||||
enableCmd := fmt.Sprintf("systemctl enable %s", systemdName)
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Setting up Systemd service: %s\n", systemdName)
|
||||
ExecInteractive("/bin/sh", "-c", startCmd)
|
||||
ExecInteractive("/bin/sh", "-c", enableCmd)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ const ConfigFile = "/etc/warewulf/warewulf.conf"
|
||||
type ControllerConf struct {
|
||||
Comment string `yaml:"comment"`
|
||||
Ipaddr string `yaml:"ipaddr"`
|
||||
Netmask string `yaml:"netmask,omitempty"`
|
||||
Netmask string `yaml:"netmask"`
|
||||
Fqdn string `yaml:"fqdn,omitempty"`
|
||||
Warewulf *WarewulfConf `yaml:"warewulf"`
|
||||
Dhcp *DhcpConf `yaml:"dhcp"`
|
||||
@@ -20,35 +20,30 @@ type ControllerConf struct {
|
||||
}
|
||||
|
||||
type WarewulfConf struct {
|
||||
Port int `yaml:"port,omitempty"`
|
||||
Secure bool `yaml:"secure,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
UpdateInterval int `yaml:"update interval,omitempty"`
|
||||
Port int `yaml:"port"`
|
||||
Secure bool `yaml:"secure"`
|
||||
UpdateInterval int `yaml:"update interval"`
|
||||
}
|
||||
|
||||
type DhcpConf struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Template string `yaml:"template,omitempty"`
|
||||
RangeStart string `yaml:"range start,omitempty"`
|
||||
RangeEnd string `yaml:"range end,omitempty"`
|
||||
ConfigFile string `yaml:"config file,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Template string `yaml:"template"`
|
||||
RangeStart string `yaml:"range start"`
|
||||
RangeEnd string `yaml:"range end"`
|
||||
SystemdName string `yaml:"systemd name"`
|
||||
ConfigFile string `yaml:"config file"`
|
||||
}
|
||||
|
||||
type TftpConf struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Root string `yaml:"root,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
TftpRoot string `yaml:"tftproot"`
|
||||
SystemdName string `yaml:"systemd name"`
|
||||
}
|
||||
|
||||
type NfsConf struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Exports []string `yaml:"exports,omitempty"`
|
||||
Enable string `yaml:"enable command,omitempty"`
|
||||
Restart string `yaml:"restart command,omitempty"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Exports []string `yaml:"exports"`
|
||||
SystemdName string `yaml:"systemd name"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user