This commit is contained in:
Mikaël Cluseau 2018-12-10 21:52:14 +11:00
parent 6acf004eab
commit 68c87509f2
3 changed files with 40 additions and 11 deletions

View File

@ -11,18 +11,20 @@ type Host struct {
MACs []string
IPs []string
Kernel string
Initrd string
Layers map[string]string
IPXE string
Config []byte
Kernel string
Initrd string
Versions map[string]string
Config string
}
func (h *Host) WriteHashDataTo(w io.Writer) error {
return yaml.NewEncoder(w).Encode(Host{
Kernel: h.Kernel,
Initrd: h.Initrd,
Layers: h.Layers,
Config: h.Config,
Kernel: h.Kernel,
Initrd: h.Initrd,
Versions: h.Versions,
Config: h.Config,
})
}

View File

@ -1,6 +1,7 @@
package localconfig
import (
"io"
"io/ioutil"
"strings"
@ -8,13 +9,14 @@ import (
)
type Config struct {
Clusters []*Cluster
Hosts []*Host
Clusters []*Cluster
Hosts []*Host
SSLConfig string
}
type Cluster struct {
Name string
Addons []byte
Addons string
}
func FromBytes(data []byte) (*Config, error) {
@ -34,6 +36,19 @@ func FromFile(path string) (*Config, error) {
return FromBytes(ba)
}
func (c *Config) WriteTo(w io.Writer) error {
return yaml.NewEncoder(w).Encode(c)
}
func (c *Config) Cluster(name string) *Cluster {
for _, cluster := range c.Clusters {
if cluster.Name == name {
return cluster
}
}
return nil
}
func (c *Config) ClusterByName(name string) *Cluster {
for _, cluster := range c.Clusters {
if cluster.Name == name {
@ -43,6 +58,15 @@ func (c *Config) ClusterByName(name string) *Cluster {
return nil
}
func (c *Config) Host(name string) *Host {
for _, host := range c.Hosts {
if host.Name == name {
return host
}
}
return nil
}
func (c *Config) HostByIP(ip string) *Host {
for _, host := range c.Hosts {
for _, hostIP := range host.IPs {

3
modd.conf Normal file
View File

@ -0,0 +1,3 @@
**/*.go {
prep: go test ./...
}