host templates

This commit is contained in:
Mikaël Cluseau
2024-04-15 15:32:43 +02:00
parent d4dbe709e0
commit 699b8e71a6
16 changed files with 315 additions and 46 deletions

View File

@ -31,6 +31,8 @@ type State struct {
Config *localconfig.Config
Downloads map[string]DownloadSpec
HostTemplates []string
}
type ClusterState struct {
@ -45,6 +47,8 @@ type HostState struct {
Name string
Cluster string
IPs []string
Template string `json:",omitempty"`
}
type CAState struct {
@ -117,22 +121,44 @@ func updateState() {
clusters = append(clusters, c)
}
hosts := make([]HostState, 0, len(cfg.Hosts))
hfts, err := hostsFromTemplate.List("")
if err != nil {
log.Print("failed to read hosts from template: ", err)
}
hosts := make([]HostState, 0, len(cfg.Hosts)+len(hfts))
for _, host := range cfg.Hosts {
h := HostState{
Name: host.Name,
Cluster: host.ClusterName,
IPs: host.IPs,
}
hosts = append(hosts, h)
}
for _, kv := range hfts {
name, hft := kv.K, kv.V
h := HostState{
Name: name,
Cluster: hft.ClusterName(cfg),
IPs: []string{hft.IP},
Template: hft.Template,
}
hosts = append(hosts, h)
}
hostTemplates := make([]string, 0, len(cfg.HostTemplates))
for _, ht := range cfg.HostTemplates {
hostTemplates = append(hostTemplates, ht.Name)
}
// done
wState.Change(func(v *State) {
v.HasConfig = true
v.Store.KeyNames = keyNames
v.Clusters = clusters
v.Hosts = hosts
v.HostTemplates = hostTemplates
})
}