github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/machiner/state.go (about)

     1  // Copyright 2015 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  	"github.com/juju/names/v5"
     9  
    10  	"github.com/juju/juju/api/agent/machiner"
    11  	"github.com/juju/juju/core/life"
    12  	"github.com/juju/juju/core/network"
    13  	"github.com/juju/juju/core/status"
    14  	"github.com/juju/juju/core/watcher"
    15  	"github.com/juju/juju/rpc/params"
    16  )
    17  
    18  type MachineAccessor interface {
    19  	Machine(names.MachineTag) (Machine, error)
    20  }
    21  
    22  type Machine interface {
    23  	Refresh() error
    24  	Life() life.Value
    25  	EnsureDead() error
    26  	SetMachineAddresses(addresses []network.MachineAddress) error
    27  	SetStatus(machineStatus status.Status, info string, data map[string]interface{}) error
    28  	Watch() (watcher.NotifyWatcher, error)
    29  	SetObservedNetworkConfig(netConfig []params.NetworkConfig) error
    30  }
    31  
    32  type APIMachineAccessor struct {
    33  	State *machiner.State
    34  }
    35  
    36  func (a APIMachineAccessor) Machine(tag names.MachineTag) (Machine, error) {
    37  	m, err := a.State.Machine(tag)
    38  	if err != nil {
    39  		return nil, errors.Trace(err)
    40  	}
    41  	return m, nil
    42  }