github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/api/agent/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/names/v5"
     8  
     9  	"github.com/juju/juju/api/base"
    10  	"github.com/juju/juju/api/common"
    11  	"github.com/juju/juju/core/life"
    12  	"github.com/juju/juju/rpc/params"
    13  )
    14  
    15  const deployerFacade = "Deployer"
    16  
    17  // State provides access to the deployer worker's idea of the state.
    18  type State struct {
    19  	facade base.FacadeCaller
    20  }
    21  
    22  // NewState creates a new State instance that makes API calls
    23  // through the given caller.
    24  func NewState(caller base.APICaller) *State {
    25  	facadeCaller := base.NewFacadeCaller(caller, deployerFacade)
    26  	return &State{facade: facadeCaller}
    27  
    28  }
    29  
    30  // unitLife returns the lifecycle state of the given unit.
    31  func (st *State) unitLife(tag names.UnitTag) (life.Value, error) {
    32  	return common.OneLife(st.facade, tag)
    33  }
    34  
    35  // Unit returns the unit with the given tag.
    36  func (st *State) Unit(tag names.UnitTag) (*Unit, error) {
    37  	life, err := st.unitLife(tag)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	return &Unit{
    42  		tag:  tag,
    43  		life: life,
    44  		st:   st,
    45  	}, nil
    46  }
    47  
    48  // Machine returns the machine with the given tag.
    49  func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
    50  	// TODO(dfc) this cannot return an error any more
    51  	return &Machine{
    52  		tag: tag,
    53  		st:  st,
    54  	}, nil
    55  }
    56  
    57  // ConnectionInfo returns all the address information that the deployer task
    58  // needs in one call.
    59  func (st *State) ConnectionInfo() (result params.DeployerConnectionValues, err error) {
    60  	err = st.facade.FacadeCall("ConnectionInfo", nil, &result)
    61  	return result, err
    62  }