github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/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  	"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 deployerFacade = "Deployer"
    13  
    14  // State provides access to the deployer worker's idea of the state.
    15  type State struct {
    16  	caller base.Caller
    17  	*common.APIAddresser
    18  }
    19  
    20  // NewState creates a new State instance that makes API calls
    21  // through the given caller.
    22  func NewState(caller base.Caller) *State {
    23  	return &State{
    24  		APIAddresser: common.NewAPIAddresser(deployerFacade, caller),
    25  		caller:       caller,
    26  	}
    27  
    28  }
    29  
    30  func (st *State) call(method string, params, result interface{}) error {
    31  	return st.caller.Call(deployerFacade, "", method, params, result)
    32  }
    33  
    34  // unitLife returns the lifecycle state of the given unit.
    35  func (st *State) unitLife(tag string) (params.Life, error) {
    36  	return common.Life(st.caller, deployerFacade, tag)
    37  }
    38  
    39  // Unit returns the unit with the given tag.
    40  func (st *State) Unit(tag string) (*Unit, error) {
    41  	life, err := st.unitLife(tag)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  	return &Unit{
    46  		tag:  tag,
    47  		life: life,
    48  		st:   st,
    49  	}, nil
    50  }
    51  
    52  // Machine returns the machine with the given tag.
    53  func (st *State) Machine(tag string) (*Machine, error) {
    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.call("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.call("ConnectionInfo", nil, &result)
    74  	return result, err
    75  }