forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.go
186 lines (160 loc) · 5.26 KB
/
paths.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright 2014 Canonical Ltd.
// Copyright 2014 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.
package paths
import (
"os"
jujuos "github.com/juju/os"
"github.com/juju/os/series"
)
type osVarType int
const (
tmpDir osVarType = iota
logDir
dataDir
storageDir
confDir
jujuRun
certDir
metricsSpoolDir
uniterStateDir
jujuDumpLogs
jujuIntrospect
jujuUpdateSeries
instanceCloudInitDir
cloudInitCfgDir
curtinInstallConfig
)
const (
// NixDataDir is location for agent binaries on *nix operating systems.
NixDataDir = "/var/lib/juju"
// NixLogDir is location for Juju logs on *nix operating systems.
NixLogDir = "/var/log"
)
var nixVals = map[osVarType]string{
tmpDir: "/tmp",
logDir: NixLogDir,
dataDir: NixDataDir,
storageDir: "/var/lib/juju/storage",
confDir: "/etc/juju",
jujuRun: "/usr/bin/juju-run",
jujuDumpLogs: "/usr/bin/juju-dumplogs",
jujuIntrospect: "/usr/bin/juju-introspect",
jujuUpdateSeries: "/usr/bin/juju-updateseries",
certDir: "/etc/juju/certs.d",
metricsSpoolDir: "/var/lib/juju/metricspool",
uniterStateDir: "/var/lib/juju/uniter/state",
instanceCloudInitDir: "/var/lib/cloud/instance",
cloudInitCfgDir: "/etc/cloud/cloud.cfg.d",
curtinInstallConfig: "/root/curtin-install-cfg.yaml",
}
var winVals = map[osVarType]string{
tmpDir: "C:/Juju/tmp",
logDir: "C:/Juju/log",
dataDir: "C:/Juju/lib/juju",
storageDir: "C:/Juju/lib/juju/storage",
confDir: "C:/Juju/etc",
jujuRun: "C:/Juju/bin/juju-run.exe",
jujuDumpLogs: "C:/Juju/bin/juju-dumplogs.exe",
jujuIntrospect: "C:/Juju/bin/juju-introspect.exe",
jujuUpdateSeries: "C:/Juju/bin/juju-updateseries.exe",
certDir: "C:/Juju/certs",
metricsSpoolDir: "C:/Juju/lib/juju/metricspool",
uniterStateDir: "C:/Juju/lib/juju/uniter/state",
}
// Chown is a variable here so it can be mocked out in tests to a no-op.
// Agents run as root, but users don't.
var Chown = os.Chown
// osVal will lookup the value of the key valname
// in the appropriate map, based on the series. This will
// help reduce boilerplate code
func osVal(ser string, valname osVarType) (string, error) {
os, err := series.GetOSFromSeries(ser)
if err != nil {
return "", err
}
switch os {
case jujuos.Windows:
return winVals[valname], nil
default:
return nixVals[valname], nil
}
}
// TempDir returns the path on disk to the correct tmp directory
// for the series. This value will be the same on virtually
// all linux systems, but will differ on windows
func TempDir(series string) (string, error) {
return osVal(series, tmpDir)
}
// LogDir returns filesystem path the directory where juju may
// save log files.
func LogDir(series string) (string, error) {
return osVal(series, logDir)
}
// DataDir returns a filesystem path to the folder used by juju to
// store tools, charms, locks, etc
func DataDir(series string) (string, error) {
return osVal(series, dataDir)
}
// MetricsSpoolDir returns a filesystem path to the folder used by juju
// to store metrics.
func MetricsSpoolDir(series string) (string, error) {
return osVal(series, metricsSpoolDir)
}
// CertDir returns a filesystem path to the folder used by juju to
// store certificates that are added by default to the Juju client
// api certificate pool.
func CertDir(series string) (string, error) {
return osVal(series, certDir)
}
// StorageDir returns a filesystem path to the folder used by juju to
// mount machine-level storage.
func StorageDir(series string) (string, error) {
return osVal(series, storageDir)
}
// ConfDir returns the path to the directory where Juju may store
// configuration files.
func ConfDir(series string) (string, error) {
return osVal(series, confDir)
}
// JujuRun returns the absolute path to the juju-run binary for
// a particular series.
func JujuRun(series string) (string, error) {
return osVal(series, jujuRun)
}
// JujuDumpLogs returns the absolute path to the juju-dumplogs binary
// for a particular series.
func JujuDumpLogs(series string) (string, error) {
return osVal(series, jujuDumpLogs)
}
// JujuIntrospect returns the absolute path to the juju-introspect
// binary for a particular series.
func JujuIntrospect(series string) (string, error) {
return osVal(series, jujuIntrospect)
}
// MachineCloudInitDir returns the absolute path to the instance
// cloudinit directory for a particular series.
func MachineCloudInitDir(series string) (string, error) {
return osVal(series, instanceCloudInitDir)
}
// CurtinInstallConfig returns the absolute path the configuration file
// written by Curtin during machine provisioning.
func CurtinInstallConfig(series string) (string, error) {
return osVal(series, curtinInstallConfig)
}
// CloudInitCfgDir returns the absolute path to the instance
// cloud config directory for a particular series.
func CloudInitCfgDir(series string) (string, error) {
return osVal(series, cloudInitCfgDir)
}
// JujuUpdateSeries returns the absolute path to the juju-updateseries
// binary for a particular series.
func JujuUpdateSeries(series string) (string, error) {
return osVal(series, jujuUpdateSeries)
}
func MustSucceed(s string, e error) string {
if e != nil {
panic(e)
}
return s
}