testing profile set
This commit is contained in:
@@ -45,7 +45,7 @@ func init() {
|
||||
var emptyNodeConf node.NodeConf
|
||||
emptyNodeConf.Kernel = new(node.KernelConf)
|
||||
emptyNodeConf.Ipmi = new(node.IpmiConf)
|
||||
OptionStrMap = myBase.CreateFlags(emptyNodeConf)
|
||||
OptionStrMap = myBase.CreateFlags(emptyNodeConf, []string{})
|
||||
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetDevDel, "netdel", "D", "", "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package set
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
@@ -45,8 +46,15 @@ func init() {
|
||||
var emptyNodeConf node.NodeConf
|
||||
emptyNodeConf.Kernel = new(node.KernelConf)
|
||||
emptyNodeConf.Ipmi = new(node.IpmiConf)
|
||||
OptionStrMap = myBase.CreateFlags(emptyNodeConf)
|
||||
|
||||
OptionStrMap = myBase.CreateFlags(emptyNodeConf, []string{})
|
||||
fmt.Println(baseCmd.Flags().Args())
|
||||
flag := baseCmd.Flag("ipaddr")
|
||||
if flag != nil {
|
||||
flag.Name = "donotuse"
|
||||
flag.Usage = "FooBaar"
|
||||
} else {
|
||||
fmt.Println("Flag not found")
|
||||
}
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetDevDel, "netdel", "D", "", "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")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
// NodeSet is the wwapiv1 implmentation for updating node fields.
|
||||
// NodeSet is the wwapiv1 implmentation for updating nodeinfo fields.
|
||||
func ProfileSet(set *wwapiv1.NodeSetParameter) (err error) {
|
||||
|
||||
if set == nil {
|
||||
@@ -25,7 +25,7 @@ func ProfileSet(set *wwapiv1.NodeSetParameter) (err error) {
|
||||
return apinode.DbSave(&nodeDB)
|
||||
}
|
||||
|
||||
// NodeSetParameterCheck does error checking on NodeSetParameter.
|
||||
// ProfileSetParameterCheck does error checking on ProfileSetParameter.
|
||||
// Output to the console if console is true.
|
||||
// TODO: Determine if the console switch does wwlog or not.
|
||||
// - console may end up being textOutput?
|
||||
@@ -49,13 +49,13 @@ func ProfileSetParameterCheck(set *wwapiv1.NodeSetParameter, console bool) (node
|
||||
|
||||
nodeDB, err = node.New()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not open configuration: %s\n", err)
|
||||
wwlog.Error("Could not open configuration: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err := nodeDB.FindAllProfiles()
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not get profile list: %s\n", err)
|
||||
wwlog.Error("Could not get profile list: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -65,8 +65,6 @@ func ProfileSetParameterCheck(set *wwapiv1.NodeSetParameter, console bool) (node
|
||||
if console {
|
||||
fmt.Printf("\n*** WARNING: This command will modify all profiles! ***\n\n")
|
||||
}
|
||||
} else {
|
||||
profiles = node.FilterByName(profiles, set.NodeNames)
|
||||
}
|
||||
|
||||
if len(profiles) == 0 {
|
||||
@@ -89,17 +87,17 @@ func ProfileSetParameterCheck(set *wwapiv1.NodeSetParameter, console bool) (node
|
||||
|
||||
if _, ok := p.NetDevs[set.NetdevDelete]; !ok {
|
||||
err = fmt.Errorf("Network device name doesn't exist: %s", set.NetdevDelete)
|
||||
wwlog.Printf(wwlog.ERROR, fmt.Sprintf("%v\n", err.Error()))
|
||||
wwlog.Error(fmt.Sprintf("%v\n", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", p.Id.Get(), set.NetdevDelete)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Deleting network device: %s\n", p.Id.Get(), set.NetdevDelete)
|
||||
delete(p.NetDevs, set.NetdevDelete)
|
||||
}
|
||||
|
||||
err := nodeDB.NodeUpdate(p)
|
||||
err := nodeDB.ProfileUpdate(p)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
wwlog.Error("%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -512,7 +513,7 @@ Get all names of the fields in the given struct (recursive)
|
||||
and create a map[name of struct field]*string if the the field
|
||||
of the struct bears the comment tag.
|
||||
*/
|
||||
func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*string {
|
||||
func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}, excludeList []string) map[string]*string {
|
||||
optionsMap := make(map[string]*string)
|
||||
structVal := reflect.ValueOf(theStruct)
|
||||
structTyp := structVal.Type()
|
||||
@@ -521,7 +522,7 @@ func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*stri
|
||||
//fmt.Printf("%s: field.Kind() == %s\n", field.Name, field.Type.Kind())
|
||||
if field.Type.Kind() == reflect.Ptr {
|
||||
a := structVal.Field(i).Elem().Interface()
|
||||
subStruct := baseCmd.CreateFlags(a)
|
||||
subStruct := baseCmd.CreateFlags(a, excludeList)
|
||||
for key, val := range subStruct {
|
||||
optionsMap[field.Name+"."+key] = val
|
||||
}
|
||||
@@ -531,7 +532,7 @@ func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*stri
|
||||
mapType := field.Type.Elem()
|
||||
if mapType.Kind() == reflect.Ptr {
|
||||
//a := reflect.ValueOf((mapType.Elem())) node.NetDevs
|
||||
subMap := baseCmd.CreateFlags(reflect.New(mapType.Elem()).Elem().Interface())
|
||||
subMap := baseCmd.CreateFlags(reflect.New(mapType.Elem()).Elem().Interface(), excludeList)
|
||||
for key, val := range subMap {
|
||||
optionsMap[field.Name+"."+key] = val
|
||||
}
|
||||
@@ -558,7 +559,7 @@ func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*stri
|
||||
wwlog.Warn("handling of %v not implemented\n", field.Type)
|
||||
}
|
||||
|
||||
} else if field.Tag.Get("comment") != "" {
|
||||
} else if field.Tag.Get("comment") != "" && !util.InSlice(excludeList, field.Name) {
|
||||
var newStr string
|
||||
optionsMap[field.Name] = &newStr
|
||||
if field.Tag.Get("sopt") != "" {
|
||||
@@ -567,7 +568,7 @@ func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*stri
|
||||
field.Tag.Get("sopt"),
|
||||
field.Tag.Get("default"),
|
||||
field.Tag.Get("comment"))
|
||||
} else {
|
||||
} else if !util.InSlice(excludeList, field.Name) {
|
||||
baseCmd.PersistentFlags().StringVar(&newStr,
|
||||
field.Tag.Get("lopt"),
|
||||
field.Tag.Get("default"),
|
||||
|
||||
Reference in New Issue
Block a user