github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/state/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/juju/state/api/base"
     8  	"github.com/juju/juju/state/api/common"
     9  	"github.com/juju/juju/state/api/params"
    10  )
    11  
    12  const machinerFacade = "Machiner"
    13  
    14  // State provides access to the Machiner API facade.
    15  type State struct {
    16  	caller base.Caller
    17  	*common.APIAddresser
    18  }
    19  
    20  func (st *State) call(method string, params, result interface{}) error {
    21  	return st.caller.Call(machinerFacade, "", method, params, result)
    22  }
    23  
    24  // NewState creates a new client-side Machiner facade.
    25  func NewState(caller base.Caller) *State {
    26  	return &State{
    27  		caller:       caller,
    28  		APIAddresser: common.NewAPIAddresser(machinerFacade, caller),
    29  	}
    30  
    31  }
    32  
    33  // machineLife requests the lifecycle of the given machine from the server.
    34  func (st *State) machineLife(tag string) (params.Life, error) {
    35  	return common.Life(st.caller, machinerFacade, tag)
    36  }
    37  
    38  // Machine provides access to methods of a state.Machine through the facade.
    39  func (st *State) Machine(tag string) (*Machine, error) {
    40  	life, err := st.machineLife(tag)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	return &Machine{
    45  		tag:  tag,
    46  		life: life,
    47  		st:   st,
    48  	}, nil
    49  }