Added support for tftp service and updated service interface and config

This commit is contained in:
Gregory Kurtzer
2020-12-04 22:14:29 -08:00
parent 4dff726a36
commit 4efb27a82f
11 changed files with 193 additions and 80 deletions

View File

@@ -23,13 +23,13 @@ if exists user-class and option user-class = "iPXE" {
} elsif option architecture-type = 00:0A {
filename "/warewulf/ipxe/bin-arm32-efi/placeholder.efi";
} elsif option architecture-type = 00:09 {
filename "/warewulf/ipxe/bin-x86_64-efi/snp.efi";
filename "/warewulf/x86.efi";
} elsif option architecture-type = 00:07 {
filename "/warewulf/ipxe/bin-x86_64-efi/snp.efi";
filename "/warewulf/x86.efi";
} elsif option architecture-type = 00:06 {
filename "/warewulf/ipxe/bin-i386-efi/snp.efi";
filename "/warewulf/i386.efi";
} elsif option architecture-type = 00:00 {
filename "/warewulf/ipxe/bin-i386-pcbios/undionly.kpxe";
filename "/warewulf/i386.kpxe";
}
}

View File

@@ -23,13 +23,13 @@ if exists user-class and option user-class = "iPXE" {
} elsif option architecture-type = 00:0A {
filename "/warewulf/ipxe/bin-arm32-efi/placeholder.efi";
} elsif option architecture-type = 00:09 {
filename "/warewulf/ipxe/bin-x86_64-efi/snp.efi";
filename "/warewulf/x86.efi";
} elsif option architecture-type = 00:07 {
filename "/warewulf/ipxe/bin-x86_64-efi/snp.efi";
filename "/warewulf/x86.efi";
} elsif option architecture-type = 00:06 {
filename "/warewulf/ipxe/bin-i386-efi/snp.efi";
filename "/warewulf/i386.efi";
} elsif option architecture-type = 00:00 {
filename "/warewulf/ipxe/bin-i386-pcbios/undionly.kpxe";
filename "/warewulf/i386.kpxe";
}
}

View File

@@ -9,4 +9,8 @@ dhcp:
range start: 192.168.1.150
range end: 192.168.1.200
template: default
systemd name: dhcp-server
tftp:
enabled: true
tftproot: /var/lib/tftpboot
systemd name: tftp-server

70
go.mod
View File

@@ -3,48 +3,48 @@ module github.com/hpcng/warewulf
go 1.15
require (
github.com/BurntSushi/toml v0.3.1
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5
github.com/beorn7/perks v1.0.1
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/brotherpowers/ipsubnet v0.0.0-20170914094241-30bc98f0a5b1
github.com/containerd/containerd v1.3.2
github.com/containerd/containerd v1.3.2 // indirect
github.com/containers/image/v5 v5.7.0
github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b
github.com/containers/ocicrypt v1.0.3
github.com/containers/storage v1.23.6
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v1.4.2-0.20191219165747-a9416c67da9f
github.com/docker/docker-credential-helpers v0.6.3
github.com/docker/go-connections v0.4.0
github.com/docker/go-metrics v0.0.1
github.com/docker/go-units v0.4.0
github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b // indirect
github.com/containers/ocicrypt v1.0.3 // indirect
github.com/containers/storage v1.23.6 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.4.2-0.20191219165747-a9416c67da9f // indirect
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.4.2
github.com/gorilla/mux v1.7.4
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a
github.com/kelseyhightower/envconfig v1.4.0
github.com/klauspost/compress v1.11.1
github.com/klauspost/pgzip v1.2.5
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/gorilla/mux v1.7.4 // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/klauspost/compress v1.11.1 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-colorable v0.1.6
github.com/mattn/go-isatty v0.0.12
github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/mtrmac/gpgme v0.1.2
github.com/opencontainers/go-digest v1.0.0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mtrmac/gpgme v0.1.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
github.com/opencontainers/umoci v0.4.6
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/prometheus/common v0.6.0
github.com/prometheus/procfs v0.0.3
github.com/russross/blackfriday/v2 v2.0.1
github.com/sirupsen/logrus v1.7.0
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.1.0 // indirect
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect
github.com/prometheus/common v0.6.0 // indirect
github.com/prometheus/procfs v0.0.3 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/spf13/cobra v1.1.1
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/vbauerster/mpb/v5 v5.3.0 // indirect
go.etcd.io/bbolt v1.3.5 // indirect

View File

@@ -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)

View File

@@ -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)")
}

View File

@@ -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
}

View 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
}

View 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
}

View File

@@ -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
}

View File

@@ -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() {