Merge upstream

This commit is contained in:
Carter Dodd
2022-05-13 19:42:18 -05:00
22 changed files with 88 additions and 47 deletions

View File

@@ -104,7 +104,7 @@ func update42to43(conf42 vers42.NodeConf) vers43.NodeConf {
var device vers43.NetDevs = vers43.NetDevs{
Type: netdev.Type,
Device: devn,
Default: printB(netdev.Default),
Primary: printB(netdev.Default),
Hwaddr: netdev.Hwaddr,
Ipaddr: netdev.Ipaddr,
IpCIDR: netdev.IpCIDR,

View File

@@ -60,6 +60,6 @@ type NetDevs struct {
Prefix string `yaml:"prefix,omitempty"`
Netmask string `yaml:"netmask,omitempty"`
Gateway string `yaml:"gateway,omitempty"`
Default string `yaml:"default,omitempty"`
Primary string `yaml:"primary,omitempty"`
Tags map[string]string `yaml:"tags,omitempty"`
}

View File

@@ -130,8 +130,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Warn("Could not copy /etc/resolv.conf into container: %s", err)
}
err = container.SyncUids(name, !NoSyncUser)
if err != nil && !NoSyncUser {
err = container.SyncUids(name, !SyncUser)
if err != nil && !SyncUser {
wwlog.Error("Error in user sync, fix error and run 'syncuser' manually: %s", err)
os.Exit(1)
}

View File

@@ -24,7 +24,7 @@ Imported containers are used to create bootable VNFS images.`,
SetUpdate bool
SetBuild bool
SetDefault bool
NoSyncUser bool
SyncUser bool
)
func init() {
@@ -32,7 +32,7 @@ func init() {
baseCmd.PersistentFlags().BoolVarP(&SetUpdate, "update", "u", false, "Update and overwrite an existing container")
baseCmd.PersistentFlags().BoolVarP(&SetBuild, "build", "b", false, "Build container when after pulling")
baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this container for the default profile")
baseCmd.PersistentFlags().BoolVar(&NoSyncUser, "nosyncuser", false, "Don't synchronize uis/gods from host to container")
baseCmd.PersistentFlags().BoolVar(&SyncUser, "syncuser", false, "Synchronize uis/gods from host to container")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -14,7 +14,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if !container.ValidName(containerName) {
return fmt.Errorf("%s is not a valid container", containerName)
}
err := container.SyncUids(containerName, noSyncUser)
err := container.SyncUids(containerName, !write)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Error in synchronize: %s\n", err)
os.Exit(1)

View File

@@ -24,11 +24,11 @@ uid/gid collision is detected. File ownerships are also changed.`,
Args: cobra.MinimumNArgs(1),
}
noSyncUser bool
write bool
)
func init() {
baseCmd.PersistentFlags().BoolVar(&noSyncUser, "nosyncuser", false, "Don't synchronize uis/gods just check")
baseCmd.PersistentFlags().BoolVar(&write, "write", false, "Synchronize uis/gids and write files in container")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -71,7 +71,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
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())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":ONBOOT", netdev.OnBoot.Source(), netdev.OnBoot.PrintB())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":DEFAULT", netdev.Default.Source(), netdev.Default.PrintB())
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":PRIMARY", netdev.Primary.Source(), netdev.Primary.PrintB())
for keyname, key := range netdev.Tags {
fmt.Printf("%-20s %-18s %-12s %s\n", node.Id.Get(), name+":TAG["+keyname+"]", key.Source(), key.Print())
}

View File

@@ -188,13 +188,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
SetNetOnBoot = "yes"
for _, n := range n.NetDevs {
if n.Default.GetB() {
if n.Primary.GetB() {
def = false
}
}
if def {
SetNetDefault = "yes"
SetNetPrimary = "yes"
}
}
@@ -276,24 +276,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
if SetNetDefault != "" {
if SetNetPrimary != "" {
if SetNetName == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n")
os.Exit(1)
}
if SetNetDefault == "yes" || SetNetDefault == "y" || SetNetDefault == "1" || SetNetDefault == "true" {
if SetNetPrimary == "yes" || SetNetPrimary == "y" || SetNetPrimary == "1" || SetNetPrimary == "true" {
// Set all other devices to non-default
for _, n := range n.NetDevs {
n.Default.SetB(false)
n.Primary.SetB(false)
}
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Setting PRIMARY\n", n.Id.Get(), SetNetName)
n.NetDevs[SetNetName].Default.SetB(true)
n.NetDevs[SetNetName].Primary.SetB(true)
} else {
wwlog.Printf(wwlog.VERBOSE, "Node: %s:%s, Unsetting PRIMARY\n", n.Id.Get(), SetNetName)
n.NetDevs[SetNetName].Default.SetB(false)
n.NetDevs[SetNetName].Primary.SetB(false)
}
}

View File

@@ -44,7 +44,7 @@ var (
SetHwaddr string
SetType string
SetNetOnBoot string
SetNetDefault string
SetNetPrimary string
SetNetDevDel bool
SetClusterName string
SetIpxe string
@@ -143,7 +143,7 @@ func init() {
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
baseCmd.PersistentFlags().StringVarP(&SetType, "type", "T", "", "Set the node's network device type")
baseCmd.PersistentFlags().StringVar(&SetNetOnBoot, "onboot", "", "Enable/disable device (yes/no)")
baseCmd.PersistentFlags().StringVar(&SetNetDefault, "primary", "", "Enable/disable device as primary (yes/no)")
baseCmd.PersistentFlags().StringVar(&SetNetPrimary, "primary", "", "Enable/disable device as primary (yes/no)")
baseCmd.PersistentFlags().BoolVar(&SetNetDevDel, "netdel", false, "Delete the node's network device")
baseCmd.PersistentFlags().StringSliceVar(&SetNetTags, "nettag", []string{}, "Define custom tag to network device (key=value)")

View File

@@ -7,6 +7,7 @@ import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"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/pkg/hostlist"
@@ -37,7 +38,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
args = hostlist.Expand(args)
for _, node := range nodes {
return overlay.BuildOverlayIndir(node, strings.Split(OverlayName, ","), OverlayDir)
if util.InSlice(node.RuntimeOverlay.GetSlice(), OverlayName) ||
util.InSlice(node.SystemOverlay.GetSlice(), OverlayName) {
return overlay.BuildOverlayIndir(node, strings.Split(OverlayName, ","), OverlayDir)
} else {
return errors.New("no node uses the given overlay")
}
}
} else {
var host node.NodeInfo
@@ -68,7 +74,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
} else {
if OverlayName != "" {
err = overlay.BuildSpecificOverlays(nodes, OverlayName)
for _, n := range nodes {
if util.InSlice(n.RuntimeOverlay.GetSlice(), OverlayName) ||
util.InSlice(n.SystemOverlay.GetSlice(), OverlayName) {
err = overlay.BuildSpecificOverlays([]node.NodeInfo{n}, OverlayName)
}
}
} else {
err = overlay.BuildAllOverlays(nodes)
}

View File

@@ -62,7 +62,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":HWADDR", netdev.Hwaddr.Print())
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":TYPE", netdev.Hwaddr.Print())
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":ONBOOT", netdev.OnBoot.PrintB())
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":DEFAULT", netdev.Default.PrintB())
fmt.Printf("%-20s %-18s %s\n", profile.Id.Get(), name+":PRIMARY", netdev.Primary.PrintB())
for keyname, key := range netdev.Tags {
fmt.Printf("%-20s %-18s %-12s %s\n", profile.Id.Get(), name+":TAG["+keyname+"]", key.Source(), key.Print())
}

View File

@@ -211,24 +211,24 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
if SetNetDefault != "" {
if SetNetPrimary != "" {
if SetNetName == "" {
wwlog.Printf(wwlog.ERROR, "You must include the '--netname' option\n")
os.Exit(1)
}
if SetNetDefault == "yes" || SetNetDefault == "y" || SetNetDefault == "1" || SetNetDefault == "true" {
if SetNetPrimary == "yes" || SetNetPrimary == "y" || SetNetPrimary == "1" || SetNetPrimary == "true" {
// Set all other networks to non-default
for _, n := range p.NetDevs {
n.Default.SetB(false)
n.Primary.SetB(false)
}
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Setting PRIMARY\n", p.Id.Get(), SetNetName)
p.NetDevs[SetNetName].Default.SetB(true)
p.NetDevs[SetNetName].Primary.SetB(true)
} else {
wwlog.Printf(wwlog.VERBOSE, "Profile: %s:%s, Unsetting PRIMARY\n", p.Id.Get(), SetNetName)
p.NetDevs[SetNetName].Default.SetB(false)
p.NetDevs[SetNetName].Primary.SetB(false)
}
}

View File

@@ -57,7 +57,7 @@ var (
SetGateway string
SetType string
SetNetOnBoot string
SetNetDefault string
SetNetPrimary string
SetNetDevDel bool
SetDiscoverable bool
SetUndiscoverable bool
@@ -118,7 +118,7 @@ func init() {
baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure")
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Set the node's network device")
baseCmd.PersistentFlags().StringVar(&SetNetDefault, "primary", "", "Enable/disable device as primary (yes/no)")
baseCmd.PersistentFlags().StringVar(&SetNetPrimary, "primary", "", "Enable/disable device as primary (yes/no)")
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(&SetType, "type", "T", "", "Set the node's network device type")

View File

@@ -100,7 +100,8 @@ func SyncUids(containerName string, showOnly bool) error {
*/
}
if !showOnly {
if showOnly {
wwlog.Printf(wwlog.INFO, "uid./gid not synced, run \nwwctl container syncuser --write %s\nto synchronize uid/gids.\n", containerName)
return nil
}
// create list of files which need changed ownerships in order to change them later what

View File

@@ -166,10 +166,11 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.NetDevs[devname].Gateway.Set(netdev.Gateway)
n.NetDevs[devname].Type.Set(netdev.Type)
n.NetDevs[devname].OnBoot.Set(netdev.OnBoot)
n.NetDevs[devname].Default.Set(netdev.Default)
// for just one netdev, it is always the default
n.NetDevs[devname].Primary.Set(netdev.Primary)
n.NetDevs[devname].Primary.Set(netdev.Default) // backwards compatibility
// for just one netdev, it is always the primary
if len(node.NetDevs) == 1 {
n.NetDevs[devname].Default.Set("true")
n.NetDevs[devname].Primary.Set("true")
}
n.NetDevs[devname].Tags = make(map[string]*Entry)
for keyname, key := range netdev.Tags {
@@ -253,7 +254,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.NetDevs[devname].Gateway.SetAlt(netdev.Gateway, p)
n.NetDevs[devname].Type.SetAlt(netdev.Type, p)
n.NetDevs[devname].OnBoot.SetAlt(netdev.OnBoot, p)
n.NetDevs[devname].Default.SetAlt(netdev.Default, p)
n.NetDevs[devname].Primary.SetAlt(netdev.Primary, p)
if len(netdev.Tags) != 0 {
for keyname, key := range netdev.Tags {
if _, ok := n.NetDevs[devname].Tags[keyname]; !ok {
@@ -376,7 +377,8 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) {
p.NetDevs[devname].Gateway.Set(netdev.Gateway)
p.NetDevs[devname].Type.Set(netdev.Type)
p.NetDevs[devname].OnBoot.Set(netdev.OnBoot)
p.NetDevs[devname].Default.Set(netdev.Default)
p.NetDevs[devname].Primary.Set(netdev.Primary)
p.NetDevs[devname].Primary.Set(netdev.Default) // backwards compatibility
// The following should not be set in a profile.
if netdev.Ipaddr != "" {

View File

@@ -75,7 +75,8 @@ type NetDevs struct {
Prefix string `yaml:"prefix,omitempty"`
Netmask string `yaml:"netmask,omitempty"`
Gateway string `yaml:"gateway,omitempty"`
Default string `yaml:"primary,omitempty"`
Primary string `yaml:"primary,omitempty"`
Default string `yaml:"default,omitempty"` /* backward compatibility */
Tags map[string]string `yaml:"tags,omitempty"`
}
@@ -149,7 +150,7 @@ type NetDevEntry struct {
Prefix Entry
Netmask Entry
Gateway Entry
Default Entry
Primary Entry
Tags map[string]*Entry
}

View File

@@ -101,7 +101,7 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error {
config.Nodes[nodeID].NetDevs[devname].Gateway = netdev.Gateway.GetReal()
config.Nodes[nodeID].NetDevs[devname].Type = netdev.Type.GetReal()
config.Nodes[nodeID].NetDevs[devname].OnBoot = netdev.OnBoot.GetReal()
config.Nodes[nodeID].NetDevs[devname].Default = netdev.Default.GetReal()
config.Nodes[nodeID].NetDevs[devname].Primary = netdev.Primary.GetReal()
config.Nodes[nodeID].NetDevs[devname].Tags = make(map[string]string)
for keyname, key := range netdev.Tags {
if key.GetReal() != "" {
@@ -207,7 +207,7 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error {
config.NodeProfiles[profileID].NetDevs[devname].Gateway = netdev.Gateway.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Type = netdev.Type.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].OnBoot = netdev.OnBoot.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Default = netdev.Default.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Primary = netdev.Primary.GetReal()
config.NodeProfiles[profileID].NetDevs[devname].Tags = make(map[string]string)
for key := range netdev.Tags {
config.NodeProfiles[profileID].NetDevs[devname].Tags[key] = netdev.Tags[key].GetReal()

View File

@@ -254,7 +254,7 @@ func BuildOverlayIndir(nodeInfo node.NodeInfo, overlayNames []string, outputDir
tstruct.NetDevs[devname].Gateway = netdev.Gateway.Get()
tstruct.NetDevs[devname].Type = netdev.Type.Get()
tstruct.NetDevs[devname].OnBoot = netdev.OnBoot.Get()
tstruct.NetDevs[devname].Default = netdev.Default.Get()
tstruct.NetDevs[devname].Primary = netdev.Primary.Get()
mask := net.IPMask(net.ParseIP(netdev.Netmask.Get()).To4())
ipaddr := net.ParseIP(netdev.Ipaddr.Get()).To4()
netaddr := net.IPNet{IP: ipaddr, Mask: mask}

View File

@@ -74,6 +74,33 @@ func RandomString(n int) string {
return string(b)
}
/*
Checks if given string is in slice. I yes returns true, false otherwise.
*/
func InSlice(slice []string, match string) bool {
for _, val := range slice {
if val == match {
return true
}
}
return false
}
/*
Checks if one or more elements of a slice A are a part of slice B. Returns true
as soon as one element matches.\
*/
func SliceInSlice(A []string, B []string) bool {
for _, a := range A {
for _, b := range B {
if a == b {
return true
}
}
}
return false
}
func IsDir(path string) bool {
wwlog.Debug("Checking if path exists as a directory: %s", path)

View File

@@ -71,7 +71,7 @@ host {{$nodes.Id.Get}}-{{if $netdevs.Device.Defined}}{{$netdevs.Device.Get}}{{el
{{- if $netdevs.Ipaddr.Defined}}
fixed-address {{$netdevs.Ipaddr.Get}};
{{- end}}
{{- if $netdevs.Default.GetB}}
{{- if $netdevs.Primary.GetB}}
option host-name "{{$nodes.Id.Get}}";
{{else}}
option host-name "{{$nodes.Id.Get}}-{{if $netdevs.Device.Defined}}{{$netdevs.Device.Get}}{{else}}{{$netname}}{{end}}";

View File

@@ -10,11 +10,10 @@
# Entry for {{$node.Id.Get}}
{{- range $devname, $netdev := $node.NetDevs}} {{/* for each network device on the node */}}
{{- if $netdev.Ipaddr.Defined}} {{/* if we have an ip address on this network device */}}
{{- /* emit the node name as hostname if this is the default */}}
{{$netdev.Ipaddr.Get}}
{{- if $netdev.Default.GetB}} {{$node.Id.Get}}
{{else}} {{$node.Id.Get}}-{{if $netdev.Device.Defined}}{{$netdev.Device.Get}}{{else}}{{$devname}}{{end}}
{{- end}}
{{- /* emit the node name as hostname if this is the primary */}}
{{$netdev.Ipaddr.Get}} {{$node.Id.Get}}-{{$devname}}
{{- if $netdev.Device.Defined}} {{$node.Id.Get}}-{{$netdev.Device.Get}}{{end}}
{{- if $netdev.Primary.GetB}} {{$node.Id.Get}}{{end}}
{{- end}} {{/* end if ip */}}
{{- end}} {{/* end for each network device */}}
{{- end}} {{/* end for each node */}}

View File

@@ -1,6 +1,6 @@
# /etc/systemd/network/10-persistent-net.link
{{range $devname, $netdev := .NetDevs}}
{{- if $netdev.Default}}
{{- if $netdev.Primary}}
[Match]
MACAddress={{$netdev.Hwaddr}}
[Link]