Major refactor for Cobra and new pkg/app structure for wwctl
This commit is contained in:
9
Makefile
9
Makefile
@@ -40,7 +40,7 @@ lint:
|
|||||||
@echo Running golangci-lint...
|
@echo Running golangci-lint...
|
||||||
@$(GOLANGCI_LINT) run --build-tags "$(WW_BUILD_GO_BUILD_TAGS)" ./...
|
@$(GOLANGCI_LINT) run --build-tags "$(WW_BUILD_GO_BUILD_TAGS)" ./...
|
||||||
|
|
||||||
all: warewulfd wwbuild wwclient
|
all: warewulfd wwctl wwclient
|
||||||
|
|
||||||
files: all
|
files: all
|
||||||
install -d -m 0755 /var/warewulf/
|
install -d -m 0755 /var/warewulf/
|
||||||
@@ -67,8 +67,8 @@ services: files
|
|||||||
warewulfd:
|
warewulfd:
|
||||||
cd cmd/warewulfd; go build -mod vendor -o ../../warewulfd
|
cd cmd/warewulfd; go build -mod vendor -o ../../warewulfd
|
||||||
|
|
||||||
wwbuild:
|
wwctl:
|
||||||
cd cmd/wwbuild; go build -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwbuild
|
cd cmd/wwctl; go build -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl
|
||||||
|
|
||||||
wwclient:
|
wwclient:
|
||||||
cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags '-extldflags -static' -o ../../wwclient
|
cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags '-extldflags -static' -o ../../wwclient
|
||||||
@@ -76,7 +76,6 @@ wwclient:
|
|||||||
clean:
|
clean:
|
||||||
rm -f warewulfd
|
rm -f warewulfd
|
||||||
rm -f wwbuild
|
rm -f wwbuild
|
||||||
rm -f wwclient
|
rm -f wwctl
|
||||||
|
|
||||||
install: files services
|
install: files services
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func runtimeOverlaySend(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(503)
|
w.WriteHeader(503)
|
||||||
log.Printf("ERROR: No 'runtime overlay' set for node %s\n", node.Fqdn)
|
log.Printf("ERROR: No 'runtime system-overlay' set for node %s\n", node.Fqdn)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func systemOverlaySend(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(503)
|
w.WriteHeader(503)
|
||||||
log.Printf("ERROR: No 'system overlay' set for node %s\n", node.Fqdn)
|
log.Printf("ERROR: No 'system system-overlay' set for node %s\n", node.Fqdn)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ func main() {
|
|||||||
http.HandleFunc("/kernel/", kernelSend)
|
http.HandleFunc("/kernel/", kernelSend)
|
||||||
http.HandleFunc("/kmods/", kmodsSend)
|
http.HandleFunc("/kmods/", kmodsSend)
|
||||||
http.HandleFunc("/vnfs/", vnfsSend)
|
http.HandleFunc("/vnfs/", vnfsSend)
|
||||||
http.HandleFunc("/overlay-system/", systemOverlaySend)
|
http.HandleFunc("/system-overlay-system/", systemOverlaySend)
|
||||||
http.HandleFunc("/overlay-runtime", runtimeOverlaySend)
|
http.HandleFunc("/system-overlay-runtime", runtimeOverlaySend)
|
||||||
|
|
||||||
http.ListenAndServe(":9873", nil)
|
http.ListenAndServe(":9873", nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ func overlayRuntime(node assets.NodeInfo, replace map[string]string, wg *sync.Wa
|
|||||||
/*
|
/*
|
||||||
destModTime := time.Time{}
|
destModTime := time.Time{}
|
||||||
destMod, err := os.Stat(OverlayFile)
|
destMod, err := os.Stat(OverlayFile)
|
||||||
if err == nil {
|
if err == n
|
||||||
|
|
||||||
|
il {
|
||||||
destModTime = destMod.ModTime()
|
destModTime = destMod.ModTime()
|
||||||
}
|
}
|
||||||
configMod, err := os.Stat("/etc/warewulf/nodes.conf")
|
configMod, err := os.Stat("/etc/warewulf/nodes.conf")
|
||||||
@@ -43,7 +45,7 @@ func overlayRuntime(node assets.NodeInfo, replace map[string]string, wg *sync.Wa
|
|||||||
// if sourceModTime.After(destModTime) || configModTime.After(destModTime) {
|
// if sourceModTime.After(destModTime) || configModTime.After(destModTime) {
|
||||||
fmt.Printf("RUNTIME: %s\n", node.Fqdn)
|
fmt.Printf("RUNTIME: %s\n", node.Fqdn)
|
||||||
|
|
||||||
overlayDest := "/tmp/.overlay-" + util.RandomString(16)
|
overlayDest := "/tmp/.system-overlay-" + util.RandomString(16)
|
||||||
BuildOverlayDir(OverlayDir, overlayDest, replace)
|
BuildOverlayDir(OverlayDir, overlayDest, replace)
|
||||||
|
|
||||||
cmd := fmt.Sprintf("cd %s && find . | cpio --quiet -o -H newc -F \"%s\"", overlayDest, OverlayFile)
|
cmd := fmt.Sprintf("cd %s && find . | cpio --quiet -o -H newc -F \"%s\"", overlayDest, OverlayFile)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func overlaySystem(node assets.NodeInfo, replace map[string]string, wg *sync.Wai
|
|||||||
if sourceModTime.After(destModTime) || configModTime.After(destModTime) {
|
if sourceModTime.After(destModTime) || configModTime.After(destModTime) {
|
||||||
fmt.Printf("SYSTEM: %s\n", node.Fqdn)
|
fmt.Printf("SYSTEM: %s\n", node.Fqdn)
|
||||||
|
|
||||||
overlayDest := "/tmp/.overlay-" + util.RandomString(16)
|
overlayDest := "/tmp/.system-overlay-" + util.RandomString(16)
|
||||||
BuildOverlayDir(OverlayDir, overlayDest, replace)
|
BuildOverlayDir(OverlayDir, overlayDest, replace)
|
||||||
|
|
||||||
cmd := fmt.Sprintf("cd %s && find . | cpio --quiet -o -H newc -F \"%s\"", overlayDest, OverlayFile)
|
cmd := fmt.Sprintf("cd %s && find . | cpio --quiet -o -H newc -F \"%s\"", overlayDest, OverlayFile)
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
func vnfsLocalBuild(vnfsPath string, wg *sync.WaitGroup) {
|
|
||||||
defer wg.Done()
|
|
||||||
v := vnfs.New(vnfsPath)
|
|
||||||
|
|
||||||
if _, err := os.Stat(vnfsPath); err == nil {
|
|
||||||
// TODO: Build VNFS to temporary file and move to real location when complete atomically
|
|
||||||
// TODO: Check time stamps of sourcedir and build file to see if we need to rebuild or skip
|
|
||||||
|
|
||||||
//vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(vnfsPath))
|
|
||||||
|
|
||||||
fmt.Printf("Building local Container: %s\n", vnfsPath)
|
|
||||||
|
|
||||||
err := os.MkdirAll(path.Dir(v.Image()), 0755)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = buildVnfs(vnfsPath, v.Image())
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = buildLinks(v, vnfsPath)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
fmt.Printf("SKIPPING VNFS: (bad path) %s\n", vnfsPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
@@ -16,7 +21,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Printf("USAGE: %s [vnfs/kernel/overlay] (node regex)\n", os.Args[0])
|
fmt.Printf("USAGE: %s [vnfs/kernel/system-overlay] (node regex)\n", os.Args[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +112,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if os.Args[1] == "overlay" {
|
} else if os.Args[1] == "system-overlay" {
|
||||||
var nodeList []assets.NodeInfo
|
var nodeList []assets.NodeInfo
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func main() {
|
|||||||
time.Sleep(5000 * time.Millisecond)
|
time.Sleep(5000 * time.Millisecond)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Called via: %s\n", os.Args[0])
|
fmt.Printf("Called via: %s\n", os.Args[0])
|
||||||
fmt.Printf("Runtime overlay is being put in '/warewulf/wwclient-test' rather than '/'\n")
|
fmt.Printf("Runtime system-overlay is being put in '/warewulf/wwclient-test' rather than '/'\n")
|
||||||
os.MkdirAll("/warewulf/wwclient-test", 0755)
|
os.MkdirAll("/warewulf/wwclient-test", 0755)
|
||||||
os.Chdir("/warewulf/wwclient-test")
|
os.Chdir("/warewulf/wwclient-test")
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func main() {
|
|||||||
for true {
|
for true {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
getString := fmt.Sprintf("http://%s:%d/overlay-runtime", config.Ipaddr, config.Port)
|
getString := fmt.Sprintf("http://%s:%d/system-overlay-runtime", config.Ipaddr, config.Port)
|
||||||
resp, err = webclient.Get(getString)
|
resp, err = webclient.Get(getString)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
@@ -84,7 +84,7 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
log.Printf("Not updating runtime overlay, got status code: %d\n", resp.StatusCode)
|
log.Printf("Not updating runtime system-overlay, got status code: %d\n", resp.StatusCode)
|
||||||
time.Sleep(60000 * time.Millisecond)
|
time.Sleep(60000 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
root := wwctl.GetRootCommand()
|
root := wwctl.GetRootCommand()
|
||||||
|
|
||||||
root.Execute()
|
root.Execute()
|
||||||
|
|||||||
79
internal/app/wwctl/build/build.go
Normal file
79
internal/app/wwctl/build/build.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hpcng/warewulf/internal/app/wwctl/build/kernel"
|
||||||
|
runtime_overlay "github.com/hpcng/warewulf/internal/app/wwctl/build/runtime-overlay"
|
||||||
|
system_overlay "github.com/hpcng/warewulf/internal/app/wwctl/build/system-overlay"
|
||||||
|
"github.com/hpcng/warewulf/internal/app/wwctl/build/vnfs"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
|
var nodeList []assets.NodeInfo
|
||||||
|
|
||||||
|
if buildAll == true {
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Building all components\n")
|
||||||
|
buildVnfs = true
|
||||||
|
buildKernel = true
|
||||||
|
buildSystemOverlay = true;
|
||||||
|
buildRuntimeOverlay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) >= 1 {
|
||||||
|
nodeList, _ = assets.SearchByName(args[0])
|
||||||
|
} else {
|
||||||
|
nodeList, _ = assets.FindAllNodes()
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(nodeList) == 0 {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "No nodes found matching: '%s'\n", args[0])
|
||||||
|
os.Exit(255)
|
||||||
|
} else {
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Found matching nodes for build: %d\n", len(nodeList))
|
||||||
|
}
|
||||||
|
|
||||||
|
if buildVnfs == true {
|
||||||
|
// wwlog.Printf(wwlog.INFO, "===============================================================================\n")
|
||||||
|
|
||||||
|
err := vnfs.Build(nodeList, buildForce)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if buildKernel == true {
|
||||||
|
// wwlog.Printf(wwlog.INFO, "===============================================================================\n")
|
||||||
|
|
||||||
|
err := kernel.Build(nodeList, buildForce)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if buildSystemOverlay == true {
|
||||||
|
// wwlog.Printf(wwlog.INFO, "===============================================================================\n")
|
||||||
|
err := system_overlay.Build(nodeList, buildForce)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if buildRuntimeOverlay == true {
|
||||||
|
// wwlog.Printf(wwlog.INFO, "===============================================================================\n")
|
||||||
|
err := runtime_overlay.Build(nodeList, buildForce)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
os.Exit(255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
74
internal/app/wwctl/build/kernel/kernel.go
Normal file
74
internal/app/wwctl/build/kernel/kernel.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package kernel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
const kernelProvisionPath = "/provision/kernel/"
|
||||||
|
|
||||||
|
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||||
|
set := make(map[string]int)
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.INFO, "Importing Kernels:\n")
|
||||||
|
wwlog.SetIndent(4)
|
||||||
|
|
||||||
|
for _, node := range nodeList {
|
||||||
|
if node.KernelVersion != "" {
|
||||||
|
set[node.KernelVersion] ++
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Node '%s' has KernelVersion '%s'\n", node.Fqdn, node.KernelVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for kernelVersion := range set {
|
||||||
|
kernelImage := "/boot/vmlinuz-"+kernelVersion
|
||||||
|
kernelDrivers := "/lib/modules/"+kernelVersion
|
||||||
|
kernelDestination := path.Join(config.LocalStateDir, kernelProvisionPath, "vmlinuz-"+kernelVersion)
|
||||||
|
driversDestination := path.Join(config.LocalStateDir, kernelProvisionPath, "kmods-"+kernelVersion+".img")
|
||||||
|
|
||||||
|
|
||||||
|
// Create the kernel destination path just in case it doesn't exist
|
||||||
|
os.MkdirAll(path.Join(config.LocalStateDir, kernelProvisionPath), 0755)
|
||||||
|
|
||||||
|
if _, err := os.Stat(kernelImage); err == nil {
|
||||||
|
if util.PathIsNewer(kernelImage, kernelDestination) && force == false {
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, kernel is current\n", "vmlinuz-"+kernelVersion)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
err := util.CopyFile(kernelImage, kernelDestination)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "Failed copying kernel image: %s\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", "vmlinuz-"+kernelVersion)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(kernelDrivers); err == nil {
|
||||||
|
if util.PathIsNewer(kernelDrivers, driversDestination) && force == false {
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, kernel 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 {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "Could not generate kernel driver overlay: %s\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", "kmods-"+kernelVersion+".img")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.SetIndent(0)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,16 +8,26 @@ var (
|
|||||||
buildCmd = &cobra.Command{
|
buildCmd = &cobra.Command{
|
||||||
Use: "build",
|
Use: "build",
|
||||||
Short: "Warewulf build subcommand",
|
Short: "Warewulf build subcommand",
|
||||||
Long: "Warewulf build is used to build VNFS, kernel, and overlay objects for provisioning.",
|
Long: "Warewulf build is used to build VNFS, kernel, and system-overlay objects for\n" +
|
||||||
RunE: buildRunE,
|
"provisioning. The default usage will be to build and/or update anything\n" +
|
||||||
|
"that seems to be needed.",
|
||||||
|
RunE: CobraRunE,
|
||||||
}
|
}
|
||||||
option string
|
buildVnfs bool
|
||||||
|
buildKernel bool
|
||||||
|
buildRuntimeOverlay bool
|
||||||
|
buildSystemOverlay bool
|
||||||
|
buildAll bool
|
||||||
|
buildForce bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//buildCmd.PersistentFlags().StringVar(&flagHost, FlagHost, "localhost:7331", "Address of the Fuzzball Host.")
|
buildCmd.PersistentFlags().BoolVarP(&buildVnfs, "vnfs", "V", false, "Build and/or update VNFS images.")
|
||||||
|
buildCmd.PersistentFlags().BoolVarP(&buildKernel, "kernel", "K", false, "Build and/or update Kernel images.")
|
||||||
buildCmd.PersistentFlags().StringVarP(&option, "testopt", "t", "default", "This is a test option")
|
buildCmd.PersistentFlags().BoolVarP(&buildRuntimeOverlay, "runtime", "R", false, "Build and/or update runtime overlays")
|
||||||
|
buildCmd.PersistentFlags().BoolVarP(&buildSystemOverlay, "system", "S", false, "Build and/or update system overlays")
|
||||||
|
buildCmd.PersistentFlags().BoolVarP(&buildAll, "all", "A", false, "Build and/or update all components")
|
||||||
|
buildCmd.PersistentFlags().BoolVarP(&buildForce, "force", "f", false, "Force build even if nothing has been updated.")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,10 +35,3 @@ func init() {
|
|||||||
func GetCommand() *cobra.Command {
|
func GetCommand() *cobra.Command {
|
||||||
return buildCmd
|
return buildCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildRunE(cmd *cobra.Command, args []string) error {
|
|
||||||
fmt.Printf("Hello World. Got Option: %s, %s\n", option, args)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
133
internal/app/wwctl/build/runtime-overlay/runtime-overlay.go
Normal file
133
internal/app/wwctl/build/runtime-overlay/runtime-overlay.go
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
package runtime_overlay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||||
|
wwlog.Printf(wwlog.INFO, "Building Runtime Overlays:\n")
|
||||||
|
wwlog.SetIndent(4)
|
||||||
|
|
||||||
|
for _, node := range nodeList {
|
||||||
|
if node.RuntimeOverlay != "" {
|
||||||
|
OverlayDir := path.Join(config.LocalStateDir, "/overlays/runtime/", node.RuntimeOverlay)
|
||||||
|
OverlayFile := path.Join(config.LocalStateDir, "/provision/overlays/runtime/", node.Fqdn+".img")
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Building Runtime Overlay for: %s\n", node.Fqdn)
|
||||||
|
|
||||||
|
tmpDir, err := ioutil.TempDir(os.TempDir(), ".wwctl-runtime-overlay-")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(OverlayDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(path.Dir(OverlayFile), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if force == false {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Checking if overlay is required\n")
|
||||||
|
}
|
||||||
|
if util.PathIsNewer(OverlayDir, OverlayFile) {
|
||||||
|
if force == false {
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, overlay is current\n", node.Fqdn)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlayDir)
|
||||||
|
err = os.Chdir(OverlayDir)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "Could not chdir() to OverlayDir: %s\n", OverlayDir)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Walking the file system: %s\n", OverlayDir)
|
||||||
|
err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found directory: %s\n", location)
|
||||||
|
|
||||||
|
err := os.MkdirAll(path.Join(tmpDir, location), info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if filepath.Ext(location) == ".ww" {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found template file: %s\n", location)
|
||||||
|
|
||||||
|
destFile := strings.TrimSuffix(location, ".ww")
|
||||||
|
|
||||||
|
tmpl, err := template.ParseGlob(path.Join(OverlayDir, destFile) + ".ww*")
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := os.OpenFile(path.Join(tmpDir, destFile), os.O_RDWR|os.O_CREATE, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer w.Close()
|
||||||
|
|
||||||
|
err = tmpl.Execute(w, node)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if b, _ := regexp.MatchString(`\.ww[a-zA-Z0-9\-\._]*$`, location); b == true {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Ignoring WW template file: %s\n", location)
|
||||||
|
} else {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found file: %s\n", location)
|
||||||
|
|
||||||
|
err := util.CopyFile(path.Join(OverlayDir, location), path.Join(tmpDir, location))
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", node.Fqdn)
|
||||||
|
|
||||||
|
cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc -F \"%s\"", tmpDir, OverlayFile)
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd)
|
||||||
|
err = exec.Command("/bin/sh", "-c", cmd).Run()
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "Could not generate runtime image overlay: %s\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-3s: Done\n", node.Fqdn)
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Removing temporary directory: %s\n", tmpDir)
|
||||||
|
os.RemoveAll(tmpDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.SetIndent(0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
133
internal/app/wwctl/build/system-overlay/system-overlay.go
Normal file
133
internal/app/wwctl/build/system-overlay/system-overlay.go
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
package system_overlay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Build(nodeList []assets.NodeInfo, force bool) error {
|
||||||
|
wwlog.Printf(wwlog.INFO, "Building System Overlays:\n")
|
||||||
|
wwlog.SetIndent(4)
|
||||||
|
|
||||||
|
for _, node := range nodeList {
|
||||||
|
if node.SystemOverlay != "" {
|
||||||
|
OverlayDir := path.Join(config.LocalStateDir, "/overlays/system/", node.SystemOverlay)
|
||||||
|
OverlayFile := path.Join(config.LocalStateDir, "/provision/overlays/system/", node.Fqdn+".img")
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Building System Overlay for: %s\n", node.Fqdn)
|
||||||
|
|
||||||
|
tmpDir, err := ioutil.TempDir(os.TempDir(), ".wwctl-system-overlay-")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(OverlayDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(path.Dir(OverlayFile), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if force == false {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Checking if overlay is required\n")
|
||||||
|
}
|
||||||
|
if util.PathIsNewer(OverlayDir, OverlayFile) {
|
||||||
|
if force == false {
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, overlay is current\n", node.Fqdn)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Changing directory to OverlayDir: %s\n", OverlayDir)
|
||||||
|
err = os.Chdir(OverlayDir)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "Could not chdir() to OverlayDir: %s\n", OverlayDir)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Walking the file system: %s\n", OverlayDir)
|
||||||
|
err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found directory: %s\n", location)
|
||||||
|
|
||||||
|
err := os.MkdirAll(path.Join(tmpDir, location), info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if filepath.Ext(location) == ".ww" {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found template file: %s\n", location)
|
||||||
|
|
||||||
|
destFile := strings.TrimSuffix(location, ".ww")
|
||||||
|
|
||||||
|
tmpl, err := template.ParseGlob(path.Join(OverlayDir, destFile) + ".ww*")
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := os.OpenFile(path.Join(tmpDir, destFile), os.O_RDWR|os.O_CREATE, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer w.Close()
|
||||||
|
|
||||||
|
err = tmpl.Execute(w, node)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if b, _ := regexp.MatchString(`\.ww[a-zA-Z0-9\-\._]*$`, location); b == true {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Ignoring WW template file: %s\n", location)
|
||||||
|
} else {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Found file: %s\n", location)
|
||||||
|
|
||||||
|
err := util.CopyFile(path.Join(OverlayDir, location), path.Join(tmpDir, location))
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", node.Fqdn)
|
||||||
|
|
||||||
|
cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc -F \"%s\"", tmpDir, OverlayFile)
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd)
|
||||||
|
err = exec.Command("/bin/sh", "-c", cmd).Run()
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.ERROR, "Could not generate system image overlay: %s\n", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", node.Fqdn)
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Removing temporary directory: %s\n", tmpDir)
|
||||||
|
os.RemoveAll(tmpDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.SetIndent(0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
50
internal/app/wwctl/build/vnfs/containerdir.go
Normal file
50
internal/app/wwctl/build/vnfs/containerdir.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package vnfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BuildContainerdir(v vnfs.VnfsObject) {
|
||||||
|
|
||||||
|
if _, err := os.Stat(v.Source()); err != nil {
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping (bad path)\n", v.Name())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Checking if there have been any updates to the VNFS directory\n")
|
||||||
|
if util.PathIsNewer(v.Source(), v.Image()) {
|
||||||
|
if buildForce == false {
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", v.Name())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Making the directory: %s\n", path.Dir(v.Image()))
|
||||||
|
err := os.MkdirAll(path.Dir(v.Image()), 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", v.Source(), v.Image())
|
||||||
|
err = buildVnfs(v.Source(), v.Image())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Building links for Warewulf access to chroot\n")
|
||||||
|
err = buildLinks(v, v.Source())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", v.Name())
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package vnfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -6,10 +6,9 @@ import (
|
|||||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/oci"
|
"github.com/hpcng/warewulf/internal/pkg/oci"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||||
"log"
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -17,21 +16,17 @@ const (
|
|||||||
VnfsHashDir = config.LocalStateDir + "/oci/vnfs/hash/"
|
VnfsHashDir = config.LocalStateDir + "/oci/vnfs/hash/"
|
||||||
)
|
)
|
||||||
|
|
||||||
func vnfsOciBuild(OciPath string, wg *sync.WaitGroup) {
|
func BuildDocker(v vnfs.VnfsObject) {
|
||||||
v := vnfs.New(OciPath)
|
wwlog.Printf(wwlog.VERBOSE, "Building OCI Container: %s\n", v.Source())
|
||||||
|
|
||||||
// vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(OciPath))
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
log.Printf("Building OCI Container: %s\n", OciPath)
|
|
||||||
|
|
||||||
c, err := oci.NewCache(oci.OptSetCachePath(OciCacheDir))
|
c, err := oci.NewCache(oci.OptSetCachePath(OciCacheDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
log.Printf("Downloading OCI container layers\n")
|
|
||||||
sourcePath, err := c.Pull(context.Background(), OciPath, nil)
|
wwlog.Printf(wwlog.VERBOSE, "Downloading OCI container layers\n")
|
||||||
|
sourcePath, err := c.Pull(context.Background(), v.Source(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -42,7 +37,7 @@ func vnfsOciBuild(OciPath string, wg *sync.WaitGroup) {
|
|||||||
name, err := os.Readlink(v.Image())
|
name, err := os.Readlink(v.Image())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if name == hashDestination {
|
if name == hashDestination {
|
||||||
log.Printf("Container already built, no update available\n")
|
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", v.Name())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +58,7 @@ func vnfsOciBuild(OciPath string, wg *sync.WaitGroup) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Building bootable VNFS image\n")
|
wwlog.Printf(wwlog.VERBOSE, "Building bootable VNFS image\n")
|
||||||
|
|
||||||
err = buildVnfs(sourcePath, hashDestination)
|
err = buildVnfs(sourcePath, hashDestination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -71,23 +66,24 @@ func vnfsOciBuild(OciPath string, wg *sync.WaitGroup) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Finalizing Build\n")
|
wwlog.Printf(wwlog.VERBOSE, "Finalizing Build\n")
|
||||||
|
|
||||||
_ = os.Remove(v.Image() + "-link")
|
_ = os.Remove(v.Image() + "-link")
|
||||||
err = os.Symlink(hashDestination, v.Image()+"-link")
|
err = os.Symlink(hashDestination, v.Image()+"-link")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
err = os.Rename(v.Image()+"-link", v.Image())
|
err = os.Rename(v.Image()+"-link", v.Image())
|
||||||
|
|
||||||
err = buildLinks(v, sourcePath)
|
err = buildLinks(v, sourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Completed building VNFS: %s\n", path.Base(OciPath))
|
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", v.Name())
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
package main
|
package vnfs
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildVnfs(source string, dest string) error {
|
func buildVnfs(source string, dest string) error {
|
||||||
@@ -20,6 +22,9 @@ func buildLinks(v vnfs.VnfsObject, source string) error {
|
|||||||
// Just incase the temporary link location is present, remove it if we can
|
// Just incase the temporary link location is present, remove it if we can
|
||||||
_ = os.Remove(v.Root() + "-link")
|
_ = os.Remove(v.Root() + "-link")
|
||||||
|
|
||||||
|
// Just incase the directory doesn't exist, make it
|
||||||
|
_ = os.MkdirAll(path.Dir(v.Root()), 0755)
|
||||||
|
|
||||||
// Link to a temporary location so we can atomically move the link into place
|
// Link to a temporary location so we can atomically move the link into place
|
||||||
err := os.Symlink(source, v.Root()+"-link")
|
err := os.Symlink(source, v.Root()+"-link")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
51
internal/app/wwctl/build/vnfs/vnfs.go
Normal file
51
internal/app/wwctl/build/vnfs/vnfs.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package vnfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildForce bool
|
||||||
|
|
||||||
|
func Build(nodeList []assets.NodeInfo, force bool) (error) {
|
||||||
|
set := make(map[string]int)
|
||||||
|
|
||||||
|
wwlog.Printf(wwlog.INFO, "Importing VNFS Images:\n")
|
||||||
|
wwlog.SetIndent(4)
|
||||||
|
|
||||||
|
buildForce = force
|
||||||
|
|
||||||
|
for _, node := range nodeList {
|
||||||
|
if node.Vnfs != "" {
|
||||||
|
set[node.Vnfs] ++
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Node '%s' has VNFS '%s'\n", node.Fqdn, node.Vnfs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for uri := range set {
|
||||||
|
v := vnfs.New(uri)
|
||||||
|
wwlog.Printf(wwlog.VERBOSE, "VNFS found: %s (nodes: %d)\n", uri, set[uri])
|
||||||
|
if strings.HasPrefix(uri, "docker://") {
|
||||||
|
BuildDocker(v)
|
||||||
|
|
||||||
|
} else if strings.HasPrefix(uri, "docker-daemon://") {
|
||||||
|
//wwlog.Printf(wwlog.INFO, "Building VNFS from Docker service: %s\n", uri)
|
||||||
|
wwlog.Printf(wwlog.INFO, "Building VNFS from Docker service is not supported yet: %s\n", uri)
|
||||||
|
|
||||||
|
} else if strings.HasPrefix(uri, "/") {
|
||||||
|
if strings.HasSuffix(uri, "tar.gz") {
|
||||||
|
//wwlog.Printf(wwlog.WARN, "Building VNFS from local tarball: %s\n", uri)
|
||||||
|
wwlog.Printf(wwlog.WARN, "Building VNFS from local tarball is not supported yet: %s\n", uri)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
BuildContainerdir(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wwlog.SetIndent(0)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -9,16 +9,14 @@ import (
|
|||||||
var (
|
var (
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "wwctl",
|
Use: "wwctl",
|
||||||
Short: "Warewulf CTL",
|
Short: "Warewulf Control",
|
||||||
Long: "Fuzzball CLI is an application for interacting with a Fuzzball Service.",
|
Long: "Control interface to the Cluster Warewulf Provisioning System.",
|
||||||
PersistentPreRunE: rootPersistentPreRunE,
|
PersistentPreRunE: rootPersistentPreRunE,
|
||||||
}
|
}
|
||||||
verboseArg bool
|
verboseArg bool
|
||||||
debugArg bool
|
debugArg bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().BoolVarP(&verboseArg, "verbose", "v", false, "Run with increased verbosity.")
|
rootCmd.PersistentFlags().BoolVarP(&verboseArg, "verbose", "v", false, "Run with increased verbosity.")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&debugArg, "debug", "d", false, "Run with debugging messages enabled.")
|
rootCmd.PersistentFlags().BoolVarP(&debugArg, "debug", "d", false, "Run with debugging messages enabled.")
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ type nodeGroup struct {
|
|||||||
Comment string
|
Comment string
|
||||||
Vnfs string
|
Vnfs string
|
||||||
Ipxe string `yaml:"ipxe template"`
|
Ipxe string `yaml:"ipxe template"`
|
||||||
SystemOverlay string `yaml:"system overlay""`
|
SystemOverlay string `yaml:"system system-overlay""`
|
||||||
RuntimeOverlay string `yaml:"runtime overlay""`
|
RuntimeOverlay string `yaml:"runtime system-overlay""`
|
||||||
DomainSuffix string `yaml:"domain suffix"`
|
DomainSuffix string `yaml:"domain suffix"`
|
||||||
KernelVersion string `yaml:"kernel version"`
|
KernelVersion string `yaml:"kernel version"`
|
||||||
Nodes map[string]nodeEntry
|
Nodes map[string]nodeEntry
|
||||||
@@ -42,8 +42,8 @@ type nodeEntry struct {
|
|||||||
Hostname string
|
Hostname string
|
||||||
Vnfs string
|
Vnfs string
|
||||||
Ipxe string `yaml:"ipxe template"`
|
Ipxe string `yaml:"ipxe template"`
|
||||||
SystemOverlay string `yaml:"system overlay"`
|
SystemOverlay string `yaml:"system system-overlay"`
|
||||||
RuntimeOverlay string `yaml:"runtime overlay"`
|
RuntimeOverlay string `yaml:"runtime system-overlay"`
|
||||||
DomainSuffix string `yaml:"domain suffix"`
|
DomainSuffix string `yaml:"domain suffix"`
|
||||||
KernelVersion string `yaml:"kernel version"`
|
KernelVersion string `yaml:"kernel version"`
|
||||||
IpmiIpaddr string `yaml:"ipmi ipaddr"`
|
IpmiIpaddr string `yaml:"ipmi ipaddr"`
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
@@ -31,6 +32,22 @@ func DirModTime(path string) (time.Time, error) {
|
|||||||
return lastTime, nil
|
return lastTime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PathIsNewer(source string, compare string) bool {
|
||||||
|
time1, err := DirModTime(source)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "%s\n", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
time2, err := DirModTime(compare)
|
||||||
|
if err != nil {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "%s\n", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return time1.Before(time2)
|
||||||
|
}
|
||||||
|
|
||||||
func RandomString(n int) string {
|
func RandomString(n int) string {
|
||||||
var letter = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
var letter = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
|
|
||||||
@@ -42,6 +59,7 @@ func RandomString(n int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CopyFile(source string, dest string) error {
|
func CopyFile(source string, dest string) error {
|
||||||
|
wwlog.Printf(wwlog.DEBUG, "Copying '%s' to '%s'\n", source, dest)
|
||||||
sourceFD, err := os.Open(source)
|
sourceFD, err := os.Open(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -7,45 +7,67 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VnfsObject struct {
|
type VnfsObject struct {
|
||||||
Source string
|
SourcePath string
|
||||||
RootPath string
|
RootPath string
|
||||||
ImagePath string
|
ImagePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(s string) VnfsObject {
|
func New(s string) VnfsObject {
|
||||||
var ret VnfsObject
|
var ret VnfsObject
|
||||||
|
|
||||||
ret.Source = s
|
ret.SourcePath = s
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (self *VnfsObject) Name() string {
|
func (self *VnfsObject) Name() string {
|
||||||
if self.Source == "" {
|
if self.SourcePath == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(self.Source, "/") {
|
if strings.HasPrefix(self.SourcePath, "/") {
|
||||||
return path.Base(self.Source)
|
return path.Base(self.SourcePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := strings.Split(self.Source, "://")
|
return self.SourcePath
|
||||||
|
|
||||||
return strings.ReplaceAll(uri[0]+":"+uri[1], "/", "_")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VnfsObject) Image() string {
|
func (self *VnfsObject) NameClean() string {
|
||||||
if self.Source == "" {
|
if self.SourcePath == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.LocalStateDir + "/provision/vnfs/" + self.Name() + ".img.gz"
|
if strings.HasPrefix(self.SourcePath, "/") {
|
||||||
|
return path.Base(self.SourcePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := strings.Split(self.SourcePath, "://")
|
||||||
|
|
||||||
|
return strings.ReplaceAll(uri[1], "/", "_")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *VnfsObject) Source() string {
|
||||||
|
if self.SourcePath == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.SourcePath
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *VnfsObject) Image() string {
|
||||||
|
if self.SourcePath == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.LocalStateDir + "/provision/vnfs/" + self.NameClean() + ".img.gz"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VnfsObject) Root() string {
|
func (self *VnfsObject) Root() string {
|
||||||
if self.Source == "" {
|
if self.SourcePath == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.LocalStateDir + "/chroots/" + self.Name()
|
return config.LocalStateDir + "/chroots/" + self.NameClean()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package wwlog
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -15,32 +16,33 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
logLevel uint
|
logLevel uint
|
||||||
|
Indent string
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetLevel(level uint) {
|
func SetLevel(level uint) {
|
||||||
logLevel = level
|
logLevel = level
|
||||||
|
|
||||||
if logLevel == DEBUG {
|
log.SetFlags(0)
|
||||||
log.SetFlags(log.Lmicroseconds | log.Llongfile)
|
Printf(DEBUG, "Set log level to: %d\n", logLevel)
|
||||||
} else {
|
}
|
||||||
log.SetFlags(0)
|
|
||||||
}
|
func SetIndent(i int) {
|
||||||
Printf(VERBOSE, "Set log level to: %d\n", logLevel)
|
Indent = strings.Repeat(" ", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prefixLevel(level uint) {
|
func prefixLevel(level uint) {
|
||||||
if level == DEBUG {
|
if level == DEBUG {
|
||||||
log.SetPrefix("[DEBUG] ")
|
log.SetPrefix("[DEBUG] "+Indent)
|
||||||
} else if level == VERBOSE {
|
} else if level == VERBOSE {
|
||||||
log.SetPrefix("[VERBOSE] ")
|
log.SetPrefix("[VERBOSE] "+Indent)
|
||||||
} else if level == INFO {
|
} else if level == INFO {
|
||||||
log.SetPrefix("[INFO] ")
|
log.SetPrefix("[INFO] "+Indent)
|
||||||
} else if level == WARN {
|
} else if level == WARN {
|
||||||
log.SetPrefix("[WARN] ")
|
log.SetPrefix("[WARN] "+Indent)
|
||||||
} else if level == ERROR {
|
} else if level == ERROR {
|
||||||
log.SetPrefix("[ERROR] ")
|
log.SetPrefix("[ERROR] "+Indent)
|
||||||
} else if level == CRITICAL {
|
} else if level == CRITICAL {
|
||||||
log.SetPrefix("[CRITICAL] ")
|
log.SetPrefix("[CRITICAL] "+Indent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +51,8 @@ func Println(level uint, message string) {
|
|||||||
prefixLevel(level)
|
prefixLevel(level)
|
||||||
log.Println(message)
|
log.Println(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.SetPrefix("[LOG] "+Indent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Printf(level uint, message string, a...interface{}) {
|
func Printf(level uint, message string, a...interface{}) {
|
||||||
@@ -56,4 +60,6 @@ func Printf(level uint, message string, a...interface{}) {
|
|||||||
prefixLevel(level)
|
prefixLevel(level)
|
||||||
log.Printf(message, a...)
|
log.Printf(message, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.SetPrefix("[LOG] "+Indent)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user