From bc435a88a1453059df80dfc58c460ec8ed03906c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Mon, 10 Dec 2018 17:22:01 +1100 Subject: [PATCH] feat(local-config): initial commit --- localconfig/localconfig.go | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 localconfig/localconfig.go diff --git a/localconfig/localconfig.go b/localconfig/localconfig.go new file mode 100644 index 0000000..1a97ed9 --- /dev/null +++ b/localconfig/localconfig.go @@ -0,0 +1,60 @@ +package localconfig + +import "strings" + +type LocalConfig struct { + Clusters []*Cluster + Hosts []*Host +} + +type Cluster struct { + Name string + Addons []byte +} + +type Host struct { + Name string + MACs []string + IPs []string + + Kernel string + Initrd string + Layers map[string]string + + Config []byte +} + +func (c *LocalConfig) ClusterByName(name string) *Cluster { + for _, cluster := range c.Clusters { + if cluster.Name == name { + return cluster + } + } + return nil +} + +func (c *LocalConfig) HostByIP(ip string) *Host { + for _, host := range c.Hosts { + for _, hostIP := range host.IPs { + if hostIP == ip { + return host + } + } + } + return nil +} + +func (c *LocalConfig) HostByMAC(mac string) *Host { + // a bit of normalization + mac = strings.Replace(strings.ToLower(mac), "-", ":", -1) + + for _, host := range c.Hosts { + for _, hostMAC := range host.MACs { + if strings.ToLower(hostMAC) == mac { + return host + } + } + } + + return nil +}