-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirror.go
104 lines (84 loc) · 2.1 KB
/
mirror.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
package main
import (
"github.com/rivo/tview"
"os"
"path/filepath"
)
const defaultEnableMirror = false
var initialValueLoaded = false
var enableMirror bool
var mirrors map[string]string
func initFlexMirror() {
formMirror := tview.NewForm()
formMirror.SetTitle("Public Download Mirror").SetBorder(true)
mirrorFile := filepath.Join(projectPath, "group_vars/all/mirror.yml")
if !initialValueLoaded {
enableMirror = defaultEnableMirror
_, err := os.Stat(mirrorFile)
if err == nil {
enableMirror = true
}
initialValueLoaded = true
}
formMirror.AddCheckbox("Enable public download mirror: ", enableMirror, func(checked bool) {
enableMirror = checked
flexMirror.Clear()
initFlexMirror()
})
if enableMirror {
if mirrors == nil {
mirrors = make(map[string]string)
// Load default values
for _, item := range appConfig.Default_mirrors {
for k, v := range item {
mirrors[k] = v
}
}
// Load values from inventory file
for k, v := range mirrors {
if extraVars[k] != nil {
mirrors[k] = v
}
}
}
// To order the display
for _, item := range appConfig.Default_mirrors {
for k := range item {
formMirror.AddInputField(k+": ", mirrors[k], 0, nil, func(text string) {
mirrors[k] = text
})
}
}
}
formDown := tview.NewForm()
formDown.AddButton("Save & Next", func() {
if enableMirror {
execCommand("cp -f "+filepath.Join(projectPath, "group_vars/all/offline.yml")+" "+mirrorFile, 0)
execCommand("sed -i -E '/# .*\\{\\{ files_repo/s/^# //g' "+mirrorFile, 0)
for k, v := range mirrors {
extraVars[k] = v
}
} else {
err := os.Remove(mirrorFile)
check(err)
for k := range mirrors {
delete(extraVars, k)
}
}
saveInventory()
flexDeployCluster.Clear()
initFlexDeployCluster()
pages.SwitchToPage("Deploy Cluster")
})
formDown.AddButton("Back", func() {
initialValueLoaded = false
mirrors = nil
pages.SwitchToPage("Network")
})
formDown.AddButton("Quit", func() {
showQuitModal()
})
flexMirror.SetDirection(tview.FlexRow).
AddItem(formMirror, 0, 1, true).
AddItem(formDown, 3, 1, false)
}