mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 11:37:00 -07:00
Added DHCPD and hostfile plugins
This commit is contained in:
parent
f443558b50
commit
a7d78e8240
3 changed files with 86 additions and 0 deletions
65
internal/generator/plugins/dhcpd/dhcpd.go
Normal file
65
internal/generator/plugins/dhcpd/dhcpd.go
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||||
|
"github.com/OpenCHAMI/configurator/internal/generator"
|
||||||
|
"github.com/OpenCHAMI/configurator/internal/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Dhcpd struct{}
|
||||||
|
|
||||||
|
func (g *Dhcpd) GetName() string {
|
||||||
|
return "dhcpd"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Dhcpd) Generate(config *configurator.Config, opts ...util.Option) (generator.Files, error) {
|
||||||
|
var (
|
||||||
|
params = generator.GetParams(opts...)
|
||||||
|
client = generator.GetClient(params)
|
||||||
|
targetKey = params["target"].(string)
|
||||||
|
target = config.Targets[targetKey]
|
||||||
|
compute_nodes = ""
|
||||||
|
eths []configurator.EthernetInterface = nil
|
||||||
|
err error = nil
|
||||||
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
if client != nil {
|
||||||
|
eths, err = client.FetchEthernetInterfaces(opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch ethernet interfaces with client: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if we have the required params first
|
||||||
|
if eths == nil {
|
||||||
|
return nil, fmt.Errorf("invalid ethernet interfaces (variable is nil)")
|
||||||
|
}
|
||||||
|
if len(eths) <= 0 {
|
||||||
|
return nil, fmt.Errorf("no ethernet interfaces found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// format output to write to config file
|
||||||
|
compute_nodes = "# ========== DYNAMICALLY GENERATED BY OPENCHAMI CONFIGURATOR ==========\n"
|
||||||
|
for _, eth := range eths {
|
||||||
|
if len(eth.IpAddresses) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
compute_nodes += fmt.Sprintf("host %s { hardware ethernet %s; fixed-address %s} ", eth.ComponentId, eth.MacAddress, eth.IpAddresses[0])
|
||||||
|
}
|
||||||
|
compute_nodes += "# ====================================================================="
|
||||||
|
|
||||||
|
if verbose, ok := params["verbose"].(bool); ok {
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return generator.ApplyTemplates(generator.Mappings{
|
||||||
|
"compute_nodes": compute_nodes,
|
||||||
|
"node_entries": "",
|
||||||
|
}, target.Templates...)
|
||||||
|
}
|
||||||
|
|
||||||
|
var Generator Dhcpd
|
||||||
20
internal/generator/plugins/hostfile/hostfile.go
Normal file
20
internal/generator/plugins/hostfile/hostfile.go
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||||
|
"github.com/OpenCHAMI/configurator/internal/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Hostfile struct{}
|
||||||
|
|
||||||
|
func (g *Hostfile) GetName() string {
|
||||||
|
return "hostfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Hostfile) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
|
||||||
|
return nil, fmt.Errorf("plugin does not implement generation function")
|
||||||
|
}
|
||||||
|
|
||||||
|
var Generator Hostfile
|
||||||
1
internal/generator/plugins/hostfile/hostfile_test.go
Normal file
1
internal/generator/plugins/hostfile/hostfile_test.go
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
package main
|
||||||
Loading…
Add table
Add a link
Reference in a new issue