Merge branch 'main' of github.com:ctrl-cmd/warewulf into main

This commit is contained in:
Shannon V. Davidson
2020-12-01 13:49:28 -06:00
85 changed files with 3085 additions and 1440 deletions

View File

@@ -46,7 +46,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.INFO, "Building VNFS images...\n")
for _, node := range nodes {
set[node.Vnfs] ++
set[node.Vnfs.String()] ++
}
for e := range set {
vnfs.Build(e, buildForce)
@@ -60,7 +60,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.INFO, "Building Kernel images...\n")
for _, node := range nodes {
set[node.KernelVersion] ++
set[node.KernelVersion.String()] ++
}
for e := range set {
kernel.Build(e)

View File

@@ -0,0 +1,29 @@
package add
import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed opening node database: %s\n", err)
os.Exit(1)
}
for _, c := range args {
err = nodeDB.AddController(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
nodeDB.Persist()
return nil
}

View File

@@ -0,0 +1,23 @@
package add
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "add",
Short: "Add",
Long: "Add",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetController string
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,61 @@
package delete
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var count int
var numNodes int
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB. FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err)
os.Exit(1)
}
for _, c := range args {
err := nodeDB.DelController(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
} else {
for _, n := range nodes {
if n.Cid.Get() == c {
numNodes ++
}
}
count ++
}
}
if count > 0 {
q := fmt.Sprintf("Are you sure you want to delete %d controllers(s) (%d nodes)", count, numNodes)
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
wwlog.Printf(wwlog.INFO, "No controllers found\n")
}
return nil
}

View File

@@ -0,0 +1,23 @@
package delete
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "delete",
Short: "Delete",
Long: "Delete",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetController string
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,45 @@
package list
import "C"
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
"reflect"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
controllers, err := nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all nodes: %s\n", err)
os.Exit(1)
}
if ShowAll == true {
for _, controller := range controllers {
v := reflect.ValueOf(controller)
typeOfS := v.Type()
fmt.Printf("################################################################################\n")
for i := 0; i< v.NumField(); i++ {
fmt.Printf("%-25s %s = %v\n", controller.Id, typeOfS.Field(i).Name, v.Field(i).Interface())
}
}
} else {
fmt.Printf("%-22s\n", "CONTROLLER NAME")
for _, c := range controllers {
fmt.Printf("%-22s\n", c.Id)
}
}
return nil
}

View File

@@ -0,0 +1,23 @@
package list
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "list",
Short: "List",
Long: "List",
RunE: CobraRunE,
}
ShowAll bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,30 @@
package controller
import (
"github.com/spf13/cobra"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/add"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/delete"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/list"
"github.com/hpcng/warewulf/internal/app/wwctl/controller/set"
)
var (
baseCmd = &cobra.Command{
Use: "controller",
Short: "Controller management",
Long: "Management of group settings and power management",
}
)
func init() {
baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(set.GetCommand())
baseCmd.AddCommand(add.GetCommand())
baseCmd.AddCommand(delete.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,94 @@
package set
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var err error
var controllers []node.ControllerInfo
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
if SetAll == true {
var tmp []node.ControllerInfo
tmp, err = nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, c := range tmp {
controllers = append(controllers, c)
}
} else if len(args) > 0 {
var tmp []node.ControllerInfo
tmp, err = nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, a := range args {
for _, c := range tmp {
if c.Id == a {
controllers = append(controllers, c)
}
}
}
} else {
cmd.Usage()
os.Exit(1)
}
for _, c := range controllers {
if SetIpaddr != "" {
wwlog.Printf(wwlog.VERBOSE, "Controller: %s, Setting IP Addr to: %s\n", c.Id, SetIpaddr)
c.Ipaddr = SetIpaddr
err := nodeDB.ControllerUpdate(c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
}
if len(controllers) > 0 {
q := fmt.Sprintf("Are you sure you want to modify %d group(s)", len(controllers))
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
fmt.Printf("No controllers found\n")
}
return nil
}

View File

@@ -0,0 +1,26 @@
package set
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "set",
Short: "Set",
Long: "Set",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetAll bool
SetIpaddr string
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all controllers")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "i", "", "Set the controller's IP address")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -15,7 +15,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, g := range args {
err = nodeDB.AddGroup(g)
err = nodeDB.AddGroup(SetController, g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)

View File

@@ -10,13 +10,12 @@ var (
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetVnfs string
SetKernel string
SetController string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add group to")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -26,12 +26,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, g := range args {
err := nodeDB.DelGroup(g)
err := nodeDB.DelGroup(SetController, g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
} else {
for _, n := range nodes {
if n.GroupName == g {
if n.Gid.Get() == g {
numNodes ++
}
}

View File

@@ -9,14 +9,11 @@ var (
Long: "Add a new node group ",
RunE: CobraRunE,
}
SetVnfs string
SetKernel string
// SetGroupLevel bool
SetController string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add group to")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"
"os"
"reflect"
"strings"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
@@ -33,9 +34,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
} else {
fmt.Printf("%-22s %-16s %-30s %-30s %-16s\n", "GROUP NAME", "DOMAINNAME", "KERNEL VERSION", "VNFS IMAGE", "RUNTIME OVERLAY")
fmt.Printf("%-22s %-16s %-16s %s\n", "GROUP NAME", "DOMAINNAME", "CONTROLLER", "PROFILES")
for _, g := range groups {
fmt.Printf("%-22s %-16s %-30s %-30s %-16s\n", g.GroupName, g.DomainName, g.KernelVersion, g.Vnfs, g.RuntimeOverlay)
fmt.Printf("%-22s %-16s %-16s %s\n", g.Id, g.DomainName, g.Cid, strings.Join(g.Profiles, ","))
}
}

View File

@@ -3,6 +3,7 @@ package set
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
@@ -24,7 +25,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
if len(args) > 0 {
if SetGroupAll == true {
var tmp []node.GroupInfo
tmp, err = nodeDB.FindAllGroups()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, g := range tmp {
groups = append(groups, g)
}
} else if len(args) > 0 {
var tmp []node.GroupInfo
tmp, err = nodeDB.FindAllGroups()
if err != nil {
@@ -46,181 +59,100 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, g := range groups {
if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting vnfs to: %s\n", g.Id, SetVnfs)
err := nodeDB.SetGroupVal(g.Id, "vnfs", SetVnfs)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "vnfs", "")
}
}
}
if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting kernel to: %s\n", g.Id, SetVnfs)
err := nodeDB.SetGroupVal(g.Id, "kernel", SetKernel)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "kernel", "")
}
}
}
if SetDomainName != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting domain name to: %s\n", g.Id, SetDomainName)
err := nodeDB.SetGroupVal(g.Id, "domain", SetDomainName)
g.DomainName = SetDomainName
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "domain", "")
}
}
}
if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting VNFS to: %s\n", g.Id, SetVnfs)
if SetIpxe != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting iPXE template to: %s\n", g.Id, SetIpxe)
err := nodeDB.SetGroupVal(g.Id, "ipxe", SetIpxe)
g.Vnfs = SetVnfs
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "ipxe", "")
}
}
}
if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting kernel to: %s\n", g.Id, SetKernel)
if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting runtime overlay to: %s\n", g.Id, SetRuntimeOverlay)
err := nodeDB.SetGroupVal(g.Id, "runtimeoverlay", SetRuntimeOverlay)
g.KernelVersion = SetKernel
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "runtimeoverlay", "")
}
}
}
if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting system overlay to: %s\n", g.Id, SetSystemOverlay)
err := nodeDB.SetGroupVal(g.Id, "systemoverlay", SetSystemOverlay)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "systemoverlay", "")
}
}
}
if SetIpmiIpaddr != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI IP address to: %s\n", g.Id, SetIpmiIpaddr)
err := nodeDB.SetGroupVal(g.Id, "ipmiipaddr", SetIpmiIpaddr)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "ipmiipaddr", "")
}
}
}
if SetIpmiUsername != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI IP username to: %s\n", g.Id, SetIpmiUsername)
err := nodeDB.SetGroupVal(g.Id, "ipmiusername", SetIpmiUsername)
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI username to: %s\n", g.Id, SetIpmiUsername)
g.IpmiUserName = SetIpmiUsername
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "ipmiusername", "")
}
}
}
if SetIpmiPassword != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI IP password to: %s\n", g.Id, SetIpmiPassword)
err := nodeDB.SetGroupVal(g.Id, "ipmipassword", SetIpmiPassword)
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI password to: %s\n", g.Id, SetIpmiPassword)
g.IpmiPassword = SetIpmiPassword
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if SetClearNodes == true {
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, n := range nodes {
_ = nodeDB.SetNodeVal(g.Id, n.Id, "ipmipassword", "")
}
}
if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting system overlay to: %s\n", g.Id, SetSystemOverlay)
g.SystemOverlay = SetSystemOverlay
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting runtime overlay to: %s\n", g.Id, SetRuntimeOverlay)
g.RuntimeOverlay = SetRuntimeOverlay
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if len(SetAddProfile) > 0 {
for _, p := range SetAddProfile {
wwlog.Printf(wwlog.VERBOSE, "Adding profile to '%s': '%s'\n", g.Id, p)
g.Profiles = util.SliceAddUniqueElement(g.Profiles, p)
}
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if len(SetDelProfile) > 0 {
for _, p := range SetDelProfile {
wwlog.Printf(wwlog.VERBOSE, "Removing profile to '%s': '%s'\n", g.Id, p)
g.Profiles = util.SliceRemoveElement(g.Profiles, p)
}
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
}

View File

@@ -15,12 +15,12 @@ var (
SetIpxe string
SetRuntimeOverlay string
SetSystemOverlay string
SetHostname string
SetClearNodes bool
SetIpmiIpaddr string
SetIpmiUsername string
SetIpmiPassword string
SetGroupAll bool
SetAddProfile []string
SetDelProfile []string
)
func init() {
@@ -30,11 +30,15 @@ func init() {
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI address")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringSliceVarP(&SetAddProfile, "addprofile", "p", []string{}, "Add Profile(s) to group")
baseCmd.PersistentFlags().StringSliceVarP(&SetDelProfile, "delprofile", "r", []string{}, "Remove Profile(s) to group")
baseCmd.PersistentFlags().BoolVarP(&SetClearNodes, "clear", "c", false, "Clear node configurations when setting parent group")
baseCmd.PersistentFlags().BoolVarP(&SetGroupAll, "all", "a", false, "Set all nodes")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -27,7 +27,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodes {
set[node.KernelVersion] ++
if node.KernelVersion.Defined() == true {
set[node.KernelVersion.Get()] ++
}
}
} else if BuildAll == true {
@@ -39,7 +41,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodes {
set[node.KernelVersion] ++
wwlog.Printf(wwlog.DEBUG, "evaluating node/kernel: %s/%s\n", node.Fqdn.Get(), node.KernelVersion.String())
if node.KernelVersion.Defined() == true {
set[node.KernelVersion.Get()] ++
}
}
} else if len(args) == 1 {
@@ -50,6 +55,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for k := range set {
wwlog.Printf(wwlog.INFO, "Building kernel: %s\n", k)
err := kernel.Build(k)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)

View File

@@ -2,11 +2,52 @@ package list
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/spf13/cobra"
"io/ioutil"
"os"
"path"
"strings"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("This command is coming soon...\n")
config := config.New()
nconfig, _ := node.New()
nodes, _ := nconfig.FindAllNodes()
nodemap := make(map[string]int)
for _, n := range nodes {
nodemap[n.KernelVersion.String()] ++
}
images, _ := ioutil.ReadDir(config.KernelParentDir())
fmt.Printf("%-38s %-16s %-16s %s\n", "KERNEL VERSION", "KERNEL SIZE(k)", "KMODS SIZE(k)", "NODES")
fmt.Println(strings.Repeat("=", 80))
for _, file := range images {
if util.IsDir(path.Join(config.KernelParentDir(), file.Name())) {
var kernel_size int64
var kmods_size int64
if util.IsFile( config.KernelImage(file.Name())) {
s, _ := os.Stat(config.KernelImage(file.Name()))
kernel_size = s.Size() / 1024
}
if util.IsFile( config.KmodsImage(file.Name())) {
s, _ := os.Stat(config.KmodsImage(file.Name()))
kmods_size = s.Size() / 1024
}
if nodemap[file.Name()] > 0 {
fmt.Printf("%-38s %-16d %-16d %d\n", file.Name(), kernel_size, kmods_size, nodemap[file.Name()])
} else {
fmt.Printf("%-38s %-16d %-16d %d\n", file.Name(), kernel_size, kmods_size, 0)
}
}
}
return nil
}

View File

@@ -1,6 +1,7 @@
package add
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
@@ -15,11 +16,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, a := range args {
err = nodeDB.AddNode(SetGroup, a)
err = nodeDB.AddNode(SetController, SetGroup, a)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
fmt.Printf("Added node: %s\n", a)
}
nodeDB.Persist()

View File

@@ -11,10 +11,12 @@ var (
Args: cobra.MinimumNArgs(1),
}
SetGroup string
SetController string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetGroup, "group", "g", "default", "Set group to add nodes to")
baseCmd.PersistentFlags().StringVarP(&SetGroup, "group", "g", "default", "Group to add nodes to")
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add nodes to")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -21,11 +21,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeList, err := nodeDB.SearchByNameList(args)
for _, n := range nodeList {
if SetGroup != "" && SetGroup != n.GroupName {
wwlog.Printf(wwlog.DEBUG, "skipping node of different group: %s/%s\n", n.GroupName, n.Id)
if SetGroup != "" && SetGroup != n.Gid.String() {
wwlog.Printf(wwlog.DEBUG, "skipping node of different group: %s/%s\n", n.Gid, n.Id)
continue
}
err := nodeDB.DelNode(n.GroupName, n.Id)
err := nodeDB.DelNode(n.Cid.Get(), n.Gid.Get(), n.Id.Get())
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
} else {

View File

@@ -11,11 +11,13 @@ var (
}
SetForce string
SetGroup string
SetController string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetForce, "force", "f", "", "Force node delete")
baseCmd.PersistentFlags().StringVarP(&SetGroup, "group", "g", "default", "Set group to delete nodes from")
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add nodes to")
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
"reflect"
"strings"
)
@@ -34,36 +34,76 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if ShowAll == true {
for _, node := range nodes {
v := reflect.ValueOf(node)
typeOfS := v.Type()
fmt.Printf("################################################################################\n")
for i := 0; i< v.NumField(); i++ {
fmt.Printf("%-25s %s = %v\n", node.Fqdn, typeOfS.Field(i).Name, v.Field(i).Interface())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Id", node.Id.Source(), node.Id.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Comment", node.Comment.Source(), node.Comment.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "GroupName", node.Gid.Source(), node.Gid.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "DomainName", node.DomainName.Source(), node.DomainName.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Profiles (Group)", "group", strings.Join(node.GroupProfiles, ","))
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Profiles (Node)", "node", strings.Join(node.Profiles, ","))
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Vnfs", node.Vnfs.Source(), node.Vnfs.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "KernelVersion", node.KernelVersion.Source(), node.KernelVersion.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "KernelArgs", node.KernelArgs.Source(), node.KernelArgs.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "RuntimeOverlay", node.RuntimeOverlay.Source(), node.RuntimeOverlay.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "SystemOverlay", node.SystemOverlay.Source(), node.SystemOverlay.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "IpmiIpaddr", node.IpmiIpaddr.Source(), node.IpmiIpaddr.String())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Ipxe", node.Ipxe.Source(), node.Ipxe.String())
for name, netdev := range node.NetDevs {
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name +":IPADDR", "node", netdev.Ipaddr)
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name +":NETMASK", "node", netdev.Netmask)
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name +":GATEWAY", "node", netdev.Gateway)
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name +":HWADDR", "node", netdev.Hwaddr)
}
// v := reflect.ValueOf(node)
// typeOfS := v.Type()
// for i := 0; i< v.NumField(); i++ {
// //TODO: Fix for NetDevs and Interface should print Fprint() method
// fmt.Printf("%-25s %s = %#v\n", node.Fqdn.Get(), typeOfS.Field(i).Name, v.Field(i).Interface())
// }
}
} else if ShowNet == true {
fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", "NODE NAME", "DEVICE", "HWADDR", "IPADDR", "NETMASK", "GATEWAY", "TYPE")
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", "NODE NAME", "DEVICE", "HWADDR", "IPADDR", "GATEWAY")
fmt.Println(strings.Repeat("=", 80))
for _, node := range nodes {
for name, dev := range node.NetDevs {
fmt.Printf("%-22s %-10s %-20s %-16s %-16s %-16s %s\n", node.Fqdn, name, dev.Hwaddr, dev.Ipaddr, dev.Netmask, dev.Gateway, dev.Type)
if len(node.NetDevs) > 0 {
for name, dev := range node.NetDevs {
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Fqdn.Get(), name, dev.Hwaddr, dev.Ipaddr, dev.Gateway)
}
} else {
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Fqdn.Get(), "--", "--", "--", "--")
}
}
} else if ShowIpmi == true {
fmt.Printf("%-22s %-16s %-20s %-20s\n", "NODE NAME", "IPMI IPADDR", "IPMI USERNAME", "IPMI PASSWORD")
fmt.Println(strings.Repeat("=", 80))
for _, node := range nodes {
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn, node.IpmiIpaddr, node.IpmiUserName, node.IpmiPassword)
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn.Get(), node.IpmiIpaddr.String(), node.IpmiUserName.String(), node.IpmiPassword.String())
}
} else if ShowLong == true {
fmt.Printf("%-22s %-12s %-26s %-35s %s\n", "NODE NAME", "GROUP NAME", "KERNEL VERSION", "VNFS IMAGE", "OVERLAYS (S/R)")
fmt.Println(strings.Repeat("=", 120))
for _, node := range nodes {
fmt.Printf("%-22s %-12s %-26s %-35s %s\n", node.Fqdn.Get(), node.Gid.String(), node.KernelVersion.String(), node.Vnfs.String(), node.SystemOverlay.String() +"/"+ node.RuntimeOverlay.String())
}
} else {
fmt.Printf("%-22s %-16s %-30s %-30s %-16s\n", "NODE NAME", "GROUP NAME", "KERNEL VERSION", "VNFS IMAGE", "RUNTIME OVERLAY")
fmt.Printf("%-22s %-30s %s\n", "NODE NAME", "VNFS", "PROFILES")
fmt.Println(strings.Repeat("=", 80))
for _, node := range nodes {
fmt.Printf("%-22s %-16s %-30s %-30s %-16s\n", node.Fqdn, node.GroupName, node.KernelVersion, node.Vnfs, node.RuntimeOverlay)
fmt.Printf("%-22s %-30s %s\n", node.Fqdn.Get(), node.Vnfs.String(), strings.Join(append(node.GroupProfiles, node.Profiles...), ","))
}
}

View File

@@ -12,12 +12,14 @@ var (
ShowNet bool
ShowIpmi bool
ShowAll bool
ShowLong bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&ShowNet, "net", "n", false, "Show node network configurations")
baseCmd.PersistentFlags().BoolVarP(&ShowIpmi, "ipmi", "i", false, "Show node IPMI configurations")
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
baseCmd.PersistentFlags().BoolVarP(&ShowLong, "long", "l", false, "Show long or wide format")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodeList {
if node.IpmiIpaddr == "" {
if node.IpmiIpaddr.String() == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
continue
}
ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr,
HostName: node.IpmiIpaddr.String(),
User: "ADMIN",
Password: "ADMIN",
AuthType: "MD5",

View File

@@ -36,13 +36,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var powerCmd power.PowerOnInterface
if node.IpmiIpaddr == "" {
if node.IpmiIpaddr.String() == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
continue
}
ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr,
HostName: node.IpmiIpaddr.String(),
User: "ADMIN",
Password: "ADMIN",
AuthType: "MD5",

View File

@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodeList {
if node.IpmiIpaddr == "" {
if node.IpmiIpaddr.String() == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName)
continue
}
ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr,
HostName: node.IpmiIpaddr.String(),
User: "ADMIN",
Password: "ADMIN",
AuthType: "MD5",

View File

@@ -3,6 +3,7 @@ package set
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
@@ -24,31 +25,42 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
if len(args) > 0 {
nodes, err = nodeDB.SearchByNameList(args)
if SetNodeAll == true {
nodes, err = nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
} else if len(args) > 0 {
nodes, err = nodeDB.SearchByNameList(args)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
} else {
cmd.Usage()
os.Exit(1)
}
for _, n := range nodes {
wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Fqdn)
wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Fqdn.String())
if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting vnfs to: %s\n", n.Fqdn, SetVnfs)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "vnfs", SetVnfs)
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting vnfs to: %s\n", n.Fqdn.String(), SetVnfs)
n.Vnfs.Set(SetVnfs)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Fqdn, SetVnfs)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "kernel", SetKernel)
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Fqdn.String(), SetKernel)
n.KernelVersion.Set(SetKernel)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -56,7 +68,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetDomainName != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting domain name to: %s\n", n.Fqdn, SetDomainName)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "domain", SetDomainName)
n.DomainName.Set(SetDomainName)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -64,7 +78,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetIpxe != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting iPXE template to: %s\n", n.Fqdn, SetIpxe)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipxe", SetIpxe)
n.Ipxe.Set(SetIpxe)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -72,7 +88,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting runtime overlay to: %s\n", n.Fqdn, SetRuntimeOverlay)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "runtimeoverlay", SetRuntimeOverlay)
n.RuntimeOverlay.Set(SetRuntimeOverlay)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -80,7 +98,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting system overlay to: %s\n", n.Fqdn, SetSystemOverlay)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "systemoverlay", SetSystemOverlay)
n.SystemOverlay.Set(SetSystemOverlay)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -88,7 +108,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetHostname != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting hostname to: %s\n", n.Fqdn, SetHostname)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "hostname", SetHostname)
n.HostName.Set(SetHostname)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -96,7 +118,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetIpmiIpaddr != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP address to: %s\n", n.Fqdn, SetIpmiIpaddr)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipmiipaddr", SetIpmiIpaddr)
n.IpmiIpaddr.Set(SetIpmiIpaddr)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -104,7 +128,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetIpmiUsername != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP username to: %s\n", n.Fqdn, SetIpmiUsername)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipmiusername", SetIpmiUsername)
n.IpmiUserName.Set(SetIpmiUsername)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -112,7 +138,32 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if SetIpmiPassword != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP password to: %s\n", n.Fqdn, SetIpmiPassword)
err := nodeDB.SetNodeVal(n.Gid, n.Id, "ipmipassword", SetIpmiPassword)
n.IpmiPassword.Set(SetIpmiPassword)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if len(SetAddProfile) > 0 {
for _, p := range SetAddProfile {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile to '%s'\n", n.Fqdn, p)
n.Profiles = util.SliceAddUniqueElement(n.Profiles, p)
}
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if len(SetDelProfile) > 0 {
for _, p := range SetDelProfile {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile from '%s'\n", n.Fqdn, p)
n.Profiles = util.SliceRemoveElement(n.Profiles, p)
}
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -127,20 +178,33 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", n.Fqdn, SetNetDev)
err := nodeDB.DelNodeNet(n.Gid, n.Id, SetNetDev)
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
delete(n.NetDevs, SetNetDev)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpaddr != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Fqdn, SetNetDev, SetIpaddr)
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "ipaddr", SetIpaddr)
n.NetDevs[SetNetDev].Ipaddr = SetIpaddr
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -151,8 +215,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Fqdn, SetNetDev, SetNetmask)
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "netmask", SetNetmask)
n.NetDevs[SetNetDev].Netmask = SetNetmask
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -163,8 +234,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Fqdn, SetNetDev, SetGateway)
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "gateway", SetGateway)
n.NetDevs[SetNetDev].Gateway = SetGateway
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -175,8 +253,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Fqdn, SetNetDev, SetHwaddr)
err := nodeDB.SetNodeNet(n.Gid, n.Id, SetNetDev, "hwaddr", SetHwaddr)
n.NetDevs[SetNetDev].Hwaddr = SetHwaddr
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
@@ -185,17 +270,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(nodes) > 0 {
q := fmt.Sprintf("Are you sure you want to modify %d nodes(s)", len(nodes))
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
if SetYes == true {
nodeDB.Persist()
} else {
q := fmt.Sprintf("Are you sure you want to modify %d nodes(s)", len(nodes))
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
}
} else {

View File

@@ -25,7 +25,10 @@ var (
SetIpmiIpaddr string
SetIpmiUsername string
SetIpmiPassword string
SetNodeAll bool
SetYes bool
SetAddProfile []string
SetDelProfile []string
)
func init() {
@@ -35,17 +38,23 @@ func init() {
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
baseCmd.PersistentFlags().StringVarP(&SetHostname, "hostname", "H", "", "Set the node's hostname")
baseCmd.PersistentFlags().StringVarP(&SetHostname, "hostname", "N", "", "Set the node's hostname")
baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI address")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringSliceVarP(&SetAddProfile, "addprofile", "p", []string{}, "Add Profile(s) to node")
baseCmd.PersistentFlags().StringSliceVarP(&SetDelProfile, "delprofile", "r", []string{}, "Remove Profile(s) to node")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "n", "", "Define the network device to configure")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "N", "", "Set the node's network device HW address")
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "delete", false, "Delete the node's network device")
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
}

View File

@@ -25,9 +25,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
} else if node.RuntimeOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
}
}
@@ -43,16 +43,16 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.DEBUG, "Checking on system overlay update\n")
if SystemOverlay == true || BuildAll == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
err := overlay.SystemBuild(updateNodes, true)
err := overlay.BuildSystemOverlay(updateNodes)
if err != nil {
wwlog.Printf(wwlog.WARN, "Some system overlays failed to be generated\n")
wwlog.Printf(wwlog.WARN, "Some system overlays failed to be generated: %s\n", err)
}
}
wwlog.Printf(wwlog.DEBUG, "Checking on system overlay update\n")
if SystemOverlay == false || BuildAll == true {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
err := overlay.RuntimeBuild(updateNodes, true)
err := overlay.BuildRuntimeOverlay(updateNodes)
if err != nil {
wwlog.Printf(wwlog.WARN, "Some runtime overlays failed to be generated\n")
}

View File

@@ -64,19 +64,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == overlayName {
if SystemOverlay == true && node.SystemOverlay.String() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == overlayName {
} else if node.RuntimeOverlay.String() == overlayName {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
return overlay.BuildSystemOverlay(updateNodes)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
return overlay.BuildRuntimeOverlay(updateNodes)
}
}

View File

@@ -48,19 +48,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
} else if node.RuntimeOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
return overlay.BuildSystemOverlay(updateNodes)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
return overlay.BuildRuntimeOverlay(updateNodes)
}
}

View File

@@ -110,19 +110,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
} else if node.RuntimeOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
return overlay.BuildSystemOverlay(updateNodes)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
return overlay.BuildRuntimeOverlay(updateNodes)
}
}

View File

@@ -69,7 +69,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Fprintf(w, "\n")
}
shasum1, err := util.ShaSumFile(overlayFile)
if err != nil {
wwlog.Printf(wwlog.WARN, "Could not open overlay file for checksum: %s\n", err)
@@ -80,7 +79,7 @@ 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] )
wwlog.Printf(wwlog.INFO, "Updated: %s %s\n", args[0], args[1])
shasum2, err := util.ShaSumFile(overlayFile)
if err != nil {
@@ -108,22 +107,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
} else if node.RuntimeOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
return overlay.BuildSystemOverlay(updateNodes)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
return overlay.BuildRuntimeOverlay(updateNodes)
}
}
return nil
}

View File

@@ -60,19 +60,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == overlayName {
if SystemOverlay == true && node.SystemOverlay.String() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == overlayName {
} else if node.RuntimeOverlay.String() == overlayName {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
return overlay.BuildSystemOverlay(updateNodes)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
return overlay.BuildRuntimeOverlay(updateNodes)
}
}

View File

@@ -31,14 +31,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} else {
fmt.Printf("%-10s %5s %-5s %-18s %s\n", "PERM MODE", "UID", "GID", "SYSTEM-OVERLAY", "FILE PATH")
}
o, err = overlay.FindAllSystemOverlays()
o, err = overlay.FindSystemOverlays()
} else {
if ListLong == false {
fmt.Printf("%-30s %-12s %-12s\n", "RUNTIME OVERLAY NAME", "NODES", "FILES/DIRS")
} else {
fmt.Printf("%-10s %5s %-5s %-18s %s\n", "PERM MODE", "UID", "GID", "RUNTIME-OVERLAY", "FILE PATH")
}
o, err = overlay.FindAllRuntimeOverlays()
o, err = overlay.FindRuntimeOverlays()
}
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not get system overlays: %s\n", err)
@@ -53,12 +53,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodeList {
if SystemOverlay == true {
if node.SystemOverlay != "" {
set[node.SystemOverlay] ++
if node.SystemOverlay.Get() != "" {
set[node.SystemOverlay.Get()] ++
}
} else {
if node.RuntimeOverlay != "" {
set[node.RuntimeOverlay] ++
if node.RuntimeOverlay.Get() != "" {
set[node.RuntimeOverlay.Get()] ++
}
}
}

View File

@@ -57,19 +57,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo
for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay == args[0] {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay == args[0] {
} else if node.RuntimeOverlay.String() == args[0] {
updateNodes = append(updateNodes, node)
}
}
if SystemOverlay == true {
wwlog.Printf(wwlog.INFO, "Updating System Overlays...\n")
return overlay.SystemBuild(updateNodes, true)
return overlay.BuildSystemOverlay(updateNodes)
} else {
wwlog.Printf(wwlog.INFO, "Updating Runtime Overlays...\n")
return overlay.RuntimeBuild(updateNodes, true)
return overlay.BuildRuntimeOverlay(updateNodes)
}
}

View File

@@ -10,7 +10,6 @@ import (
"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"
"github.com/spf13/cobra"
)
@@ -35,7 +34,6 @@ func init() {
baseCmd.AddCommand(build.GetCommand())
baseCmd.AddCommand(imprt.GetCommand())
baseCmd.AddCommand(chmod.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -0,0 +1,28 @@
package add
import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed opening node database: %s\n", err)
os.Exit(1)
}
for _, p := range args {
err = nodeDB.AddProfile(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
nodeDB.Persist()
return nil
}

View File

@@ -0,0 +1,20 @@
package add
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "add",
Short: "Add profiles",
Long: "Profile configurations ",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,85 @@
package delete
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var count int
var numNodes int
var numGroups int
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err)
os.Exit(1)
}
groups, err := nodeDB.FindAllGroups()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not load all groups: %s\n", err)
os.Exit(1)
}
for _, p := range args {
err := nodeDB.DelProfile(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
continue
}
for _, n := range nodes {
for _, np := range n.Profiles {
if np == p {
numNodes++
wwlog.Printf(wwlog.VERBOSE, "Removing profile from node %s: %s\n", n.Fqdn.Get(), p)
n.Profiles = util.SliceRemoveElement(n.Profiles, p)
nodeDB.NodeUpdate(n)
}
}
}
for _, g := range groups {
for _, np := range g.Profiles {
if np == p {
numGroups++
wwlog.Printf(wwlog.VERBOSE, "Removing profile from group %s: %s\n", g.Id, p)
g.Profiles = util.SliceRemoveElement(g.Profiles, p)
nodeDB.GroupUpdate(g)
}
}
}
count++
}
if count > 0 {
q := fmt.Sprintf("Are you sure you want to delete %d profile(s) (%d groups, %d nodes)", count, numGroups, numNodes)
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
wwlog.Printf(wwlog.INFO, "No groups found\n")
}
return nil
}

View File

@@ -0,0 +1,20 @@
package delete
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "delete",
Short: "Delete profiles",
Long: "Profile configurations ",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,36 @@
package list
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
"reflect"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
profiles, err := nodeDB.FindAllProfiles()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all nodes: %s\n", err)
os.Exit(1)
}
for _, group := range profiles {
v := reflect.ValueOf(group)
typeOfS := v.Type()
fmt.Printf("################################################################################\n")
for i := 0; i< v.NumField(); i++ {
fmt.Printf("%-25s %s = %v\n", group.Id, typeOfS.Field(i).Name, v.Field(i).Interface())
}
}
return nil
}

View File

@@ -0,0 +1,20 @@
package list
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "list",
Short: "List profiles",
Long: "Profile configurations ",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,30 @@
package profile
import (
"github.com/hpcng/warewulf/internal/app/wwctl/profile/add"
"github.com/hpcng/warewulf/internal/app/wwctl/profile/delete"
"github.com/hpcng/warewulf/internal/app/wwctl/profile/list"
"github.com/hpcng/warewulf/internal/app/wwctl/profile/set"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "profile",
Short: "Management of node configuration profiles",
Long: "Warewulf profiles...",
}
test bool
)
func init() {
baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(set.GetCommand())
baseCmd.AddCommand(add.GetCommand())
baseCmd.AddCommand(delete.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,164 @@
package set
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var err error
var profiles []node.ProfileInfo
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
if SetAll == true {
var tmp []node.ProfileInfo
tmp, err = nodeDB.FindAllProfiles()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, p := range tmp {
profiles = append(profiles, p)
}
} else if len(args) > 0 {
var tmp []node.ProfileInfo
tmp, err = nodeDB.FindAllProfiles()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, a := range args {
for _, p := range tmp {
if p.Id == a {
profiles = append(profiles, p)
}
}
}
} else {
cmd.Usage()
os.Exit(1)
}
for _, p := range profiles {
if SetDomainName != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting domain name to: %s\n", p.Id, SetDomainName)
p.DomainName = SetDomainName
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting VNFS to: %s\n", p.Id, SetVnfs)
p.Vnfs = SetVnfs
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel version to: %s\n", p.Id, SetKernel)
p.KernelVersion = SetKernel
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpxe != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting iPXE template to: %s\n", p.Id, SetIpxe)
p.Ipxe = SetIpxe
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting runtime overlay to: %s\n", p.Id, SetRuntimeOverlay)
p.RuntimeOverlay = SetRuntimeOverlay
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting system overlay to: %s\n", p.Id, SetSystemOverlay)
p.SystemOverlay = SetSystemOverlay
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpmiUsername != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiUsername)
p.IpmiUserName = SetIpmiUsername
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpmiPassword != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiPassword)
p.IpmiPassword = SetIpmiPassword
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
}
if len(profiles) > 0 {
q := fmt.Sprintf("Are you sure you want to modify %d profile(s)", len(profiles))
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
fmt.Printf("No profiles found\n")
}
return nil
}

View File

@@ -0,0 +1,40 @@
package set
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "set",
Short: "Set profile configurations",
Long: "Profile configurations ",
RunE: CobraRunE,
}
SetAll bool
SetVnfs string
SetKernel string
SetDomainName string
SetIpxe string
SetRuntimeOverlay string
SetSystemOverlay string
SetIpmiUsername string
SetIpmiPassword string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name")
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all profiles")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,37 +1,44 @@
package wwctl
import (
"github.com/hpcng/warewulf/internal/app/wwctl/build"
"github.com/hpcng/warewulf/internal/app/wwctl/controller"
"github.com/hpcng/warewulf/internal/app/wwctl/group"
"github.com/hpcng/warewulf/internal/app/wwctl/kernel"
"github.com/hpcng/warewulf/internal/app/wwctl/node"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay"
"github.com/hpcng/warewulf/internal/app/wwctl/profile"
"github.com/hpcng/warewulf/internal/app/wwctl/services"
"github.com/hpcng/warewulf/internal/app/wwctl/vnfs"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "wwctl",
Short: "Warewulf Control",
Long: "Control interface to the Cluster Warewulf Provisioning System.",
PersistentPreRunE: rootPersistentPreRunE,
Use: "wwctl",
Short: "Warewulf Control",
Long: "Control interface to the Cluster Warewulf Provisioning System.",
PersistentPreRunE: rootPersistentPreRunE,
}
verboseArg bool
debugArg bool
debugArg bool
)
func init() {
rootCmd.PersistentFlags().BoolVarP(&verboseArg, "verbose", "v", false, "Run with increased verbosity.")
rootCmd.PersistentFlags().BoolVarP(&debugArg, "debug", "d", false, "Run with debugging messages enabled.")
rootCmd.AddCommand(build.GetCommand())
//rootCmd.AddCommand(build.GetCommand())
rootCmd.AddCommand(overlay.GetCommand())
rootCmd.AddCommand(controller.GetCommand())
rootCmd.AddCommand(vnfs.GetCommand())
rootCmd.AddCommand(node.GetCommand())
rootCmd.AddCommand(kernel.GetCommand())
rootCmd.AddCommand(group.GetCommand())
rootCmd.AddCommand(profile.GetCommand())
rootCmd.AddCommand(services.GetCommand())
}
@@ -49,4 +56,4 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) error {
wwlog.SetLevel(wwlog.INFO)
}
return nil
}
}

View File

@@ -0,0 +1,109 @@
package dhcp
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"net"
"os"
"text/template"
)
type dhcpTemplate struct {
Ipaddr string
RangeStart string
RangeEnd string
Netmask string
Nodes []node.NodeInfo
}
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
controllers, err := nodeDB.FindAllControllers()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err)
os.Exit(1)
}
for _, controller := range controllers {
var d dhcpTemplate
var configured bool
addrs, err := net.InterfaceAddrs()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not get network interfaces: %s\n", err)
os.Exit(1)
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.String() == controller.Ipaddr {
mask := ipnet.IP.DefaultMask()
d.Ipaddr = ipnet.IP.String()
d.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3])
d.RangeStart = controller.Services.Dhcp.RangeStart
d.RangeEnd = controller.Services.Dhcp.RangeEnd
configured = true
fmt.Printf("%#v\n", d)
break
}
}
}
if configured == false {
wwlog.Printf(wwlog.ERROR, "Could not identify this system in the Warewulf configuration by it's IP address\n")
os.Exit(1)
}
if controller.Services.Dhcp.ConfigFile == "" {
wwlog.Printf(wwlog.ERROR, "Could not locate the DHCP configuration file for this controller\n")
os.Exit(1)
}
if _, ok := nodeDB.Controllers[controller.Id]; !ok {
wwlog.Printf(wwlog.ERROR, "We should never get here, but since we did, Hello! %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err)
os.Exit(1)
}
for _, node := range nodes {
d.Nodes = append(d.Nodes, node)
}
tmpl, err := template.New("default-dhcpd.conf").ParseFiles("/etc/warewulf/dhcp/default-dhcpd.conf")
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
// w, err := os.OpenFile(controller.Services.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE, 0640)
// if err != nil {
// wwlog.Printf(wwlog.ERROR, "%s\n", err)
// os.Exit(1)
// }
// defer w.Close()
err = tmpl.Execute(os.Stdout, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
// Just in case we get here, we've now finished the loop
break
}
return nil
}

View File

@@ -0,0 +1,23 @@
package dhcp
import (
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "dhcp",
Short: "DHCP configuration",
Long: "DHCP Config",
RunE: CobraRunE,
}
test bool
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,23 @@
package services
import (
"github.com/hpcng/warewulf/internal/app/wwctl/services/dhcp"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "services",
Short: "Initialize Warewulf services",
Long: "Warewulf Initialization",
}
)
func init() {
baseCmd.AddCommand(dhcp.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -28,7 +28,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodes {
set[node.Vnfs] ++
if node.Vnfs.Defined() == true {
set[node.Vnfs.Get()] ++
}
}
} else if BuildAll == true {
@@ -40,7 +42,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
for _, node := range nodes {
set[node.Vnfs] ++
if node.Vnfs.Defined() == true {
set[node.Vnfs.Get()] ++
}
}
} else if len(args) == 1 {

View File

@@ -3,25 +3,62 @@ package list
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/vnfs"
"github.com/spf13/cobra"
"io/ioutil"
"os"
"path"
"strings"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
nconfig, _ := node.New()
nodes, _ := nconfig.FindAllNodes()
nodemap := make(map[string]int)
files, err := ioutil.ReadDir(config.VnfsImageParentDir())
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
for _, n := range nodes {
nodemap[n.Vnfs.Get()] ++
}
for _, f := range files {
fmt.Println(f.Name())
}
images, _ := ioutil.ReadDir(config.VnfsImageParentDir())
fmt.Printf("VNFS LIST: work in progress: %s\n", config.VnfsImageParentDir())
fmt.Printf("%-38s %-16s %s\n", "VNFS Name", "VNFS SIZE(k)", "NODES")
fmt.Println(strings.Repeat("=", 80))
for _, file := range images {
v, err := vnfs.Load(file.Name())
if err == nil {
var vnfs_size int64
if util.IsFile( config.VnfsImage(file.Name())) {
s, _ := os.Stat(config.VnfsImage(file.Name()))
vnfs_size = s.Size() / 1024
}
if nodemap[v.Source] > 0 {
fmt.Printf("%-38s %-16d %d\n", v.Source, vnfs_size, nodemap[v.Source])
} else {
fmt.Printf("%-38s %-16d %d\n", v.Source, vnfs_size, 0)
}
}
continue
if util.IsDir(path.Join(config.VnfsImageParentDir(), file.Name())) {
var vnfs_size int64
if util.IsFile( config.VnfsImage(file.Name())) {
s, _ := os.Stat(config.VnfsImage(file.Name()))
vnfs_size = s.Size() / 1024
}
if nodemap[file.Name()] > 0 {
fmt.Printf("%-38s %-16d %d\n", file.Name(), vnfs_size, nodemap[file.Name()])
} else {
fmt.Printf("%-38s %-16d %d\n", file.Name(), vnfs_size, 0)
}
}
}
return nil
}

View File

@@ -14,8 +14,8 @@ var (
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)")
//baseCmd.PersistentFlags().BoolVarP(&SystemOverlay, "system", "s", false, "Show System Overlays as well")
//baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "Build all overlays (runtime and system)")
}