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 MACs []string
IPs []string IPs []string
Kernel string IPXE string
Initrd string
Layers map[string]string
Config []byte Kernel string
Initrd string
Versions map[string]string
Config string
} }
func (h *Host) WriteHashDataTo(w io.Writer) error { func (h *Host) WriteHashDataTo(w io.Writer) error {
return yaml.NewEncoder(w).Encode(Host{ return yaml.NewEncoder(w).Encode(Host{
Kernel: h.Kernel, Kernel: h.Kernel,
Initrd: h.Initrd, Initrd: h.Initrd,
Layers: h.Layers, Versions: h.Versions,
Config: h.Config, Config: h.Config,
}) })
} }

View File

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

3
modd.conf Normal file
View File

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