github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/juju/paths/paths.go (about) 1 package paths 2 3 import ( 4 jujuos "github.com/juju/utils/os" 5 "github.com/juju/utils/series" 6 ) 7 8 type osVarType int 9 10 const ( 11 tmpDir osVarType = iota 12 logDir 13 dataDir 14 storageDir 15 confDir 16 jujuRun 17 certDir 18 metricsSpoolDir 19 uniterStateDir 20 jujuDumpLogs 21 ) 22 23 var nixVals = map[osVarType]string{ 24 tmpDir: "/tmp", 25 logDir: "/var/log", 26 dataDir: "/var/lib/juju", 27 storageDir: "/var/lib/juju/storage", 28 confDir: "/etc/juju", 29 jujuRun: "/usr/bin/juju-run", 30 jujuDumpLogs: "/usr/bin/juju-dumplogs", 31 certDir: "/etc/juju/certs.d", 32 metricsSpoolDir: "/var/lib/juju/metricspool", 33 uniterStateDir: "/var/lib/juju/uniter/state", 34 } 35 36 var winVals = map[osVarType]string{ 37 tmpDir: "C:/Juju/tmp", 38 logDir: "C:/Juju/log", 39 dataDir: "C:/Juju/lib/juju", 40 storageDir: "C:/Juju/lib/juju/storage", 41 confDir: "C:/Juju/etc", 42 jujuRun: "C:/Juju/bin/juju-run.exe", 43 jujuDumpLogs: "C:/Juju/bin/juju-dumplogs.exe", 44 certDir: "C:/Juju/certs", 45 metricsSpoolDir: "C:/Juju/lib/juju/metricspool", 46 uniterStateDir: "C:/Juju/lib/juju/uniter/state", 47 } 48 49 // osVal will lookup the value of the key valname 50 // in the apropriate map, based on the series. This will 51 // help reduce boilerplate code 52 func osVal(ser string, valname osVarType) (string, error) { 53 os, err := series.GetOSFromSeries(ser) 54 if err != nil { 55 return "", err 56 } 57 switch os { 58 case jujuos.Windows: 59 return winVals[valname], nil 60 default: 61 return nixVals[valname], nil 62 } 63 } 64 65 // TempDir returns the path on disk to the corect tmp directory 66 // for the series. This value will be the same on virtually 67 // all linux systems, but will differ on windows 68 func TempDir(series string) (string, error) { 69 return osVal(series, tmpDir) 70 } 71 72 // LogDir returns filesystem path the directory where juju may 73 // save log files. 74 func LogDir(series string) (string, error) { 75 return osVal(series, logDir) 76 } 77 78 // DataDir returns a filesystem path to the folder used by juju to 79 // store tools, charms, locks, etc 80 func DataDir(series string) (string, error) { 81 return osVal(series, dataDir) 82 } 83 84 // MetricsSpoolDir returns a filesystem path to the folder used by juju 85 // to store metrics. 86 func MetricsSpoolDir(series string) (string, error) { 87 return osVal(series, metricsSpoolDir) 88 } 89 90 // CertDir returns a filesystem path to the folder used by juju to 91 // store certificates that are added by default to the Juju client 92 // api certificate pool. 93 func CertDir(series string) (string, error) { 94 return osVal(series, certDir) 95 } 96 97 // StorageDir returns a filesystem path to the folder used by juju to 98 // mount machine-level storage. 99 func StorageDir(series string) (string, error) { 100 return osVal(series, storageDir) 101 } 102 103 // ConfDir returns the path to the directory where Juju may store 104 // configuration files. 105 func ConfDir(series string) (string, error) { 106 return osVal(series, confDir) 107 } 108 109 // JujuRun returns the absolute path to the juju-run binary for 110 // a particular series. 111 func JujuRun(series string) (string, error) { 112 return osVal(series, jujuRun) 113 } 114 115 // JujuDumpLogs returns the absolute path to the juju-dumplogs binary 116 // for a particular series. 117 func JujuDumpLogs(series string) (string, error) { 118 return osVal(series, jujuDumpLogs) 119 } 120 121 func MustSucceed(s string, e error) string { 122 if e != nil { 123 panic(e) 124 } 125 return s 126 }