host templates in localconfig

This commit is contained in:
Mikaël Cluseau 2024-04-15 13:47:50 +02:00
parent 8498a10279
commit 0d2e181a4e

View File

@ -2,16 +2,17 @@ package localconfig
import ( import (
"io" "io"
"io/ioutil" "os"
"strings" "strings"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
type Config struct { type Config struct {
Clusters []*Cluster Clusters []*Cluster
Hosts []*Host Hosts []*Host
SSLConfig string HostTemplates []*Host
SSLConfig string
} }
type Cluster struct { type Cluster struct {
@ -29,7 +30,7 @@ func FromBytes(data []byte) (*Config, error) {
} }
func FromFile(path string) (*Config, error) { func FromFile(path string) (*Config, error) {
ba, err := ioutil.ReadFile(path) ba, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -68,6 +69,15 @@ func (c *Config) Host(name string) *Host {
return nil return nil
} }
func (c *Config) HostTemplate(name string) *Host {
for _, host := range c.HostTemplates {
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 {