github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/state/api/deployer/deployer.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package deployer 5 6 import ( 7 "launchpad.net/juju-core/state/api/base" 8 "launchpad.net/juju-core/state/api/common" 9 "launchpad.net/juju-core/state/api/params" 10 ) 11 12 // State provides access to the deployer worker's idea of the state. 13 type State struct { 14 caller base.Caller 15 } 16 17 // NewState creates a new State instance that makes API calls 18 // through the given caller. 19 func NewState(caller base.Caller) *State { 20 return &State{caller} 21 } 22 23 // unitLife returns the lifecycle state of the given unit. 24 func (st *State) unitLife(tag string) (params.Life, error) { 25 return common.Life(st.caller, "Deployer", tag) 26 } 27 28 // Unit returns the unit with the given tag. 29 func (st *State) Unit(tag string) (*Unit, error) { 30 life, err := st.unitLife(tag) 31 if err != nil { 32 return nil, err 33 } 34 return &Unit{ 35 tag: tag, 36 life: life, 37 st: st, 38 }, nil 39 } 40 41 // Machine returns the machine with the given tag. 42 func (st *State) Machine(tag string) (*Machine, error) { 43 return &Machine{ 44 tag: tag, 45 st: st, 46 }, nil 47 } 48 49 // StateAddresses returns the list of addresses used to connect to the state. 50 func (st *State) StateAddresses() ([]string, error) { 51 var result params.StringsResult 52 err := st.caller.Call("Deployer", "", "StateAddresses", nil, &result) 53 if err != nil { 54 return nil, err 55 } 56 return result.Result, nil 57 } 58 59 // APIAddresses returns the list of addresses used to connect to the API. 60 func (st *State) APIAddresses() ([]string, error) { 61 var result params.StringsResult 62 err := st.caller.Call("Deployer", "", "APIAddresses", nil, &result) 63 if err != nil { 64 return nil, err 65 } 66 return result.Result, nil 67 } 68 69 // CACert returns the certificate used to validate the state connection. 70 func (st *State) CACert() ([]byte, error) { 71 var result params.BytesResult 72 err := st.caller.Call("Deployer", "", "CACert", nil, &result) 73 if err != nil { 74 return nil, err 75 } 76 return result.Result, nil 77 } 78 79 // ConnectionInfo returns all the address information that the deployer task 80 // needs in one call. 81 func (st *State) ConnectionInfo() (result params.DeployerConnectionValues, err error) { 82 err = st.caller.Call("Deployer", "", "ConnectionInfo", nil, &result) 83 return result, err 84 }