Files
warewulf/internal/app/wwctl/overlay/build/main.go
2022-02-26 22:39:50 +00:00

48 lines
1.1 KiB
Go

package build
import (
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/hpcng/warewulf/pkg/hostlist"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
if BuildHost || (!BuildHost && !BuildNodes) {
err := overlay.BuildHostOverlay()
if err != nil {
wwlog.Printf(wwlog.WARN, "host overlay could not be built: %s\n", err)
}
}
if BuildNodes || (!BuildHost && !BuildNodes) {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not get node list: %s\n", err)
os.Exit(1)
}
if len(args) > 0 {
args = hostlist.Expand(args)
err = overlay.BuildAllOverlays(node.FilterByName(nodes, args))
} else {
err = overlay.BuildAllOverlays(nodes)
}
if err != nil {
wwlog.Printf(wwlog.WARN, "Some system overlays failed to be generated: %s\n", err)
}
}
return nil
}