@@ -3,6 +3,7 @@ package set
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/node"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
var nodes []node.NodeInfo
|
||||
var SetProfiles []string
|
||||
|
||||
nodeDB, err := node.New()
|
||||
if err != nil {
|
||||
@@ -63,6 +65,42 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if SetProfile != "" {
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
for _, r := range strings.Split(SetProfile, ",") {
|
||||
var match bool
|
||||
|
||||
for _, p := range profiles {
|
||||
if p.Id.Get() == r || SetForce {
|
||||
match = true
|
||||
SetProfiles = append(SetProfiles, r)
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
wwlog.Printf(wwlog.WARN, "Requested profile is undefined: %s\n", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(SetAddProfile) > 0 {
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
for _, r := range SetAddProfile {
|
||||
var match bool
|
||||
|
||||
for _, p := range profiles {
|
||||
if p.Id.Get() == r || SetForce {
|
||||
match = true
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
wwlog.Printf(wwlog.WARN, "Requested profile is undefined: %s\n", r)
|
||||
SetAddProfile = util.SliceRemoveElement(SetAddProfile, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, n := range nodes {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Id.Get())
|
||||
|
||||
@@ -151,16 +189,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
n.Discoverable.SetB(false)
|
||||
}
|
||||
|
||||
if len(SetProfiles) > 0 {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting profiles to: %s\n", n.Id.Get(), strings.Join(SetProfiles, ","))
|
||||
n.Profiles = SetProfiles
|
||||
}
|
||||
|
||||
if len(SetAddProfile) > 0 {
|
||||
for _, p := range SetAddProfile {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile to '%s'\n", n.Id.Get(), p)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile '%s'\n", n.Id.Get(), p)
|
||||
n.Profiles = util.SliceAddUniqueElement(n.Profiles, p)
|
||||
}
|
||||
}
|
||||
|
||||
if len(SetDelProfile) > 0 {
|
||||
for _, p := range SetDelProfile {
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile from '%s'\n", n.Id.Get(), p)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile '%s'\n", n.Id.Get(), p)
|
||||
n.Profiles = util.SliceRemoveElement(n.Profiles, p)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user