github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/juju/paths/paths.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Copyright 2014 Cloudbase Solutions SRL 3 // Licensed under the AGPLv3, see LICENCE file for details. 4 5 package paths 6 7 import ( 8 jujuos "github.com/juju/os" 9 "github.com/juju/os/series" 10 ) 11 12 type osVarType int 13 14 const ( 15 tmpDir osVarType = iota 16 logDir 17 dataDir 18 storageDir 19 confDir 20 jujuRun 21 certDir 22 metricsSpoolDir 23 uniterStateDir 24 jujuDumpLogs 25 jujuIntrospect 26 jujuUpdateSeries 27 instanceCloudInitDir 28 cloudInitCfgDir 29 ) 30 31 const ( 32 // NixDataDir is location for agent binaries on *nix operating systems. 33 NixDataDir = "/var/lib/juju" 34 35 // NixDataDir is location for Juju logs on *nix operating systems. 36 NixLogDir = "/var/log" 37 ) 38 39 var nixVals = map[osVarType]string{ 40 tmpDir: "/tmp", 41 logDir: NixLogDir, 42 dataDir: NixDataDir, 43 storageDir: "/var/lib/juju/storage", 44 confDir: "/etc/juju", 45 jujuRun: "/usr/bin/juju-run", 46 jujuDumpLogs: "/usr/bin/juju-dumplogs", 47 jujuIntrospect: "/usr/bin/juju-introspect", 48 jujuUpdateSeries: "/usr/bin/juju-updateseries", 49 certDir: "/etc/juju/certs.d", 50 metricsSpoolDir: "/var/lib/juju/metricspool", 51 uniterStateDir: "/var/lib/juju/uniter/state", 52 instanceCloudInitDir: "/var/lib/cloud/instance", 53 cloudInitCfgDir: "/etc/cloud/cloud.cfg.d", 54 } 55 56 var winVals = map[osVarType]string{ 57 tmpDir: "C:/Juju/tmp", 58 logDir: "C:/Juju/log", 59 dataDir: "C:/Juju/lib/juju", 60 storageDir: "C:/Juju/lib/juju/storage", 61 confDir: "C:/Juju/etc", 62 jujuRun: "C:/Juju/bin/juju-run.exe", 63 jujuDumpLogs: "C:/Juju/bin/juju-dumplogs.exe", 64 jujuIntrospect: "C:/Juju/bin/juju-introspect.exe", 65 jujuUpdateSeries: "C:/Juju/bin/juju-updateseries.exe", 66 certDir: "C:/Juju/certs", 67 metricsSpoolDir: "C:/Juju/lib/juju/metricspool", 68 uniterStateDir: "C:/Juju/lib/juju/uniter/state", 69 } 70 71 // osVal will lookup the value of the key valname 72 // in the appropriate map, based on the series. This will 73 // help reduce boilerplate code 74 func osVal(ser string, valname osVarType) (string, error) { 75 os, err := series.GetOSFromSeries(ser) 76 if err != nil { 77 return "", err 78 } 79 switch os { 80 case jujuos.Windows: 81 return winVals[valname], nil 82 default: 83 return nixVals[valname], nil 84 } 85 } 86 87 // TempDir returns the path on disk to the corect tmp directory 88 // for the series. This value will be the same on virtually 89 // all linux systems, but will differ on windows 90 func TempDir(series string) (string, error) { 91 return osVal(series, tmpDir) 92 } 93 94 // LogDir returns filesystem path the directory where juju may 95 // save log files. 96 func LogDir(series string) (string, error) { 97 return osVal(series, logDir) 98 } 99 100 // DataDir returns a filesystem path to the folder used by juju to 101 // store tools, charms, locks, etc 102 func DataDir(series string) (string, error) { 103 return osVal(series, dataDir) 104 } 105 106 // MetricsSpoolDir returns a filesystem path to the folder used by juju 107 // to store metrics. 108 func MetricsSpoolDir(series string) (string, error) { 109 return osVal(series, metricsSpoolDir) 110 } 111 112 // CertDir returns a filesystem path to the folder used by juju to 113 // store certificates that are added by default to the Juju client 114 // api certificate pool. 115 func CertDir(series string) (string, error) { 116 return osVal(series, certDir) 117 } 118 119 // StorageDir returns a filesystem path to the folder used by juju to 120 // mount machine-level storage. 121 func StorageDir(series string) (string, error) { 122 return osVal(series, storageDir) 123 } 124 125 // ConfDir returns the path to the directory where Juju may store 126 // configuration files. 127 func ConfDir(series string) (string, error) { 128 return osVal(series, confDir) 129 } 130 131 // JujuRun returns the absolute path to the juju-run binary for 132 // a particular series. 133 func JujuRun(series string) (string, error) { 134 return osVal(series, jujuRun) 135 } 136 137 // JujuDumpLogs returns the absolute path to the juju-dumplogs binary 138 // for a particular series. 139 func JujuDumpLogs(series string) (string, error) { 140 return osVal(series, jujuDumpLogs) 141 } 142 143 // JujuIntrospect returns the absolute path to the juju-introspect 144 // binary for a particular series. 145 func JujuIntrospect(series string) (string, error) { 146 return osVal(series, jujuIntrospect) 147 } 148 149 // MachineCloudInitDir returns the absolute path to the instance 150 // cloudinit directory for a particular series. 151 func MachineCloudInitDir(series string) (string, error) { 152 return osVal(series, instanceCloudInitDir) 153 } 154 155 // CloudInitCfgDir returns the absolute path to the instance 156 // cloud config directory for a particular series. 157 func CloudInitCfgDir(series string) (string, error) { 158 return osVal(series, cloudInitCfgDir) 159 } 160 161 // JujuUpdateSeries returns the absolute path to the juju-updateseries 162 // binary for a particular series. 163 func JujuUpdateSeries(series string) (string, error) { 164 return osVal(series, jujuUpdateSeries) 165 } 166 167 func MustSucceed(s string, e error) string { 168 if e != nil { 169 panic(e) 170 } 171 return s 172 }