Use ProfileConf rather than NodeConf for profile commands
This removes node-only attributes, like a profile list, from profile commands. Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
type variables struct {
|
||||
netName string
|
||||
profileConf node.NodeConf
|
||||
profileConf node.ProfileConf
|
||||
SetNetDevDel string
|
||||
SetNodeAll bool
|
||||
SetYes bool
|
||||
@@ -25,7 +25,7 @@ type variables struct {
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
vars.profileConf = node.NewNode("")
|
||||
vars.profileConf = node.NewProfile("")
|
||||
baseCmd := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "add PROFILE",
|
||||
|
||||
@@ -41,7 +41,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
Output: args,
|
||||
}
|
||||
profileListMsg := apiprofile.FilteredProfiles(&filterList)
|
||||
profileMap := make(map[string]*node.NodeConf)
|
||||
profileMap := make(map[string]*node.ProfileConf)
|
||||
// got proper yaml back
|
||||
_ = yaml.Unmarshal([]byte(profileListMsg.NodeConfMapYaml), profileMap)
|
||||
file, err := os.CreateTemp(os.TempDir(), "ww4ProfileEdit*.yaml")
|
||||
@@ -49,7 +49,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Error("Could not create temp file:%s \n", err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
yamlTemplate := node.UnmarshalConf(node.NodeConf{}, []string{"tagsdel"})
|
||||
yamlTemplate := node.UnmarshalConf(node.ProfileConf{}, []string{"tagsdel"})
|
||||
for {
|
||||
_ = file.Truncate(0)
|
||||
_, _ = file.Seek(0, 0)
|
||||
@@ -77,7 +77,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
wwlog.Debug("Hashes are before %s and after %s\n", sum1, sum2)
|
||||
if sum1 != sum2 {
|
||||
wwlog.Debug("Profiles were modified")
|
||||
modifiedProfileMap := make(map[string]*node.NodeConf)
|
||||
modifiedProfileMap := make(map[string]*node.ProfileConf)
|
||||
_, _ = file.Seek(0, 0)
|
||||
// ignore error as only may occurs under strange circumstances
|
||||
buffer, _ := io.ReadAll(file)
|
||||
|
||||
@@ -21,14 +21,14 @@ type variables struct {
|
||||
partName string
|
||||
diskName string
|
||||
fsName string
|
||||
profileConf node.NodeConf
|
||||
profileConf node.ProfileConf
|
||||
profileDel node.NodeConfDel
|
||||
profileAdd node.NodeConfAdd
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
vars := variables{}
|
||||
vars.profileConf = node.NewNode("")
|
||||
vars.profileConf = node.NewProfile("")
|
||||
|
||||
baseCmd := &cobra.Command{
|
||||
Use: "set [OPTIONS] [PROFILE ...]",
|
||||
|
||||
@@ -17,19 +17,29 @@ Checks if for NodeConf all values can be parsed according to their type.
|
||||
func (nodeConf *NodeConf) Check() (err error) {
|
||||
nodeInfoType := reflect.TypeOf(nodeConf)
|
||||
nodeInfoVal := reflect.ValueOf(nodeConf)
|
||||
return check(nodeInfoType, nodeInfoVal)
|
||||
}
|
||||
|
||||
func (profileConf *ProfileConf) Check() (err error) {
|
||||
profileInfoType := reflect.TypeOf(profileConf)
|
||||
profileInfoVal := reflect.ValueOf(profileConf)
|
||||
return check(profileInfoType, profileInfoVal)
|
||||
}
|
||||
|
||||
func check(infoType reflect.Type, infoVal reflect.Value) (err error) {
|
||||
// now iterate of every field
|
||||
for i := 0; i < nodeInfoVal.Elem().NumField(); i++ {
|
||||
//wwlog.Debug("checking field: %s type: %s", nodeInfoType.Elem().Field(i).Name, nodeInfoVal.Elem().Field(i).Type())
|
||||
if nodeInfoType.Elem().Field(i).Type.Kind() == reflect.String {
|
||||
newFmt, err := checker(nodeInfoVal.Elem().Field(i).Interface().(string), nodeInfoType.Elem().Field(i).Tag.Get("type"))
|
||||
for i := 0; i < infoVal.Elem().NumField(); i++ {
|
||||
//wwlog.Debug("checking field: %s type: %s", infoType.Elem().Field(i).Name, infoVal.Elem().Field(i).Type())
|
||||
if infoType.Elem().Field(i).Type.Kind() == reflect.String {
|
||||
newFmt, err := checker(infoVal.Elem().Field(i).Interface().(string), infoType.Elem().Field(i).Tag.Get("type"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("field: %s value:%s err: %s", nodeInfoType.Elem().Field(i).Name, nodeInfoVal.Elem().Field(i).String(), err)
|
||||
return fmt.Errorf("field: %s value:%s err: %s", infoType.Elem().Field(i).Name, infoVal.Elem().Field(i).String(), err)
|
||||
} else if newFmt != "" {
|
||||
nodeInfoVal.Elem().Field(i).SetString(newFmt)
|
||||
infoVal.Elem().Field(i).SetString(newFmt)
|
||||
}
|
||||
} else if nodeInfoType.Elem().Field(i).Type.Kind() == reflect.Ptr && !nodeInfoVal.Elem().Field(i).IsNil() {
|
||||
nestType := reflect.TypeOf(nodeInfoVal.Elem().Field(i).Interface())
|
||||
nestVal := reflect.ValueOf(nodeInfoVal.Elem().Field(i).Interface())
|
||||
} else if infoType.Elem().Field(i).Type.Kind() == reflect.Ptr && !infoVal.Elem().Field(i).IsNil() {
|
||||
nestType := reflect.TypeOf(infoVal.Elem().Field(i).Interface())
|
||||
nestVal := reflect.ValueOf(infoVal.Elem().Field(i).Interface())
|
||||
for j := 0; j < nestType.Elem().NumField(); j++ {
|
||||
if nestType.Elem().Field(j).Type.Kind() == reflect.String {
|
||||
//wwlog.Debug("checking field: %s type: %s", nestType.Elem().Field(j).Name, nestType.Elem().Field(j).Tag.Get("type"))
|
||||
@@ -41,8 +51,8 @@ func (nodeConf *NodeConf) Check() (err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if nodeInfoType.Elem().Field(i).Type == reflect.TypeOf(map[string]*NetDevs(nil)) {
|
||||
netMap := nodeInfoVal.Elem().Field(i).Interface().(map[string]*NetDevs)
|
||||
} else if infoType.Elem().Field(i).Type == reflect.TypeOf(map[string]*NetDevs(nil)) {
|
||||
netMap := infoVal.Elem().Field(i).Interface().(map[string]*NetDevs)
|
||||
for _, val := range netMap {
|
||||
netType := reflect.TypeOf(val)
|
||||
netVal := reflect.ValueOf(val)
|
||||
|
||||
@@ -35,6 +35,10 @@ func (nodeConf *NodeConf) CreateFlags(baseCmd *cobra.Command) {
|
||||
recursiveCreateFlags(nodeConf, baseCmd)
|
||||
}
|
||||
|
||||
func (profileConf *ProfileConf) CreateFlags(baseCmd *cobra.Command) {
|
||||
recursiveCreateFlags(profileConf, baseCmd)
|
||||
}
|
||||
|
||||
func (del *NodeConfDel) CreateDelFlags(baseCmd *cobra.Command) {
|
||||
recursiveCreateFlags(del, baseCmd)
|
||||
|
||||
|
||||
@@ -92,6 +92,12 @@ func NewNode(id string) (nodeconf NodeConf) {
|
||||
return nodeconf
|
||||
}
|
||||
|
||||
func NewProfile(id string) (profileconf ProfileConf) {
|
||||
profileconf = EmptyProfile()
|
||||
profileconf.id = id
|
||||
return profileconf
|
||||
}
|
||||
|
||||
func EmptyNode() (nodeconf NodeConf) {
|
||||
nodeconf.Ipmi = new(IpmiConf)
|
||||
nodeconf.Ipmi.Tags = map[string]string{}
|
||||
|
||||
Reference in New Issue
Block a user