-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.go
119 lines (111 loc) · 3.67 KB
/
execute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"os"
"path/filepath"
"github.com/cantara/bragi/sbragi"
"github.com/cantara/nerthus2/config"
)
type Provision func(conf config.Environment)
func init() {
var err error
wd, err = os.Getwd()
sbragi.WithError(err).Fatal("while getting working dir")
systemDir = filepath.Join(wd, "systems")
}
var wd string
var systemDir string
func ExecuteEnv(env string, prov Provision) (id string, err error) {
envDir := filepath.Join(systemDir, env)
files, systems, err := config.FindFilesAndSystems(envDir)
if sbragi.WithError(err).Trace("getting files and systems", "env", env) {
return "", err
}
for _, system := range systems {
conf, err := config.ParseSystem(files, system, envDir)
if sbragi.WithError(err).Trace("parsing system", "env", env, "dir", envDir, "system", system, "files", files) {
return "", err
}
prov(conf)
}
/*
envConf, err := config.ReadFullEnv(env, baseFS)
if err != nil {
log.WithError(err).Fatal("while reading env config")
}
if bootstrap {
envConf.SystemConfigs = map[string]system.System{"nerthus": envConf.SystemConfigs["nerthus"]}
}
prov(envConf)
for _, systemConf := range envConf.SystemConfigs {
for _, cluster := range systemConf.Clusters {
log.Info("executing cluster", "env", envConf.Name, "system", systemConf.Name, "cluster", cluster.Name, "overrides", cluster.Override)
for _, service := range cluster.Services {
serviceVars := config.ServiceProvisioningVars(envConf, systemConf, *cluster, *service)
for nodeNum, nodeName := range cluster.NodeNames {
serviceNodeVars := config.ServiceNodeVars(*cluster, nodeNum, serviceVars)
serviceProvisioningPlayYaml, err := generators.PlayToYaml(generators.GenerateServicePlay(*cluster, *service, serviceNodeVars))
if err != nil {
log.WithError(err).Error("while trying to create playbook yaml")
continue
}
ha, ok := hostActions.Get(nodeName)
if !ok {
ha = make(chan message.Action, 10)
hostActions.Set(nodeName, ha)
}
ha <- message.Action{
Action: message.Playbook,
Data: serviceProvisioningPlayYaml,
}
}
}
}
}
*/
return
}
/*
func ExecuteServ(env, sys, cluster, serv string) {
if bootstrap {
log.Fatal("can't bootstrap a single service", "env", env, "system", sys, "cluster", cluster, "service", serv)
}
envConf, err := config.ReadFullEnv(env, baseFS)
if err != nil {
log.WithError(err).Fatal("while reading env config")
}
for _, systemConf := range envConf.SystemConfigs {
if strings.ToLower(systemConf.Name) != sys {
continue
}
for _, clusterConf := range systemConf.Clusters {
if strings.ToLower(clusterConf.Name) != cluster {
continue
}
log.Info("executing cluster", "env", envConf.Name, "system", systemConf.Name, "cluster", clusterConf.Name, "overrides", clusterConf.Override)
for _, service := range clusterConf.Services {
if strings.ToLower(service.Name) != serv {
continue
}
serviceVars := config.ServiceProvisioningVars(envConf, systemConf, *clusterConf, *service)
for nodeNum, nodeName := range clusterConf.NodeNames {
serviceNodeVars := config.ServiceNodeVars(*clusterConf, nodeNum, serviceVars)
serviceProvisioningPlayYaml, err := generators.PlayToYaml(generators.GenerateServicePlay(*clusterConf, *service, serviceNodeVars))
if err != nil {
log.WithError(err).Error("while trying to create playbook yaml")
continue
}
ha, ok := hostActions.Get(nodeName)
if !ok {
ha = make(chan message.Action, 10)
hostActions.Set(nodeName, ha)
}
ha <- message.Action{
Action: message.Playbook,
Data: serviceProvisioningPlayYaml,
}
}
}
}
}
}
*/