github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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/errors" 8 "gopkg.in/juju/names.v2" 9 10 "github.com/juju/juju/api/base" 11 "github.com/juju/juju/api/common" 12 "github.com/juju/juju/apiserver/params" 13 ) 14 15 const machinerFacade = "Machiner" 16 17 // State provides access to the Machiner API facade. 18 type State struct { 19 facade base.FacadeCaller 20 *common.APIAddresser 21 } 22 23 // NewState creates a new client-side Machiner facade. 24 func NewState(caller base.APICaller) *State { 25 facadeCaller := base.NewFacadeCaller(caller, machinerFacade) 26 return &State{ 27 facade: facadeCaller, 28 APIAddresser: common.NewAPIAddresser(facadeCaller), 29 } 30 31 } 32 33 // machineLife requests the lifecycle of the given machine from the server. 34 func (st *State) machineLife(tag names.MachineTag) (params.Life, error) { 35 return common.Life(st.facade, tag) 36 } 37 38 // Machine provides access to methods of a state.Machine through the facade. 39 func (st *State) Machine(tag names.MachineTag) (*Machine, error) { 40 life, err := st.machineLife(tag) 41 if err != nil { 42 return nil, errors.Annotate(err, "can't get life for machine") 43 } 44 return &Machine{ 45 tag: tag, 46 life: life, 47 st: st, 48 }, nil 49 }