github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/worker/uniter/paths.go (about) 1 // Copyright 2012-2014 Canonical Ltd. 2 3 // Licensed under the AGPLv3, see LICENCE file for details. 4 5 package uniter 6 7 import ( 8 "fmt" 9 "path/filepath" 10 11 "github.com/juju/names" 12 13 "github.com/juju/juju/agent/tools" 14 "github.com/juju/juju/version" 15 ) 16 17 // Paths represents the set of filesystem paths a uniter worker has reason to 18 // care about. 19 type Paths struct { 20 21 // ToolsDir is the directory containing the jujud executable running this 22 // process; and also containing jujuc tool symlinks to that executable. It's 23 // the only path in this struct that is not typically pointing inside the 24 // directory reserved for the exclusive use of this worker (typically 25 // /var/lib/juju/agents/$UNIT_TAG/ ) 26 ToolsDir string 27 28 // Runtime represents the set of paths that are relevant at runtime. 29 Runtime RuntimePaths 30 31 // State represents the set of paths that hold persistent local state for 32 // the uniter. 33 State StatePaths 34 } 35 36 // GetToolsDir exists to satisfy the context.Paths interface. 37 func (paths Paths) GetToolsDir() string { 38 return paths.ToolsDir 39 } 40 41 // GetCharmDir exists to satisfy the context.Paths interface. 42 func (paths Paths) GetCharmDir() string { 43 return paths.State.CharmDir 44 } 45 46 // GetJujucSocket exists to satisfy the context.Paths interface. 47 func (paths Paths) GetJujucSocket() string { 48 return paths.Runtime.JujucServerSocket 49 } 50 51 // RuntimePaths represents the set of paths that are relevant at runtime. 52 type RuntimePaths struct { 53 54 // JujuRunSocket listens for juju-run invocations, and is always 55 // active. 56 JujuRunSocket string 57 58 // JujucServerSocket listens for jujuc invocations, and is only 59 // active when supporting a jujuc execution context. 60 JujucServerSocket string 61 } 62 63 // StatePaths represents the set of paths that hold persistent local state for 64 // the uniter. 65 type StatePaths struct { 66 67 // CharmDir is the directory to which the charm the uniter runs is deployed. 68 CharmDir string 69 70 // OperationsFile holds information about what the uniter is doing 71 // and/or has done. 72 OperationsFile string 73 74 // RelationsDir holds relation-sepcific information about what the 75 // uniter is doing and/or has done. 76 RelationsDir string 77 78 // BundlesDir holds downloaded charms. 79 BundlesDir string 80 81 // DeployerDir holds metadata about charms that are installing or have 82 // been installed. 83 DeployerDir string 84 } 85 86 // NewPaths returns the set of filesystem paths that the supplied unit should 87 // use, given the supplied root juju data directory path. 88 func NewPaths(dataDir string, unitTag names.UnitTag) Paths { 89 90 join := filepath.Join 91 baseDir := join(dataDir, "agents", unitTag.String()) 92 stateDir := join(baseDir, "state") 93 94 socket := func(name string, abstract bool) string { 95 if version.Current.OS == version.Windows { 96 return fmt.Sprintf(`\\.\pipe\%s-%s`, unitTag, name) 97 } 98 path := join(baseDir, name+".socket") 99 if abstract { 100 path = "@" + path 101 } 102 return path 103 } 104 105 return Paths{ 106 ToolsDir: tools.ToolsDir(dataDir, unitTag.String()), 107 Runtime: RuntimePaths{ 108 JujuRunSocket: socket("run", false), 109 JujucServerSocket: socket("agent", true), 110 }, 111 State: StatePaths{ 112 CharmDir: join(baseDir, "charm"), 113 OperationsFile: join(stateDir, "uniter"), 114 RelationsDir: join(stateDir, "relations"), 115 BundlesDir: join(stateDir, "bundles"), 116 DeployerDir: join(stateDir, "deployer"), 117 }, 118 } 119 }