store the ovelats as yaml list

This commit is contained in:
Christian Goll
2022-03-24 19:45:51 +01:00
parent a2fd8ab112
commit c0f7ecf357
10 changed files with 174 additions and 80 deletions

View File

@@ -95,8 +95,8 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.IpmiPassword.Set(node.IpmiPassword)
n.IpmiInterface.Set(node.IpmiInterface)
n.IpmiWrite.SetB(node.IpmiWrite)
n.SystemOverlay.Set(node.SystemOverlay)
n.RuntimeOverlay.Set(node.RuntimeOverlay)
n.SystemOverlay.SetSlice(node.SystemOverlay)
n.RuntimeOverlay.SetSlice(node.RuntimeOverlay)
n.Root.Set(node.Root)
n.AssetKey.Set(node.AssetKey)
n.Discoverable.Set(node.Discoverable)
@@ -181,8 +181,8 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
n.IpmiPassword.SetAlt(config.NodeProfiles[p].IpmiPassword, p)
n.IpmiInterface.SetAlt(config.NodeProfiles[p].IpmiInterface, p)
n.IpmiWrite.SetB(config.NodeProfiles[p].IpmiWrite)
n.SystemOverlay.SetAlt(config.NodeProfiles[p].SystemOverlay, p)
n.RuntimeOverlay.SetAlt(config.NodeProfiles[p].RuntimeOverlay, p)
n.SystemOverlay.SetAltSlice(config.NodeProfiles[p].SystemOverlay, p)
n.RuntimeOverlay.SetAltSlice(config.NodeProfiles[p].RuntimeOverlay, p)
n.Root.SetAlt(config.NodeProfiles[p].Root, p)
n.AssetKey.SetAlt(config.NodeProfiles[p].AssetKey, p)
n.Discoverable.SetAlt(config.NodeProfiles[p].Discoverable, p)
@@ -268,8 +268,8 @@ func (config *nodeYaml) FindAllProfiles() ([]NodeInfo, error) {
p.IpmiPassword.Set(profile.IpmiPassword)
p.IpmiInterface.Set(profile.IpmiInterface)
p.IpmiWrite.SetB(profile.IpmiWrite)
p.RuntimeOverlay.Set(profile.RuntimeOverlay)
p.SystemOverlay.Set(profile.SystemOverlay)
p.RuntimeOverlay.SetSlice(profile.RuntimeOverlay)
p.SystemOverlay.SetSlice(profile.SystemOverlay)
p.Root.Set(profile.Root)
p.AssetKey.Set(profile.AssetKey)
p.Discoverable.Set(profile.Discoverable)

View File

@@ -30,8 +30,8 @@ type NodeConf struct {
IpmiGateway string `yaml:"ipmi gateway,omitempty"`
IpmiInterface string `yaml:"ipmi interface,omitempty"`
IpmiWrite bool `yaml:"ipmi write,omitempty"`
RuntimeOverlay string `yaml:"runtime overlay,omitempty"`
SystemOverlay string `yaml:"system overlay,omitempty"`
RuntimeOverlay []string `yaml:"runtime overlay,omitempty"`
SystemOverlay []string `yaml:"system overlay,omitempty"`
Init string `yaml:"init,omitempty"`
Root string `yaml:"root,omitempty"`
AssetKey string `yaml:"asset key,omitempty"`
@@ -59,12 +59,16 @@ type NetDevs struct {
/******
* Internal code data representations
******/
/*
Holds a strtng value, when accessed via Get, its value
is returned which is the default or if set the value
from the profile or if set the value of the node itself
*/
type Entry struct {
value string
altvalue string
value []string
altvalue []string
from string
def string
def []string
}
type NodeInfo struct {

View File

@@ -10,7 +10,10 @@ import (
* Filters
*
*********/
/*
Filter a given slice of NodeInfo against a given
regular expression
*/
func FilterByName(set []NodeInfo, searchList []string) []NodeInfo {
var ret []NodeInfo
unique := make(map[string]NodeInfo)
@@ -40,46 +43,94 @@ func FilterByName(set []NodeInfo, searchList []string) []NodeInfo {
*
*********/
/*
Set value. If argument is 'UNDEF', 'DELETE',
'UNSET" or '--'. The value is removed.
N.B. the '--' might never ever happen as '--'
is parsed out by cobra
*/
func (ent *Entry) Set(val string) {
if val == "" {
return
}
if val == "UNDEF" || val == "DELETE" || val == "UNSET" || val == "--" {
ent.value = ""
ent.value = []string{}
} else {
ent.value = []string{val}
}
}
/*
Set bool
*/
func (ent *Entry) SetB(val bool) {
if val {
ent.value = []string{"true"}
}
}
func (ent *Entry) SetSlice(val []string) {
if len(val) == 0 {
return
}
if val[0] == "UNDEF" || val[0] == "DELETE" || val[0] == "UNSET" || val[0] == "--" {
ent.value = []string{}
} else {
ent.value = val
}
}
func (ent *Entry) SetB(val bool) {
if val {
ent.value = "true"
}
}
/*
Set alternative value
*/
func (ent *Entry) SetAlt(val string, from string) {
if val == "" {
return
}
ent.altvalue = val
ent.altvalue = []string{val}
ent.from = from
}
/*
Sets alternative bool
*/
func (ent *Entry) SetAltB(val bool, from string) {
if val {
ent.altvalue = "true"
ent.altvalue = []string{"true"}
ent.from = from
}
}
/*
Sets alternative slice
*/
func (ent *Entry) SetAltSlice(val []string, from string) {
if len(val) == 0 {
return
}
ent.altvalue = val
ent.from = from
}
/*
Sets the default value of an entry.
*/
func (ent *Entry) SetDefault(val string) {
if val == "" {
return
}
ent.def = []string{val}
}
/*
Set the default entry as slice
*/
func (ent *Entry) SetDefaultSlice(val []string) {
if len(val) == 0 {
return
}
ent.def = val
}
@@ -89,23 +140,31 @@ func (ent *Entry) SetDefault(val string) {
* Gets
*
*********/
/*
Gets the the entry of the value in folowing order
* node value if set
* profile value if set
* default value if set
*/
func (ent *Entry) Get() string {
if ent.value != "" {
return ent.value
if len(ent.value) != 0 {
return ent.value[0]
}
if ent.altvalue != "" {
return ent.altvalue
if len(ent.altvalue) != 0 {
return ent.altvalue[0]
}
if ent.def != "" {
return ent.def
if len(ent.def) != 0 {
return ent.def[0]
}
return ""
}
/*
Get the bool value of an entry.
*/
func (ent *Entry) GetB() bool {
if ent.value == "false" || ent.value == "no" || ent.value == "" {
if ent.altvalue == "false" || ent.altvalue == "no" || ent.altvalue == "" {
if len(ent.value) == 0 || ent.value[0] == "false" || ent.value[0] == "no" {
if len(ent.altvalue) == 0 || ent.altvalue[0] == "false" || ent.altvalue[0] == "no" {
return false
}
return false
@@ -113,47 +172,63 @@ func (ent *Entry) GetB() bool {
return true
}
func (ent *Entry) GetReal() string {
return ent.value
}
/*
Returns a string slice created from a comma seperated list of the value.
*/
func (ent *Entry) GetSlice() []string {
var retval []string
if ent.value != "" {
//retval = util.SliceAppendUniq(retval, strings.Split(ent.value, ","))
return strings.Split(ent.value, ",")
if len(ent.value) != 0 {
return ent.value
}
if ent.altvalue != "" {
//retval = util.SliceAppendUniq(retval, strings.Split(ent.altvalue, ","))
return strings.Split(ent.altvalue, ",")
if len(ent.altvalue) != 0 {
return ent.altvalue
}
//if ent.def != "" && len(retval) == 0 {
if ent.def != "" {
//retval = util.SliceAppendUniq(retval, strings.Split(ent.def, ","))
return strings.Split(ent.def, ",")
if len(ent.def) != 0 {
return ent.def
}
return retval
}
/*
Get the real value, not the alternative of default one.
*/
func (ent *Entry) GetReal() string {
if len(ent.value) == 0 {
return ""
}
return ent.value[0]
}
/*
Get the real value, not the alternative of default one.
*/
func (ent *Entry) GetRealSlice() []string {
if len(ent.value) == 0 {
return []string{}
}
return ent.value
}
/**********
*
* Misc
*
*********/
/*
Returns the value of Entry if it was defined set or
alternative is presend. Default value is in '()'. If
nothing is defined '--' is returned.
*/
func (ent *Entry) Print() string {
if ent.value != "" {
return ent.value
if len(ent.value) != 0 {
return strings.Join(ent.value, ",")
}
if ent.altvalue != "" {
return ent.altvalue
if len(ent.altvalue) != 0 {
return strings.Join(ent.altvalue, ",")
}
if ent.def != "" {
return "(" + ent.def + ")"
if len(ent.def) != 0 {
return "(" + strings.Join(ent.def, ",") + ")"
}
return "--"
}
@@ -168,12 +243,20 @@ func (ent *Entry) PrintComb() string {
return ent.Print()
}
*/
/*
same as GetB()
*/
func (ent *Entry) PrintB() bool {
return ent.GetB()
}
/*
Returns SUPERSEDED if value was set per node or
per profile. Else -- is returned.
*/
func (ent *Entry) Source() string {
if ent.value != "" && ent.altvalue != "" {
if len(ent.value) != 0 && len(ent.altvalue) != 0 {
return "SUPERSEDED"
//return fmt.Sprintf("[%s]", ent.from)
} else if ent.from == "" {
@@ -182,14 +265,17 @@ func (ent *Entry) Source() string {
return ent.from
}
/*
Check if value was defined.
*/
func (ent *Entry) Defined() bool {
if ent.value != "" {
if len(ent.value) != 0 {
return true
}
if ent.altvalue != "" {
if len(ent.altvalue) != 0 {
return true
}
if ent.def != "" {
if len(ent.def) != 0 {
return true
}
return false

View File

@@ -70,8 +70,8 @@ func (config *nodeYaml) NodeUpdate(node NodeInfo) error {
config.Nodes[nodeID].IpmiPassword = node.IpmiPassword.GetReal()
config.Nodes[nodeID].IpmiInterface = node.IpmiInterface.GetReal()
config.Nodes[nodeID].IpmiWrite = node.IpmiWrite.GetB()
config.Nodes[nodeID].RuntimeOverlay = node.RuntimeOverlay.GetReal()
config.Nodes[nodeID].SystemOverlay = node.SystemOverlay.GetReal()
config.Nodes[nodeID].RuntimeOverlay = node.RuntimeOverlay.GetRealSlice()
config.Nodes[nodeID].SystemOverlay = node.SystemOverlay.GetRealSlice()
config.Nodes[nodeID].Root = node.Root.GetReal()
config.Nodes[nodeID].AssetKey = node.AssetKey.GetReal()
config.Nodes[nodeID].Discoverable = node.Discoverable.GetReal()
@@ -159,8 +159,8 @@ func (config *nodeYaml) ProfileUpdate(profile NodeInfo) error {
config.NodeProfiles[profileID].IpmiPassword = profile.IpmiPassword.GetReal()
config.NodeProfiles[profileID].IpmiInterface = profile.IpmiInterface.GetReal()
config.NodeProfiles[profileID].IpmiWrite = profile.IpmiInterface.GetB()
config.NodeProfiles[profileID].RuntimeOverlay = profile.RuntimeOverlay.GetReal()
config.NodeProfiles[profileID].SystemOverlay = profile.SystemOverlay.GetReal()
config.NodeProfiles[profileID].RuntimeOverlay = profile.RuntimeOverlay.GetRealSlice()
config.NodeProfiles[profileID].SystemOverlay = profile.SystemOverlay.GetRealSlice()
config.NodeProfiles[profileID].Root = profile.Root.GetReal()
config.NodeProfiles[profileID].AssetKey = profile.AssetKey.GetReal()
config.NodeProfiles[profileID].Discoverable = profile.Discoverable.GetReal()