github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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 "gopkg.in/juju/names.v2" 8 9 "github.com/juju/juju/api/base" 10 "github.com/juju/juju/api/common" 11 "github.com/juju/juju/apiserver/params" 12 ) 13 14 const deployerFacade = "Deployer" 15 16 // State provides access to the deployer worker's idea of the state. 17 type State struct { 18 facade base.FacadeCaller 19 *common.APIAddresser 20 } 21 22 // NewState creates a new State instance that makes API calls 23 // through the given caller. 24 func NewState(caller base.APICaller) *State { 25 facadeCaller := base.NewFacadeCaller(caller, deployerFacade) 26 return &State{ 27 facade: facadeCaller, 28 APIAddresser: common.NewAPIAddresser(facadeCaller), 29 } 30 31 } 32 33 // unitLife returns the lifecycle state of the given unit. 34 func (st *State) unitLife(tag names.UnitTag) (params.Life, error) { 35 return common.Life(st.facade, tag) 36 } 37 38 // Unit returns the unit with the given tag. 39 func (st *State) Unit(tag names.UnitTag) (*Unit, error) { 40 life, err := st.unitLife(tag) 41 if err != nil { 42 return nil, err 43 } 44 return &Unit{ 45 tag: tag, 46 life: life, 47 st: st, 48 }, nil 49 } 50 51 // Machine returns the machine with the given tag. 52 func (st *State) Machine(tag names.MachineTag) (*Machine, error) { 53 // TODO(dfc) this cannot return an error any more 54 return &Machine{ 55 tag: tag, 56 st: st, 57 }, nil 58 } 59 60 // StateAddresses returns the list of addresses used to connect to the state. 61 func (st *State) StateAddresses() ([]string, error) { 62 var result params.StringsResult 63 err := st.facade.FacadeCall("StateAddresses", nil, &result) 64 if err != nil { 65 return nil, err 66 } 67 return result.Result, nil 68 } 69 70 // ConnectionInfo returns all the address information that the deployer task 71 // needs in one call. 72 func (st *State) ConnectionInfo() (result params.DeployerConnectionValues, err error) { 73 err = st.facade.FacadeCall("ConnectionInfo", nil, &result) 74 return result, err 75 }