use list of resources in profiles/nodes
access the resource not at node or profile level but in the templates as global variable Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
5ff27061a3
commit
07c77a63d5
@@ -479,7 +479,8 @@ nodes:
|
||||
"Tags": {},
|
||||
"PrimaryNetDev": "",
|
||||
"Disks": null,
|
||||
"FileSystems": null
|
||||
"FileSystems": null,
|
||||
"ResourceList": null
|
||||
}
|
||||
]
|
||||
`,
|
||||
@@ -529,7 +530,8 @@ nodes:
|
||||
"Tags": {},
|
||||
"PrimaryNetDev": "",
|
||||
"Disks": null,
|
||||
"FileSystems": null
|
||||
"FileSystems": null,
|
||||
"ResourceList": null
|
||||
},
|
||||
{
|
||||
"Discoverable": "",
|
||||
@@ -563,7 +565,8 @@ nodes:
|
||||
"Tags": {},
|
||||
"PrimaryNetDev": "",
|
||||
"Disks": null,
|
||||
"FileSystems": null
|
||||
"FileSystems": null,
|
||||
"ResourceList": null
|
||||
}
|
||||
]
|
||||
`,
|
||||
|
||||
@@ -169,7 +169,8 @@ nodes:
|
||||
"Tags": null,
|
||||
"PrimaryNetDev": "",
|
||||
"Disks": null,
|
||||
"FileSystems": null
|
||||
"FileSystems": null,
|
||||
"ResourceList": null
|
||||
}
|
||||
}
|
||||
`,
|
||||
@@ -220,7 +221,8 @@ nodes:
|
||||
"Tags": null,
|
||||
"PrimaryNetDev": "",
|
||||
"Disks": null,
|
||||
"FileSystems": null
|
||||
"FileSystems": null,
|
||||
"ResourceList": null
|
||||
},
|
||||
"test": {
|
||||
"Profiles": null,
|
||||
@@ -238,7 +240,8 @@ nodes:
|
||||
"Tags": null,
|
||||
"PrimaryNetDev": "",
|
||||
"Disks": null,
|
||||
"FileSystems": null
|
||||
"FileSystems": null,
|
||||
"ResourceList": null
|
||||
}
|
||||
}
|
||||
`,
|
||||
|
||||
@@ -18,13 +18,13 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
return fmt.Errorf("resource %s already exists", args[0])
|
||||
}
|
||||
if nodeYml.Resource == nil {
|
||||
nodeYml.Resource = make(map[string]*node.RemoteRes)
|
||||
nodeYml.Resource = make(map[string]node.RemoteRes)
|
||||
}
|
||||
res := node.RemoteRes{}
|
||||
for key, val := range vars.tags {
|
||||
res[key] = val
|
||||
}
|
||||
nodeYml.Resource[args[0]] = &res
|
||||
nodeYml.Resource[args[0]] = res
|
||||
err = nodeYml.Persist()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
}
|
||||
if ok := nodeYml.Resource[args[0]] != nil; ok {
|
||||
if nodeYml.Resource == nil {
|
||||
nodeYml.Resource = make(map[string]*node.RemoteRes)
|
||||
nodeYml.Resource = make(map[string]node.RemoteRes)
|
||||
}
|
||||
res := *nodeYml.Resource[args[0]]
|
||||
res := nodeYml.Resource[args[0]]
|
||||
for key, val := range vars.tags {
|
||||
res[key] = val
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ get the given resource
|
||||
*/
|
||||
func (config *NodesYaml) GetResource(id string) (res RemoteRes, err error) {
|
||||
if found, ok := config.Resource[id]; ok {
|
||||
return *found, nil
|
||||
return found, nil
|
||||
}
|
||||
return res, ErrNotFound
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ nodes:
|
||||
network devices:
|
||||
net0:
|
||||
device: eth0
|
||||
resource_list:
|
||||
- NFSHOME
|
||||
test_node2:
|
||||
primary network: net1
|
||||
network devices:
|
||||
@@ -51,7 +53,10 @@ nodes:
|
||||
network devices:
|
||||
override:
|
||||
device: ib1
|
||||
`
|
||||
resource:
|
||||
NFSHOME:
|
||||
mountpoint: /home
|
||||
`
|
||||
var ret NodesYaml
|
||||
err := yaml.Unmarshal([]byte(data), &ret)
|
||||
assert.NoError(t, err)
|
||||
@@ -117,6 +122,12 @@ func Test_Primary_Network(t *testing.T) {
|
||||
assert.Equal(t, "ib1", test_node6.NetDevs["override"].Device)
|
||||
assert.Equal(t, "profile", test_node6.NetDevs["override"].Type)
|
||||
})
|
||||
t.Run("resource is defined", func(t *testing.T) {
|
||||
assert.Contains(t, test_node1.ResourceList, "NFSHOME")
|
||||
res, err := c.GetResource(test_node1.ResourceList[0])
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, res, "mountpoint")
|
||||
})
|
||||
}
|
||||
|
||||
var findDiscoverableNodeTests = []struct {
|
||||
|
||||
@@ -17,7 +17,7 @@ Structure of which goes to disk
|
||||
type NodesYaml struct {
|
||||
NodeProfiles map[string]*Profile
|
||||
Nodes map[string]*Node
|
||||
Resource map[string]*RemoteRes `yaml:"resource,omitempty"`
|
||||
Resource map[string]RemoteRes `yaml:"resource,omitempty"`
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -54,8 +54,7 @@ type Profile struct {
|
||||
PrimaryNetDev string `yaml:"primary network,omitempty" lopt:"primarynet" sopt:"p" comment:"Set the primary network interface"`
|
||||
Disks map[string]*Disk `yaml:"disks,omitempty"`
|
||||
FileSystems map[string]*FileSystem `yaml:"filesystems,omitempty"`
|
||||
resource map[string]*RemoteRes `yaml:"omitempty"`
|
||||
Resources []string `yaml:"resources,omitempty" lopt:"resources" comment:"Set the resources available to the node or profile"`
|
||||
ResourceList []string `yaml:"resource_list,omitempty" lopt:"resources" comment:"Set the resources available to the node or profile"`
|
||||
}
|
||||
|
||||
type IpmiConf struct {
|
||||
|
||||
@@ -103,7 +103,6 @@ func EmptyNode() (nodeconf Node) {
|
||||
nodeconf.Ipmi.Tags = map[string]string{}
|
||||
nodeconf.Kernel = new(KernelConf)
|
||||
nodeconf.NetDevs = make(map[string]*NetDev)
|
||||
nodeconf.resource = make(map[string]*RemoteRes)
|
||||
nodeconf.Tags = map[string]string{}
|
||||
return nodeconf
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ type TemplateStruct struct {
|
||||
Tftp warewulfconf.TFTPConf
|
||||
Paths warewulfconf.BuildConfig
|
||||
AllNodes []node.Node
|
||||
Resource map[string]node.RemoteRes
|
||||
node.Node
|
||||
// backward compatiblity
|
||||
Container string
|
||||
@@ -80,7 +81,8 @@ func InitStruct(overlayName string, nodeData node.Node, allNodes []node.Node) (T
|
||||
dt := time.Now()
|
||||
tstruct.BuildTime = dt.Format("01-02-2006 15:04:05 MST")
|
||||
tstruct.BuildTimeUnix = strconv.FormatInt(dt.Unix(), 10)
|
||||
tstruct.Node.Tags = map[string]string{}
|
||||
// tstruct.Node.Tags = map[string]string{}
|
||||
tstruct.Resource = nodeDB.Resource
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
dec := gob.NewDecoder(&buf)
|
||||
|
||||
Reference in New Issue
Block a user