Fixes for kernel identification within the container
This commit is contained in:
@@ -3,7 +3,6 @@ package list
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
|
|
||||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||||
@@ -27,14 +26,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
nodemap[n.ContainerName.Get()]++
|
nodemap[n.ContainerName.Get()]++
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%-25s %-6s %-6s\n", "CONTAINER NAME", "NODES", "KERNEL")
|
fmt.Printf("%-25s %-6s %-6s\n", "CONTAINER NAME", "NODES", "KERNEL VERSION")
|
||||||
for _, source := range sources {
|
for _, source := range sources {
|
||||||
if nodemap[source] == 0 {
|
if nodemap[source] == 0 {
|
||||||
nodemap[source] = 0
|
nodemap[source] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel := container.KernelFind(source)
|
kernelVersion := container.KernelVersion(source)
|
||||||
fmt.Printf("%-25s %-6d %s\n", source, nodemap[source], path.Base(kernel))
|
fmt.Printf("%-25s %-6d %s\n", source, nodemap[source], kernelVersion)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
kernelSearchPaths = []string{
|
kernelSearchPaths = []string{
|
||||||
// This is a printf format where the %s will be the kernel version
|
// This is a printf format where the %s will be the kernel version
|
||||||
"/boot/vmlinuz-*",
|
`/boot/vmlinuz-%s`,
|
||||||
"/lib/modules/*/vmlinuz*",
|
`/boot/vmlinuz-%s.gz`,
|
||||||
|
`/lib/modules/%s/vmlinuz`,
|
||||||
|
`/lib/modules/%s/vmlinuz.gz`,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,26 +26,48 @@ func KernelFind(container string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, searchPath := range kernelSearchPaths {
|
kernelVersion := KernelVersion(container)
|
||||||
|
if kernelVersion == "" {
|
||||||
check_path := path.Join(container_path, searchPath)
|
return ""
|
||||||
|
|
||||||
wwlog.Printf(wwlog.DEBUG, "Searching for kernel(s) at: %s\n", check_path)
|
|
||||||
kernels, err := filepath.Glob(check_path)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(kernels) > 1 {
|
|
||||||
sort.Slice(kernels, func(i, j int) bool {
|
|
||||||
return kernels[i] > kernels[j]
|
|
||||||
})
|
|
||||||
wwlog.Printf(wwlog.VERBOSE, "Multiple kernels found in container: %s\n", container)
|
|
||||||
return kernels[0]
|
|
||||||
} else if len(kernels) == 1 {
|
|
||||||
return kernels[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return "NOT_FOUND"
|
|
||||||
|
for _, searchPath := range kernelSearchPaths {
|
||||||
|
testPath := fmt.Sprintf(searchPath, kernelVersion)
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Looking for kernel at: '%s'\n", testPath)
|
||||||
|
if util.IsFile(path.Join(container_path, testPath)) {
|
||||||
|
return path.Join(container_path, testPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func KernelVersion(container string) string {
|
||||||
|
container_path := RootFsDir(container)
|
||||||
|
if container_path == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
module_lib_path := path.Join(container_path, "/lib/modules/*")
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Searching for kernel modules at: %s\n", module_lib_path)
|
||||||
|
kernelversions, err := filepath.Glob(module_lib_path)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(kernelversions) > 1 {
|
||||||
|
sort.Slice(kernelversions, func(i, j int) bool {
|
||||||
|
return kernelversions[i] > kernelversions[j]
|
||||||
|
})
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Multiple kernels found in container: %s\n", container)
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found lib path: '%s'\n", kernelversions[0])
|
||||||
|
return path.Base(kernelversions[0])
|
||||||
|
} else if len(kernelversions) == 1 {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found lib path: '%s'\n", kernelversions[0])
|
||||||
|
|
||||||
|
return path.Base(kernelversions[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user