Building set commands for nodes and groups and templating out CLI further
This commit is contained in:
@@ -2,10 +2,8 @@ package node
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"github.com/hpcng/warewulf/internal/pkg/errors"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/vnfs"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
@@ -21,7 +19,7 @@ func init() {
|
||||
}
|
||||
|
||||
type nodeYaml struct {
|
||||
NodeGroups map[string]nodeGroup //`yaml:"nodegroups"`
|
||||
NodeGroups map[string]*nodeGroup //`yaml:"nodegroups"`
|
||||
}
|
||||
|
||||
type nodeGroup struct {
|
||||
@@ -33,7 +31,7 @@ type nodeGroup struct {
|
||||
DomainSuffix string `yaml:"domain suffix"`
|
||||
KernelVersion string `yaml:"kernel version"`
|
||||
KernelArgs string `yaml:"kernel args"`
|
||||
Nodes map[string]nodeEntry
|
||||
Nodes map[string]*nodeEntry
|
||||
}
|
||||
|
||||
type nodeEntry struct {
|
||||
@@ -60,6 +58,7 @@ type netDevs struct {
|
||||
}
|
||||
|
||||
type NodeInfo struct {
|
||||
Id string
|
||||
GroupName string
|
||||
HostName string
|
||||
DomainName string
|
||||
@@ -77,8 +76,6 @@ type NodeInfo struct {
|
||||
NetDevs map[string]netDevs
|
||||
}
|
||||
|
||||
|
||||
|
||||
func New() (nodeYaml, error) {
|
||||
var ret nodeYaml
|
||||
|
||||
@@ -97,16 +94,90 @@ func New() (nodeYaml, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self nodeYaml) SetNodeVal(nodename string, entry string, value string) (int, error) {
|
||||
func (self *nodeYaml) AddGroup(groupname string) error {
|
||||
var group nodeGroup
|
||||
|
||||
self.NodeGroups[groupname] = &group
|
||||
self.NodeGroups[groupname].DomainSuffix = groupname
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *nodeYaml) AddNode(groupname string, nodename string) error {
|
||||
var node nodeEntry
|
||||
|
||||
self.NodeGroups[groupname].Nodes[nodename] = &node
|
||||
self.NodeGroups[groupname].Nodes[nodename].Hostname = nodename
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *nodeYaml) SetGroupVal(groupID string, entry string, value string) (int, error) {
|
||||
var count int
|
||||
|
||||
for gname, group := range self.NodeGroups {
|
||||
for nname, _ := range group.Nodes {
|
||||
if nodename == nname {
|
||||
for gid, group := range self.NodeGroups {
|
||||
for nid := range group.Nodes {
|
||||
if groupID == gid {
|
||||
if entry == "vnfs" {
|
||||
var foo = self.NodeGroups[gname].Nodes[nname]
|
||||
foo.Vnfs = value
|
||||
// node.Vnfs = value
|
||||
self.NodeGroups[gid].Vnfs = value
|
||||
self.NodeGroups[gid].Nodes[nid].Vnfs = ""
|
||||
count++
|
||||
} else if entry == "kernel" {
|
||||
self.NodeGroups[gid].KernelVersion = value
|
||||
self.NodeGroups[gid].Nodes[nid].KernelVersion = ""
|
||||
count++
|
||||
} else if entry == "domainsuffix" {
|
||||
self.NodeGroups[gid].DomainSuffix = value
|
||||
self.NodeGroups[gid].Nodes[nid].DomainSuffix = ""
|
||||
count++
|
||||
} else if entry == "ipxe" {
|
||||
self.NodeGroups[gid].Ipxe = value
|
||||
self.NodeGroups[gid].Nodes[nid].Ipxe = ""
|
||||
count++
|
||||
} else if entry == "systemoverlay" {
|
||||
self.NodeGroups[gid].SystemOverlay = value
|
||||
self.NodeGroups[gid].Nodes[nid].SystemOverlay = ""
|
||||
count++
|
||||
} else if entry == "runtimeoverlay" {
|
||||
self.NodeGroups[gid].RuntimeOverlay = value
|
||||
self.NodeGroups[gid].Nodes[nid].RuntimeOverlay = ""
|
||||
count++
|
||||
} else if entry == "hostname" {
|
||||
self.NodeGroups[gid].Nodes[nid].Hostname = value
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (self *nodeYaml) SetNodeVal(nodeID string, entry string, value string) (int, error) {
|
||||
var count int
|
||||
|
||||
for gid, group := range self.NodeGroups {
|
||||
for nid := range group.Nodes {
|
||||
if nodeID == gid+":"+nid {
|
||||
if entry == "vnfs" {
|
||||
self.NodeGroups[gid].Nodes[nid].Vnfs = value
|
||||
count++
|
||||
} else if entry == "kernel" {
|
||||
self.NodeGroups[gid].Nodes[nid].KernelVersion = value
|
||||
count++
|
||||
} else if entry == "domainsuffix" {
|
||||
self.NodeGroups[gid].Nodes[nid].DomainSuffix = value
|
||||
count++
|
||||
} else if entry == "ipxe" {
|
||||
self.NodeGroups[gid].Nodes[nid].Ipxe = value
|
||||
count++
|
||||
} else if entry == "systemoverlay" {
|
||||
self.NodeGroups[gid].Nodes[nid].SystemOverlay = value
|
||||
count++
|
||||
} else if entry == "runtimeoverlay" {
|
||||
self.NodeGroups[gid].Nodes[nid].RuntimeOverlay = value
|
||||
count++
|
||||
} else if entry == "hostname" {
|
||||
self.NodeGroups[gid].Nodes[nid].Hostname = value
|
||||
count++
|
||||
}
|
||||
}
|
||||
@@ -128,16 +199,14 @@ func (self *nodeYaml) Persist() error {
|
||||
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 {
|
||||
for nodename, node := range group.Nodes {
|
||||
var n NodeInfo
|
||||
|
||||
n.Id = groupname + ":" + nodename
|
||||
n.GroupName = groupname
|
||||
n.HostName = node.Hostname
|
||||
n.IpmiIpaddr = node.IpmiIpaddr
|
||||
@@ -191,16 +260,13 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.Fqdn = node.Hostname
|
||||
}
|
||||
|
||||
util.ValidateOrDie(n.Fqdn, "group name", n.GroupName, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "vnfs", n.Vnfs, "^[a-zA-Z0-9-._:/]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "system overlay", n.SystemOverlay, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "runtime overlay", n.RuntimeOverlay, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "domain suffix", n.DomainName, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "hostname", n.HostName, "^[a-zA-Z0-9-_]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "kernel version", n.KernelVersion, "^[a-zA-Z0-9-._]+$")
|
||||
|
||||
v := vnfs.New(n.Vnfs)
|
||||
n.VnfsDir = config.VnfsChroot(v.NameClean())
|
||||
util.ValidateOrDie(n.Fqdn, "group name", n.GroupName, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "vnfs", n.Vnfs, "^[a-zA-Z0-9-._:/]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "system overlay", n.SystemOverlay, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "runtime overlay", n.RuntimeOverlay, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "domain suffix", n.DomainName, "^[a-zA-Z0-9-._]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "hostname", n.HostName, "^[a-zA-Z0-9-_]+$")
|
||||
util.ValidateOrDie(n.Fqdn, "kernel version", n.KernelVersion, "^[a-zA-Z0-9-._]+$")
|
||||
|
||||
ret = append(ret, n)
|
||||
}
|
||||
@@ -209,7 +275,6 @@ func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
func (nodes *nodeYaml) FindByHwaddr(hwa string) (NodeInfo, error) {
|
||||
var ret NodeInfo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user