github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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  // machineLife requests the lifecycle of the given machine from the server.
    33  func (st *State) machineLife(tag names.MachineTag) (params.Life, error) {
    34  	return common.OneLife(st.facade, tag)
    35  }
    36  
    37  // Machine provides access to methods of a state.Machine through the facade.
    38  func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
    39  	life, err := st.machineLife(tag)
    40  	if err != nil {
    41  		return nil, errors.Annotate(err, "can't get life for machine")
    42  	}
    43  	return &Machine{
    44  		tag:  tag,
    45  		life: life,
    46  		st:   st,
    47  	}, nil
    48  }