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