Merge branch 'main' of github.com:ctrl-cmd/warewulf into main

This commit is contained in:
Shannon V. Davidson
2020-12-03 19:43:06 -06:00
72 changed files with 1358 additions and 1799 deletions

View File

@@ -2,14 +2,14 @@ package main
import ( import (
"fmt" "fmt"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"log" "log"
"net" "net"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"time" "time"
"github.com/hpcng/warewulf/internal/pkg/config"
) )
func main() { func main() {
@@ -24,10 +24,14 @@ func main() {
os.Chdir("/warewulf/wwclient-test") os.Chdir("/warewulf/wwclient-test")
} }
config := config.New() conf, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not get Warewulf configuration: %s\n", err)
os.Exit(1)
}
localTCPAddr := net.TCPAddr{} localTCPAddr := net.TCPAddr{}
if config.InsecureRuntime == false { if conf.Warewulf.Secure == true {
// Setup local port to something privileged (<1024) // Setup local port to something privileged (<1024)
localTCPAddr.Port = 987 localTCPAddr.Port = 987
} else { } else {
@@ -56,7 +60,7 @@ func main() {
for true { for true {
var err error var err error
getString := fmt.Sprintf("http://%s:%d/overlay-runtime", config.Ipaddr, config.Port) getString := fmt.Sprintf("http://%s:%d/overlay-runtime", conf.Ipaddr, conf.Warewulf.Port)
resp, err = webclient.Get(getString) resp, err = webclient.Get(getString)
if err == nil { if err == nil {
break break

View File

@@ -1,87 +1,36 @@
nodeprofiles: nodeprofiles:
default: default:
comment: "" comment: "Hello from the default profile"
vnfs: "" vnfs: ""
kernel version: "" kernel version: ""
kernel args: crashkernel=no quiet kernel args: crashkernel=no quiet
control: nodes:
headnode01: n0000.cluster01:
comment: This is the first control system network devices:
ipaddr: 192.168.1.1 eth0:
services: type: ethernet
warewulfd: hwaddr: 00:0c:29:23:8b:48
port: 9873 ipaddr: 192.168.1.100
secure: true netmask: 255.255.255.0
dhcp: ib0:
enabled: true type: infiniband
range start: 192.168.1.100 hwaddr: aa:bb:cc:dd:ee:a0
range end: 192.168.1.250 ipaddr: 192.168.10.100
assign static: false netmask: 255.255.255.0
config file: /etc/dhcp/dhcpd.conf n0001.cluster01:
start command: systemctl start dhcpd network devices:
restart command: systemctl restart dhcpd eth0:
enable command: systemctl enable dhcpd hwaddr: aa:bb:cc:dd:ee:b0
tftp: ipaddr: 192.168.1.101
enabled: true ib0:
tftproot: /var/lib/tftproot hwaddr: aa:bb:cc:dd:ee:b1
start command: service tftp start ipaddr: 192.168.10.100
restart command: service tftp restart netmask: 255.255.255.0
enable command: chkconfig tftp on n0000.cluster02:
nfs: network devices:
enabled: true eth0:
config file: /etc/exports hwaddr: aa:bb:cc:dd:ee:c0
exports: ipaddr: 192.168.2.100
- /var/warewulf 192.168.1.1/255.255.255.0(ro,no_root_squash) netmask: 255.255.255.0
- /home 192.168.1.1/255.255.255.0(rw,no_root_squash) gateway: 192.168.1.1
start command: service nfs start
restart command: service nfs restart
enable command: chkconfig nfs on
nodegroups:
default:
comment: This is the default group
domain name: cluster01
profiles:
- default
nodes:
n0000:
hostname: n0000
netdevs:
eth0:
type: ethernet
hwaddr: 00:0c:29:23:8b:48
ipaddr: 192.168.1.100
netmask: 255.255.255.0
gateway: 192.168.1.1
ib0:
type: infiniband
hwaddr: aa:bb:cc:dd:ee:a0
ipaddr: 192.168.10.100
netmask: 255.255.255.0
n0001:
hostname: n0001
ipmi ipaddr: x.x.x.x
netdevs:
eth0:
hwaddr: aa:bb:cc:dd:ee:b0
ipaddr: 192.168.1.101
netmask: 255.255.255.0
gateway: 192.168.1.1
ib0:
hwaddr: aa:bb:cc:dd:ee:b1
ipaddr: 192.168.10.100
netmask: 255.255.255.0
group_1:
comment: This is the group 1
domain name: group1
profiles:
- default
nodes:
n0000:
hostname: n0000
netdevs:
eth0:
hwaddr: aa:bb:cc:dd:ee:c0
ipaddr: 192.168.2.100
netmask: 255.255.255.0
gateway: 192.168.2.1

View File

@@ -1,4 +1,11 @@
warewulfd ipaddr: 192.168.1.1 ipaddr: 192.168.1.1
warewulfd port: 9873 netmask: 255.255.255.0
insecure runtime: false warewulf:
debug: false port: 9873
secure: true
dhcp:
enabled: true
range start: 192.168.1.150
range end: 192.168.1.200
template: default

23
go.mod
View File

@@ -44,16 +44,17 @@ require (
github.com/russross/blackfriday/v2 v2.0.1 github.com/russross/blackfriday/v2 v2.0.1
github.com/sirupsen/logrus v1.7.0 github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.1 github.com/spf13/cobra v1.1.1
github.com/ulikunitz/xz v0.5.8 github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31
github.com/vbauerster/mpb/v5 v5.3.0 github.com/ulikunitz/xz v0.5.8 // indirect
go.etcd.io/bbolt v1.3.5 github.com/vbauerster/mpb/v5 v5.3.0 // indirect
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 go.etcd.io/bbolt v1.3.5 // indirect
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
google.golang.org/grpc v1.27.0 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.24.0 google.golang.org/grpc v1.27.0 // indirect
gopkg.in/square/go-jose.v2 v2.3.1 google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/square/go-jose.v2 v2.3.1 // indirect
gopkg.in/yaml.v2 v2.3.0 gopkg.in/yaml.v2 v2.3.0
) )

2
go.sum
View File

@@ -384,6 +384,8 @@ github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eN
github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao=
github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 h1:OXcKh35JaYsGMRzpvFkLv/MEyPuL49CThT1pZ8aSml4=
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ= github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=

View File

@@ -2,8 +2,8 @@ package response
import ( import (
"fmt" "fmt"
"github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"log" "log"
"net/http" "net/http"
@@ -13,16 +13,15 @@ import (
) )
type iPxeTemplate struct { type iPxeTemplate struct {
Hostname string Hostname string
Fqdn string Fqdn string
Vnfs string Vnfs string
Hwaddr string Hwaddr string
Ipaddr string Ipaddr string
Port string Port string
Kernelargs string Kernelargs string
} }
func IpxeSend(w http.ResponseWriter, req *http.Request) { func IpxeSend(w http.ResponseWriter, req *http.Request) {
url := strings.Split(req.URL.Path, "/") url := strings.Split(req.URL.Path, "/")
@@ -47,9 +46,13 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
} }
if node.Id.Defined() == true { if node.Id.Defined() == true {
conf := config.New() conf, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
return
}
log.Printf("IPXE: %15s: %s\n", node.Fqdn.Get(), req.URL.Path) log.Printf("IPXE: %15s: %s\n", node.Id.Get(), req.URL.Path)
// TODO: Fix template path to use config package // TODO: Fix template path to use config package
ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/%s.ipxe", node.Ipxe.Get()) ipxeTemplate := fmt.Sprintf("/etc/warewulf/ipxe/%s.ipxe", node.Ipxe.Get())
@@ -62,10 +65,10 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
var replace iPxeTemplate var replace iPxeTemplate
replace.Fqdn = node.Fqdn.Get() replace.Fqdn = node.Id.Get()
replace.Ipaddr = conf.Ipaddr replace.Ipaddr = conf.Ipaddr
replace.Port = strconv.Itoa(conf.Port) replace.Port = strconv.Itoa(conf.Warewulf.Port)
replace.Hostname = node.HostName.Get() replace.Hostname = node.Id.Get()
replace.Hwaddr = url[2] replace.Hwaddr = url[2]
replace.Vnfs = node.Vnfs.Get() replace.Vnfs = node.Vnfs.Get()
replace.Kernelargs = node.KernelArgs.Get() replace.Kernelargs = node.KernelArgs.Get()
@@ -76,7 +79,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
return return
} }
log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), ipxeTemplate) log.Printf("SEND: %15s: %s\n", node.Id.Get(), ipxeTemplate)
} else { } else {
log.Printf("ERROR: iPXE request from unknown Node (hwaddr=%s)\n", url[2]) log.Printf("ERROR: iPXE request from unknown Node (hwaddr=%s)\n", url[2])

View File

@@ -7,7 +7,6 @@ import (
) )
func KernelSend(w http.ResponseWriter, req *http.Request) { func KernelSend(w http.ResponseWriter, req *http.Request) {
config := config.New()
node, err := getSanity(req) node, err := getSanity(req)
if err != nil { if err != nil {
@@ -19,16 +18,16 @@ func KernelSend(w http.ResponseWriter, req *http.Request) {
if node.KernelVersion.Defined() == true { if node.KernelVersion.Defined() == true {
fileName := config.KernelImage(node.KernelVersion.Get()) fileName := config.KernelImage(node.KernelVersion.Get())
err := sendFile(w, fileName, node.Fqdn.Get()) err := sendFile(w, fileName, node.Id.Get())
if err != nil { if err != nil {
log.Printf("ERROR: %s\n", err) log.Printf("ERROR: %s\n", err)
} else { } else {
log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName)
} }
} else { } else {
w.WriteHeader(503) w.WriteHeader(503)
log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Fqdn.Get()) log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Id.Get())
} }
return return

View File

@@ -7,7 +7,6 @@ import (
) )
func KmodsSend(w http.ResponseWriter, req *http.Request) { func KmodsSend(w http.ResponseWriter, req *http.Request) {
config := config.New()
node, err := getSanity(req) node, err := getSanity(req)
if err != nil { if err != nil {
@@ -19,16 +18,16 @@ func KmodsSend(w http.ResponseWriter, req *http.Request) {
if node.KernelVersion.Defined() == true { if node.KernelVersion.Defined() == true {
fileName := config.KmodsImage(node.KernelVersion.Get()) fileName := config.KmodsImage(node.KernelVersion.Get())
err := sendFile(w, fileName, node.Fqdn.Get()) err := sendFile(w, fileName, node.Id.Get())
if err != nil { if err != nil {
log.Printf("ERROR: %s\n", err) log.Printf("ERROR: %s\n", err)
} else { } else {
log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName)
} }
} else { } else {
w.WriteHeader(503) w.WriteHeader(503)
log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Fqdn.Get()) log.Printf("ERROR: No 'kernel version' set for node %s\n", node.Id.Get())
} }
return return

View File

@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/hpcng/warewulf/internal/pkg/config" "github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
@@ -11,7 +12,13 @@ import (
) )
func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) { func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) {
config := config.New() conf, err := warewulfconf.New()
if err != nil {
log.Printf("Could not read Warewulf configuration file: %s\n", err)
w.WriteHeader(503)
return
}
nodes, err := node.New() nodes, err := node.New()
if err != nil { if err != nil {
log.Printf("Could not read node configuration file: %s\n", err) log.Printf("Could not read node configuration file: %s\n", err)
@@ -32,7 +39,7 @@ func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) {
return return
} }
if config.InsecureRuntime == false { if conf.Warewulf.Secure == true {
if port >= 1024 { if port >= 1024 {
log.Panicf("DENIED: Connection coming from non-privledged port: %s\n", req.RemoteAddr) log.Panicf("DENIED: Connection coming from non-privledged port: %s\n", req.RemoteAddr)
w.WriteHeader(401) w.WriteHeader(401)
@@ -52,21 +59,21 @@ func RuntimeOverlaySend(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(404) w.WriteHeader(404)
return return
} else { } else {
log.Printf("REQ: %15s: %s\n", node.Fqdn.Get(), req.URL.Path) log.Printf("REQ: %15s: %s\n", node.Id.Get(), req.URL.Path)
} }
if node.RuntimeOverlay.Defined() == true { if node.RuntimeOverlay.Defined() == true {
fileName := config.RuntimeOverlayImage(node.Fqdn.Get()) fileName := config.RuntimeOverlayImage(node.Id.Get())
err := sendFile(w, fileName, node.Fqdn.Get()) err := sendFile(w, fileName, node.Id.Get())
if err != nil { if err != nil {
log.Printf("ERROR: %s\n", err) log.Printf("ERROR: %s\n", err)
} else { } else {
log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName)
} }
} else { } else {
w.WriteHeader(503) w.WriteHeader(503)
log.Printf("ERROR: No 'runtime system-overlay' set for node %s\n", node.Fqdn.Get()) log.Printf("ERROR: No 'runtime system-overlay' set for node %s\n", node.Id.Get())
} }
return return

View File

@@ -7,8 +7,6 @@ import (
) )
func SystemOverlaySend(w http.ResponseWriter, req *http.Request) { func SystemOverlaySend(w http.ResponseWriter, req *http.Request) {
config := config.New()
node, err := getSanity(req) node, err := getSanity(req)
if err != nil { if err != nil {
w.WriteHeader(404) w.WriteHeader(404)
@@ -17,17 +15,17 @@ func SystemOverlaySend(w http.ResponseWriter, req *http.Request) {
} }
if node.SystemOverlay.Defined() == true { if node.SystemOverlay.Defined() == true {
fileName := config.SystemOverlayImage(node.Fqdn.Get()) fileName := config.SystemOverlayImage(node.Id.Get())
err := sendFile(w, fileName, node.Fqdn.Get()) err := sendFile(w, fileName, node.Id.Get())
if err != nil { if err != nil {
log.Printf("ERROR: %s\n", err) log.Printf("ERROR: %s\n", err)
} else { } else {
log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), fileName) log.Printf("SEND: %15s: %s\n", node.Id.Get(), fileName)
} }
} else { } else {
w.WriteHeader(503) w.WriteHeader(503)
log.Printf("ERROR: No 'system system-overlay' set for node %s\n", node.Fqdn.Get()) log.Printf("ERROR: No 'system system-overlay' set for node %s\n", node.Id.Get())
} }
return return

View File

@@ -27,12 +27,7 @@ func getSanity(req *http.Request) (node.NodeInfo, error) {
return ret, errors.New("Could not find node by HW address") return ret, errors.New("Could not find node by HW address")
} }
if ret.Fqdn.Defined() == false { log.Printf("REQ: %15s: %s\n", ret.Id.Get(), req.URL.Path)
log.Printf("UNKNOWN: %15s: %s\n", hwaddr, req.URL.Path)
return ret, errors.New("Unknown node HW address: " + hwaddr)
} else {
log.Printf("REQ: %15s: %s\n", ret.Fqdn.Get(), req.URL.Path)
}
return ret, nil return ret, nil
} }

View File

@@ -20,19 +20,19 @@ func VnfsSend(w http.ResponseWriter, req *http.Request) {
v, err := vnfs.Load(node.Vnfs.Get()) v, err := vnfs.Load(node.Vnfs.Get())
if err != nil { if err != nil {
w.WriteHeader(503) w.WriteHeader(503)
log.Printf("ERROR: Could not load VNFS: %s\n", node.Fqdn.Get()) log.Printf("ERROR: Could not load VNFS: %s\n", node.Id.Get())
return return
} }
err = sendFile(w, v.Image, node.Fqdn.Get()) err = sendFile(w, v.Image, node.Id.Get())
if err != nil { if err != nil {
log.Printf("ERROR1: %s\n", err) log.Printf("ERROR1: %s\n", err)
} else { } else {
log.Printf("SEND: %15s: %s\n", node.Fqdn.Get(), v.Image) log.Printf("SEND: %15s: %s\n", node.Id.Get(), v.Image)
} }
} else { } else {
w.WriteHeader(503) w.WriteHeader(503)
log.Printf("ERROR: No VNFS set for node %s\n", node.Fqdn.Get()) log.Printf("ERROR: No VNFS set for node %s\n", node.Id.Get())
} }
return return

View File

@@ -3,14 +3,12 @@ package build
import ( import (
"github.com/hpcng/warewulf/internal/pkg/kernel" "github.com/hpcng/warewulf/internal/pkg/kernel"
"github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/vnfs" "github.com/hpcng/warewulf/internal/pkg/vnfs"
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os" "os"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
var nodes []node.NodeInfo var nodes []node.NodeInfo
showHelp := true showHelp := true
@@ -46,7 +44,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.INFO, "Building VNFS images...\n") wwlog.Printf(wwlog.INFO, "Building VNFS images...\n")
for _, node := range nodes { for _, node := range nodes {
set[node.Vnfs.String()] ++ set[node.Vnfs.Get()]++
} }
for e := range set { for e := range set {
vnfs.Build(e, buildForce) vnfs.Build(e, buildForce)
@@ -60,7 +58,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.INFO, "Building Kernel images...\n") wwlog.Printf(wwlog.INFO, "Building Kernel images...\n")
for _, node := range nodes { for _, node := range nodes {
set[node.KernelVersion.String()] ++ set[node.KernelVersion.Get()]++
} }
for e := range set { for e := range set {
kernel.Build(e) kernel.Build(e)
@@ -71,14 +69,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.INFO, "Building System Overlays...\n") wwlog.Printf(wwlog.INFO, "Building System Overlays...\n")
showHelp = false showHelp = false
overlay.SystemBuild(nodes, buildForce) // overlay.SystemBuild(nodes, buildForce)
} }
if buildRuntimeOverlay == true || buildAll == true { if buildRuntimeOverlay == true || buildAll == true {
wwlog.Printf(wwlog.INFO, "Building Runtime Overlays...n") wwlog.Printf(wwlog.INFO, "Building Runtime Overlays...n")
showHelp = false showHelp = false
overlay.RuntimeBuild(nodes, buildForce) // overlay.RuntimeBuild(nodes, buildForce)
} }
if showHelp == true { if showHelp == true {

View File

@@ -34,22 +34,28 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Enable CMD", c.Services.Warewulfd.EnableCmd) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Enable CMD", c.Services.Warewulfd.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Restart CMD", c.Services.Warewulfd.RestartCmd) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "Warewulf", "Restart CMD", c.Services.Warewulfd.RestartCmd)
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "DHCPD", "Enabled", c.Services.Dhcp.Enabled) fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "DHCPD", "Enabled", c.Services.Dhcp.Enabled)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Template", c.Services.Dhcp.Template) if c.Services.Dhcp.Enabled == true {
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "ConfigFile", c.Services.Dhcp.ConfigFile) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Template", c.Services.Dhcp.Template)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "RangeStart", c.Services.Dhcp.RangeStart) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "ConfigFile", c.Services.Dhcp.ConfigFile)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "RangeEnd", c.Services.Dhcp.RangeEnd) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "RangeStart", c.Services.Dhcp.RangeStart)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Enable CMD", c.Services.Dhcp.EnableCmd) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "RangeEnd", c.Services.Dhcp.RangeEnd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Restart CMD", c.Services.Dhcp.RestartCmd) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Enable CMD", c.Services.Dhcp.EnableCmd)
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "TFTP", "Enabled", c.Services.Tftp.Enabled) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "DHCPD", "Restart CMD", c.Services.Dhcp.RestartCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "TftpRoot", c.Services.Tftp.TftpRoot) }
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "Enable CMD", c.Services.Tftp.EnableCmd) fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "TFTP", "Enabled", c.Services.Tftp.Enabled)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "Restart CMD", c.Services.Tftp.RestartCmd) if c.Services.Tftp.Enabled == true {
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "NFS", "Enabled", c.Services.Nfs.Enabled) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "TftpRoot", c.Services.Tftp.TftpRoot)
for _, e := range c.Services.Nfs.Exports { fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "Enable CMD", c.Services.Tftp.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Exports", e) fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "TFTP", "Restart CMD", c.Services.Tftp.RestartCmd)
}
fmt.Printf("%-15s %15s : %s = %t\n", c.Id, "NFS", "Enabled", c.Services.Nfs.Enabled)
if c.Services.Nfs.Enabled == true {
for _, e := range c.Services.Nfs.Exports {
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Exports", e)
}
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Enable CMD", c.Services.Nfs.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Restart CMD", c.Services.Nfs.RestartCmd)
} }
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Enable CMD", c.Services.Nfs.EnableCmd)
fmt.Printf("%-15s %15s : %s = %s\n", c.Id, "NFS", "Restart CMD", c.Services.Nfs.RestartCmd)
} }
} else { } else {

View File

@@ -24,19 +24,18 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if len(args) == 0 {
args = append(args, "localhost")
}
if SetAll == true { if SetAll == true {
var tmp []node.ControllerInfo controllers, err = nodeDB.FindAllControllers()
tmp, err = nodeDB.FindAllControllers()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1) os.Exit(1)
} }
for _, c := range tmp { } else {
controllers = append(controllers, c)
}
} else if len(args) > 0 {
var tmp []node.ControllerInfo var tmp []node.ControllerInfo
tmp, err = nodeDB.FindAllControllers() tmp, err = nodeDB.FindAllControllers()
if err != nil { if err != nil {
@@ -51,10 +50,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
} }
} else {
cmd.Usage()
os.Exit(1)
} }
for _, c := range controllers { for _, c := range controllers {

View File

@@ -1,29 +0,0 @@
package add
import (
"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 {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed opening node database: %s\n", err)
os.Exit(1)
}
for _, g := range args {
err = nodeDB.AddGroup(SetController, g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
nodeDB.Persist()
return nil
}

View File

@@ -1,24 +0,0 @@
package add
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "add",
Short: "Add a new node group",
Long: "Add a new node group ",
RunE: CobraRunE,
Args: cobra.MinimumNArgs(1),
}
SetController string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add group to")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,61 +0,0 @@
package delete
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var count int
var numNodes int
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB. FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err)
os.Exit(1)
}
for _, g := range args {
err := nodeDB.DelGroup(SetController, g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
} else {
for _, n := range nodes {
if n.Gid.Get() == g {
numNodes ++
}
}
count ++
}
}
if count > 0 {
q := fmt.Sprintf("Are you sure you want to delete %d group(s) (%d nodes)", count, numNodes)
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
wwlog.Printf(wwlog.INFO, "No groups found\n")
}
return nil
}

View File

@@ -1,22 +0,0 @@
package delete
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "delete",
Short: "Add a new node group",
Long: "Add a new node group ",
RunE: CobraRunE,
}
SetController string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add group to")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,45 +0,0 @@
package list
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
"reflect"
"strings"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
groups, err := nodeDB.FindAllGroups()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all nodes: %s\n", err)
os.Exit(1)
}
if ShowAll == true {
for _, group := range groups {
v := reflect.ValueOf(group)
typeOfS := v.Type()
fmt.Printf("################################################################################\n")
for i := 0; i< v.NumField(); i++ {
fmt.Printf("%-25s %s = %v\n", group.Id, typeOfS.Field(i).Name, v.Field(i).Interface())
}
}
} else {
fmt.Printf("%-22s %-16s %-16s %s\n", "GROUP NAME", "DOMAINNAME", "CONTROLLER", "PROFILES")
for _, g := range groups {
fmt.Printf("%-22s %-16s %-16s %s\n", g.Id, g.DomainName, g.Cid, strings.Join(g.Profiles, ","))
}
}
return nil
}

View File

@@ -1,23 +0,0 @@
package list
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "list",
Short: "List group configurations",
Long: "List group configurations ",
RunE: CobraRunE,
}
ShowAll bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&ShowAll, "all", "a", false, "Show all node configurations")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,29 +0,0 @@
package group
import (
"github.com/hpcng/warewulf/internal/app/wwctl/group/add"
"github.com/hpcng/warewulf/internal/app/wwctl/group/delete"
"github.com/hpcng/warewulf/internal/app/wwctl/group/list"
"github.com/hpcng/warewulf/internal/app/wwctl/group/set"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "group",
Short: "Group management",
Long: "Management of group settings and power management",
}
)
func init() {
baseCmd.AddCommand(list.GetCommand())
baseCmd.AddCommand(set.GetCommand())
baseCmd.AddCommand(add.GetCommand())
baseCmd.AddCommand(delete.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,188 +0,0 @@
package set
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var err error
var groups []node.GroupInfo
nodeDB, 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 SetGroupAll == true {
var tmp []node.GroupInfo
tmp, err = nodeDB.FindAllGroups()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, g := range tmp {
groups = append(groups, g)
}
} else if len(args) > 0 {
var tmp []node.GroupInfo
tmp, err = nodeDB.FindAllGroups()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
for _, a := range args {
for _, g := range tmp {
if g.Id == a {
groups = append(groups, g)
}
}
}
} else {
cmd.Usage()
os.Exit(1)
}
for _, g := range groups {
if SetDomainName != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting domain name to: %s\n", g.Id, SetDomainName)
g.DomainName = SetDomainName
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting VNFS to: %s\n", g.Id, SetVnfs)
g.Vnfs = SetVnfs
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting kernel to: %s\n", g.Id, SetKernel)
g.KernelVersion = SetKernel
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpmiNetmask != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI username to: %s\n", g.Id, SetIpmiNetmask)
g.IpmiNetmask = SetIpmiNetmask
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpmiUsername != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI username to: %s\n", g.Id, SetIpmiUsername)
g.IpmiUserName = SetIpmiUsername
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpmiPassword != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting IPMI password to: %s\n", g.Id, SetIpmiPassword)
g.IpmiPassword = SetIpmiPassword
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting system overlay to: %s\n", g.Id, SetSystemOverlay)
g.SystemOverlay = SetSystemOverlay
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Group: %s, Setting runtime overlay to: %s\n", g.Id, SetRuntimeOverlay)
g.RuntimeOverlay = SetRuntimeOverlay
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if len(SetAddProfile) > 0 {
for _, p := range SetAddProfile {
wwlog.Printf(wwlog.VERBOSE, "Adding profile to '%s': '%s'\n", g.Id, p)
g.Profiles = util.SliceAddUniqueElement(g.Profiles, p)
}
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if len(SetDelProfile) > 0 {
for _, p := range SetDelProfile {
wwlog.Printf(wwlog.VERBOSE, "Removing profile to '%s': '%s'\n", g.Id, p)
g.Profiles = util.SliceRemoveElement(g.Profiles, p)
}
err := nodeDB.GroupUpdate(g)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
}
if len(groups) > 0 {
q := fmt.Sprintf("Are you sure you want to modify %d group(s)", len(groups))
prompt := promptui.Prompt{
Label: q,
IsConfirm: true,
}
result, _ := prompt.Run()
if result == "y" || result == "yes" {
nodeDB.Persist()
}
} else {
fmt.Printf("No groups found\n")
}
return nil
}

View File

@@ -1,49 +0,0 @@
package set
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "set",
Short: "Set group configurations",
Long: "Set group configurations ",
RunE: CobraRunE,
}
SetVnfs string
SetKernel string
SetDomainName string
SetIpxe string
SetRuntimeOverlay string
SetSystemOverlay string
SetClearNodes bool
SetIpmiNetmask string
SetIpmiUsername string
SetIpmiPassword string
SetGroupAll bool
SetAddProfile []string
SetDelProfile []string
)
func init() {
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name")
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringSliceVarP(&SetAddProfile, "addprofile", "p", []string{}, "Add Profile(s) to group")
baseCmd.PersistentFlags().StringSliceVarP(&SetDelProfile, "delprofile", "r", []string{}, "Remove Profile(s) to group")
baseCmd.PersistentFlags().BoolVarP(&SetClearNodes, "clear", "c", false, "Clear node configurations when setting parent group")
baseCmd.PersistentFlags().BoolVarP(&SetGroupAll, "all", "a", false, "Set all nodes")
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -28,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodes { for _, node := range nodes {
if node.KernelVersion.Defined() == true { if node.KernelVersion.Defined() == true {
set[node.KernelVersion.Get()] ++ set[node.KernelVersion.Get()]++
} }
} }
@@ -41,14 +41,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
for _, node := range nodes { for _, node := range nodes {
wwlog.Printf(wwlog.DEBUG, "evaluating node/kernel: %s/%s\n", node.Fqdn.Get(), node.KernelVersion.String()) wwlog.Printf(wwlog.DEBUG, "evaluating node/kernel: %s/%s\n", node.Id.Get(), node.KernelVersion.Get())
if node.KernelVersion.Defined() == true { if node.KernelVersion.Defined() == true {
set[node.KernelVersion.Get()] ++ set[node.KernelVersion.Get()]++
} }
} }
} else if len(args) == 1 { } else if len(args) == 1 {
set[args[0]] ++ set[args[0]]++
} else { } else {
cmd.Usage() cmd.Usage()
os.Exit(1) os.Exit(1)
@@ -64,4 +64,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -13,13 +13,12 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
nconfig, _ := node.New() nconfig, _ := node.New()
nodes, _ := nconfig.FindAllNodes() nodes, _ := nconfig.FindAllNodes()
nodemap := make(map[string]int) nodemap := make(map[string]int)
for _, n := range nodes { for _, n := range nodes {
nodemap[n.KernelVersion.String()] ++ nodemap[n.KernelVersion.Get()]++
} }
images, _ := ioutil.ReadDir(config.KernelParentDir()) images, _ := ioutil.ReadDir(config.KernelParentDir())
@@ -31,11 +30,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if util.IsDir(path.Join(config.KernelParentDir(), file.Name())) { if util.IsDir(path.Join(config.KernelParentDir(), file.Name())) {
var kernel_size int64 var kernel_size int64
var kmods_size int64 var kmods_size int64
if util.IsFile( config.KernelImage(file.Name())) { if util.IsFile(config.KernelImage(file.Name())) {
s, _ := os.Stat(config.KernelImage(file.Name())) s, _ := os.Stat(config.KernelImage(file.Name()))
kernel_size = s.Size() / 1024 kernel_size = s.Size() / 1024
} }
if util.IsFile( config.KmodsImage(file.Name())) { if util.IsFile(config.KmodsImage(file.Name())) {
s, _ := os.Stat(config.KmodsImage(file.Name())) s, _ := os.Stat(config.KmodsImage(file.Name()))
kmods_size = s.Size() / 1024 kmods_size = s.Size() / 1024
} }
@@ -48,6 +47,5 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
return nil return nil
} }

View File

@@ -16,15 +16,95 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
for _, a := range args { for _, a := range args {
err = nodeDB.AddNode(SetController, SetGroup, a) n, err := nodeDB.AddNode(a)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1) os.Exit(1)
} }
fmt.Printf("Added node: %s\n", a) fmt.Printf("Added node: %s\n", a)
if SetIpaddr != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
var netdev node.NetDevEntry
n.NetDevs[SetNetDev] = &netdev
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id, SetNetDev, SetIpaddr)
n.NetDevs[SetNetDev].Ipaddr.Set(SetIpaddr)
n.NetDevs[SetNetDev].Default.SetB(true)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetNetmask != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id, SetNetDev, SetNetmask)
n.NetDevs[SetNetDev].Netmask.Set(SetNetmask)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetGateway != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id, SetNetDev, SetGateway)
n.NetDevs[SetNetDev].Gateway.Set(SetGateway)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetHwaddr != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id, SetNetDev, SetHwaddr)
n.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
} }
nodeDB.Persist() nodeDB.Persist()
return nil return nil
} }

View File

@@ -4,19 +4,30 @@ import "github.com/spf13/cobra"
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
Use: "add", Use: "add",
Short: "Add new node", Short: "Add new node",
Long: "Add new node ", Long: "Add new node ",
RunE: CobraRunE, RunE: CobraRunE,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
} }
SetGroup string SetGroup string
SetController string SetController string
SetNetDev string
SetIpaddr string
SetNetmask string
SetGateway string
SetHwaddr string
) )
func init() { func init() {
baseCmd.PersistentFlags().StringVarP(&SetGroup, "group", "g", "default", "Group to add nodes to") baseCmd.PersistentFlags().StringVarP(&SetGroup, "group", "g", "default", "Group to add nodes to")
baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "default", "Controller to add nodes to") baseCmd.PersistentFlags().StringVarP(&SetController, "controller", "c", "localhost", "Controller to add nodes to")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "n", "eth0", "Define the network device to configure")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -21,11 +21,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeList, err := nodeDB.SearchByNameList(args) nodeList, err := nodeDB.SearchByNameList(args)
for _, n := range nodeList { for _, n := range nodeList {
if SetGroup != "" && SetGroup != n.Gid.String() { err := nodeDB.DelNode(n.Id.Get())
wwlog.Printf(wwlog.DEBUG, "skipping node of different group: %s/%s\n", n.Gid, n.Id)
continue
}
err := nodeDB.DelNode(n.Cid.Get(), n.Gid.Get(), n.Id.Get())
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
} else { } else {

View File

@@ -6,6 +6,7 @@ import (
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os" "os"
"sort"
"strings" "strings"
) )
@@ -29,31 +30,42 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
sort.Slice(nodes, func(i, j int) bool {
if nodes[i].DomainName.Get() < nodes[j].DomainName.Get() {
return true
} else if nodes[i].DomainName.Get() == nodes[j].DomainName.Get() {
if nodes[i].Id.Get() < nodes[j].Id.Get() {
return true
}
}
return false
})
if ShowAll == true { if ShowAll == true {
for _, node := range nodes { for _, node := range nodes {
fmt.Printf("################################################################################\n") fmt.Printf("################################################################################\n")
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Id", node.Id.Source(), node.Id.String()) fmt.Printf("%-20s %-18s %-12s %s\n", "NODE", "FIELD", "PROFILE", "VALUE")
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Comment", node.Comment.Source(), node.Comment.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Id", node.Id.Source(), node.Id.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "GroupName", node.Gid.Source(), node.Gid.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Comment", node.Comment.Source(), node.Comment.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "DomainName", node.DomainName.Source(), node.DomainName.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "DomainName", node.DomainName.Source(), node.DomainName.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Profiles (Group)", "group", strings.Join(node.GroupProfiles, ",")) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Profiles", "--", strings.Join(node.Profiles, ","))
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Profiles (Node)", "node", strings.Join(node.Profiles, ","))
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Vnfs", node.Vnfs.Source(), node.Vnfs.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Vnfs", node.Vnfs.Source(), node.Vnfs.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "KernelVersion", node.KernelVersion.Source(), node.KernelVersion.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "KernelVersion", node.KernelVersion.Source(), node.KernelVersion.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "KernelArgs", node.KernelArgs.Source(), node.KernelArgs.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "KernelArgs", node.KernelArgs.Source(), node.KernelArgs.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "RuntimeOverlay", node.RuntimeOverlay.Source(), node.RuntimeOverlay.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "RuntimeOverlay", node.RuntimeOverlay.Source(), node.RuntimeOverlay.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "SystemOverlay", node.SystemOverlay.Source(), node.SystemOverlay.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "SystemOverlay", node.SystemOverlay.Source(), node.SystemOverlay.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "Ipxe", node.Ipxe.Source(), node.Ipxe.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "Ipxe", node.Ipxe.Source(), node.Ipxe.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "IpmiIpaddr", node.IpmiIpaddr.Source(), node.IpmiIpaddr.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiIpaddr", node.IpmiIpaddr.Source(), node.IpmiIpaddr.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "IpmiNetmask", node.IpmiNetmask.Source(), node.IpmiNetmask.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiNetmask", node.IpmiNetmask.Source(), node.IpmiNetmask.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.String()) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), "IpmiUserName", node.IpmiUserName.Source(), node.IpmiUserName.Print())
for name, netdev := range node.NetDevs { for name, netdev := range node.NetDevs {
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name+":IPADDR", "node", netdev.Ipaddr) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":HWADDR", netdev.Hwaddr.Source(), netdev.Hwaddr.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name+":NETMASK", "node", netdev.Netmask) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":IPADDR", netdev.Ipaddr.Source(), netdev.Ipaddr.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name+":GATEWAY", "node", netdev.Gateway) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":NETMASK", netdev.Netmask.Source(), netdev.Netmask.Print())
fmt.Printf("%-20s %-18s %8s: %s\n", node.Fqdn.Get(), name+":HWADDR", "node", netdev.Hwaddr) fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":GATEWAY", netdev.Gateway.Source(), netdev.Gateway.Print())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":TYPE", netdev.Type.Source(), netdev.Type.Print())
} }
// v := reflect.ValueOf(node) // v := reflect.ValueOf(node)
@@ -71,10 +83,10 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodes { for _, node := range nodes {
if len(node.NetDevs) > 0 { if len(node.NetDevs) > 0 {
for name, dev := range node.NetDevs { for name, dev := range node.NetDevs {
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Fqdn.Get(), name, dev.Hwaddr, dev.Ipaddr, dev.Gateway) fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Id.Get(), name, dev.Hwaddr, dev.Ipaddr, dev.Gateway)
} }
} else { } else {
fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Fqdn.Get(), "--", "--", "--", "--") fmt.Printf("%-22s %-6s %-18s %-15s %-15s\n", node.Id.Get(), "--", "--", "--", "--")
} }
} }
@@ -83,23 +95,30 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Println(strings.Repeat("=", 80)) fmt.Println(strings.Repeat("=", 80))
for _, node := range nodes { for _, node := range nodes {
fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Fqdn.Get(), node.IpmiIpaddr.String(), node.IpmiUserName.String(), node.IpmiPassword.String()) fmt.Printf("%-22s %-16s %-20s %-20s\n", node.Id.Get(), node.IpmiIpaddr.Print(), node.IpmiUserName.Print(), node.IpmiPassword.Print())
} }
} else if ShowLong == true { } else if ShowLong == true {
fmt.Printf("%-22s %-12s %-26s %-35s %s\n", "NODE NAME", "GROUP NAME", "KERNEL VERSION", "VNFS IMAGE", "OVERLAYS (S/R)") fmt.Printf("%-22s %-26s %-35s %s\n", "NODE NAME", "KERNEL VERSION", "VNFS IMAGE", "OVERLAYS (S/R)")
fmt.Println(strings.Repeat("=", 120)) fmt.Println(strings.Repeat("=", 120))
for _, node := range nodes { for _, node := range nodes {
fmt.Printf("%-22s %-12s %-26s %-35s %s\n", node.Fqdn.Get(), node.Gid.String(), node.KernelVersion.String(), node.Vnfs.String(), node.SystemOverlay.String()+"/"+node.RuntimeOverlay.String()) fmt.Printf("%-22s %-26s %-35s %s\n", node.Id.Get(), node.KernelVersion.Print(), node.Vnfs.Print(), node.SystemOverlay.Print()+"/"+node.RuntimeOverlay.Print())
} }
} else { } else {
fmt.Printf("%-22s %-30s %s\n", "NODE NAME", "VNFS", "PROFILES") fmt.Printf("%-22s %-26s %s\n", "NODE NAME", "PROFILES", "NETWORK")
fmt.Println(strings.Repeat("=", 80))
for _, node := range nodes { for _, node := range nodes {
fmt.Printf("%-22s %-30s %s\n", node.Fqdn.Get(), node.Vnfs.String(), strings.Join(append(node.GroupProfiles, node.Profiles...), ",")) var netdevs []string
if len(node.NetDevs) > 0 {
for name, dev := range node.NetDevs {
netdevs = append(netdevs, fmt.Sprintf("%s:%s", name, dev.Ipaddr.Get()))
}
}
sort.Strings(netdevs)
fmt.Printf("%-22s %-26s %s\n", node.Id.Get(), strings.Join(node.Profiles, ","), strings.Join(netdevs, ", "))
} }
} }

View File

@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodeList { for _, node := range nodeList {
if node.IpmiIpaddr.String() == "" { if node.IpmiIpaddr.Get() == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName) wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue continue
} }
ipmiCmd := power.IPMI{ ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr.String(), HostName: node.IpmiIpaddr.Get(),
User: "ADMIN", User: "ADMIN",
Password: "ADMIN", Password: "ADMIN",
AuthType: "MD5", AuthType: "MD5",
@@ -49,12 +49,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := ipmiCmd.PowerOff() out, err := ipmiCmd.PowerOff()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.HostName, out) wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.Id.Get(), out)
returnErr = err returnErr = err
continue continue
} }
wwlog.Printf(wwlog.INFO, "%s: %s\n", node.HostName, out) wwlog.Printf(wwlog.INFO, "%s: %s\n", node.Id.Get(), out)
} }
return returnErr return returnErr

View File

@@ -36,13 +36,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var powerCmd power.PowerOnInterface var powerCmd power.PowerOnInterface
if node.IpmiIpaddr.String() == "" { if node.IpmiIpaddr.Get() == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName) wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue continue
} }
ipmiCmd := power.IPMI{ ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr.String(), HostName: node.IpmiIpaddr.Get(),
User: "ADMIN", User: "ADMIN",
Password: "ADMIN", Password: "ADMIN",
AuthType: "MD5", AuthType: "MD5",
@@ -53,12 +53,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := powerCmd.PowerOn() out, err := powerCmd.PowerOn()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.HostName, out) wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.Id.Get(), out)
returnErr = err returnErr = err
continue continue
} }
wwlog.Printf(wwlog.INFO, "%s: %s\n", node.HostName, out) wwlog.Printf(wwlog.INFO, "%s: %s\n", node.Id.Get(), out)
} }
return returnErr return returnErr

View File

@@ -34,13 +34,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodeList { for _, node := range nodeList {
if node.IpmiIpaddr.String() == "" { if node.IpmiIpaddr.Get() == "" {
wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.HostName) wwlog.Printf(wwlog.ERROR, "%s: No IPMI IP address\n", node.Id.Get())
continue continue
} }
ipmiCmd := power.IPMI{ ipmiCmd := power.IPMI{
HostName: node.IpmiIpaddr.String(), HostName: node.IpmiIpaddr.Get(),
User: "ADMIN", User: "ADMIN",
Password: "ADMIN", Password: "ADMIN",
AuthType: "MD5", AuthType: "MD5",
@@ -49,12 +49,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
out, err := ipmiCmd.PowerStatus() out, err := ipmiCmd.PowerStatus()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.HostName, out) wwlog.Printf(wwlog.ERROR, "%s: %s\n", node.Id.Get(), out)
returnErr = err returnErr = err
continue continue
} }
wwlog.Printf(wwlog.INFO, "%s: %s\n", node.HostName, out) wwlog.Printf(wwlog.INFO, "%s: %s\n", node.Id.Get(), out)
} }
return returnErr return returnErr

View File

@@ -44,10 +44,20 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
for _, n := range nodes { for _, n := range nodes {
wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Fqdn.String()) wwlog.Printf(wwlog.VERBOSE, "Evaluating node: %s\n", n.Id.Get())
if SetComment != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting comment to: %s\n", n.Id.Get(), SetComment)
n.Comment.Set(SetComment)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetVnfs != "" { if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting vnfs to: %s\n", n.Fqdn.String(), SetVnfs) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting vnfs to: %s\n", n.Id.Get(), SetVnfs)
n.Vnfs.Set(SetVnfs) n.Vnfs.Set(SetVnfs)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -57,7 +67,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetKernel != "" { if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Fqdn.String(), SetKernel) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting kernel to: %s\n", n.Id.Get(), SetKernel)
n.KernelVersion.Set(SetKernel) n.KernelVersion.Set(SetKernel)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -67,7 +77,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetDomainName != "" { if SetDomainName != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting domain name to: %s\n", n.Fqdn, SetDomainName) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting domain name to: %s\n", n.Id.Get(), SetDomainName)
n.DomainName.Set(SetDomainName) n.DomainName.Set(SetDomainName)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -77,7 +87,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetIpxe != "" { if SetIpxe != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting iPXE template to: %s\n", n.Fqdn, SetIpxe) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting iPXE template to: %s\n", n.Id.Get(), SetIpxe)
n.Ipxe.Set(SetIpxe) n.Ipxe.Set(SetIpxe)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -87,7 +97,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetRuntimeOverlay != "" { if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting runtime overlay to: %s\n", n.Fqdn, SetRuntimeOverlay) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting runtime overlay to: %s\n", n.Id.Get(), SetRuntimeOverlay)
n.RuntimeOverlay.Set(SetRuntimeOverlay) n.RuntimeOverlay.Set(SetRuntimeOverlay)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -97,7 +107,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetSystemOverlay != "" { if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting system overlay to: %s\n", n.Fqdn, SetSystemOverlay) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting system overlay to: %s\n", n.Id.Get(), SetSystemOverlay)
n.SystemOverlay.Set(SetSystemOverlay) n.SystemOverlay.Set(SetSystemOverlay)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -106,18 +116,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
} }
if SetHostname != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting hostname to: %s\n", n.Fqdn, SetHostname)
n.HostName.Set(SetHostname)
err := nodeDB.NodeUpdate(n)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpmiIpaddr != "" { if SetIpmiIpaddr != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP address to: %s\n", n.Fqdn, SetIpmiIpaddr) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP address to: %s\n", n.Id.Get(), SetIpmiIpaddr)
n.IpmiIpaddr.Set(SetIpmiIpaddr) n.IpmiIpaddr.Set(SetIpmiIpaddr)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -127,7 +127,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetIpmiNetmask != "" { if SetIpmiNetmask != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI netmask to: %s\n", n.Fqdn, SetIpmiNetmask) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI netmask to: %s\n", n.Id.Get(), SetIpmiNetmask)
n.IpmiNetmask.Set(SetIpmiNetmask) n.IpmiNetmask.Set(SetIpmiNetmask)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -137,7 +137,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetIpmiUsername != "" { if SetIpmiUsername != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP username to: %s\n", n.Fqdn, SetIpmiUsername) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP username to: %s\n", n.Id.Get(), SetIpmiUsername)
n.IpmiUserName.Set(SetIpmiUsername) n.IpmiUserName.Set(SetIpmiUsername)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -147,7 +147,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
if SetIpmiPassword != "" { if SetIpmiPassword != "" {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP password to: %s\n", n.Fqdn, SetIpmiPassword) wwlog.Printf(wwlog.VERBOSE, "Node: %s, Setting IPMI IP password to: %s\n", n.Id.Get(), SetIpmiPassword)
n.IpmiPassword.Set(SetIpmiPassword) n.IpmiPassword.Set(SetIpmiPassword)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -159,7 +159,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if len(SetAddProfile) > 0 { if len(SetAddProfile) > 0 {
for _, p := range SetAddProfile { for _, p := range SetAddProfile {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile to '%s'\n", n.Fqdn, p) wwlog.Printf(wwlog.VERBOSE, "Node: %s, adding profile to '%s'\n", n.Id.Get(), p)
n.Profiles = util.SliceAddUniqueElement(n.Profiles, p) n.Profiles = util.SliceAddUniqueElement(n.Profiles, p)
} }
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -170,7 +170,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(SetDelProfile) > 0 { if len(SetDelProfile) > 0 {
for _, p := range SetDelProfile { for _, p := range SetDelProfile {
wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile from '%s'\n", n.Fqdn, p) wwlog.Printf(wwlog.VERBOSE, "Node: %s, deleting profile from '%s'\n", n.Id.Get(), p)
n.Profiles = util.SliceRemoveElement(n.Profiles, p) n.Profiles = util.SliceRemoveElement(n.Profiles, p)
} }
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
@@ -185,13 +185,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n") wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1) os.Exit(1)
} }
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", n.Fqdn, SetNetDev)
if _, ok := n.NetDevs[SetNetDev]; !ok { if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev) wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev)
os.Exit(1) os.Exit(1)
} }
wwlog.Printf(wwlog.VERBOSE, "Node: %s, Deleting network device: %s\n", n.Id.Get(), SetNetDev)
delete(n.NetDevs, SetNetDev) delete(n.NetDevs, SetNetDev)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
if err != nil { if err != nil {
@@ -206,12 +207,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if _, ok := n.NetDevs[SetNetDev]; !ok { if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev) var nd node.NetDevEntry
os.Exit(1) n.NetDevs[SetNetDev] = &nd
} }
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Fqdn, SetNetDev, SetIpaddr)
n.NetDevs[SetNetDev].Ipaddr = SetIpaddr wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting Ipaddr to: %s\n", n.Id.Get(), SetNetDev, SetIpaddr)
n.NetDevs[SetNetDev].Ipaddr.Set(SetIpaddr)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -225,12 +227,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if _, ok := n.NetDevs[SetNetDev]; !ok { if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev) var nd node.NetDevEntry
os.Exit(1) n.NetDevs[SetNetDev] = &nd
} }
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Fqdn, SetNetDev, SetNetmask)
n.NetDevs[SetNetDev].Netmask = SetNetmask wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting netmask to: %s\n", n.Id.Get(), SetNetDev, SetNetmask)
n.NetDevs[SetNetDev].Netmask.Set(SetNetmask)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -244,12 +247,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if _, ok := n.NetDevs[SetNetDev]; !ok { if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev) var nd node.NetDevEntry
os.Exit(1) n.NetDevs[SetNetDev] = &nd
} }
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Fqdn, SetNetDev, SetGateway)
n.NetDevs[SetNetDev].Gateway = SetGateway wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting gateway to: %s\n", n.Id.Get(), SetNetDev, SetGateway)
n.NetDevs[SetNetDev].Gateway.Set(SetGateway)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -263,12 +267,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if _, ok := n.NetDevs[SetNetDev]; !ok { if _, ok := n.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Network Device doesn't exist: %s\n", SetNetDev) var nd node.NetDevEntry
os.Exit(1) n.NetDevs[SetNetDev] = &nd
} }
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Fqdn, SetNetDev, SetHwaddr)
n.NetDevs[SetNetDev].Hwaddr = SetHwaddr wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting HW address to: %s\n", n.Id.Get(), SetNetDev, SetHwaddr)
n.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr)
err := nodeDB.NodeUpdate(n) err := nodeDB.NodeUpdate(n)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)

View File

@@ -9,6 +9,7 @@ var (
Long: "Set node configurations ", Long: "Set node configurations ",
RunE: CobraRunE, RunE: CobraRunE,
} }
SetComment string
SetVnfs string SetVnfs string
SetKernel string SetKernel string
SetNetDev string SetNetDev string
@@ -21,7 +22,6 @@ var (
SetIpxe string SetIpxe string
SetRuntimeOverlay string SetRuntimeOverlay string
SetSystemOverlay string SetSystemOverlay string
SetHostname string
SetIpmiIpaddr string SetIpmiIpaddr string
SetIpmiNetmask string SetIpmiNetmask string
SetIpmiUsername string SetIpmiUsername string
@@ -33,13 +33,13 @@ var (
) )
func init() { func init() {
baseCmd.PersistentFlags().StringVarP(&SetComment, "comment", "C", "", "Set a comment for this node")
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)") baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes") baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name") baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name")
baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name") baseCmd.PersistentFlags().StringVarP(&SetIpxe, "ipxe", "P", "", "Set the node's iPXE template name")
baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay") baseCmd.PersistentFlags().StringVarP(&SetRuntimeOverlay, "runtime", "R", "", "Set the node's runtime overlay")
baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay") baseCmd.PersistentFlags().StringVarP(&SetSystemOverlay, "system", "S", "", "Set the node's system overlay")
baseCmd.PersistentFlags().StringVarP(&SetHostname, "hostname", "N", "", "Set the node's hostname")
baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI IP address") baseCmd.PersistentFlags().StringVar(&SetIpmiIpaddr, "ipmi", "", "Set the node's IPMI IP address")
baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask") baseCmd.PersistentFlags().StringVar(&SetIpmiNetmask, "ipminetmask", "", "Set the node's IPMI netmask")
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username") baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
@@ -53,7 +53,7 @@ func init() {
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask") baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway") baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address") baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "delete", false, "Delete the node's network device") baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes") baseCmd.PersistentFlags().BoolVarP(&SetNodeAll, "all", "a", false, "Set all nodes")
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked") baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")

View File

@@ -25,9 +25,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] { if SystemOverlay == true && node.SystemOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == args[0] { } else if node.RuntimeOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }
@@ -59,4 +59,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -13,7 +13,6 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
var overlaySourceDir string var overlaySourceDir string
overlayName := args[0] overlayName := args[0]
fileName := args[2] fileName := args[2]
@@ -64,9 +63,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo var updateNodes []node.NodeInfo
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == overlayName { if SystemOverlay == true && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == overlayName { } else if node.RuntimeOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }
@@ -81,4 +80,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -8,8 +8,6 @@ import (
"os" "os"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
if len(args) < 1 { if len(args) < 1 {
cmd.Help() cmd.Help()
@@ -48,9 +46,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo var updateNodes []node.NodeInfo
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] { if SystemOverlay == true && node.SystemOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == args[0] { } else if node.RuntimeOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }
@@ -64,6 +62,5 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
return nil return nil
} }

View File

@@ -14,7 +14,6 @@ import (
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
var overlayPath string var overlayPath string
config := config.New()
if SystemOverlay == true { if SystemOverlay == true {
overlayPath = config.SystemOverlaySource(args[0]) overlayPath = config.SystemOverlaySource(args[0])
@@ -110,9 +109,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo var updateNodes []node.NodeInfo
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] { if SystemOverlay == true && node.SystemOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == args[0] { } else if node.RuntimeOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }
@@ -127,4 +126,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -14,8 +14,7 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New() editor := os.Getenv("EDITOR")
editor := config.Editor
var overlaySourceDir string var overlaySourceDir string
if SystemOverlay == true { if SystemOverlay == true {
@@ -107,9 +106,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo var updateNodes []node.NodeInfo
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] { if SystemOverlay == true && node.SystemOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == args[0] { } else if node.RuntimeOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }

View File

@@ -12,7 +12,6 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
overlayName := args[0] overlayName := args[0]
source := args[1] source := args[1]
var dest string var dest string
@@ -60,9 +59,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo var updateNodes []node.NodeInfo
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == overlayName { if SystemOverlay == true && node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == overlayName { } else if node.RuntimeOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }
@@ -78,4 +77,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -13,7 +13,6 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
set := make(map[string]int) set := make(map[string]int)
var o []string var o []string
var err error var err error
@@ -54,11 +53,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodeList { for _, node := range nodeList {
if SystemOverlay == true { if SystemOverlay == true {
if node.SystemOverlay.Get() != "" { if node.SystemOverlay.Get() != "" {
set[node.SystemOverlay.Get()] ++ set[node.SystemOverlay.Get()]++
} }
} else { } else {
if node.RuntimeOverlay.Get() != "" { if node.RuntimeOverlay.Get() != "" {
set[node.RuntimeOverlay.Get()] ++ set[node.RuntimeOverlay.Get()]++
} }
} }
} }

View File

@@ -13,10 +13,8 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
var overlaySourceDir string var overlaySourceDir string
// mode := uint32(strconv.ParseUint(PermMode, 8, 32)) // mode := uint32(strconv.ParseUint(PermMode, 8, 32))
if SystemOverlay == true { if SystemOverlay == true {
overlaySourceDir = config.SystemOverlaySource(args[0]) overlaySourceDir = config.SystemOverlaySource(args[0])
@@ -57,9 +55,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var updateNodes []node.NodeInfo var updateNodes []node.NodeInfo
for _, node := range nodes { for _, node := range nodes {
if SystemOverlay == true && node.SystemOverlay.String() == args[0] { if SystemOverlay == true && node.SystemOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.String() == args[0] { } else if node.RuntimeOverlay.Get() == args[0] {
updateNodes = append(updateNodes, node) updateNodes = append(updateNodes, node)
} }
} }
@@ -74,4 +72,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -12,7 +12,6 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
var overlaySourceDir string var overlaySourceDir string
overlayName := args[0] overlayName := args[0]
fileName := args[1] fileName := args[1]
@@ -44,4 +43,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Print(string(f)) fmt.Print(string(f))
return nil return nil
} }

View File

@@ -15,7 +15,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
for _, p := range args { for _, p := range args {
err = nodeDB.AddProfile(p) _, err := nodeDB.AddProfile(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1) os.Exit(1)
@@ -25,4 +25,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB.Persist() nodeDB.Persist()
return nil return nil
} }

View File

@@ -15,7 +15,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
var numNodes int var numNodes int
var numGroups int var numGroups int
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err) wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err)
@@ -27,12 +26,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not load all nodes: %s\n", err)
os.Exit(1) os.Exit(1)
} }
groups, err := nodeDB.FindAllGroups()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not load all groups: %s\n", err)
os.Exit(1)
}
for _, p := range args { for _, p := range args {
err := nodeDB.DelProfile(p) err := nodeDB.DelProfile(p)
@@ -44,22 +37,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, np := range n.Profiles { for _, np := range n.Profiles {
if np == p { if np == p {
numNodes++ numNodes++
wwlog.Printf(wwlog.VERBOSE, "Removing profile from node %s: %s\n", n.Fqdn.Get(), p) wwlog.Printf(wwlog.VERBOSE, "Removing profile from node %s: %s\n", n.Id.Get(), p)
n.Profiles = util.SliceRemoveElement(n.Profiles, p) n.Profiles = util.SliceRemoveElement(n.Profiles, p)
nodeDB.NodeUpdate(n) nodeDB.NodeUpdate(n)
} }
} }
} }
for _, g := range groups {
for _, np := range g.Profiles {
if np == p {
numGroups++
wwlog.Printf(wwlog.VERBOSE, "Removing profile from group %s: %s\n", g.Id, p)
g.Profiles = util.SliceRemoveElement(g.Profiles, p)
nodeDB.GroupUpdate(g)
}
}
}
count++ count++
} }

View File

@@ -6,7 +6,7 @@ import (
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os" "os"
"reflect" "sort"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
@@ -23,14 +23,37 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
for _, group := range profiles { sort.Slice(profiles, func(i, j int) bool {
v := reflect.ValueOf(group) if profiles[i].Id.Get() < profiles[j].Id.Get() {
typeOfS := v.Type() return true
}
return false
})
for _, node := range profiles {
fmt.Printf("################################################################################\n") fmt.Printf("################################################################################\n")
for i := 0; i< v.NumField(); i++ { fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "Id", node.Id.Print())
fmt.Printf("%-25s %s = %v\n", group.Id, typeOfS.Field(i).Name, v.Field(i).Interface()) fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "Comment", node.Comment.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "Vnfs", node.Vnfs.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "KernelVersion", node.KernelVersion.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "KernelArgs", node.KernelArgs.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "RuntimeOverlay", node.RuntimeOverlay.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "SystemOverlay", node.SystemOverlay.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "Ipxe", node.Ipxe.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "IpmiIpaddr", node.IpmiIpaddr.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "IpmiNetmask", node.IpmiNetmask.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), "IpmiUserName", node.IpmiUserName.Print())
for name, netdev := range node.NetDevs {
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), name+":IPADDR", netdev.Ipaddr.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), name+":NETMASK", netdev.Netmask.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), name+":GATEWAY", netdev.Gateway.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), name+":HWADDR", netdev.Hwaddr.Print())
fmt.Printf("%-20s %-18s: %s\n", node.Id.Get(), name+":TYPE", netdev.Hwaddr.Print())
} }
} }
return nil return nil
} }

View File

@@ -11,7 +11,7 @@ import (
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
var err error var err error
var profiles []node.ProfileInfo var profiles []node.NodeInfo
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
@@ -19,25 +19,18 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1) os.Exit(1)
} }
if err != nil { if len(args) == 0 {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err) args = append(args, "default")
os.Exit(1)
} }
if SetAll == true { if SetAll == true {
var tmp []node.ProfileInfo profiles, err = nodeDB.FindAllProfiles()
tmp, err = nodeDB.FindAllProfiles()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1) os.Exit(1)
} }
} else {
for _, p := range tmp { var tmp []node.NodeInfo
profiles = append(profiles, p)
}
} else if len(args) > 0 {
var tmp []node.ProfileInfo
tmp, err = nodeDB.FindAllProfiles() tmp, err = nodeDB.FindAllProfiles()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -46,23 +39,30 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, a := range args { for _, a := range args {
for _, p := range tmp { for _, p := range tmp {
if p.Id == a { if p.Id.Get() == a {
profiles = append(profiles, p) profiles = append(profiles, p)
} }
} }
} }
} else {
cmd.Usage()
os.Exit(1)
} }
for _, p := range profiles { for _, p := range profiles {
wwlog.Printf(wwlog.VERBOSE, "Modifying profile: %s\n", p.Id.Get())
if SetComment != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting comment to: %s\n", p.Id, SetComment)
p.Comment.Set(SetComment)
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetDomainName != "" { if SetDomainName != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting domain name to: %s\n", p.Id, SetDomainName) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting domain name to: %s\n", p.Id, SetDomainName)
p.DomainName = SetDomainName p.DomainName.Set(SetDomainName)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -72,7 +72,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetVnfs != "" { if SetVnfs != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting VNFS to: %s\n", p.Id, SetVnfs) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting VNFS to: %s\n", p.Id, SetVnfs)
p.Vnfs = SetVnfs p.Vnfs.Set(SetVnfs)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -82,7 +82,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetKernel != "" { if SetKernel != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel version to: %s\n", p.Id, SetKernel) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting Kernel version to: %s\n", p.Id, SetKernel)
p.KernelVersion = SetKernel p.KernelVersion.Set(SetKernel)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -92,7 +92,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetIpxe != "" { if SetIpxe != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting iPXE template to: %s\n", p.Id, SetIpxe) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting iPXE template to: %s\n", p.Id, SetIpxe)
p.Ipxe = SetIpxe p.Ipxe.Set(SetIpxe)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -102,7 +102,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetRuntimeOverlay != "" { if SetRuntimeOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting runtime overlay to: %s\n", p.Id, SetRuntimeOverlay) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting runtime overlay to: %s\n", p.Id, SetRuntimeOverlay)
p.RuntimeOverlay = SetRuntimeOverlay p.RuntimeOverlay.Set(SetRuntimeOverlay)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -112,7 +112,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetSystemOverlay != "" { if SetSystemOverlay != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting system overlay to: %s\n", p.Id, SetSystemOverlay) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting system overlay to: %s\n", p.Id, SetSystemOverlay)
p.SystemOverlay = SetSystemOverlay p.SystemOverlay.Set(SetSystemOverlay)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -122,7 +122,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetIpmiNetmask != "" { if SetIpmiNetmask != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiNetmask) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiNetmask)
p.IpmiNetmask = SetIpmiNetmask p.IpmiNetmask.Set(SetIpmiNetmask)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -132,7 +132,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetIpmiUsername != "" { if SetIpmiUsername != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiUsername) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiUsername)
p.IpmiUserName = SetIpmiUsername p.IpmiUserName.Set(SetIpmiUsername)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -142,7 +142,108 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if SetIpmiPassword != "" { if SetIpmiPassword != "" {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiPassword) wwlog.Printf(wwlog.VERBOSE, "Profile: %s, Setting IPMI username to: %s\n", p.Id, SetIpmiPassword)
p.IpmiPassword = SetIpmiPassword p.IpmiPassword.Set(SetIpmiPassword)
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetNetDevDel == true {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := p.NetDevs[SetNetDev]; !ok {
wwlog.Printf(wwlog.ERROR, "Profile '%s': network Device doesn't exist: %s\n", p.Id.Get(), SetNetDev)
os.Exit(1)
}
wwlog.Printf(wwlog.VERBOSE, "Profile %s: Deleting network device: %s\n", p.Id.Get(), SetNetDev)
delete(p.NetDevs, SetNetDev)
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetIpaddr != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := p.NetDevs[SetNetDev]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetDev] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting IP address to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr)
p.NetDevs[SetNetDev].Ipaddr.Set(SetIpaddr)
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetNetmask != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := p.NetDevs[SetNetDev]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetDev] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting netmask to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr)
p.NetDevs[SetNetDev].Netmask.Set(SetNetmask)
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetGateway != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := p.NetDevs[SetNetDev]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetDev] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting gateway to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr)
p.NetDevs[SetNetDev].Gateway.Set(SetGateway)
err := nodeDB.ProfileUpdate(p)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
if SetHwaddr != "" {
if SetNetDev == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netdev' option\n")
os.Exit(1)
}
if _, ok := p.NetDevs[SetNetDev]; !ok {
var nd node.NetDevEntry
p.NetDevs[SetNetDev] = &nd
}
wwlog.Printf(wwlog.VERBOSE, "Profile '%s': Setting HW address to: %s:%s\n", p.Id.Get(), SetNetDev, SetHwaddr)
p.NetDevs[SetNetDev].Hwaddr.Set(SetHwaddr)
err := nodeDB.ProfileUpdate(p) err := nodeDB.ProfileUpdate(p)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)

View File

@@ -10,6 +10,7 @@ var (
RunE: CobraRunE, RunE: CobraRunE,
} }
SetAll bool SetAll bool
SetComment string
SetVnfs string SetVnfs string
SetKernel string SetKernel string
SetDomainName string SetDomainName string
@@ -19,9 +20,16 @@ var (
SetIpmiNetmask string SetIpmiNetmask string
SetIpmiUsername string SetIpmiUsername string
SetIpmiPassword string SetIpmiPassword string
SetNetDev string
SetIpaddr string
SetNetmask string
SetGateway string
SetHwaddr string
SetNetDevDel bool
) )
func init() { func init() {
baseCmd.PersistentFlags().StringVarP(&SetComment, "comment", "C", "", "Set a comment for this node")
baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)") baseCmd.PersistentFlags().StringVarP(&SetVnfs, "vnfs", "V", "", "Set node Virtual Node File System (VNFS)")
baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes") baseCmd.PersistentFlags().StringVarP(&SetKernel, "kernel", "K", "", "Set Kernel version for nodes")
baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name") baseCmd.PersistentFlags().StringVarP(&SetDomainName, "domain", "D", "", "Set the node's domain name")
@@ -32,6 +40,13 @@ func init() {
baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username") baseCmd.PersistentFlags().StringVar(&SetIpmiUsername, "ipmiuser", "", "Set the node's IPMI username")
baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password") baseCmd.PersistentFlags().StringVar(&SetIpmiPassword, "ipmipass", "", "Set the node's IPMI password")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "n", "", "Define the network device to configure")
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all profiles") baseCmd.PersistentFlags().BoolVarP(&SetAll, "all", "a", false, "Set all profiles")
} }

View File

@@ -0,0 +1,97 @@
package ready
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/vnfs"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
nodes, err := n.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Cloud not get nodeList: %s\n", err)
os.Exit(1)
}
fmt.Printf("%-25s %-10s %-6s %-6s %-6s %-6s %-6s\n", "NODE NAME", "STATUS", "VNFS", "KERNEL", "KMODS", "SYS-OL", "RUN-OL")
for _, node := range nodes {
var vnfs_good bool
var kernel_good bool
var kmods_good bool
var systemo_good bool
var runtimeo_good bool
status := true
if node.Vnfs.Get() != "" {
v, _ := vnfs.Load(node.Vnfs.Get())
if util.IsFile(v.Image) == true {
vnfs_good = true
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "VNFS not found: %s, %s\n", node.Id.Get(), v.Source)
}
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "Node Kernel not defined: %s\n", node.Id.Get())
}
if node.KernelVersion.Get() != "" {
if util.IsFile(config.KernelImage(node.KernelVersion.Get())) == true {
kernel_good = true
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "Node Kernel not found: %s, %s\n", node.Id.Get(), node.KernelVersion.Get())
}
if util.IsFile(config.KmodsImage(node.KernelVersion.Get())) == true {
kmods_good = true
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "Node Kmods not found: %s, %s\n", node.Id.Get(), node.KernelVersion.Get())
}
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "Node Kernel version not defined: %s\n", node.Id.Get())
}
if node.SystemOverlay.Get() != "" {
if util.IsFile(config.SystemOverlayImage(node.Id.Get())) == true {
systemo_good = true
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "System Overlay not found: %s\n", config.SystemOverlayImage(node.Id.Get()))
}
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "System Overlay not defined: %s\n", node.Id.Get())
}
if node.RuntimeOverlay.Get() != "" {
if util.IsFile(config.RuntimeOverlayImage(node.Id.Get())) == true {
runtimeo_good = true
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "Runtime Overlay not found: %s\n", config.RuntimeOverlaySource(node.Id.Get()))
}
} else {
status = false
wwlog.Printf(wwlog.VERBOSE, "Runtime Overlay not defined: %s\n", node.Id.Get())
}
fmt.Printf("%-25s %-10t %-6t %-6t %-6t %-6t %-6t\n", node.Id.Get(), status, vnfs_good, kernel_good, kmods_good, systemo_good, runtimeo_good)
}
return nil
}

View File

@@ -0,0 +1,22 @@
package ready
import (
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "ready",
Short: "Warewulf Status Check",
Long: "Warewulf Status Check",
RunE: CobraRunE,
}
)
func init() {
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -1,12 +1,11 @@
package wwctl package wwctl
import ( import (
"github.com/hpcng/warewulf/internal/app/wwctl/controller"
"github.com/hpcng/warewulf/internal/app/wwctl/group"
"github.com/hpcng/warewulf/internal/app/wwctl/kernel" "github.com/hpcng/warewulf/internal/app/wwctl/kernel"
"github.com/hpcng/warewulf/internal/app/wwctl/node" "github.com/hpcng/warewulf/internal/app/wwctl/node"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay" "github.com/hpcng/warewulf/internal/app/wwctl/overlay"
"github.com/hpcng/warewulf/internal/app/wwctl/profile" "github.com/hpcng/warewulf/internal/app/wwctl/profile"
"github.com/hpcng/warewulf/internal/app/wwctl/ready"
"github.com/hpcng/warewulf/internal/app/wwctl/service" "github.com/hpcng/warewulf/internal/app/wwctl/service"
"github.com/hpcng/warewulf/internal/app/wwctl/vnfs" "github.com/hpcng/warewulf/internal/app/wwctl/vnfs"
@@ -32,13 +31,14 @@ func init() {
//rootCmd.AddCommand(build.GetCommand()) //rootCmd.AddCommand(build.GetCommand())
rootCmd.AddCommand(overlay.GetCommand()) rootCmd.AddCommand(overlay.GetCommand())
rootCmd.AddCommand(controller.GetCommand()) // rootCmd.AddCommand(controller.GetCommand())
rootCmd.AddCommand(vnfs.GetCommand()) rootCmd.AddCommand(vnfs.GetCommand())
rootCmd.AddCommand(node.GetCommand()) rootCmd.AddCommand(node.GetCommand())
rootCmd.AddCommand(kernel.GetCommand()) rootCmd.AddCommand(kernel.GetCommand())
rootCmd.AddCommand(group.GetCommand()) // rootCmd.AddCommand(group.GetCommand())
rootCmd.AddCommand(profile.GetCommand()) rootCmd.AddCommand(profile.GetCommand())
rootCmd.AddCommand(service.GetCommand()) rootCmd.AddCommand(service.GetCommand())
rootCmd.AddCommand(ready.GetCommand())
} }

View File

@@ -5,6 +5,7 @@ import (
"github.com/brotherpowers/ipsubnet" "github.com/brotherpowers/ipsubnet"
"github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"net" "net"
@@ -28,125 +29,120 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
func ConfigureDHCP() error { func ConfigureDHCP() error {
var d dhcpTemplate
var templateFile string
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1) os.Exit(1)
} }
controllers, err := nodeDB.FindAllControllers() controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if controller.Ipaddr == "" {
wwlog.Printf(wwlog.ERROR, "The Warewulf IP Address is not properly configured\n")
os.Exit(1)
}
if controller.Netmask == "" {
wwlog.Printf(wwlog.ERROR, "The Warewulf Netmask is not properly configured\n")
os.Exit(1)
}
if controller.Dhcp.Enabled == false {
wwlog.Printf(wwlog.INFO, "This system is not configured as a Warewulf DHCP controller\n")
os.Exit(1)
}
if controller.Dhcp.RangeStart == "" {
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range start`\n")
os.Exit(1)
}
if controller.Dhcp.RangeEnd == "" {
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range end`\n")
os.Exit(1)
}
if controller.Dhcp.ConfigFile == "" {
controller.Dhcp.ConfigFile = "/etc/dhcp/dhcpd.conf"
}
nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err)
os.Exit(1) os.Exit(1)
} }
for _, controller := range controllers { for _, node := range nodes {
var templateFile string d.Nodes = append(d.Nodes, node)
var d dhcpTemplate }
var configured bool
addrs, err := net.InterfaceAddrs() if controller.Dhcp.Template == "" {
if err != nil { templateFile = "/etc/warewulf/dhcp/default-dhcpd.conf"
wwlog.Printf(wwlog.ERROR, "Could not get network interfaces: %s\n", err) } else {
os.Exit(1) if strings.HasPrefix(controller.Dhcp.Template, "/") {
} templateFile = controller.Dhcp.Template
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.String() == controller.Ipaddr {
m, _ := ipnet.Mask.Size()
sub := ipsubnet.SubnetCalculator(ipnet.IP.String(), m)
d.Ipaddr = ipnet.IP.String()
d.Network = sub.GetNetworkPortion()
d.Netmask = sub.GetSubnetMask()
d.RangeStart = controller.Services.Dhcp.RangeStart
d.RangeEnd = controller.Services.Dhcp.RangeEnd
configured = true
break
}
}
}
hostname, err := os.Hostname()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not obtain system's hostname\n")
os.Exit(1)
}
if hostname != controller.Fqdn {
wwlog.Printf(wwlog.WARN, "The system hostname does not match Warewulf config: %s != %s\n", hostname, controller.Fqdn)
}
if configured == false {
wwlog.Printf(wwlog.ERROR, "Could not identify this system in the Warewulf configuration by it's IP address\n")
os.Exit(1)
}
if controller.Services.Dhcp.ConfigFile == "" {
wwlog.Printf(wwlog.ERROR, "Could not locate the DHCP configuration file for this controller\n")
os.Exit(1)
}
if _, ok := nodeDB.Controllers[controller.Id]; !ok {
wwlog.Printf(wwlog.ERROR, "We should never get here, but since we did, Hello! %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err)
os.Exit(1)
}
for _, node := range nodes {
d.Nodes = append(d.Nodes, node)
}
if controller.Services.Dhcp.Template == "" {
templateFile = "/etc/warewulf/dhcp/default-dhcpd.conf"
} else { } else {
if strings.HasPrefix(controller.Services.Dhcp.Template, "/") { templateFile = fmt.Sprintf("/etc/warewulf/dhcp/%s-dhcpd.conf", controller.Dhcp.Template)
templateFile = controller.Services.Dhcp.Template
} else {
templateFile = fmt.Sprintf("/etc/warewulf/dhcp/%s-dhcpd.conf", controller.Services.Dhcp.Template)
}
} }
}
tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile) tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
mask := net.IPMask(net.ParseIP(controller.Netmask).To4())
size, _ := mask.Size()
sub := ipsubnet.SubnetCalculator(controller.Ipaddr, size)
d.Ipaddr = controller.Ipaddr
d.Network = sub.GetNetworkPortion()
d.Netmask = sub.GetSubnetMask()
d.RangeStart = controller.Dhcp.RangeStart
d.RangeEnd = controller.Dhcp.RangeEnd
if DoConfig == true {
fmt.Printf("Writing the DHCP configuration file\n")
configWriter, err := os.OpenFile(controller.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer configWriter.Close()
err = tmpl.Execute(configWriter, d)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1) os.Exit(1)
} }
if DoConfig == true { fmt.Printf("Enabling and restarting the DHCP services\n")
fmt.Printf("Writing the DHCP configuration file\n") if controller.Dhcp.Enable != "" {
configWriter, err := os.OpenFile(controller.Services.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640) util.ExecInteractive("/bin/sh", "-c", controller.Dhcp.Enable)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer configWriter.Close()
err = tmpl.Execute(configWriter, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
fmt.Printf("Enabling and restarting the DHCP services\n")
util.ExecInteractive("/bin/sh", "-c", controller.Services.Dhcp.EnableCmd)
util.ExecInteractive("/bin/sh", "-c", controller.Services.Dhcp.RestartCmd)
} else { } else {
err = tmpl.Execute(os.Stdout, d) util.ExecInteractive("/bin/sh", "-c", "systemctl enable dhcpd")
if err != nil { }
wwlog.Printf(wwlog.ERROR, "%s\n", err) if controller.Dhcp.Restart != "" {
os.Exit(1) util.ExecInteractive("/bin/sh", "-c", controller.Dhcp.Restart)
} } else {
util.ExecInteractive("/bin/sh", "-c", "systemctl restart dhcpd")
}
} else {
err = tmpl.Execute(os.Stdout, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
} }
// Just in case we get here, we've now finished the loop
break
} }
return nil return nil

View File

@@ -9,7 +9,7 @@ var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
Use: "service", Use: "service",
Short: "Initialize Warewulf services", Short: "Initialize Warewulf services",
Long: "Warewulf Initialization", Long: "Warewulf Service Initialization",
} }
) )

View File

@@ -29,7 +29,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodes { for _, node := range nodes {
if node.Vnfs.Defined() == true { if node.Vnfs.Defined() == true {
set[node.Vnfs.Get()] ++ set[node.Vnfs.Get()]++
} }
} }
@@ -43,12 +43,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
for _, node := range nodes { for _, node := range nodes {
if node.Vnfs.Defined() == true { if node.Vnfs.Defined() == true {
set[node.Vnfs.Get()] ++ wwlog.Printf(wwlog.VERBOSE, "Adding VNFS to list: %s (%s)\n", node.Vnfs.Get(), node.Id.Get())
set[node.Vnfs.Get()]++
} }
} }
} else if len(args) == 1 { } else if len(args) == 1 {
set[args[0]] ++ set[args[0]]++
} else { } else {
cmd.Usage() cmd.Usage()
os.Exit(1) os.Exit(1)
@@ -64,4 +65,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
return nil return nil
} }

View File

@@ -14,13 +14,12 @@ import (
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
config := config.New()
nconfig, _ := node.New() nconfig, _ := node.New()
nodes, _ := nconfig.FindAllNodes() nodes, _ := nconfig.FindAllNodes()
nodemap := make(map[string]int) nodemap := make(map[string]int)
for _, n := range nodes { for _, n := range nodes {
nodemap[n.Vnfs.Get()] ++ nodemap[n.Vnfs.Get()]++
} }
images, _ := ioutil.ReadDir(config.VnfsImageParentDir()) images, _ := ioutil.ReadDir(config.VnfsImageParentDir())
@@ -32,7 +31,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
v, err := vnfs.Load(file.Name()) v, err := vnfs.Load(file.Name())
if err == nil { if err == nil {
var vnfs_size int64 var vnfs_size int64
if util.IsFile( config.VnfsImage(file.Name())) { if util.IsFile(config.VnfsImage(file.Name())) {
s, _ := os.Stat(config.VnfsImage(file.Name())) s, _ := os.Stat(config.VnfsImage(file.Name()))
vnfs_size = s.Size() / 1024 vnfs_size = s.Size() / 1024
} }
@@ -48,7 +47,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if util.IsDir(path.Join(config.VnfsImageParentDir(), file.Name())) { if util.IsDir(path.Join(config.VnfsImageParentDir(), file.Name())) {
var vnfs_size int64 var vnfs_size int64
if util.IsFile( config.VnfsImage(file.Name())) { if util.IsFile(config.VnfsImage(file.Name())) {
s, _ := os.Stat(config.VnfsImage(file.Name())) s, _ := os.Stat(config.VnfsImage(file.Name()))
vnfs_size = s.Size() / 1024 vnfs_size = s.Size() / 1024
} }
@@ -61,4 +60,4 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
} }
return nil return nil
} }

View File

@@ -4,99 +4,42 @@ import (
"fmt" "fmt"
"github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/kelseyhightower/envconfig"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path" "path"
) )
const (
LocalStateDir = "/var/warewulf"
)
type Config struct { func NodeConfig() string {
Port int `yaml:"warewulfd port", envconfig:"WAREWULFD_PORT"` return fmt.Sprintf("%s/nodes.conf", LocalStateDir)
Ipaddr string `yaml:"warewulfd ipaddr", envconfig:"WAREWULFD_IPADDR"`
InsecureRuntime bool `yaml:"insecure runtime"`
Debug bool `yaml:"debug"`
SysConfDir string `yaml:"system config dir"`
LocalStateDir string `yaml:"local state dir"`
Editor string `yaml:"default editor", envconfig:"EDITOR"`
} }
var c Config func OverlayDir() string {
return fmt.Sprintf("%s/overlays/", LocalStateDir)
func init() {
fd, err := ioutil.ReadFile("/etc/warewulf/warewulf.conf")
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not read config file: %s\n", err)
os.Exit(255)
}
err = yaml.Unmarshal(fd, &c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not unmarshal config file: %s\n", err)
os.Exit(255)
}
err = envconfig.Process("", &c)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not obtain environment configuration: %s\n", err)
os.Exit(255)
}
if c.Ipaddr == "" {
fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in /etc/warewulf/warewulf.conf\n")
}
if c.SysConfDir == "" {
c.SysConfDir = "/etc/warewulf"
}
if c.LocalStateDir == "" {
c.LocalStateDir = "/var/warewulf"
}
if c.Editor == "" {
c.Editor = "vi"
}
util.ValidateOrDie("warewulfd ipaddr", c.Ipaddr, "^[0-9]+.[0-9]+.[0-9]+.[0-9]+$")
util.ValidateOrDie("system config dir", c.SysConfDir, "^[a-zA-Z0-9-._:/]+$")
util.ValidateOrDie("local state dir", c.LocalStateDir, "^[a-zA-Z0-9-._:/]+$")
util.ValidateOrDie("default editor", c.LocalStateDir, "^[a-zA-Z0-9-._:/]+$")
} }
func New() (Config) { func SystemOverlayDir() string {
return c return path.Join(OverlayDir(), "/system")
} }
func (self *Config) NodeConfig() string { func RuntimeOverlayDir() string {
return fmt.Sprintf("%s/nodes.conf", self.LocalStateDir) return path.Join(OverlayDir(), "/runtime")
} }
func (self *Config) OverlayDir() string { func VnfsImageParentDir() string {
return fmt.Sprintf("%s/overlays/", self.LocalStateDir) return fmt.Sprintf("%s/provision/vnfs/", LocalStateDir)
} }
func (self *Config) SystemOverlayDir() string { func VnfsChrootParentDir() string {
return path.Join(self.OverlayDir(), "/system") return fmt.Sprintf("%s/chroot/", LocalStateDir)
} }
func (self *Config) RuntimeOverlayDir() string { func KernelParentDir() string {
return path.Join(self.OverlayDir(), "/runtime") return fmt.Sprintf("%s/provision/kernel/", LocalStateDir)
} }
func (self *Config) VnfsImageParentDir() string { func SystemOverlaySource(overlayName string) string {
return fmt.Sprintf("%s/provision/vnfs/", self.LocalStateDir)
}
func (self *Config) VnfsChrootParentDir() string {
return fmt.Sprintf("%s/chroot/", self.LocalStateDir)
}
func (self *Config) KernelParentDir() string {
return fmt.Sprintf("%s/provision/kernel/", self.LocalStateDir)
}
func (self *Config) SystemOverlaySource(overlayName string) string {
if overlayName == "" { if overlayName == "" {
wwlog.Printf(wwlog.ERROR, "System overlay name is not defined\n") wwlog.Printf(wwlog.ERROR, "System overlay name is not defined\n")
return "" return ""
@@ -107,11 +50,10 @@ func (self *Config) SystemOverlaySource(overlayName string) string {
return "" return ""
} }
return path.Join(self.SystemOverlayDir(), overlayName) return path.Join(SystemOverlayDir(), overlayName)
} }
func RuntimeOverlaySource(overlayName string) string {
func (self *Config) RuntimeOverlaySource(overlayName string) string {
if overlayName == "" { if overlayName == "" {
wwlog.Printf(wwlog.ERROR, "Runtime overlay name is not defined\n") wwlog.Printf(wwlog.ERROR, "Runtime overlay name is not defined\n")
return "" return ""
@@ -122,10 +64,10 @@ func (self *Config) RuntimeOverlaySource(overlayName string) string {
return "" return ""
} }
return path.Join(self.RuntimeOverlayDir(), overlayName) return path.Join(RuntimeOverlayDir(), overlayName)
} }
func (self *Config) KernelImage(kernelVersion string) string { func KernelImage(kernelVersion string) string {
if kernelVersion == "" { if kernelVersion == "" {
wwlog.Printf(wwlog.ERROR, "Kernel Version is not defined\n") wwlog.Printf(wwlog.ERROR, "Kernel Version is not defined\n")
return "" return ""
@@ -136,10 +78,10 @@ func (self *Config) KernelImage(kernelVersion string) string {
return "" return ""
} }
return path.Join(self.KernelParentDir(), kernelVersion, "vmlinuz") return path.Join(KernelParentDir(), kernelVersion, "vmlinuz")
} }
func (self *Config) KmodsImage(kernelVersion string) string { func KmodsImage(kernelVersion string) string {
if kernelVersion == "" { if kernelVersion == "" {
wwlog.Printf(wwlog.ERROR, "Kernel Version is not defined\n") wwlog.Printf(wwlog.ERROR, "Kernel Version is not defined\n")
return "" return ""
@@ -150,10 +92,10 @@ func (self *Config) KmodsImage(kernelVersion string) string {
return "" return ""
} }
return path.Join(self.KernelParentDir(), kernelVersion, "kmods.img") return path.Join(KernelParentDir(), kernelVersion, "kmods.img")
} }
func (self *Config) SystemOverlayImage(nodeName string) string { func SystemOverlayImage(nodeName string) string {
if nodeName == "" { if nodeName == "" {
wwlog.Printf(wwlog.ERROR, "Node name is not defined\n") wwlog.Printf(wwlog.ERROR, "Node name is not defined\n")
return "" return ""
@@ -164,10 +106,10 @@ func (self *Config) SystemOverlayImage(nodeName string) string {
return "" return ""
} }
return fmt.Sprintf("%s/provision/overlays/system/%s.img", self.LocalStateDir, nodeName) return fmt.Sprintf("%s/provision/overlays/system/%s.img", LocalStateDir, nodeName)
} }
func (self *Config) RuntimeOverlayImage(nodeName string) string { func RuntimeOverlayImage(nodeName string) string {
if nodeName == "" { if nodeName == "" {
wwlog.Printf(wwlog.ERROR, "Node name is not defined\n") wwlog.Printf(wwlog.ERROR, "Node name is not defined\n")
return "" return ""
@@ -178,10 +120,10 @@ func (self *Config) RuntimeOverlayImage(nodeName string) string {
return "" return ""
} }
return fmt.Sprintf("%s/provision/overlays/runtime/%s.img", self.LocalStateDir, nodeName) return fmt.Sprintf("%s/provision/overlays/runtime/%s.img", LocalStateDir, nodeName)
} }
func (self *Config) VnfsImageDir(uri string) string { func VnfsImageDir(uri string) string {
if uri == "" { if uri == "" {
wwlog.Printf(wwlog.ERROR, "VNFS URI is not defined\n") wwlog.Printf(wwlog.ERROR, "VNFS URI is not defined\n")
return "" return ""
@@ -192,14 +134,14 @@ func (self *Config) VnfsImageDir(uri string) string {
return "" return ""
} }
return path.Join(self.VnfsImageParentDir(), uri) return path.Join(VnfsImageParentDir(), uri)
} }
func (self *Config) VnfsImage(uri string) string { func VnfsImage(uri string) string {
return path.Join(self.VnfsImageDir(uri), "image") return path.Join(VnfsImageDir(uri), "image")
} }
func (self *Config) VnfsChroot(uri string) string { func VnfsChroot(uri string) string {
if uri == "" { if uri == "" {
wwlog.Printf(wwlog.ERROR, "VNFS name is not defined\n") wwlog.Printf(wwlog.ERROR, "VNFS name is not defined\n")
return "" return ""
@@ -210,5 +152,5 @@ func (self *Config) VnfsChroot(uri string) string {
return "" return ""
} }
return path.Join(self.VnfsChrootParentDir(), uri) return path.Join(VnfsChrootParentDir(), uri)
} }

View File

@@ -12,7 +12,6 @@ import (
) )
func Build(kernelVersion string) error { func Build(kernelVersion string) error {
config := config.New()
kernelImage := "/boot/vmlinuz-" + kernelVersion kernelImage := "/boot/vmlinuz-" + kernelVersion
kernelDrivers := "/lib/modules/" + kernelVersion kernelDrivers := "/lib/modules/" + kernelVersion

View File

@@ -7,8 +7,11 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
"regexp" "regexp"
"strings"
) )
const ConfigFile = "/etc/warewulf/nodes.conf"
func New() (nodeYaml, error) { func New() (nodeYaml, error) {
var ret nodeYaml var ret nodeYaml
@@ -19,211 +22,149 @@ func New() (nodeYaml, error) {
return ret, err return ret, err
} }
wwlog.Printf(wwlog.DEBUG, "Unmarshaling the node configuration\n")
err = yaml.Unmarshal(data, &ret) err = yaml.Unmarshal(data, &ret)
if err != nil { if err != nil {
return ret, err return ret, err
} }
wwlog.Printf(wwlog.DEBUG, "Returning node object\n")
return ret, nil return ret, nil
} }
func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) { func (self *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
var ret []NodeInfo var ret []NodeInfo
for controllername, controller := range self.Controllers { wwlog.Printf(wwlog.DEBUG, "Finding all nodes...\n")
for groupname, group := range controller.NodeGroups { for nodename, node := range self.Nodes {
for nodename, node := range group.Nodes { var n NodeInfo
var n NodeInfo
var allProfiles []string
if node.Disabled == true || group.Disabled == true { wwlog.Printf(wwlog.DEBUG, "In node loop: %s\n", nodename)
wwlog.Printf(wwlog.VERBOSE, "Skipping disabled node: %s/%s\n", groupname, nodename) n.NetDevs = make(map[string]*NetDevEntry)
continue n.SystemOverlay.SetDefault("default")
n.RuntimeOverlay.SetDefault("default")
n.Ipxe.SetDefault("default")
fullname := strings.SplitN(nodename, ".", 2)
if len(fullname) > 1 {
n.DomainName.SetDefault(fullname[1])
}
if len(node.Profiles) == 0 {
n.Profiles = []string{"default"}
} else {
n.Profiles = node.Profiles
}
n.Id.Set(nodename)
n.Comment.Set(node.Comment)
n.Vnfs.Set(node.Vnfs)
n.KernelVersion.Set(node.KernelVersion)
n.KernelArgs.Set(node.KernelArgs)
n.DomainName.Set(node.DomainName)
n.Ipxe.Set(node.Ipxe)
n.IpmiIpaddr.Set(node.IpmiIpaddr)
n.IpmiNetmask.Set(node.IpmiNetmask)
n.IpmiUserName.Set(node.IpmiUserName)
n.IpmiPassword.Set(node.IpmiPassword)
n.SystemOverlay.Set(node.SystemOverlay)
n.RuntimeOverlay.Set(node.RuntimeOverlay)
for devname, netdev := range node.NetDevs {
if _, ok := n.NetDevs[devname]; !ok {
var netdev NetDevEntry
n.NetDevs[devname] = &netdev
}
n.NetDevs[devname].Ipaddr.Set(netdev.Ipaddr)
n.NetDevs[devname].Netmask.Set(netdev.Netmask)
n.NetDevs[devname].Hwaddr.Set(netdev.Hwaddr)
n.NetDevs[devname].Gateway.Set(netdev.Gateway)
n.NetDevs[devname].Type.Set(netdev.Type)
n.NetDevs[devname].Default.SetB(netdev.Default)
}
for _, p := range n.Profiles {
if _, ok := self.NodeProfiles[p]; !ok {
wwlog.Printf(wwlog.WARN, "Profile not found for node '%s': %s\n", nodename, p)
continue
}
wwlog.Printf(wwlog.VERBOSE, "Merging profile into node: %s <- %s\n", nodename, p)
pstring := fmt.Sprintf("%s", p)
n.Comment.SetAlt(self.NodeProfiles[p].Comment, pstring)
n.DomainName.SetAlt(self.NodeProfiles[p].DomainName, pstring)
n.Vnfs.SetAlt(self.NodeProfiles[p].Vnfs, pstring)
n.KernelVersion.SetAlt(self.NodeProfiles[p].KernelVersion, pstring)
n.KernelArgs.SetAlt(self.NodeProfiles[p].KernelArgs, pstring)
n.Ipxe.SetAlt(self.NodeProfiles[p].Ipxe, pstring)
n.IpmiIpaddr.SetAlt(self.NodeProfiles[p].IpmiIpaddr, pstring)
n.IpmiNetmask.SetAlt(self.NodeProfiles[p].IpmiNetmask, pstring)
n.IpmiUserName.SetAlt(self.NodeProfiles[p].IpmiUserName, pstring)
n.IpmiPassword.SetAlt(self.NodeProfiles[p].IpmiPassword, pstring)
n.SystemOverlay.SetAlt(self.NodeProfiles[p].SystemOverlay, pstring)
n.RuntimeOverlay.SetAlt(self.NodeProfiles[p].RuntimeOverlay, pstring)
for devname, netdev := range self.NodeProfiles[p].NetDevs {
if _, ok := n.NetDevs[devname]; !ok {
var netdev NetDevEntry
n.NetDevs[devname] = &netdev
} }
wwlog.Printf(wwlog.DEBUG, "Updating profile (%s) netdev: %s\n", p, devname)
n.Id.Set(nodename) n.NetDevs[devname].Ipaddr.SetAlt(netdev.Ipaddr, pstring)
n.Gid.Set(groupname) n.NetDevs[devname].Netmask.SetAlt(netdev.Netmask, pstring)
n.Cid.Set(controllername) n.NetDevs[devname].Hwaddr.SetAlt(netdev.Hwaddr, pstring)
n.HostName.Set(node.Hostname) n.NetDevs[devname].Gateway.SetAlt(netdev.Gateway, pstring)
n.IpmiIpaddr.Set(node.IpmiIpaddr) n.NetDevs[devname].Type.SetAlt(netdev.Type, pstring)
n.IpmiNetmask.Set(node.IpmiNetmask) n.NetDevs[devname].Default.SetAltB(netdev.Default, pstring)
n.DomainName.Set(node.DomainName)
n.Vnfs.Set(node.Vnfs)
n.KernelVersion.Set(node.KernelVersion)
n.KernelArgs.Set(node.KernelArgs)
n.Ipxe.Set(node.Ipxe)
n.IpmiUserName.Set(node.IpmiUserName)
n.IpmiPassword.Set(node.IpmiPassword)
n.SystemOverlay.Set(node.SystemOverlay)
n.RuntimeOverlay.Set(node.RuntimeOverlay)
n.DomainName.SetGroup(group.DomainName)
n.Vnfs.SetGroup(group.Vnfs)
n.KernelVersion.SetGroup(group.KernelVersion)
n.KernelArgs.SetGroup(group.KernelArgs)
n.Ipxe.SetGroup(group.Ipxe)
n.IpmiNetmask.SetGroup(group.IpmiNetmask)
n.IpmiUserName.SetGroup(group.IpmiUserName)
n.IpmiPassword.SetGroup(group.IpmiPassword)
n.SystemOverlay.SetGroup(group.SystemOverlay)
n.RuntimeOverlay.SetGroup(group.RuntimeOverlay)
n.RuntimeOverlay.SetDefault("default")
n.SystemOverlay.SetDefault("default")
n.Ipxe.SetDefault("default")
n.KernelArgs.SetDefault("crashkernel=no quiet")
n.GroupProfiles = group.Profiles
n.Profiles = node.Profiles
allProfiles = append(allProfiles, group.Profiles...)
allProfiles = append(allProfiles, node.Profiles...)
for _, p := range allProfiles {
if _, ok := self.NodeProfiles[p]; !ok {
wwlog.Printf(wwlog.WARN, "Profile not found for node '%s': %s\n", nodename, p)
continue
}
n.DomainName.SetProfile(self.NodeProfiles[p].DomainName)
n.Vnfs.SetProfile(self.NodeProfiles[p].Vnfs)
n.KernelVersion.SetProfile(self.NodeProfiles[p].KernelVersion)
n.KernelArgs.SetProfile(self.NodeProfiles[p].KernelArgs)
n.Ipxe.SetProfile(self.NodeProfiles[p].Ipxe)
n.IpmiNetmask.SetProfile(self.NodeProfiles[p].IpmiNetmask)
n.IpmiUserName.SetProfile(self.NodeProfiles[p].IpmiUserName)
n.IpmiPassword.SetProfile(self.NodeProfiles[p].IpmiPassword)
n.SystemOverlay.SetProfile(self.NodeProfiles[p].SystemOverlay)
n.RuntimeOverlay.SetProfile(self.NodeProfiles[p].RuntimeOverlay)
}
if n.DomainName.Defined() == true {
n.Fqdn.Set(node.Hostname + "." + n.DomainName.Get())
} else {
n.Fqdn.Set(node.Hostname)
}
n.NetDevs = node.NetDevs
ret = append(ret, n)
} }
} }
ret = append(ret, n)
} }
return ret, nil return ret, nil
} }
func (self *nodeYaml) FindAllGroups() ([]GroupInfo, error) { func (self *nodeYaml) FindAllProfiles() ([]NodeInfo, error) {
var ret []GroupInfo var ret []NodeInfo
for controllername, controller := range self.Controllers {
for groupname, group := range controller.NodeGroups {
var g GroupInfo
g.Id = groupname
g.Cid = controllername
g.DomainName = group.DomainName
g.Comment = group.Comment
g.Vnfs = group.Vnfs
g.KernelVersion = group.KernelVersion
g.KernelArgs = group.KernelArgs
g.IpmiNetmask = group.IpmiNetmask
g.IpmiPassword = group.IpmiPassword
g.IpmiUserName = group.IpmiUserName
g.SystemOverlay = group.SystemOverlay
g.RuntimeOverlay = group.RuntimeOverlay
g.Profiles = group.Profiles
// TODO: Validate or die on all inputs
ret = append(ret, g)
}
}
return ret, nil
}
func (self *nodeYaml) FindAllControllers() ([]ControllerInfo, error) {
var ret []ControllerInfo
for controllername, controller := range self.Controllers {
var c ControllerInfo
c.Id = controllername
c.Ipaddr = controller.Ipaddr
c.Comment = controller.Comment
c.Fqdn = controller.Fqdn
//TODO: Is there a better way to do this, cause EWWW!
c.Services = struct {
Warewulfd struct {
Port string
Secure bool
StartCmd string
RestartCmd string
EnableCmd string
}
Dhcp struct {
Enabled bool
Template string
RangeStart string
RangeEnd string
ConfigFile string
StartCmd string
RestartCmd string
EnableCmd string
}
Tftp struct {
Enabled bool
TftpRoot string
StartCmd string
RestartCmd string
EnableCmd string
}
Nfs struct {
Enabled bool
Exports []string
StartCmd string
RestartCmd string
EnableCmd string
}
}(controller.Services)
// Validations //
if c.Ipaddr == "" {
wwlog.Printf(wwlog.WARN, "Controller IP address is unset: %s\n", c.Id)
}
if c.Services.Warewulfd.Port == "" {
c.Services.Warewulfd.Port = "987"
}
// TODO: Validate or die on all inputs
ret = append(ret, c)
}
return ret, nil
}
func (self *nodeYaml) FindAllProfiles() ([]ProfileInfo, error) {
var ret []ProfileInfo
for name, profile := range self.NodeProfiles { for name, profile := range self.NodeProfiles {
var p ProfileInfo var p NodeInfo
p.NetDevs = make(map[string]*NetDevEntry)
p.Id = name p.Id.Set(name)
p.Comment = profile.Comment p.Comment.Set(profile.Comment)
p.Vnfs = profile.Vnfs p.Vnfs.Set(profile.Vnfs)
p.Ipxe = profile.Ipxe p.Ipxe.Set(profile.Ipxe)
p.KernelVersion = profile.KernelVersion p.KernelVersion.Set(profile.KernelVersion)
p.KernelArgs = profile.KernelArgs p.KernelArgs.Set(profile.KernelArgs)
p.IpmiNetmask = profile.IpmiNetmask p.IpmiNetmask.Set(profile.IpmiNetmask)
p.IpmiUserName = profile.IpmiUserName p.IpmiUserName.Set(profile.IpmiUserName)
p.IpmiPassword = profile.IpmiPassword p.IpmiPassword.Set(profile.IpmiPassword)
p.DomainName = profile.DomainName p.RuntimeOverlay.Set(profile.RuntimeOverlay)
p.RuntimeOverlay = profile.RuntimeOverlay p.SystemOverlay.Set(profile.SystemOverlay)
p.SystemOverlay = profile.SystemOverlay
for devname, netdev := range profile.NetDevs {
if _, ok := p.NetDevs[devname]; !ok {
var netdev NetDevEntry
p.NetDevs[devname] = &netdev
}
wwlog.Printf(wwlog.DEBUG, "Updating profile netdev: %s\n", devname)
p.NetDevs[devname].Ipaddr.Set(netdev.Ipaddr)
p.NetDevs[devname].Netmask.Set(netdev.Netmask)
p.NetDevs[devname].Hwaddr.Set(netdev.Hwaddr)
p.NetDevs[devname].Gateway.Set(netdev.Gateway)
p.NetDevs[devname].Type.Set(netdev.Type)
p.NetDevs[devname].Default.SetB(netdev.Default)
}
// TODO: Validate or die on all inputs // TODO: Validate or die on all inputs
@@ -239,7 +180,7 @@ func (self *nodeYaml) FindByHwaddr(hwa string) (NodeInfo, error) {
for _, node := range n { for _, node := range n {
for _, dev := range node.NetDevs { for _, dev := range node.NetDevs {
if dev.Hwaddr == hwa { if dev.Hwaddr.Get() == hwa {
return node, nil return node, nil
} }
} }
@@ -255,7 +196,7 @@ func (self *nodeYaml) FindByIpaddr(ipaddr string) (NodeInfo, error) {
for _, node := range n { for _, node := range n {
for _, dev := range node.NetDevs { for _, dev := range node.NetDevs {
if dev.Ipaddr == ipaddr { if dev.Ipaddr.Get() == ipaddr {
return node, nil return node, nil
} }
} }
@@ -270,7 +211,7 @@ func (nodes *nodeYaml) SearchByName(search string) ([]NodeInfo, error) {
n, _ := nodes.FindAllNodes() n, _ := nodes.FindAllNodes()
for _, node := range n { for _, node := range n {
b, _ := regexp.MatchString(search, node.Fqdn.Get()) b, _ := regexp.MatchString(search, node.Id.Get())
if b == true { if b == true {
ret = append(ret, node) ret = append(ret, node)
} }
@@ -286,7 +227,7 @@ func (nodes *nodeYaml) SearchByNameList(searchList []string) ([]NodeInfo, error)
for _, search := range searchList { for _, search := range searchList {
for _, node := range n { for _, node := range n {
b, _ := regexp.MatchString(search, node.Fqdn.Get()) b, _ := regexp.MatchString(search, node.Id.Get())
if b == true { if b == true {
ret = append(ret, node) ret = append(ret, node)
} }

View File

@@ -11,98 +11,26 @@ import (
******/ ******/
type nodeYaml struct { type nodeYaml struct {
NodeProfiles map[string]*ProfileConf NodeProfiles map[string]*NodeConf
Controllers map[string]*ControllerConf `yaml:"control"` Nodes map[string]*NodeConf
}
type ProfileConf struct {
Comment string `yaml:"comment"`
Vnfs string `yaml:"vnfs,omitempty"`
Ipxe string `yaml:"ipxe template,omitempty"`
KernelVersion string `yaml:"kernel version,omitempty"`
KernelArgs string `yaml:"kernel args,omitempty"`
IpmiNetmask string `yaml:"ipmi netmask,omitempty"`
IpmiUserName string `yaml:"ipmi username,omitempty"`
IpmiPassword string `yaml:"ipmi password,omitempty"`
DomainName string `yaml:"domain name,omitempty"`
RuntimeOverlay string `yaml:"runtime overlay files,omitempty"`
SystemOverlay string `yaml:"system overlay files,omitempty"`
}
type ControllerConf struct {
Comment string `yaml:"comment"`
Ipaddr string `yaml:"ipaddr"`
Fqdn string `yaml:"fqdn"`
Services struct {
Warewulfd struct {
Port string `yaml:"port"`
Secure bool `yaml:"secure,omitempty"`
StartCmd string `yaml:"start command,omitempty"`
RestartCmd string `yaml:"restart command,omitempty"`
EnableCmd string `yaml:"enable command,omitempty"`
} `yaml:"warewulf"`
Dhcp struct {
Enabled bool `yaml:"enabled,omitempty"`
Template string `yaml:"template,omitempty"`
RangeStart string `yaml:"range start,omitempty"`
RangeEnd string `yaml:"range end,omitempty"`
ConfigFile string `yaml:"config file,omitempty"`
StartCmd string `yaml:"start command,omitempty"`
RestartCmd string `yaml:"restart command,omitempty"`
EnableCmd string `yaml:"enable command,omitempty"`
} `yaml:"dhcp,omitempty"`
Tftp struct {
Enabled bool `yaml:"enabled,omitempty"`
TftpRoot string `yaml:"tftp root,omitempty"`
StartCmd string `yaml:"start command,omitempty"`
RestartCmd string `yaml:"restart command,omitempty"`
EnableCmd string `yaml:"enable command,omitempty"`
} `yaml:"tftp,omitempty"`
Nfs struct {
Enabled bool `yaml:"enabled,omitempty"`
Exports []string `yaml:"exports,omitempty"`
StartCmd string `yaml:"start command,omitempty"`
RestartCmd string `yaml:"restart command,omitempty"`
EnableCmd string `yaml:"enable command,omitempty"`
} `yaml:"nfs,omitempty"`
} `yaml:"services"`
NodeGroups map[string]*GroupConf
}
type GroupConf struct {
Comment string `yaml:"comment"`
Disabled bool `yaml:"disabled,omitempty"`
DomainName string `yaml:"domain name"`
Vnfs string `yaml:"vnfs,omitempty"`
Ipxe string `yaml:"ipxe template,omitempty"`
KernelVersion string `yaml:"kernel version,omitempty"`
KernelArgs string `yaml:"kernel args,omitempty"`
IpmiNetmask string `yaml:"ipmi netmask,omitempty"`
IpmiUserName string `yaml:"ipmi username,omitempty"`
IpmiPassword string `yaml:"ipmi password,omitempty"`
RuntimeOverlay string `yaml:"runtime overlay files,omitempty"`
SystemOverlay string `yaml:"system overlay files,omitempty"`
Profiles []string `yaml:"profiles,omitempty"`
Nodes map[string]*NodeConf
} }
type NodeConf struct { type NodeConf struct {
Comment string `yaml:"comment,omitempty"` Comment string `yaml:"comment,omitempty"`
Disabled bool `yaml:"disabled,omitempty"` Disabled bool `yaml:"disabled,omitempty"`
Hostname string `yaml:"hostname,omitempty"` DomainName string `yaml:"domain name,omitempty"`
DomainName string `yaml:"domain name,omitempty"` Vnfs string `yaml:"vnfs,omitempty"`
Vnfs string `yaml:"vnfs,omitempty"` Ipxe string `yaml:"ipxe template,omitempty"`
Ipxe string `yaml:"ipxe template,omitempty"` KernelVersion string `yaml:"kernel version,omitempty"`
KernelVersion string `yaml:"kernel version,omitempty"` KernelArgs string `yaml:"kernel args,omitempty"`
KernelArgs string `yaml:"kernel args,omitempty"` IpmiUserName string `yaml:"ipmi username,omitempty"`
IpmiUserName string `yaml:"ipmi username,omitempty"` IpmiPassword string `yaml:"ipmi password,omitempty"`
IpmiPassword string `yaml:"ipmi password,omitempty"` IpmiIpaddr string `yaml:"ipmi ipaddr,omitempty"`
IpmiIpaddr string `yaml:"ipmi ipaddr,omitempty"` IpmiNetmask string `yaml:"ipmi netmask,omitempty"`
IpmiNetmask string `yaml:"ipmi netmask,omitempty"` RuntimeOverlay string `yaml:"runtime overlay files,omitempty"`
RuntimeOverlay string `yaml:"runtime overlay files,omitempty"` SystemOverlay string `yaml:"system overlay files,omitempty"`
SystemOverlay string `yaml:"system overlay files,omitempty"` Profiles []string `yaml:"profiles,omitempty"`
Profiles []string `yaml:"profiles,omitempty"` NetDevs map[string]*NetDevs `yaml:"network devices,omitempty"`
NetDevs map[string]*NetDevs
} }
type NetDevs struct { type NetDevs struct {
@@ -115,115 +43,47 @@ type NetDevs struct {
} }
/****** /******
* Code internal data representations * Internal code data representations
******/ ******/
type NodeInfoEntry struct { type Entry struct {
value string value string
profile string altvalue string
group string bool bool
controller string altbool bool
def string from string
def string
} }
type NodeInfo struct { type NodeInfo struct {
Id NodeInfoEntry Id Entry
Gid NodeInfoEntry Cid Entry
Cid NodeInfoEntry Comment Entry
Comment NodeInfoEntry DomainName Entry
HostName NodeInfoEntry Vnfs Entry
Fqdn NodeInfoEntry Ipxe Entry
DomainName NodeInfoEntry KernelVersion Entry
Vnfs NodeInfoEntry KernelArgs Entry
Ipxe NodeInfoEntry IpmiIpaddr Entry
KernelVersion NodeInfoEntry IpmiNetmask Entry
KernelArgs NodeInfoEntry IpmiUserName Entry
IpmiIpaddr NodeInfoEntry IpmiPassword Entry
IpmiNetmask NodeInfoEntry RuntimeOverlay Entry
IpmiUserName NodeInfoEntry SystemOverlay Entry
IpmiPassword NodeInfoEntry
RuntimeOverlay NodeInfoEntry
SystemOverlay NodeInfoEntry
Profiles []string Profiles []string
GroupProfiles []string GroupProfiles []string
NetDevs map[string]*NetDevs NetDevs map[string]*NetDevEntry
} }
type ControllerInfo struct { type NetDevEntry struct {
Id string Type Entry `yaml:"type,omitempty"`
Comment string Default Entry `yaml:"default"`
Ipaddr string Hwaddr Entry
Fqdn string Ipaddr Entry
DomainName string Netmask Entry
Services struct { Gateway Entry `yaml:"gateway,omitempty"`
Warewulfd struct {
Port string
Secure bool
StartCmd string
RestartCmd string
EnableCmd string
}
Dhcp struct {
Enabled bool
Template string
RangeStart string
RangeEnd string
ConfigFile string
StartCmd string
RestartCmd string
EnableCmd string
}
Tftp struct {
Enabled bool
TftpRoot string
StartCmd string
RestartCmd string
EnableCmd string
}
Nfs struct {
Enabled bool
Exports []string
StartCmd string
RestartCmd string
EnableCmd string
}
}
} }
type GroupInfo struct {
Id string
Cid string
Comment string
Vnfs string
Ipxe string
KernelVersion string
KernelArgs string
IpmiNetmask string
IpmiUserName string
IpmiPassword string
DomainName string
RuntimeOverlay string
SystemOverlay string
Profiles []string
}
type ProfileInfo struct {
Id string
Comment string
Vnfs string
Ipxe string
KernelVersion string
KernelArgs string
IpmiNetmask string
IpmiUserName string
IpmiPassword string
DomainName string
RuntimeOverlay string
SystemOverlay string
}
const ConfigFile = "/etc/warewulf/nodes.conf"
func init() { func init() {
//TODO: Check to make sure nodes.conf is found //TODO: Check to make sure nodes.conf is found
if util.IsFile(ConfigFile) == false { if util.IsFile(ConfigFile) == false {

View File

@@ -4,18 +4,101 @@ import (
"strings" "strings"
) )
func (self *NodeInfoEntry) String() string { /**********
*
* Sets
*
*********/
func (self *Entry) Set(val string) {
if val == "" {
return
}
if strings.ToUpper(val) == "DELETE" {
self.value = ""
} else {
self.value = val
}
return
}
func (self *Entry) SetB(val bool) {
self.bool = val
return
}
func (self *Entry) SetAlt(val string, from string) {
if val == "" {
return
}
self.altvalue = val
self.from = from
return
}
func (self *Entry) SetAltB(val bool, from string) {
self.altbool = val
self.from = from
return
}
func (self *Entry) SetDefault(val string) {
if val == "" {
return
}
self.def = val
return
}
/**********
*
* Gets
*
*********/
func (self *Entry) Get() string {
if self.value != "" { if self.value != "" {
return self.value return self.value
} }
if self.group != "" { if self.altvalue != "" {
return self.group return self.altvalue
} }
if self.profile != "" { if self.def != "" {
return self.profile return self.def
} }
if self.controller != "" { return ""
return self.controller }
func (self *Entry) GetB() bool {
return self.bool
}
func (self *Entry) GetReal() string {
return self.value
}
func (self *Entry) GetRealB() bool {
return self.bool
}
/**********
*
* Misc
*
*********/
func (self *Entry) Print() string {
if self.value != "" {
return self.value
}
if self.altvalue != "" {
return self.altvalue
} }
if self.def != "" { if self.def != "" {
return self.def return self.def
@@ -23,93 +106,25 @@ func (self *NodeInfoEntry) String() string {
return "--" return "--"
} }
func (self *NodeInfoEntry) Source() string { func (self *Entry) Source() string {
if self.value != "" && self.altvalue != "" {
return "SUPERSEDED"
//return fmt.Sprintf("[%s]", self.from)
} else if self.from == "" {
return "--"
}
return self.from
}
func (self *Entry) Defined() bool {
if self.value != "" { if self.value != "" {
return "node" return true
} }
if self.group != "" { if self.altvalue != "" {
return "group" return true
}
if self.profile != "" {
return "profile"
}
if self.controller != "" {
return "controller"
} }
if self.def != "" { if self.def != "" {
return "default" return true
} }
return "" return false
} }
func (self *NodeInfoEntry) Get() string {
if self.value != "" {
return self.value
}
if self.group != "" {
return self.group
}
if self.profile != "" {
return self.profile
}
if self.controller != "" {
return self.controller
}
if self.def != "" {
return self.def
}
return ""
}
func (self *NodeInfoEntry) Defined() bool {
if self.Get() == "" {
return false
}
return true
}
func (self *NodeInfoEntry) SetDefault(value string) {
if value == "" {
return
}
self.def = value
}
func (self *NodeInfoEntry) SetGroup(value string) {
if value == "" {
return
}
self.group = value
}
func (self *NodeInfoEntry) SetProfile(value string) {
if value == "" {
return
}
self.profile = value
}
func (self *NodeInfoEntry) SetController(value string) {
if value == "" {
return
}
self.controller = value
}
func (self *NodeInfoEntry) Set(value string) {
if value == "" {
return
} else if strings.ToUpper(value) == "UNDEF" {
value = ""
}
self.value = value
}
func (self *NodeInfoEntry) Unset() {
self.value = ""
}
func (self *NodeInfoEntry) GetReal() string {
return self.value
}

View File

@@ -3,7 +3,6 @@ package node
import ( import (
"github.com/hpcng/warewulf/internal/pkg/errors" "github.com/hpcng/warewulf/internal/pkg/errors"
"github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"os" "os"
) )
@@ -14,225 +13,73 @@ import (
* *
****/ ****/
func (self *nodeYaml) AddNode(controllerID string, groupID string, nodeID string) error { func (self *nodeYaml) AddNode(nodeID string) (NodeInfo, error) {
var node NodeConf var node NodeConf
var n NodeInfo
wwlog.Printf(wwlog.VERBOSE, "Adding new node: %s/%s\n", groupID, nodeID) wwlog.Printf(wwlog.VERBOSE, "Adding new node: %s\n", nodeID)
if _, ok := self.Controllers[controllerID]; !ok { if _, ok := self.Nodes[nodeID]; ok {
return errors.New("Controller does not exist: " + controllerID) return n, errors.New("Nodename already exists: " + nodeID)
} }
if _, ok := self.Controllers[controllerID].NodeGroups[groupID]; !ok { self.Nodes[nodeID] = &node
return errors.New("Group does not exist: " + groupID) self.Nodes[nodeID].Profiles = []string{"default"}
} self.Nodes[nodeID].NetDevs = make(map[string]*NetDevs)
if _, ok := self.Controllers[controllerID].NodeGroups[groupID].Nodes[groupID]; ok { n.Id.Set(nodeID)
return errors.New("Nodename already exists in group: " + nodeID) n.Profiles = []string{"default"}
} n.NetDevs = make(map[string]*NetDevEntry)
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID] = &node return n, nil
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].Hostname = nodeID
return nil
} }
func (self *nodeYaml) DelNode(controllerID string, groupID string, nodeID string) error { func (self *nodeYaml) DelNode(nodeID string) error {
if _, ok := self.Controllers[controllerID]; !ok { if _, ok := self.Nodes[nodeID]; !ok {
return errors.New("Controller does not exist: " + controllerID) return errors.New("Nodename does not exist: " + nodeID)
} }
if _, ok := self.Controllers[controllerID].NodeGroups[groupID]; !ok { wwlog.Printf(wwlog.VERBOSE, "Deleting node: %s\n", nodeID)
return errors.New("Group does not exist: " + groupID) delete(self.Nodes, nodeID)
}
if _, ok := self.Controllers[controllerID].NodeGroups[groupID].Nodes[groupID]; ok {
return errors.New("Nodename does not exist in group: " + nodeID)
}
wwlog.Printf(wwlog.VERBOSE, "Deleting node network device: %s/%s\n", groupID, nodeID)
delete(self.Controllers[controllerID].NodeGroups[groupID].Nodes, nodeID)
return nil return nil
} }
func (self *nodeYaml) NodeUpdate(node NodeInfo) error { func (self *nodeYaml) NodeUpdate(node NodeInfo) error {
controllerID := node.Cid.Get()
groupID := node.Gid.Get()
nodeID := node.Id.Get() nodeID := node.Id.Get()
if _, ok := self.Controllers[controllerID]; !ok { if _, ok := self.Nodes[nodeID]; !ok {
return errors.New("Controller does not exist: " + controllerID) return errors.New("Nodename does not exist: " + nodeID)
} }
if _, ok := self.Controllers[controllerID].NodeGroups[groupID]; !ok { self.Nodes[nodeID].Comment = node.Comment.GetReal()
return errors.New("Group does not exist: " + groupID) self.Nodes[nodeID].Vnfs = node.Vnfs.GetReal()
self.Nodes[nodeID].DomainName = node.DomainName.GetReal()
self.Nodes[nodeID].Ipxe = node.Ipxe.GetReal()
self.Nodes[nodeID].KernelVersion = node.KernelVersion.GetReal()
self.Nodes[nodeID].KernelArgs = node.KernelArgs.GetReal()
self.Nodes[nodeID].IpmiIpaddr = node.IpmiIpaddr.GetReal()
self.Nodes[nodeID].IpmiNetmask = node.IpmiNetmask.GetReal()
self.Nodes[nodeID].IpmiUserName = node.IpmiUserName.GetReal()
self.Nodes[nodeID].IpmiPassword = node.IpmiPassword.GetReal()
self.Nodes[nodeID].RuntimeOverlay = node.RuntimeOverlay.GetReal()
self.Nodes[nodeID].SystemOverlay = node.SystemOverlay.GetReal()
self.Nodes[nodeID].Profiles = node.Profiles
self.Nodes[nodeID].NetDevs = make(map[string]*NetDevs)
for devname, netdev := range node.NetDevs {
var newdev NetDevs
self.Nodes[nodeID].NetDevs[devname] = &newdev
self.Nodes[nodeID].NetDevs[devname].Ipaddr = netdev.Ipaddr.GetReal()
self.Nodes[nodeID].NetDevs[devname].Netmask = netdev.Netmask.GetReal()
self.Nodes[nodeID].NetDevs[devname].Hwaddr = netdev.Hwaddr.GetReal()
self.Nodes[nodeID].NetDevs[devname].Gateway = netdev.Gateway.GetReal()
self.Nodes[nodeID].NetDevs[devname].Type = netdev.Type.GetReal()
self.Nodes[nodeID].NetDevs[devname].Default = netdev.Default.GetRealB()
} }
if _, ok := self.Controllers[controllerID].NodeGroups[groupID].Nodes[groupID]; !ok {
return errors.New("Nodename does not exist in group: " + nodeID)
}
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].Hostname = node.HostName.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].Vnfs = node.Vnfs.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].DomainName = node.DomainName.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].Ipxe = node.Ipxe.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].KernelVersion = node.KernelVersion.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].KernelArgs = node.KernelArgs.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].IpmiIpaddr = node.IpmiIpaddr.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].IpmiNetmask = node.IpmiNetmask.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].IpmiUserName = node.IpmiUserName.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].IpmiPassword = node.IpmiPassword.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].RuntimeOverlay = node.RuntimeOverlay.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].SystemOverlay = node.SystemOverlay.GetReal()
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].Profiles = node.Profiles
self.Controllers[controllerID].NodeGroups[groupID].Nodes[nodeID].NetDevs = node.NetDevs
return nil
}
/****
*
* GROUP MODIFIERS
*
****/
func (self *nodeYaml) AddGroup(controllerID string, groupID string) error {
var group GroupConf
wwlog.Printf(wwlog.VERBOSE, "Adding new group: %s/%s\n", groupID)
if _, ok := self.Controllers[controllerID]; !ok {
return errors.New("Controller does not exist: " + controllerID)
}
if _, ok := self.Controllers[controllerID].NodeGroups[groupID]; ok {
return errors.New("Group already exists: " + groupID)
}
self.Controllers[controllerID].NodeGroups[groupID] = &group
self.Controllers[controllerID].NodeGroups[groupID].DomainName = groupID
self.Controllers[controllerID].NodeGroups[groupID].Profiles = []string{"default"}
return nil
}
func (self *nodeYaml) DelGroup(controllerID string, groupID string) error {
if _, ok := self.Controllers[controllerID]; !ok {
return errors.New("Controller does not exist: " + controllerID)
}
if _, ok := self.Controllers[controllerID].NodeGroups[groupID]; !ok {
return errors.New("Group does not exist: " + groupID)
}
wwlog.Printf(wwlog.VERBOSE, "Deleting group: %s\n", groupID)
delete(self.Controllers[controllerID].NodeGroups, groupID)
return nil
}
func (self *nodeYaml) GroupUpdate(group GroupInfo) error {
controllerID := group.Cid
groupID := group.Id
if _, ok := self.Controllers[controllerID]; !ok {
return errors.New("Controller does not exist: " + controllerID)
}
if _, ok := self.Controllers[controllerID].NodeGroups[groupID]; !ok {
return errors.New("Group does not exist: " + groupID)
}
self.Controllers[controllerID].NodeGroups[groupID].DomainName = group.DomainName
self.Controllers[controllerID].NodeGroups[groupID].Vnfs = group.Vnfs
self.Controllers[controllerID].NodeGroups[groupID].KernelVersion = group.KernelVersion
self.Controllers[controllerID].NodeGroups[groupID].KernelArgs = group.KernelArgs
self.Controllers[controllerID].NodeGroups[groupID].Ipxe = group.Ipxe
self.Controllers[controllerID].NodeGroups[groupID].IpmiNetmask = group.IpmiNetmask
self.Controllers[controllerID].NodeGroups[groupID].IpmiUserName = group.IpmiUserName
self.Controllers[controllerID].NodeGroups[groupID].IpmiPassword = group.IpmiPassword
self.Controllers[controllerID].NodeGroups[groupID].RuntimeOverlay = group.RuntimeOverlay
self.Controllers[controllerID].NodeGroups[groupID].SystemOverlay = group.SystemOverlay
self.Controllers[controllerID].NodeGroups[groupID].Profiles = group.Profiles
return nil
}
/****
*
* CONTROLLER MODIFIERS
*
****/
func (self *nodeYaml) AddController(controllerID string) error {
var controller ControllerConf
var group GroupConf
wwlog.Printf(wwlog.VERBOSE, "Adding new controller: %s/%s\n", controllerID)
if _, ok := self.Controllers[controllerID]; ok {
return errors.New("Controller already exists: " + controllerID)
}
self.Controllers[controllerID] = &controller
self.Controllers[controllerID].NodeGroups = make(map[string]*GroupConf)
self.Controllers[controllerID].NodeGroups["default"] = &group
return nil
}
func (self *nodeYaml) DelController(controllerID string) error {
if _, ok := self.Controllers[controllerID]; !ok {
return errors.New("Controller does not exist: " + controllerID)
}
wwlog.Printf(wwlog.VERBOSE, "Deleting controller: %s\n", controllerID)
delete(self.Controllers, controllerID)
return nil
}
func (self *nodeYaml) ControllerUpdate(controller ControllerInfo) error {
controllerID := controller.Id
if _, ok := self.Controllers[controllerID]; !ok {
return errors.New("Controller does not exist: " + controllerID)
}
self.Controllers[controllerID].Ipaddr = controller.Ipaddr
self.Controllers[controllerID].Comment = controller.Comment
self.Controllers[controllerID].Fqdn = controller.Fqdn
self.Controllers[controllerID].Services.Warewulfd.Port = controller.Services.Warewulfd.Port
self.Controllers[controllerID].Services.Warewulfd.Secure = controller.Services.Warewulfd.Secure
self.Controllers[controllerID].Services.Warewulfd.StartCmd = controller.Services.Warewulfd.StartCmd
self.Controllers[controllerID].Services.Warewulfd.RestartCmd = controller.Services.Warewulfd.RestartCmd
self.Controllers[controllerID].Services.Warewulfd.EnableCmd = controller.Services.Warewulfd.EnableCmd
self.Controllers[controllerID].Services.Dhcp.Enabled = controller.Services.Dhcp.Enabled
self.Controllers[controllerID].Services.Dhcp.ConfigFile = controller.Services.Dhcp.ConfigFile
self.Controllers[controllerID].Services.Dhcp.RangeStart = controller.Services.Dhcp.RangeStart
self.Controllers[controllerID].Services.Dhcp.RangeEnd = controller.Services.Dhcp.RangeEnd
self.Controllers[controllerID].Services.Dhcp.StartCmd = controller.Services.Dhcp.StartCmd
self.Controllers[controllerID].Services.Dhcp.RestartCmd = controller.Services.Dhcp.RestartCmd
self.Controllers[controllerID].Services.Dhcp.EnableCmd = controller.Services.Dhcp.EnableCmd
self.Controllers[controllerID].Services.Nfs.Enabled = controller.Services.Nfs.Enabled
self.Controllers[controllerID].Services.Nfs.Exports = controller.Services.Nfs.Exports
self.Controllers[controllerID].Services.Nfs.StartCmd = controller.Services.Nfs.StartCmd
self.Controllers[controllerID].Services.Nfs.RestartCmd = controller.Services.Nfs.RestartCmd
self.Controllers[controllerID].Services.Nfs.EnableCmd = controller.Services.Nfs.EnableCmd
self.Controllers[controllerID].Services.Tftp.Enabled = controller.Services.Tftp.Enabled
self.Controllers[controllerID].Services.Tftp.TftpRoot = controller.Services.Tftp.TftpRoot
self.Controllers[controllerID].Services.Tftp.StartCmd = controller.Services.Tftp.StartCmd
self.Controllers[controllerID].Services.Tftp.RestartCmd = controller.Services.Tftp.RestartCmd
self.Controllers[controllerID].Services.Tftp.EnableCmd = controller.Services.Tftp.EnableCmd
return nil return nil
} }
@@ -242,23 +89,27 @@ func (self *nodeYaml) ControllerUpdate(controller ControllerInfo) error {
* *
****/ ****/
func (self *nodeYaml) AddProfile(profileID string) error { func (self *nodeYaml) AddProfile(profileID string) (NodeInfo, error) {
var profile ProfileConf var node NodeConf
var n NodeInfo
wwlog.Printf(wwlog.VERBOSE, "Adding new profile: %s/%s\n", profileID) wwlog.Printf(wwlog.VERBOSE, "Adding new profile: %s\n", profileID)
if _, ok := self.NodeProfiles[profileID]; ok { if _, ok := self.NodeProfiles[profileID]; ok {
return errors.New("Profile name already exists: " + profileID) return n, errors.New("Profile name already exists: " + profileID)
} }
self.NodeProfiles[profileID] = &profile self.NodeProfiles[profileID] = &node
return nil n.Id.Set(profileID)
return n, nil
} }
func (self *nodeYaml) DelProfile(profileID string) error { func (self *nodeYaml) DelProfile(profileID string) error {
if _, ok := self.NodeProfiles[profileID]; !ok { if _, ok := self.NodeProfiles[profileID]; !ok {
return errors.New("Group '" + profileID + "' was not found") return errors.New("Profile does not exist: " + profileID)
} }
wwlog.Printf(wwlog.VERBOSE, "Deleting profile: %s\n", profileID) wwlog.Printf(wwlog.VERBOSE, "Deleting profile: %s\n", profileID)
@@ -267,22 +118,37 @@ func (self *nodeYaml) DelProfile(profileID string) error {
return nil return nil
} }
func (self *nodeYaml) ProfileUpdate(profile ProfileInfo) error { func (self *nodeYaml) ProfileUpdate(profile NodeInfo) error {
profileID := profile.Id profileID := profile.Id.Get()
if _, ok := self.NodeProfiles[profileID]; !ok { if _, ok := self.NodeProfiles[profileID]; !ok {
return errors.New("Group '" + profileID + "' was not found") return errors.New("Profile name does not exist: " + profileID)
} }
self.NodeProfiles[profileID].Comment = profile.Comment.GetReal()
self.NodeProfiles[profileID].Vnfs = profile.Vnfs.GetReal()
self.NodeProfiles[profileID].Ipxe = profile.Ipxe.GetReal()
self.NodeProfiles[profileID].KernelVersion = profile.KernelVersion.GetReal()
self.NodeProfiles[profileID].KernelArgs = profile.KernelArgs.GetReal()
self.NodeProfiles[profileID].IpmiIpaddr = profile.IpmiIpaddr.GetReal()
self.NodeProfiles[profileID].IpmiNetmask = profile.IpmiNetmask.GetReal()
self.NodeProfiles[profileID].IpmiUserName = profile.IpmiUserName.GetReal()
self.NodeProfiles[profileID].IpmiPassword = profile.IpmiPassword.GetReal()
self.NodeProfiles[profileID].RuntimeOverlay = profile.RuntimeOverlay.GetReal()
self.NodeProfiles[profileID].SystemOverlay = profile.SystemOverlay.GetReal()
self.NodeProfiles[profileID].Profiles = profile.Profiles
self.NodeProfiles[profileID].NetDevs = make(map[string]*NetDevs)
self.NodeProfiles[profileID].DomainName = profile.DomainName for devname, netdev := range profile.NetDevs {
self.NodeProfiles[profileID].Vnfs = profile.Vnfs var newdev NetDevs
self.NodeProfiles[profileID].Ipxe = profile.Ipxe self.NodeProfiles[profileID].NetDevs[devname] = &newdev
self.NodeProfiles[profileID].KernelVersion = profile.KernelVersion
self.NodeProfiles[profileID].IpmiNetmask = profile.IpmiNetmask self.NodeProfiles[profileID].NetDevs[devname].Ipaddr = netdev.Ipaddr.GetReal()
self.NodeProfiles[profileID].IpmiUserName = profile.IpmiUserName self.NodeProfiles[profileID].NetDevs[devname].Netmask = netdev.Netmask.GetReal()
self.NodeProfiles[profileID].IpmiPassword = profile.IpmiPassword self.NodeProfiles[profileID].NetDevs[devname].Hwaddr = netdev.Hwaddr.GetReal()
self.NodeProfiles[profileID].RuntimeOverlay = profile.RuntimeOverlay self.NodeProfiles[profileID].NetDevs[devname].Gateway = netdev.Gateway.GetReal()
self.NodeProfiles[profileID].SystemOverlay = profile.SystemOverlay self.NodeProfiles[profileID].NetDevs[devname].Type = netdev.Type.GetReal()
self.NodeProfiles[profileID].NetDevs[devname].Default = netdev.Default.GetRealB()
}
return nil return nil
} }

View File

@@ -19,7 +19,7 @@ import (
type TemplateStruct struct { type TemplateStruct struct {
Self struct { Self struct {
Fqdn string Id string
Hostname string Hostname string
GroupName string GroupName string
Vnfs string Vnfs string
@@ -57,7 +57,6 @@ func RuntimeOverlayInit(name string) error {
} }
func findAllOverlays(overlayType string) ([]string, error) { func findAllOverlays(overlayType string) ([]string, error) {
config := config.New()
var ret []string var ret []string
var files []os.FileInfo var files []os.FileInfo
var err error var err error
@@ -89,7 +88,6 @@ func findAllOverlays(overlayType string) ([]string, error) {
func overlayInit(name string, overlayType string) error { func overlayInit(name string, overlayType string) error {
var path string var path string
config := config.New()
if overlayType == "system" { if overlayType == "system" {
wwlog.Printf(wwlog.DEBUG, "Looking for system overlays...") wwlog.Printf(wwlog.DEBUG, "Looking for system overlays...")
@@ -112,49 +110,56 @@ func overlayInit(name string, overlayType string) error {
} }
func buildOverlay(nodeList []node.NodeInfo, overlayType string) error { func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
config := config.New()
nodeDB, _ := node.New() nodeDB, _ := node.New()
allNodes, _ := nodeDB.FindAllNodes() allNodes, _ := nodeDB.FindAllNodes()
for _, node := range nodeList { for _, n := range nodeList {
var t TemplateStruct var t TemplateStruct
var OverlayDir string var OverlayDir string
var OverlayFile string var OverlayFile string
if overlayType == "runtime" { if overlayType == "runtime" {
OverlayDir = config.RuntimeOverlaySource(node.RuntimeOverlay.Get()) OverlayDir = config.RuntimeOverlaySource(n.RuntimeOverlay.Get())
OverlayFile = config.RuntimeOverlayImage(node.Fqdn.Get()) OverlayFile = config.RuntimeOverlayImage(n.Id.Get())
} else if overlayType == "system" { } else if overlayType == "system" {
OverlayDir = config.SystemOverlaySource(node.RuntimeOverlay.Get()) OverlayDir = config.SystemOverlaySource(n.RuntimeOverlay.Get())
OverlayFile = config.SystemOverlayImage(node.Fqdn.Get()) OverlayFile = config.SystemOverlayImage(n.Id.Get())
} else { } else {
wwlog.Printf(wwlog.ERROR, "overlayType requested is not supported: %s\n", overlayType) wwlog.Printf(wwlog.ERROR, "overlayType requested is not supported: %s\n", overlayType)
os.Exit(1) os.Exit(1)
} }
wwlog.Printf(wwlog.DEBUG, "Processing overlay for node: %s\n", node.Fqdn.Get()) wwlog.Printf(wwlog.DEBUG, "Processing overlay for node: %s\n", n.Id.Get())
t.Self.Fqdn = node.Fqdn.Get() t.Self.Id = n.Id.Get()
t.Self.Hostname = node.HostName.Get() t.Self.Hostname = n.Id.Get()
t.Self.GroupName = node.Gid.Get() t.Self.Vnfs = n.Vnfs.Get()
t.Self.Vnfs = node.Vnfs.Get() t.Self.IpmiIpaddr = n.IpmiIpaddr.Get()
t.Self.IpmiIpaddr = node.IpmiIpaddr.Get() t.Self.IpmiNetmask = n.IpmiNetmask.Get()
t.Self.IpmiNetmask = node.IpmiNetmask.Get() t.Self.IpmiUserName = n.IpmiUserName.Get()
t.Self.IpmiUserName = node.IpmiUserName.Get() t.Self.IpmiPassword = n.IpmiPassword.Get()
t.Self.IpmiPassword = node.IpmiPassword.Get() t.Self.NetDevs = make(map[string]*node.NetDevs)
t.Self.NetDevs = node.NetDevs for devname, netdev := range n.NetDevs {
var nd node.NetDevs
t.Self.NetDevs[devname] = &nd
t.Self.NetDevs[devname].Hwaddr = netdev.Hwaddr.Get()
t.Self.NetDevs[devname].Ipaddr = netdev.Ipaddr.Get()
t.Self.NetDevs[devname].Netmask = netdev.Netmask.Get()
t.Self.NetDevs[devname].Gateway = netdev.Gateway.Get()
t.Self.NetDevs[devname].Type = netdev.Type.Get()
}
t.AllNodes = allNodes t.AllNodes = allNodes
if overlayType == "runtime" && node.RuntimeOverlay.Defined() == false { if overlayType == "runtime" && n.RuntimeOverlay.Defined() == false {
wwlog.Printf(wwlog.WARN, "Undefined runtime overlay, skipping node: %s\n", node.Fqdn.Get()) wwlog.Printf(wwlog.WARN, "Undefined runtime overlay, skipping node: %s\n", n.Id.Get())
} }
if overlayType == "system" && node.SystemOverlay.Defined() == false { if overlayType == "system" && n.SystemOverlay.Defined() == false {
wwlog.Printf(wwlog.WARN, "Undefined system overlay, skipping node: %s\n", node.Fqdn.Get()) wwlog.Printf(wwlog.WARN, "Undefined system overlay, skipping node: %s\n", n.Id.Get())
} }
wwlog.Printf(wwlog.DEBUG, "Checking to see if overlay directory exists: %s\n", OverlayDir) wwlog.Printf(wwlog.DEBUG, "Checking to see if overlay directory exists: %s\n", OverlayDir)
if util.IsDir(OverlayDir) == false { if util.IsDir(OverlayDir) == false {
wwlog.Printf(wwlog.WARN, "%-35s: Skipped (runtime overlay template not found)\n", node.Fqdn.Get()) wwlog.Printf(wwlog.WARN, "%-35s: Skipped (runtime overlay template not found)\n", n.Id.Get())
continue continue
} }
@@ -203,7 +208,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
}).ParseGlob(path.Join(OverlayDir, destFile+".ww*")) }).ParseGlob(path.Join(OverlayDir, destFile+".ww*"))
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err return nil
} }
w, err := os.OpenFile(path.Join(tmpDir, destFile), os.O_RDWR|os.O_CREATE, info.Mode()) w, err := os.OpenFile(path.Join(tmpDir, destFile), os.O_RDWR|os.O_CREATE, info.Mode())
@@ -216,7 +221,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
err = tmpl.Execute(w, t) err = tmpl.Execute(w, t)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err) wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err return nil
} }
} else if b, _ := regexp.MatchString(`\.ww[a-zA-Z0-9\-\._]*$`, location); b == true { } else if b, _ := regexp.MatchString(`\.ww[a-zA-Z0-9\-\._]*$`, location); b == true {
@@ -235,7 +240,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
return nil return nil
}) })
wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", node.Fqdn.Get()) wwlog.Printf(wwlog.VERBOSE, "Finished generating overlay directory for: %s\n", n.Id.Get())
cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc -F \"%s\"", tmpDir, OverlayFile) cmd := fmt.Sprintf("cd \"%s\"; find . | cpio --quiet -o -H newc -F \"%s\"", tmpDir, OverlayFile)
wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd) wwlog.Printf(wwlog.DEBUG, "RUNNING: %s\n", cmd)
@@ -244,7 +249,7 @@ func buildOverlay(nodeList []node.NodeInfo, overlayType string) error {
wwlog.Printf(wwlog.ERROR, "Could not generate runtime image overlay: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not generate runtime image overlay: %s\n", err)
continue continue
} }
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", node.Fqdn.Get()) wwlog.Printf(wwlog.INFO, "%-35s: Done\n", n.Id.Get())
wwlog.Printf(wwlog.DEBUG, "Removing temporary directory: %s\n", tmpDir) wwlog.Printf(wwlog.DEBUG, "Removing temporary directory: %s\n", tmpDir)
os.RemoveAll(tmpDir) os.RemoveAll(tmpDir)

View File

@@ -11,7 +11,6 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"time" "time"
// "strings" // "strings"
) )
@@ -90,8 +89,9 @@ func CopyFile(source string, dest string) error {
//TODO: func CopyRecursive ... //TODO: func CopyRecursive ...
func IsDir(path string) bool {
wwlog.Printf(wwlog.DEBUG, "Chcking if path exists as a directory: %s\n", path)
func IsDir(path string) (bool) {
if path == "" { if path == "" {
return false return false
} }
@@ -101,7 +101,9 @@ func IsDir(path string) (bool) {
return false return false
} }
func IsFile(path string) (bool) { func IsFile(path string) bool {
wwlog.Printf(wwlog.DEBUG, "Chcking if path exists as a file: %s\n", path)
if path == "" { if path == "" {
return false return false
} }
@@ -112,7 +114,6 @@ func IsFile(path string) (bool) {
return false return false
} }
func TaintCheck(pattern string, expr string) bool { func TaintCheck(pattern string, expr string) bool {
if b, _ := regexp.MatchString(expr, pattern); b == true { if b, _ := regexp.MatchString(expr, pattern); b == true {
return true return true
@@ -148,7 +149,7 @@ func FindFiles(path string) []string {
if IsDir(location) == true { if IsDir(location) == true {
wwlog.Printf(wwlog.DEBUG, "FindFiles() found directory: %s\n", location) wwlog.Printf(wwlog.DEBUG, "FindFiles() found directory: %s\n", location)
ret = append(ret, location +"/") ret = append(ret, location+"/")
} else { } else {
wwlog.Printf(wwlog.DEBUG, "FindFiles() found file: %s\n", location) wwlog.Printf(wwlog.DEBUG, "FindFiles() found file: %s\n", location)
ret = append(ret, location) ret = append(ret, location)
@@ -163,7 +164,7 @@ func FindFiles(path string) []string {
return ret return ret
} }
func ExecInteractive(command string, a...string) error { func ExecInteractive(command string, a ...string) error {
wwlog.Printf(wwlog.DEBUG, "ExecInteractive(%s, %s)\n", command, a) wwlog.Printf(wwlog.DEBUG, "ExecInteractive(%s, %s)\n", command, a)
c := exec.Command(command, a...) c := exec.Command(command, a...)
c.Stdin = os.Stdin c.Stdin = os.Stdin
@@ -173,8 +174,6 @@ func ExecInteractive(command string, a...string) error {
return err return err
} }
func ShaSumFile(file string) (string, error) { func ShaSumFile(file string) (string, error) {
var ret string var ret string
@@ -192,7 +191,6 @@ func ShaSumFile(file string) (string, error) {
return fmt.Sprintf("%x", h.Sum(nil)), nil return fmt.Sprintf("%x", h.Sum(nil)), nil
} }
func SliceRemoveElement(array []string, remove string) []string { func SliceRemoveElement(array []string, remove string) []string {
var ret []string var ret []string
@@ -225,4 +223,4 @@ func SliceAddUniqueElement(array []string, add string) []string {
} }
return ret return ret
} }

View File

@@ -10,10 +10,8 @@ import (
"path" "path"
) )
func BuildDocker(vnfs VnfsObject, buildForce bool) { func BuildDocker(vnfs VnfsObject, buildForce bool) {
wwlog.Printf(wwlog.VERBOSE, "Building OCI Container: %s\n", vnfs.Source) wwlog.Printf(wwlog.VERBOSE, "Building OCI Container: %s\n", vnfs.Source)
config := config.New()
OciCacheDir := config.LocalStateDir + "/oci" OciCacheDir := config.LocalStateDir + "/oci"
VnfsHashDir := config.LocalStateDir + "/oci/vnfs" VnfsHashDir := config.LocalStateDir + "/oci/vnfs"
@@ -73,12 +71,12 @@ func BuildDocker(vnfs VnfsObject, buildForce bool) {
// Setup links from OCI image to provision path // Setup links from OCI image to provision path
_ = os.Remove(vnfs.Image + "-link") _ = os.Remove(vnfs.Image + "-link")
err = os.Symlink(hashDestination, vnfs.Image + "-link") err = os.Symlink(hashDestination, vnfs.Image+"-link")
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not create symlink for Image: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not create symlink for Image: %s\n", err)
os.Exit(1) os.Exit(1)
} }
err = os.Rename(vnfs.Image + "-link", vnfs.Image) err = os.Rename(vnfs.Image+"-link", vnfs.Image)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err)
os.Exit(1) os.Exit(1)
@@ -86,20 +84,18 @@ func BuildDocker(vnfs VnfsObject, buildForce bool) {
// Setup links from OCI rootfs to chroot path // Setup links from OCI rootfs to chroot path
_ = os.Remove(vnfs.Chroot + "-link") _ = os.Remove(vnfs.Chroot + "-link")
err = os.Symlink(sourcePath, vnfs.Chroot + "-link") err = os.Symlink(sourcePath, vnfs.Chroot+"-link")
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not create symlink for Chroot: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not create symlink for Chroot: %s\n", err)
os.Exit(1) os.Exit(1)
} }
err = os.Rename(vnfs.Chroot + "-link", vnfs.Chroot) err = os.Rename(vnfs.Chroot+"-link", vnfs.Chroot)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err) wwlog.Printf(wwlog.ERROR, "Could not rename link: %s\n", err)
os.Exit(1) os.Exit(1)
} }
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", vnfs.Source) wwlog.Printf(wwlog.INFO, "%-35s: Done\n", vnfs.Source)
return return
} }

View File

@@ -13,15 +13,14 @@ import (
) )
type VnfsObject struct { type VnfsObject struct {
Name string Name string
Source string Source string
Chroot string Chroot string
Image string Image string
Config string Config string
} }
func Load (name string) (VnfsObject, error) { func Load(name string) (VnfsObject, error) {
config := config.New()
var ret VnfsObject var ret VnfsObject
if name == "" { if name == "" {
@@ -68,7 +67,6 @@ func CleanName(source string) string {
func New(source string) (VnfsObject, error) { func New(source string) (VnfsObject, error) {
var ret VnfsObject var ret VnfsObject
config := config.New()
if source == "" { if source == "" {
wwlog.Printf(wwlog.DEBUG, "Called vnfs.Load() without a name, returning error\n") wwlog.Printf(wwlog.DEBUG, "Called vnfs.Load() without a name, returning error\n")
@@ -122,11 +120,6 @@ func (self *VnfsObject) SaveConfig() error {
return nil return nil
} }
func Build(name string, force bool) error { func Build(name string, force bool) error {
vnfs, err := New(name) vnfs, err := New(name)
@@ -154,12 +147,6 @@ func Build(name string, force bool) error {
return nil return nil
} }
func (self *VnfsObject) Nameold() string { func (self *VnfsObject) Nameold() string {
if self.Source == "" { if self.Source == "" {
return "" return ""
@@ -183,4 +170,4 @@ func NameClean1(SourcePath string) string {
uri := strings.Split(SourcePath, "://") uri := strings.Split(SourcePath, "://")
return strings.ReplaceAll(uri[0]+":"+uri[1], "/", "_") return strings.ReplaceAll(uri[0]+":"+uri[1], "/", "_")
} }

View File

@@ -0,0 +1,33 @@
package warewulfconf
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
"io/ioutil"
)
func New() (ControllerConf, error) {
var ret ControllerConf
wwlog.Printf(wwlog.DEBUG, "Opening Warewulf configuration file: %s\n", ConfigFile)
data, err := ioutil.ReadFile(ConfigFile)
if err != nil {
fmt.Printf("error reading node configuration file\n")
return ret, err
}
wwlog.Printf(wwlog.DEBUG, "Unmarshaling the Warewulf configuration\n")
err = yaml.Unmarshal(data, &ret)
if err != nil {
return ret, err
}
if ret.Warewulf.Port == 0 {
ret.Warewulf.Port = 9873
}
wwlog.Printf(wwlog.DEBUG, "Returning node object\n")
return ret, nil
}

View File

@@ -0,0 +1,59 @@
package warewulfconf
import (
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"os"
)
const ConfigFile = "/etc/warewulf/warewulf.conf"
type ControllerConf struct {
Comment string `yaml:"comment"`
Ipaddr string `yaml:"ipaddr"`
Netmask string `yaml:"netmask,omitempty"`
Fqdn string `yaml:"fqdn,omitempty"`
Warewulf *WarewulfConf `yaml:"warewulf"`
Dhcp *DhcpConf `yaml:"dhcp"`
Tftp *TftpConf `yaml:"tftp"`
Nfs *NfsConf `yaml:"nfs"`
}
type WarewulfConf struct {
Port int `yaml:"port,omitempty"`
Secure bool `yaml:"secure,omitempty"`
Enable string `yaml:"enable command,omitempty"`
Restart string `yaml:"restart command,omitempty"`
}
type DhcpConf struct {
Enabled bool `yaml:"enabled"`
Template string `yaml:"template,omitempty"`
RangeStart string `yaml:"range start,omitempty"`
RangeEnd string `yaml:"range end,omitempty"`
ConfigFile string `yaml:"config file,omitempty"`
Enable string `yaml:"enable command,omitempty"`
Restart string `yaml:"restart command,omitempty"`
}
type TftpConf struct {
Enabled bool `yaml:"enabled"`
Root string `yaml:"root,omitempty"`
Enable string `yaml:"enable command,omitempty"`
Restart string `yaml:"restart command,omitempty"`
}
type NfsConf struct {
Enabled bool `yaml:"enabled"`
Exports []string `yaml:"exports,omitempty"`
Enable string `yaml:"enable command,omitempty"`
Restart string `yaml:"restart command,omitempty"`
}
func init() {
//TODO: Check to make sure nodes.conf is found
if util.IsFile(ConfigFile) == false {
wwlog.Printf(wwlog.ERROR, "Configuration file not found: %s\n", ConfigFile)
os.Exit(1)
}
}

View File

@@ -0,0 +1,30 @@
package warewulfconf
import (
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
"os"
)
func (self *ControllerConf) Persist() error {
out, err := yaml.Marshal(self)
if err != nil {
return err
}
file, err := os.OpenFile(ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer file.Close()
_, err = file.WriteString(string(out))
if err != nil {
return err
}
return nil
}

View File

@@ -3,10 +3,10 @@
{{range $node := $.AllNodes}} {{range $node := $.AllNodes}}
# Entry for {{$node.Fqdn}} # Entry for {{$node.Id}}
{{- range $devname, $netdev := $node.NetDevs}} {{- range $devname, $netdev := $node.NetDevs}}
{{- if $netdev.Default}} {{- if $netdev.Default}}
{{$netdev.Ipaddr}} {{$node.Fqdn}} {{$netdev.Ipaddr}} {{$node.Id}}
{{- else}} {{- else}}
{{$netdev.Ipaddr}} {{$node.Fqdn}}-{{$devname}} {{$netdev.Ipaddr}} {{$node.Fqdn}}-{{$devname}}
{{- end}} {{- end}}

View File

@@ -1 +1 @@
{{$.Self.Fqdn}} {{$.Self.Id}}

View File

@@ -1,2 +1,2 @@
NETWORKING=yes NETWORKING=yes
HOSTNAME={{$.Self.Fqdn}} HOSTNAME={{$.Self.Id}}