paramters in node
This commit is contained in:
@@ -58,6 +58,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":TYPE", netdev.Type.Source(), netdev.Type.Print())
|
||||
fmt.Printf("%-20s %-18s %-12s %t\n", node.Id.Get(), name+":DEFAULT", netdev.Default.Source(), netdev.Default.PrintB())
|
||||
}
|
||||
|
||||
for name, param := range node.Params {
|
||||
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":VALUE", param.Value.Source(), param.Value.Print())
|
||||
}
|
||||
}
|
||||
|
||||
} else if ShowNet {
|
||||
|
||||
@@ -325,6 +325,20 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
n.NetDevs[SetNetDev].Default.SetB(true)
|
||||
}
|
||||
|
||||
if SetValue != "" {
|
||||
if SetParam == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "You must include the '--param' option\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, ok := n.Params[SetParam]; !ok {
|
||||
var nd node.ParamEntry
|
||||
n.Params[SetParam] = &nd
|
||||
}
|
||||
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Value %s\n", n.Id.Get(), SetParam, SetValue)
|
||||
n.Params[SetParam].Value.Set(SetValue)
|
||||
}
|
||||
|
||||
err := nodeDB.NodeUpdate(n)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
|
||||
@@ -41,6 +41,8 @@ var (
|
||||
SetDiscoverable bool
|
||||
SetUndiscoverable bool
|
||||
SetRoot string
|
||||
SetParam string
|
||||
SetValue string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -74,6 +76,9 @@ func init() {
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
|
||||
baseCmd.PersistentFlags().BoolVar(&SetNetDevDefault, "netdefault", false, "Set this network to be default")
|
||||
|
||||
baseCmd.PersistentFlags().StringVarP(&SetParam, "param", "p", "", "Define custom parameter")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetValue, "value", "", "", "Set custom parameter value")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
|
||||
@@ -43,6 +43,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "In node loop: %s\n", nodename)
|
||||
n.NetDevs = make(map[string]*NetDevEntry)
|
||||
n.Params = make(map[string]*ParamEntry)
|
||||
n.SystemOverlay.SetDefault("default")
|
||||
n.RuntimeOverlay.SetDefault("default")
|
||||
n.Ipxe.SetDefault("default")
|
||||
@@ -94,6 +95,14 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.NetDevs[devname].Default.SetB(netdev.Default)
|
||||
}
|
||||
|
||||
for paramname, param := range node.Params {
|
||||
if _, ok := n.Params[paramname]; !ok {
|
||||
var param ParamEntry
|
||||
n.Params[paramname] = ¶m
|
||||
}
|
||||
n.Params[paramname].Value.Set(param.Value)
|
||||
}
|
||||
|
||||
for _, p := range n.Profiles {
|
||||
if _, ok := config.NodeProfiles[p]; !ok {
|
||||
wwlog.Printf(wwlog.WARN, "Profile not found for node '%s': %s\n", nodename, p)
|
||||
|
||||
@@ -36,6 +36,7 @@ type NodeConf struct {
|
||||
Discoverable bool `yaml:"discoverable,omitempty"`
|
||||
Profiles []string `yaml:"profiles,omitempty"`
|
||||
NetDevs map[string]*NetDevs `yaml:"network devices,omitempty"`
|
||||
Params map[string]*Params `yaml:"parameters,omitempty"`
|
||||
}
|
||||
|
||||
type NetDevs struct {
|
||||
@@ -47,6 +48,10 @@ type NetDevs struct {
|
||||
Gateway string `yaml:"gateway,omitempty"`
|
||||
}
|
||||
|
||||
type Params struct {
|
||||
Value string `yaml:"value,omitempty"`
|
||||
}
|
||||
|
||||
/******
|
||||
* Internal code data representations
|
||||
******/
|
||||
@@ -82,6 +87,7 @@ type NodeInfo struct {
|
||||
Profiles []string
|
||||
GroupProfiles []string
|
||||
NetDevs map[string]*NetDevEntry
|
||||
Params map[string]*ParamEntry
|
||||
}
|
||||
|
||||
type NetDevEntry struct {
|
||||
@@ -93,6 +99,10 @@ type NetDevEntry struct {
|
||||
Gateway Entry `yaml:"gateway,omitempty"`
|
||||
}
|
||||
|
||||
type ParamEntry struct {
|
||||
Value Entry `yaml:"value,omitempty"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
//TODO: Check to make sure nodes.conf is found
|
||||
if !util.IsFile(ConfigFile) {
|
||||
|
||||
@@ -27,6 +27,7 @@ func (config *nodeYaml) AddNode(nodeID string) (NodeInfo, error) {
|
||||
config.Nodes[nodeID] = &node
|
||||
config.Nodes[nodeID].Profiles = []string{"default"}
|
||||
config.Nodes[nodeID].NetDevs = make(map[string]*NetDevs)
|
||||
// config.Nodes[nodeID].Params = make(map[string]*Params)
|
||||
|
||||
n.Id.Set(nodeID)
|
||||
n.Profiles = []string{"default"}
|
||||
@@ -75,6 +76,8 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error {
|
||||
config.Nodes[nodeID].Profiles = node.Profiles
|
||||
config.Nodes[nodeID].NetDevs = make(map[string]*NetDevs)
|
||||
|
||||
config.Nodes[nodeID].Params = make(map[string]*Params)
|
||||
|
||||
for devname, netdev := range node.NetDevs {
|
||||
var newdev NetDevs
|
||||
config.Nodes[nodeID].NetDevs[devname] = &newdev
|
||||
@@ -87,6 +90,12 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error {
|
||||
config.Nodes[nodeID].NetDevs[devname].Default = netdev.Default.GetRealB()
|
||||
}
|
||||
|
||||
for paramname, param := range node.Params {
|
||||
var newparam Params
|
||||
config.Nodes[nodeID].Params[paramname] = &newparam
|
||||
config.Nodes[nodeID].Params[paramname].Value = param.Value.GetReal()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user