Work in progress on setting variables
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/poweron"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/poweroff"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/powerstatus"
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/node/set"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -21,6 +22,7 @@ func init() {
|
||||
baseCmd.AddCommand(poweroff.GetCommand())
|
||||
baseCmd.AddCommand(powerstatus.GetCommand())
|
||||
baseCmd.AddCommand(list.GetCommand())
|
||||
baseCmd.AddCommand(set.GetCommand())
|
||||
|
||||
}
|
||||
|
||||
|
||||
40
internal/app/wwctl/node/set/main.go
Normal file
40
internal/app/wwctl/node/set/main.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package set
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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 {
|
||||
var err error
|
||||
var c int
|
||||
|
||||
n, 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 SetVnfs != "" {
|
||||
fmt.Printf("Setting vnfs to: %s\n", SetVnfs)
|
||||
n = n.SetNodeVal("n0000", "vnfs", SetVnfs)
|
||||
}
|
||||
|
||||
fmt.Printf("set count: %d\n", c)
|
||||
|
||||
a, err := n.FindByHwaddr("00:0c:29:23:8b:48")
|
||||
|
||||
fmt.Printf("VNFS: %s\n", a.Vnfs)
|
||||
|
||||
//n.Persist()
|
||||
|
||||
return nil
|
||||
}
|
||||
23
internal/app/wwctl/node/set/root.go
Normal file
23
internal/app/wwctl/node/set/root.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package set
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "set",
|
||||
Short: "Set node configurations",
|
||||
Long: "Set node configurations ",
|
||||
RunE: CobraRunE,
|
||||
}
|
||||
SetVnfs string
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
|
||||
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
@@ -30,6 +30,7 @@ func init() {
|
||||
rootCmd.AddCommand(vnfs.GetCommand())
|
||||
rootCmd.AddCommand(node.GetCommand())
|
||||
rootCmd.AddCommand(kernel.GetCommand())
|
||||
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
@@ -26,7 +26,7 @@ type nodeYaml struct {
|
||||
|
||||
type nodeGroup struct {
|
||||
Comment string
|
||||
Vnfs string
|
||||
Vnfs string `yaml:"vnfs"`
|
||||
Ipxe string `yaml:"ipxe template"`
|
||||
SystemOverlay string `yaml:"system overlay""`
|
||||
RuntimeOverlay string `yaml:"runtime overlay""`
|
||||
@@ -38,16 +38,16 @@ type nodeGroup struct {
|
||||
|
||||
type nodeEntry struct {
|
||||
Hostname string
|
||||
Vnfs string
|
||||
Ipxe string `yaml:"ipxe template"`
|
||||
SystemOverlay string `yaml:"system overlay"`
|
||||
RuntimeOverlay string `yaml:"runtime overlay"`
|
||||
DomainSuffix string `yaml:"domain suffix"`
|
||||
KernelVersion string `yaml:"kernel version"`
|
||||
KernelArgs string `yaml:"kernel args"`
|
||||
IpmiIpaddr string `yaml:"ipmi ipaddr"`
|
||||
IpmiUserName string `yaml:"ipmi username"`
|
||||
IpmiPassword string `yaml:"ipmi password"`
|
||||
Vnfs string `yaml:"vnfs,omitempty"`
|
||||
Ipxe string `yaml:"ipxe template,omitempty"`
|
||||
SystemOverlay string `yaml:"system overlay,omitempty"`
|
||||
RuntimeOverlay string `yaml:"runtime overlay,omitempty"`
|
||||
DomainSuffix string `yaml:"domain suffix,omitempty"`
|
||||
KernelVersion string `yaml:"kernel version,omitempty"`
|
||||
KernelArgs string `yaml:"kernel args,omitempty"`
|
||||
IpmiIpaddr string `yaml:"ipmi ipaddr,omitempty"`
|
||||
IpmiUserName string `yaml:"ipmi username,omitempty"`
|
||||
IpmiPassword string `yaml:"ipmi password,omitempty"`
|
||||
NetDevs map[string]netDevs
|
||||
}
|
||||
|
||||
@@ -77,30 +77,67 @@ type NodeInfo struct {
|
||||
NetDevs map[string]netDevs
|
||||
}
|
||||
|
||||
type nodeInfoContainer struct {
|
||||
Nodes []NodeInfo
|
||||
}
|
||||
|
||||
|
||||
func New() (nodeInfoContainer, error) {
|
||||
var c nodeYaml
|
||||
var ret nodeInfoContainer
|
||||
func New() (nodeYaml, error) {
|
||||
var ret nodeYaml
|
||||
|
||||
config := config.New()
|
||||
|
||||
wwlog.Printf(wwlog.DEBUG, "Opening configuration file: %s\n", ConfigFile)
|
||||
wwlog.Printf(wwlog.DEBUG, "Opening node configuration file: %s\n", ConfigFile)
|
||||
data, err := ioutil.ReadFile(ConfigFile)
|
||||
if err != nil {
|
||||
fmt.Printf("error reading node configuration file\n")
|
||||
return ret, err
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(data, &c)
|
||||
err = yaml.Unmarshal(data, &ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for groupname, group := range c.NodeGroups {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self nodeYaml) SetNodeVal(nodename string, entry string, value string) nodeYaml {
|
||||
var count int
|
||||
var ret = self
|
||||
|
||||
for gname, group := range self.NodeGroups {
|
||||
for nname, _ := range group.Nodes {
|
||||
if nodename == nname {
|
||||
if entry == "vnfs" {
|
||||
var foo = self.NodeGroups[gname].Nodes[nname]
|
||||
foo.Vnfs = value
|
||||
// self.NodeGroups[gname].Nodes[nname].Vnfs = value
|
||||
// node.Vnfs = value
|
||||
// ret.NodeGroups[gname].Nodes[nname].Vnfs = value
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *nodeYaml) Persist() error {
|
||||
|
||||
out, err := yaml.Marshal(self)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(out))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
var ret []NodeInfo
|
||||
|
||||
config := config.New()
|
||||
|
||||
for groupname, group := range self.NodeGroups {
|
||||
for _, node := range group.Nodes {
|
||||
var n NodeInfo
|
||||
|
||||
@@ -168,7 +205,7 @@ func New() (nodeInfoContainer, error) {
|
||||
v := vnfs.New(n.Vnfs)
|
||||
n.VnfsDir = config.VnfsChroot(v.NameClean())
|
||||
|
||||
ret.Nodes = append(ret.Nodes, n)
|
||||
ret = append(ret, n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,17 +213,12 @@ func New() (nodeInfoContainer, error) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func (nodes *nodeInfoContainer) FindAllNodes() ([]NodeInfo, error) {
|
||||
return nodes.Nodes, nil
|
||||
}
|
||||
|
||||
|
||||
func (nodes *nodeInfoContainer) FindByHwaddr(hwa string) (NodeInfo, error) {
|
||||
func (nodes *nodeYaml) FindByHwaddr(hwa string) (NodeInfo, error) {
|
||||
var ret NodeInfo
|
||||
|
||||
for _, node := range nodes.Nodes {
|
||||
n, _ := nodes.FindAllNodes()
|
||||
|
||||
for _, node := range n {
|
||||
for _, dev := range node.NetDevs {
|
||||
if dev.Hwaddr == hwa {
|
||||
return node, nil
|
||||
@@ -197,10 +229,12 @@ func (nodes *nodeInfoContainer) FindByHwaddr(hwa string) (NodeInfo, error) {
|
||||
return ret, errors.New("No nodes found with HW Addr: " + hwa)
|
||||
}
|
||||
|
||||
func (nodes *nodeInfoContainer) FindByIpaddr(ipaddr string) (NodeInfo, error) {
|
||||
func (nodes *nodeYaml) FindByIpaddr(ipaddr string) (NodeInfo, error) {
|
||||
var ret NodeInfo
|
||||
|
||||
for _, node := range nodes.Nodes {
|
||||
n, _ := nodes.FindAllNodes()
|
||||
|
||||
for _, node := range n {
|
||||
for _, dev := range node.NetDevs {
|
||||
if dev.Ipaddr == ipaddr {
|
||||
return node, nil
|
||||
@@ -211,10 +245,12 @@ func (nodes *nodeInfoContainer) FindByIpaddr(ipaddr string) (NodeInfo, error) {
|
||||
return ret, errors.New("No nodes found with IP Addr: " + ipaddr)
|
||||
}
|
||||
|
||||
func (nodes *nodeInfoContainer) SearchByName(search string) ([]NodeInfo, error) {
|
||||
func (nodes *nodeYaml) SearchByName(search string) ([]NodeInfo, error) {
|
||||
var ret []NodeInfo
|
||||
|
||||
for _, node := range nodes.Nodes {
|
||||
n, _ := nodes.FindAllNodes()
|
||||
|
||||
for _, node := range n {
|
||||
b, _ := regexp.MatchString(search, node.Fqdn)
|
||||
if b == true {
|
||||
ret = append(ret, node)
|
||||
@@ -224,11 +260,13 @@ func (nodes *nodeInfoContainer) SearchByName(search string) ([]NodeInfo, error)
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (nodes *nodeInfoContainer) SearchByNameList(searchList []string) ([]NodeInfo, error) {
|
||||
func (nodes *nodeYaml) SearchByNameList(searchList []string) ([]NodeInfo, error) {
|
||||
var ret []NodeInfo
|
||||
|
||||
n, _ := nodes.FindAllNodes()
|
||||
|
||||
for _, search := range searchList {
|
||||
for _, node := range nodes.Nodes {
|
||||
for _, node := range n {
|
||||
b, _ := regexp.MatchString(search, node.Fqdn)
|
||||
if b == true {
|
||||
ret = append(ret, node)
|
||||
|
||||
Reference in New Issue
Block a user