Setup kernel support
This commit is contained in:
@@ -65,7 +65,6 @@ func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", "kmods-"+kernelVersion+".img")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wwlog.SetIndent(0)
|
||||
|
||||
55
internal/app/wwctl/kernel/build/main.go
Normal file
55
internal/app/wwctl/kernel/build/main.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
var nodes []assets.NodeInfo
|
||||
set := make(map[string]int)
|
||||
|
||||
if len(args) == 1 && ByNode == true {
|
||||
var err error
|
||||
nodes, err = assets.SearchByName(args[0])
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not find nodes for search term: %s\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
set[node.KernelVersion] ++
|
||||
}
|
||||
|
||||
} else if BuildAll == true {
|
||||
var err error
|
||||
nodes, err = assets.FindAllNodes()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not get list of nodes: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
set[node.KernelVersion] ++
|
||||
}
|
||||
|
||||
} else if len(args) == 1 {
|
||||
set[args[0]] ++
|
||||
} else {
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for k := range set {
|
||||
err := kernel.Build(k)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
28
internal/app/wwctl/kernel/build/root.go
Normal file
28
internal/app/wwctl/kernel/build/root.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "build (kernel version | node search pattern)",
|
||||
Short: "Kernel Image Build",
|
||||
Long: "Build kernel images",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.RangeArgs(0,1),
|
||||
|
||||
}
|
||||
BuildAll bool
|
||||
ByNode bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)")
|
||||
baseCmd.PersistentFlags().BoolVarP(&ByNode, "node", "n", false, "Build overlay for a particular node")
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
12
internal/app/wwctl/kernel/export/main.go
Normal file
12
internal/app/wwctl/kernel/export/main.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package export
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("This command is coming soon...\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
22
internal/app/wwctl/kernel/export/root.go
Normal file
22
internal/app/wwctl/kernel/export/root.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package export
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "export",
|
||||
Short: "Kernel Image Export",
|
||||
Long: "Export kernel image",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.ExactArgs(1),
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
12
internal/app/wwctl/kernel/imprt/main.go
Normal file
12
internal/app/wwctl/kernel/imprt/main.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package imprt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("This command is coming soon...\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
22
internal/app/wwctl/kernel/imprt/root.go
Normal file
22
internal/app/wwctl/kernel/imprt/root.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package imprt
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "import",
|
||||
Short: "Kernel Image Import",
|
||||
Long: "Import kernel image",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.ExactArgs(1),
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
12
internal/app/wwctl/kernel/list/main.go
Normal file
12
internal/app/wwctl/kernel/list/main.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("This command is coming soon...\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
21
internal/app/wwctl/kernel/list/root.go
Normal file
21
internal/app/wwctl/kernel/list/root.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package list
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List Installed Kernel Images",
|
||||
Long: "List installed kernel images",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.ExactArgs(0),
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package kernel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/build"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/export"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/imprt"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/kernel/list"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -10,22 +13,17 @@ var (
|
||||
Use: "kernel",
|
||||
Short: "Kernel Image Management",
|
||||
Long: "Management of Warewulf Kernels to be used for bootstrapping nodes",
|
||||
RunE: CobraRunE,
|
||||
}
|
||||
test bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().BoolVarP(&test, "test", "t", false, "Testing.")
|
||||
|
||||
baseCmd.AddCommand(build.GetCommand())
|
||||
baseCmd.AddCommand(export.GetCommand())
|
||||
baseCmd.AddCommand(imprt.GetCommand())
|
||||
baseCmd.AddCommand(list.GetCommand())
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("Kernel: Hello World\n")
|
||||
return nil
|
||||
}
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
|
||||
var updateNodes []assets.NodeInfo
|
||||
|
||||
if len(args) > 0 && BuildAll == false {
|
||||
|
||||
61
internal/pkg/kernel/kernel.go
Normal file
61
internal/pkg/kernel/kernel.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package kernel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"github.com/hpcng/warewulf/internal/pkg/errors"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
)
|
||||
|
||||
func Build(kernelVersion string) error {
|
||||
config := config.New()
|
||||
|
||||
kernelImage := "/boot/vmlinuz-" + kernelVersion
|
||||
kernelDrivers := "/lib/modules/" + kernelVersion
|
||||
kernelDestination := config.KernelImage(kernelVersion)
|
||||
driversDestination := config.KmodsImage(kernelVersion)
|
||||
|
||||
// Create the destination paths just in case it doesn't exist
|
||||
os.MkdirAll(path.Dir(kernelDestination), 0755)
|
||||
os.MkdirAll(path.Dir(driversDestination), 0755)
|
||||
|
||||
if util.IsFile(kernelImage) == false {
|
||||
return errors.New("Could not locate kernel image: " + kernelImage)
|
||||
}
|
||||
|
||||
if util.IsDir(kernelDrivers) == false {
|
||||
return errors.New("Could not locate kernel drivers: " + kernelDrivers)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(kernelImage); err == nil {
|
||||
if util.PathIsNewer(kernelImage, kernelDestination) {
|
||||
wwlog.Printf(wwlog.INFO, "%-45s: Skipping, kernel is current\n", "vmlinuz-"+kernelVersion)
|
||||
} else {
|
||||
err := util.CopyFile(kernelImage, kernelDestination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wwlog.Printf(wwlog.INFO, "%-45s: Done\n", "vmlinuz-"+kernelVersion)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(kernelDrivers); err == nil {
|
||||
if util.PathIsNewer(kernelDrivers, driversDestination) {
|
||||
wwlog.Printf(wwlog.INFO, "%-45s: Skipping, drivers are current\n", "kmods-"+kernelVersion+".img")
|
||||
|
||||
} else {
|
||||
cmd := fmt.Sprintf("cd /; find .%s | cpio --quiet -o -H newc -F \"%s\"", kernelDrivers, driversDestination)
|
||||
err := exec.Command("/bin/sh", "-c", cmd).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wwlog.Printf(wwlog.INFO, "%-45s: Done\n", "kmods-"+kernelVersion+".img")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user