Extend and optimize relocatable build config infrastructure
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"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"
|
||||
@@ -84,12 +85,12 @@ func Configure(show bool) error {
|
||||
d.Nodes = append(d.Nodes, nodes...)
|
||||
|
||||
if controller.Dhcp.Template == "" {
|
||||
templateFile = "/etc/warewulf/dhcp/default-dhcpd.conf"
|
||||
templateFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/dhcp/default-dhcpd.conf")
|
||||
} else {
|
||||
if strings.HasPrefix(controller.Dhcp.Template, "/") {
|
||||
templateFile = controller.Dhcp.Template
|
||||
} else {
|
||||
templateFile = fmt.Sprintf("/etc/warewulf/dhcp/%s-dhcpd.conf", controller.Dhcp.Template)
|
||||
templateFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/dhcp/"+controller.Dhcp.Template+"dhcpd.conf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ package hosts
|
||||
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"
|
||||
@@ -26,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
func Configure(show bool) error {
|
||||
var replace TemplateStruct
|
||||
|
||||
if !util.IsFile("/etc/warewulf/hosts.tmpl") {
|
||||
if !util.IsFile(path.Join(buildconfig.SYSCONFDIR, "warewulf/hosts.tmpl")) {
|
||||
wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n")
|
||||
return nil
|
||||
}
|
||||
@@ -43,7 +45,7 @@ func Configure(show bool) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles("/etc/warewulf/hosts.tmpl")
|
||||
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)
|
||||
|
||||
@@ -101,7 +101,7 @@ func Configure(show bool) error {
|
||||
fmt.Printf("%s %s/%s\n", export.Path, controller.Network, controller.Netmask)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("SYSTEM OVERLAY: default/etc/fstab:\n")
|
||||
fmt.Printf("SYSTEM OVERLAY: wwinit/etc/fstab:\n")
|
||||
for _, export := range controller.Nfs.Exports {
|
||||
fmt.Printf("%s:%s %s nfs defaults 0 0\n", controller.Ipaddr, export, export)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/pkg/errors"
|
||||
@@ -19,15 +20,17 @@ func Configure(show bool) error {
|
||||
if os.Getuid() == 0 {
|
||||
fmt.Printf("Updating system keys\n")
|
||||
|
||||
err := os.MkdirAll("/etc/warewulf/keys", 0755)
|
||||
wwkeydir := path.Join(buildconfig.SYSCONFDIR, "/etc/warewulf/keys") + "/"
|
||||
|
||||
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR, "warewulf/keys"), 0755)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not create base directory: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !util.IsFile("/etc/warewulf/keys/ssh_host_rsa_key") {
|
||||
if !util.IsFile(wwkeydir + "ssh_host_rsa_key") {
|
||||
fmt.Printf("Setting up key: ssh_host_rsa_key\n")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", "/etc/warewulf/keys/ssh_host_rsa_key", "-C", "", "-N", "")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", wwkeydir+"ssh_host_rsa_key", "-C", "", "-N", "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to exec ssh-keygen command")
|
||||
}
|
||||
@@ -35,9 +38,9 @@ func Configure(show bool) error {
|
||||
fmt.Printf("Skipping, key already exists: ssh_host_rsa_key\n")
|
||||
}
|
||||
|
||||
if !util.IsFile("/etc/warewulf/keys/ssh_host_dsa_key") {
|
||||
if !util.IsFile(wwkeydir + "ssh_host_dsa_key") {
|
||||
fmt.Printf("Setting up key: ssh_host_dsa_key\n")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "dsa", "-f", "/etc/warewulf/keys/ssh_host_dsa_key", "-C", "", "-N", "")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "dsa", "-f", wwkeydir+"ssh_host_dsa_key", "-C", "", "-N", "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to exec ssh-keygen command")
|
||||
}
|
||||
@@ -45,9 +48,9 @@ func Configure(show bool) error {
|
||||
fmt.Printf("Skipping, key already exists: ssh_host_dsa_key\n")
|
||||
}
|
||||
|
||||
if !util.IsFile("/etc/warewulf/keys/ssh_host_ecdsa_key") {
|
||||
if !util.IsFile(wwkeydir + "ssh_host_ecdsa_key") {
|
||||
fmt.Printf("Setting up key: ssh_host_ecdsa_key\n")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ecdsa", "-f", "/etc/warewulf/keys/ssh_host_ecdsa_key", "-C", "", "-N", "")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ecdsa", "-f", wwkeydir+"ssh_host_ecdsa_key", "-C", "", "-N", "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to exec ssh-keygen command")
|
||||
}
|
||||
@@ -55,9 +58,9 @@ func Configure(show bool) error {
|
||||
fmt.Printf("Skipping, key already exists: ssh_host_ecdsa_key\n")
|
||||
}
|
||||
|
||||
if !util.IsFile("/etc/warewulf/keys/ssh_host_ed25519_key") {
|
||||
if !util.IsFile(wwkeydir + "ssh_host_ed25519_key") {
|
||||
fmt.Printf("Setting up key: ssh_host_ed25519_key\n")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ed25519", "-f", "/etc/warewulf/keys/ssh_host_ed25519_key", "-C", "", "-N", "")
|
||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ed25519", "-f", wwkeydir+"ssh_host_ed25519_key", "-C", "", "-N", "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to exec ssh-keygen command")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
|
||||
"github.com/hpcng/warewulf/internal/pkg/staticfiles"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
|
||||
@@ -23,40 +24,35 @@ func Configure(show bool) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if controller.Tftp.TftpRoot == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Tftp root directory is not configured in warewulfd.conf\n")
|
||||
if buildconfig.TFTPDIR == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Tftp root directory is not configured by build\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !util.IsDir(controller.Tftp.TftpRoot) {
|
||||
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)
|
||||
err = os.MkdirAll(path.Join(buildconfig.TFTPDIR, "warewulf"), 0755)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !show {
|
||||
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"))
|
||||
fmt.Printf("Writing PXE files to: %s\n", path.Join(buildconfig.TFTPDIR, "warewulf"))
|
||||
err = staticfiles.WriteData("files/tftp/x86.efi", path.Join(buildconfig.TFTPDIR, "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"))
|
||||
err = staticfiles.WriteData("files/tftp/i386.efi", path.Join(buildconfig.TFTPDIR, "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"))
|
||||
err = staticfiles.WriteData("files/tftp/i386.kpxe", path.Join(buildconfig.TFTPDIR, "warewulf/i386.kpxe"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = staticfiles.WriteData("files/tftp/arm64.efi", path.Join(controller.Tftp.TftpRoot, "warewulf/arm64.efi"))
|
||||
err = staticfiles.WriteData("files/tftp/arm64.efi", path.Join(buildconfig.TFTPDIR, "warewulf/arm64.efi"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
package ready
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
n, err := node.New()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nodes, err := n.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not get node list: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("%-25s %-10s %-6s %-6s %-6s %-6s %-6s\n", "NODE NAME", "STATUS", "VNFS", "KERNEL", "KMODS", "SYS-OL", "RUN-OL")
|
||||
|
||||
for _, node := range nodes {
|
||||
var vnfs_good bool
|
||||
var kernel_good bool
|
||||
var kmods_good bool
|
||||
var systemo_good bool
|
||||
var runtimeo_good bool
|
||||
status := true
|
||||
|
||||
if node.ContainerName.Get() != "" {
|
||||
vnfsImage := container.ImageFile(node.ContainerName.Get())
|
||||
|
||||
if util.IsFile(vnfsImage) {
|
||||
vnfs_good = true
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "VNFS not found: %s, %s\n", node.Id.Get(), vnfsImage)
|
||||
}
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node Kernel not defined: %s\n", node.Id.Get())
|
||||
}
|
||||
|
||||
if node.KernelVersion.Get() != "" {
|
||||
if util.IsFile(kernel.KernelImage(node.KernelVersion.Get())) {
|
||||
kernel_good = true
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node Kernel not found: %s, %s\n", node.Id.Get(), node.KernelVersion.Get())
|
||||
}
|
||||
if util.IsFile(kernel.KmodsImage(node.KernelVersion.Get())) {
|
||||
kmods_good = true
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node Kmods not found: %s, %s\n", node.Id.Get(), node.KernelVersion.Get())
|
||||
}
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node Kernel version not defined: %s\n", node.Id.Get())
|
||||
}
|
||||
|
||||
if node.SystemOverlay.Get() != "" {
|
||||
if util.IsFile(overlay.SystemOverlayImage(node.Id.Get())) {
|
||||
systemo_good = true
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "System Overlay not found: %s\n", overlay.SystemOverlayImage(node.Id.Get()))
|
||||
}
|
||||
} else {
|
||||
status = false
|
||||
wwlog.Printf(wwlog.VERBOSE, "System Overlay not defined: %s\n", node.Id.Get())
|
||||
}
|
||||
|
||||
fmt.Printf("%-25s %-10t %-6t %-6t %-6t %-6t %-6t\n", node.Id.Get(), status, vnfs_good, kernel_good, kmods_good, systemo_good, runtimeo_good)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package ready
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "ready [OPTIONS]",
|
||||
Short: "Warewulf status check",
|
||||
Long: "Provides the current status of all Warewulf nodes.",
|
||||
RunE: CobraRunE,
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) != 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
nodeDB, _ := node.New()
|
||||
nodes, _ := nodeDB.FindAllNodes()
|
||||
var node_names []string
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
}
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/console"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/delete"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/list"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/ready"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/sensors"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/set"
|
||||
nodestatus "github.com/hpcng/warewulf/internal/app/wwctl/node/status"
|
||||
@@ -30,7 +29,6 @@ func init() {
|
||||
baseCmd.AddCommand(add.GetCommand())
|
||||
baseCmd.AddCommand(delete.GetCommand())
|
||||
baseCmd.AddCommand(console.GetCommand())
|
||||
baseCmd.AddCommand(ready.GetCommand())
|
||||
baseCmd.AddCommand(nodestatus.GetCommand())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user