Days updates, fixes, and UI updates

This commit is contained in:
Gregory Kurtzer
2020-11-18 17:41:10 -08:00
parent ed7dbdaf32
commit 27441f77d3
22 changed files with 269 additions and 127 deletions

View File

@@ -1,7 +1,7 @@
nodegroups:
group_1:
comment: This is the group 1
vnfs: /var/chroots/test
vnfs: /var/chroots/centos-7
system overlay: default
runtime overlay: default
domain suffix: group1

View File

@@ -1,13 +0,0 @@
package copy
import (
"fmt"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("This will copy '%s' to overlay '%s'\n", args[1], args[0])
return nil
}

View File

@@ -1,25 +0,0 @@
package copy
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "copy [overlay name] [source file] (dest location)",
Short: "Copy Warewulf Overlay files",
Long: "Warewulf Copy overlay files",
RunE: CobraRunE,
Args: cobra.RangeArgs(2, 3),
Aliases: []string{"import"},
}
SystemOverlay bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,6 +1,7 @@
package create
import (
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
@@ -32,5 +33,32 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.INFO, "Created new runtime overlay: %s\n", args[0])
}
if NoOverlayUpdate == false {
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
var updateNodes []assets.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
}
}
return nil
}

View File

@@ -14,11 +14,12 @@ var (
}
SystemOverlay bool
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -48,10 +48,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
}
fmt.Printf("Deleted overlay: %s\n", args[0])
} else if len(args) > 1 {
for i := 1; i < len(args); i++ {
removePath := path.Join(overlayPath, args[i])
if util.IsDir(removePath) == true || util.IsFile(removePath) == true {
wwlog.Printf(wwlog.ERROR, "Path to remove doesn't exist in overlay: %s\n", removePath)
os.Exit(1)
}
if Force == true {
err := os.RemoveAll(removePath)
if err != nil {
@@ -68,7 +75,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
if RmEmptyDirs == true {
if Parents == true {
// Cleanup any empty directories left behind...
i := path.Dir(removePath)
for i != overlayPath {
@@ -83,36 +90,35 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
}
fmt.Printf("Deleted from overlay: %s:%s\n", args[0], args[1])
}
fmt.Printf("Deleted from overlay: %s:%s\n", args[0], args[1])
// Everything below this point is to update the relevant overlays
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
var updateNodes []assets.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
if NoOverlayUpdate == false {
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
}
var updateNodes []assets.NodeInfo
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
}
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
}
}
return nil
}

View File

@@ -15,14 +15,15 @@ var (
}
SystemOverlay bool
Force bool
RmEmptyDirs bool
Parents bool
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().BoolVarP(&Force, "force", "f", false, "Force deletion of a non-empty overlay")
baseCmd.PersistentFlags().BoolVarP(&RmEmptyDirs, "empty", "e", false, "Remove empty directories")
baseCmd.PersistentFlags().BoolVarP(&Parents, "parents", "p", false, "Remove empty parent directories")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -51,7 +51,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if util.IsFile(overlayFile) == false && filepath.Ext(overlayFile) == ".ww" {
wwlog.Printf(wwlog.WARN, "This is a new file, creating some default content\n")
w, err := os.OpenFile(overlayFile, os.O_RDWR|os.O_CREATE, 0644)
w, err := os.OpenFile(overlayFile, os.O_RDWR|os.O_CREATE, os.FileMode(PermMode))
if err != nil {
wwlog.Printf(wwlog.WARN, "Could not create file for writing: %s\n", err)
}
@@ -76,31 +76,32 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "Editor process existed with non-zero\n")
os.Exit(1)
}
wwlog.Printf(wwlog.INFO, "Updated: %s %s\n", args[0], args[1] )
// Everything below this point is to update the relevant overlays
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
var updateNodes []assets.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
if NoOverlayUpdate == false {
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
}
var updateNodes []assets.NodeInfo
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
}
}
return nil

View File

@@ -16,13 +16,16 @@ var (
SystemOverlay bool
ListFiles bool
CreateDirs bool
PermMode int32
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().BoolVarP(&ListFiles, "files", "f", false, "List files contained within a given overlay")
baseCmd.PersistentFlags().BoolVarP(&CreateDirs, "parents", "p", false, "Create any necessary parent directories")
baseCmd.PersistentFlags().Int32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -0,0 +1,75 @@
package imprt
import (
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
"path"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
overlayName := args[0]
source := args[1]
var dest string
var overlaySource string
if len(args) == 3 {
dest = args[2]
} else {
dest = source
}
if SystemOverlay == true {
wwlog.Printf(wwlog.VERBOSE, "Importing '%s' into system overlay '%s:%s'\n", source, overlayName, dest)
overlaySource = config.SystemOverlaySource(overlayName)
} else {
wwlog.Printf(wwlog.VERBOSE, "Importing '%s' into runtime overlay '%s:%s'\n", source, overlayName, dest)
overlaySource = config.RuntimeOverlaySource(overlayName)
}
if util.IsDir(overlaySource) == false {
wwlog.Printf(wwlog.ERROR, "Overlay does not exist: %s\n", overlayName)
os.Exit(1)
}
err := util.CopyFile(source, path.Join(overlaySource, dest))
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed copying file into overlay sourcedir:\n")
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if NoOverlayUpdate == false {
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
var updateNodes []assets.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == overlayName {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
}
}
return nil
}

View File

@@ -0,0 +1,28 @@
package imprt
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "import [overlay name] [source file] (dest location)",
Short: "Import Warewulf Overlay files",
Long: "Warewulf Import overlay files",
RunE: CobraRunE,
Args: cobra.RangeArgs(2, 3),
Aliases: []string{"cp"},
}
SystemOverlay bool
PermMode int32
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show system overlays instead of runtime")
baseCmd.PersistentFlags().Int32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -110,5 +110,29 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
var unconfigured bool
for overlay, _ := range set {
var overlayPath string
if SystemOverlay == true {
overlayPath = config.SystemOverlaySource(overlay)
} else {
overlayPath = config.SystemOverlaySource(overlay)
}
if util.IsDir(overlayPath) == false {
fmt.Printf("%-30s %-12d 0\n", "("+overlay+")", set[overlay])
unconfigured = true
}
}
if unconfigured == true {
fmt.Printf("\n")
wwlog.Printf(wwlog.WARN, "There are unconfigured overlays present, run the following command to\n")
wwlog.Printf(wwlog.WARN, "create a new overlay:\n")
wwlog.Printf(wwlog.WARN, "\n")
wwlog.Printf(wwlog.WARN, " $ sudo wwctl overlay create ...\n")
}
return nil
}

View File

@@ -33,7 +33,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.DEBUG, "Will create directory in overlay: %s:%s\n", args[0], overlayDir)
err := os.MkdirAll(overlayDir, 0755)
err := os.MkdirAll(overlayDir, os.FileMode(PermMode))
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not create directory: %s\n", path.Dir(overlayDir))
os.Exit(1)
@@ -41,30 +41,30 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("Created directory within overlay: %s:%s\n", args[0], args[1])
// Everything below this point is to update the relevant overlays
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
var updateNodes []assets.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
if NoOverlayUpdate == false {
nodes, err := assets.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
}
var updateNodes []assets.NodeInfo
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
}
}
return nil

View File

@@ -13,13 +13,14 @@ var (
Args: cobra.MinimumNArgs(2),
}
SystemOverlay bool
// PermMode os.FileMode
PermMode int32
NoOverlayUpdate bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
// This will be added back as soon as I figure out how to properly handle the FileMode case
// baseCmd.PersistentFlags().Uint32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")
baseCmd.PersistentFlags().Int32VarP(&PermMode, "mode", "m", 0755, "Permission mode for directory")
baseCmd.PersistentFlags().BoolVarP(&NoOverlayUpdate, "noupdate", "n", false, "Don't update overlays")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -2,10 +2,10 @@ package overlay
import (
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/build"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/copy"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/create"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/delete"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/edit"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/imprt"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/list"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/mkdir"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay/show"
@@ -32,7 +32,7 @@ func init() {
baseCmd.AddCommand(delete.GetCommand())
baseCmd.AddCommand(mkdir.GetCommand())
baseCmd.AddCommand(build.GetCommand())
baseCmd.AddCommand(copy.GetCommand())
baseCmd.AddCommand(imprt.GetCommand())
}

View File

@@ -134,7 +134,7 @@ func (p *puller) pull(ctx context.Context, uri, dst string) (err error) {
// copy to cache location
_, err = copy.Image(ctx, policyCtx, cacheRef, srcRef, &copy.Options{
//ReportWriter: os.Stdout,
ReportWriter: os.Stdout,
SourceCtx: p.sysCtx,
})
if err != nil {

View File

@@ -15,7 +15,7 @@ func templateFileInclude(path string) string {
wwlog.Printf(wwlog.DEBUG, "Including file into template: %s\n", path)
content, err := ioutil.ReadFile(path)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Template include: %s\n", err)
wwlog.Printf(wwlog.WARN, "Could not include file into template: %s\n", err)
}
return strings.TrimSuffix(string(content), "\n")
}
@@ -28,7 +28,7 @@ func templateVnfsFileInclude(vnfsname string, filepath string) string {
vnfsdir := config.VnfsChroot(v.NameClean())
if util.IsDir(vnfsdir) == false {
wwlog.Printf(wwlog.WARN, "Could not include file from non-existent VNFS cache: %s:%s\n", vnfsname, filepath)
wwlog.Printf(wwlog.WARN, "Template requesting file from non-imported VNFS: %s (%s)\n", vnfsname, filepath)
return ""
}
wwlog.Printf(wwlog.DEBUG, "IncludeVnfs file from: %s/%s\n", vnfsdir, filepath)

View File

@@ -71,7 +71,12 @@ func RuntimeBuild(nodeList []assets.NodeInfo, force bool) error {
}
if util.IsDir(OverlayDir) == false {
wwlog.Printf(wwlog.WARN, "Skipping non-existent overlay source: %s\n", OverlayDir)
wwlog.Printf(wwlog.WARN, "%-35s: Skipped (unknown runtime overlay)\n", node.Fqdn)
continue
}
if util.IsDir(node.VnfsDir) == false {
wwlog.Printf(wwlog.WARN, "%-35s: Skipped (VNFS not imported)\n", node.Fqdn)
continue
}
@@ -117,7 +122,7 @@ func RuntimeBuild(nodeList []assets.NodeInfo, force bool) error {
destFile := strings.TrimSuffix(location, ".ww")
tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": templateFileInclude, "IncludeVnfs": templateVnfsFileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*"))
tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": templateFileInclude, "IncludeFromVnfs": templateVnfsFileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err

View File

@@ -71,7 +71,12 @@ func SystemBuild(nodeList []assets.NodeInfo, force bool) error {
}
if util.IsDir(OverlayDir) == false {
wwlog.Printf(wwlog.WARN, "Skipping non-existent overlay source: %s\n", OverlayDir)
wwlog.Printf(wwlog.WARN, "%-35s: Skipped (unknown system overlay)\n", node.Fqdn)
continue
}
if util.IsDir(node.VnfsDir) == false {
wwlog.Printf(wwlog.WARN, "%-35s: Skipped (VNFS not imported)\n", node.Fqdn)
continue
}
@@ -117,7 +122,7 @@ func SystemBuild(nodeList []assets.NodeInfo, force bool) error {
destFile := strings.TrimSuffix(location, ".ww")
tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": templateFileInclude, "IncludeVnfs": templateVnfsFileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*"))
tmpl, err := template.New(path.Base(location)).Funcs(template.FuncMap{"Include": templateFileInclude, "IncludeFromVnfs": templateVnfsFileInclude}).ParseGlob(path.Join(OverlayDir, destFile + ".ww*"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err

View File

@@ -84,6 +84,8 @@ func CopyFile(source string, dest string) error {
return destFD.Close()
}
//TODO: func CopyRecursive ...
func IsDir(path string) (bool) {
if stat, err := os.Stat(path); err == nil && stat.IsDir() {

View File

@@ -1,2 +1,2 @@
{{Include (printf "%s%s" .VnfsDir "/etc/group")}}
{{IncludeFromVnfs .Vnfs "/etc/group"}}
{{Include "/etc/group"}}

View File

@@ -1,3 +1,3 @@
root::0:0:root:/root:/bin/bash
{{Include (printf "%s%s" .VnfsDir "/etc/passwd")}}
{{IncludeFromVnfs .Vnfs "/etc/passwd"}}
{{Include "/etc/passwd"}}