Merge pull request #96 from gmkurtzer/fixups

Various fixups
This commit is contained in:
Gregory M. Kurtzer
2021-08-20 19:47:30 -07:00
committed by GitHub
11 changed files with 16 additions and 414 deletions

View File

@@ -59,9 +59,6 @@ files: all
install -d -m 0755 $(DESTDIR)/var/lib/tftpboot/warewulf/ipxe/
install -d -m 0755 $(DESTDIR)/etc/bash_completion.d/
install -d -m 0755 $(DESTDIR)/usr/share/man/man1
./bash_completion $(DESTDIR)/etc/bash_completion.d/warewulf
./man_page $(DESTDIR)/usr/share/man/man1
gzip $(DESTDIR)/usr/share/man/man1/wwctl*1
test -f $(DESTDIR)/etc/warewulf/warewulf.conf || install -m 644 etc/warewulf.conf $(DESTDIR)/etc/warewulf/
test -f $(DESTDIR)/etc/warewulf/hosts.tmpl || install -m 644 etc/hosts.tmpl $(DESTDIR)/etc/warewulf/
cp -r etc/dhcp $(DESTDIR)/etc/warewulf/
@@ -78,6 +75,11 @@ files: all
mkdir -p $(DESTDIR)/usr/lib/systemd/system
install -c -m 0644 include/systemd/warewulfd.service $(DESTDIR)/usr/lib/systemd/system
systemctl daemon-reload
./bash_completion $(DESTDIR)/etc/bash_completion.d/warewulf
./man_page $(DESTDIR)/usr/share/man/man1
gzip --force $(DESTDIR)/usr/share/man/man1/wwctl*1
# cp -r tftpboot/* /var/lib/tftpboot/warewulf/ipxe/
# restorecon -r /var/lib/tftpboot/warewulf

View File

@@ -1,30 +0,0 @@
package add
import (
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed opening node database: %s\n", err)
os.Exit(1)
}
for _, c := range args {
err = nodeDB.AddController(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
nodeDB.Persist()
return nil
}

View File

@@ -1,23 +0,0 @@
package add
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "add",
Short: "Add",
Long: "Add",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetController string
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,62 +0,0 @@
package delete
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var count int
var numNodes int
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err)
os.Exit(1)
}
for _, c := range args {
err := nodeDB.DelController(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
} else {
for _, n := range nodes {
if n.Cid.Get() == c {
numNodes++
}
}
count++
}
}
if count > 0 {
q := fmt.Sprintf("Are you sure you want to delete %d controllers(s) (%d nodes)", count, numNodes)
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
wwlog.Printf(wwlog.INFO, "No controllers found\n")
}
return nil
}

View File

@@ -1,23 +0,0 @@
package delete
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "delete",
Short: "Delete",
Long: "Delete",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetController string
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,70 +0,0 @@
package list
import "C"
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
controllers, err := nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all nodes: %s\n", err)
os.Exit(1)
}
if ShowAll == true {
for _, c := range controllers {
fmt.Printf("################################################################################\n")
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "", "IP Address", c.Ipaddr)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "", "Domain Name", c.DomainName)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "", "FQDN", c.Fqdn)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "", "Comment", c.Comment)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Port", c.Services.Warewulfd.Port)
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "Warewulf", "Secure", c.Services.Warewulfd.Secure)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Enable CMD", c.Services.Warewulfd.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Restart CMD", c.Services.Warewulfd.RestartCmd)
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "DHCPD", "Enabled", c.Services.Dhcp.Enabled)
if c.Services.Dhcp.Enabled == true {
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Template", c.Services.Dhcp.Template)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "ConfigFile", c.Services.Dhcp.ConfigFile)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "RangeStart", c.Services.Dhcp.RangeStart)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "RangeEnd", c.Services.Dhcp.RangeEnd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Enable CMD", c.Services.Dhcp.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Restart CMD", c.Services.Dhcp.RestartCmd)
}
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "TFTP", "Enabled", c.Services.Tftp.Enabled)
if c.Services.Tftp.Enabled == true {
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "TftpRoot", c.Services.Tftp.TftpRoot)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "Enable CMD", c.Services.Tftp.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "Restart CMD", c.Services.Tftp.RestartCmd)
}
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "NFS", "Enabled", c.Services.Nfs.Enabled)
if c.Services.Nfs.Enabled == true {
for _, e := range c.Services.Nfs.Exports {
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Exports", e)
}
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Enable CMD", c.Services.Nfs.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Restart CMD", c.Services.Nfs.RestartCmd)
}
}
} else {
fmt.Printf("%-22s\n", "CONTROLLER NAME")
for _, c := range controllers {
fmt.Printf("%-22s\n", c.Id)
}
}
return nil
}

View File

@@ -1,23 +0,0 @@
package list
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "list",
Short: "List",
Long: "List",
RunE: CobraRunE,
}
ShowAll bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,29 +0,0 @@
package controller
import (
"github.com/hpcng/warewulf/internal/app/wwctl/controller/add"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/delete"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/list"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/set"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "controller",
Short: "Controller management",
Long: "Management of group settings and power management",
}
)
func init() {
baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(set.GetCommand())
baseCmd.AddCommand(add.GetCommand())
baseCmd.AddCommand(delete.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,110 +0,0 @@
package set
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var err error
var controllers []node.ControllerInfo
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
if len(args) == 0 {
args = append(args, "localhost")
}
if SetAll == true {
controllers, err = nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
} else {
var tmp []node.ControllerInfo
tmp, err = nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, a := range args {
for _, c := range tmp {
if c.Id == a {
controllers = append(controllers, c)
}
}
}
}
for _, c := range controllers {
if SetComment != "" {
wwlog.Printf(wwlog.VERBOSE, "Controller: %s, Setting Comment: %s\n", c.Id, SetComment)
c.Comment = SetComment
err := nodeDB.ControllerUpdate(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetFqdn != "" {
wwlog.Printf(wwlog.VERBOSE, "Controller: %s, Setting FQDN: %s\n", c.Id, SetFqdn)
c.Fqdn = SetFqdn
err := nodeDB.ControllerUpdate(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpaddr != "" {
wwlog.Printf(wwlog.VERBOSE, "Controller: %s, Setting IP Addr to: %s\n", c.Id, SetIpaddr)
c.Ipaddr = SetIpaddr
err := nodeDB.ControllerUpdate(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
}
if len(controllers) > 0 {
q := fmt.Sprintf("Are you sure you want to modify %d group(s)", len(controllers))
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
fmt.Printf("No controllers found\n")
}
return nil
}

View File

@@ -1,30 +0,0 @@
package set
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "set",
Short: "Set",
Long: "Set",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetAll bool
SetIpaddr string
SetFqdn string
SetComment string
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all controllers")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the controller's IP address")
baseCmd.PersistentFlags().StringVarP(&SetFqdn, "fqdn", "F", "", "Set the controller's FQDN")
baseCmd.PersistentFlags().StringVarP(&SetComment, "comment", "C", "", "Comments describing this controller")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -3,13 +3,13 @@ package overlay
import (
"fmt"
"io/ioutil"
"net"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
"strconv"
"strings"
"text/template"
@@ -33,9 +33,9 @@ type TemplateStruct struct {
IpmiUserName string
IpmiPassword string
IpmiInterface string
NetDevs map[string]*node.NetDevs
Keys map[string]string
AllNodes []node.NodeInfo
NetDevs map[string]*node.NetDevs
Keys map[string]string
AllNodes []node.NodeInfo
}
func BuildSystemOverlay(nodeList []node.NodeInfo) error {
@@ -164,12 +164,12 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
t.NetDevs[devname].Gateway = netdev.Gateway.Get()
t.NetDevs[devname].Type = netdev.Type.Get()
t.NetDevs[devname].Default = netdev.Default.GetB()
mask := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4())
ipaddr := net.ParseIP(netdev.Ipaddr.Get()).To4()
netaddr := net.IPNet{IP: ipaddr,Mask: mask}
netPrefix, _ := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4()).Size()
t.NetDevs[devname].Prefix = strconv.Itoa(netPrefix)
t.NetDevs[devname].IpCIDR = netaddr.String()
mask := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4())
ipaddr := net.ParseIP(netdev.Ipaddr.Get()).To4()
netaddr := net.IPNet{IP: ipaddr, Mask: mask}
netPrefix, _ := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4()).Size()
t.NetDevs[devname].Prefix = strconv.Itoa(netPrefix)
t.NetDevs[devname].IpCIDR = netaddr.String()
}
for keyname, key := range n.Keys {