-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathconfig.go
90 lines (73 loc) · 1.8 KB
/
config.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
package main
import (
"path/filepath"
"github.com/tsuru/config"
)
type Config struct {
Id string `json:"id"`
Hostname string `json:"hostname"`
Disk int `json:"disk_size"`
DiskPath string `json:"disk_path"`
Cpu int `json:"cpu_cores"`
Memory int `json:"memory"`
DNS string `json:"dns_server"`
Docker string `json:"docker_version"`
Extra string `json:"docker_args"`
Route bool `json:"route"`
}
func readConfig(path string) (Config, error) {
cfg := Config{}
configFile := filepath.Join(path, "config.yaml")
err := config.ReadConfigFile(configFile)
if err != nil {
return cfg, err
}
cfg.Id, err = config.GetString("id")
if err != nil {
return cfg, err
}
cfg.Hostname, err = config.GetString("hostname")
if err != nil {
return cfg, err
}
cfg.DiskPath = filepath.Join(path, "disk.qcow")
cfg.Disk, err = config.GetInt("disk")
if err != nil {
return cfg, err
}
cfg.Cpu, err = config.GetInt("cpu")
if err != nil {
return cfg, err
}
cfg.Memory, err = config.GetInt("memory")
if err != nil {
return cfg, err
}
cfg.DNS, err = config.GetString("dns")
if err != nil {
return cfg, err
}
cfg.Docker, err = config.GetString("docker")
if err != nil {
return cfg, err
}
cfg.Extra, err = config.GetString("extra")
if err != nil {
return cfg, err
}
cfg.Route, err = config.GetBool("route")
return cfg, err
}
func writeConfig(path string, cfg Config) error {
configFile := filepath.Join(path, "config.yaml")
config.Set("id", cfg.Id)
config.Set("hostname", cfg.Hostname)
config.Set("disk", cfg.Disk)
config.Set("cpu", cfg.Cpu)
config.Set("memory", cfg.Memory)
config.Set("dns", cfg.DNS)
config.Set("docker", cfg.Docker)
config.Set("extra", cfg.Extra)
config.Set("route", cfg.Route)
return config.WriteConfigFile(configFile, 0644)
}