github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/api/machiner/machiner.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package machiner 5 6 import ( 7 "github.com/juju/names" 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 machinerFacade = "Machiner" 15 16 // State provides access to the Machiner API facade. 17 type State struct { 18 facade base.FacadeCaller 19 *common.APIAddresser 20 } 21 22 // NewState creates a new client-side Machiner facade. 23 func NewState(caller base.APICaller) *State { 24 facadeCaller := base.NewFacadeCaller(caller, machinerFacade) 25 return &State{ 26 facade: facadeCaller, 27 APIAddresser: common.NewAPIAddresser(facadeCaller), 28 } 29 30 } 31 32 // machineLife requests the lifecycle of the given machine from the server. 33 func (st *State) machineLife(tag names.MachineTag) (params.Life, error) { 34 return common.Life(st.facade, tag) 35 } 36 37 // Machine provides access to methods of a state.Machine through the facade. 38 func (st *State) Machine(tag names.MachineTag) (*Machine, error) { 39 life, err := st.machineLife(tag) 40 if err != nil { 41 return nil, err 42 } 43 return &Machine{ 44 tag: tag, 45 life: life, 46 st: st, 47 }, nil 48 }