github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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  }
    20  
    21  // NewState creates a new State instance that makes API calls
    22  // through the given caller.
    23  func NewState(caller base.APICaller) *State {
    24  	facadeCaller := base.NewFacadeCaller(caller, deployerFacade)
    25  	return &State{facade: facadeCaller}
    26  
    27  }
    28  
    29  // unitLife returns the lifecycle state of the given unit.
    30  func (st *State) unitLife(tag names.UnitTag) (params.Life, error) {
    31  	return common.OneLife(st.facade, tag)
    32  }
    33  
    34  // Unit returns the unit with the given tag.
    35  func (st *State) Unit(tag names.UnitTag) (*Unit, error) {
    36  	life, err := st.unitLife(tag)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	return &Unit{
    41  		tag:  tag,
    42  		life: life,
    43  		st:   st,
    44  	}, nil
    45  }
    46  
    47  // Machine returns the machine with the given tag.
    48  func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
    49  	// TODO(dfc) this cannot return an error any more
    50  	return &Machine{
    51  		tag: tag,
    52  		st:  st,
    53  	}, nil
    54  }
    55  
    56  // ConnectionInfo returns all the address information that the deployer task
    57  // needs in one call.
    58  func (st *State) ConnectionInfo() (result params.DeployerConnectionValues, err error) {
    59  	err = st.facade.FacadeCall("ConnectionInfo", nil, &result)
    60  	return result, err
    61  }