github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/machiner/state.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  package machiner
     4  
     5  import (
     6  	"github.com/juju/errors"
     7  	"gopkg.in/juju/names.v2"
     8  
     9  	"github.com/juju/juju/api/machiner"
    10  	"github.com/juju/juju/apiserver/params"
    11  	"github.com/juju/juju/network"
    12  	"github.com/juju/juju/status"
    13  	"github.com/juju/juju/watcher"
    14  )
    15  
    16  type MachineAccessor interface {
    17  	Machine(names.MachineTag) (Machine, error)
    18  }
    19  
    20  type Machine interface {
    21  	Refresh() error
    22  	Life() params.Life
    23  	EnsureDead() error
    24  	SetMachineAddresses(addresses []network.Address) error
    25  	SetStatus(machineStatus status.Status, info string, data map[string]interface{}) error
    26  	Watch() (watcher.NotifyWatcher, error)
    27  	SetObservedNetworkConfig(netConfig []params.NetworkConfig) error
    28  }
    29  
    30  type APIMachineAccessor struct {
    31  	State *machiner.State
    32  }
    33  
    34  func (a APIMachineAccessor) Machine(tag names.MachineTag) (Machine, error) {
    35  	m, err := a.State.Machine(tag)
    36  	if err != nil {
    37  		return nil, errors.Trace(err)
    38  	}
    39  	return m, nil
    40  }