github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/api/deployer/machine.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  	"fmt"
     8  
     9  	"github.com/juju/names"
    10  
    11  	"github.com/juju/juju/api/watcher"
    12  	"github.com/juju/juju/apiserver/params"
    13  )
    14  
    15  // Machine represents a juju machine as seen by the deployer worker.
    16  type Machine struct {
    17  	tag names.MachineTag
    18  	st  *State
    19  }
    20  
    21  // WatchUnits starts a StringsWatcher to watch all units deployed to
    22  // the machine, in order to track which ones should be deployed or
    23  // recalled.
    24  func (m *Machine) WatchUnits() (watcher.StringsWatcher, error) {
    25  	var results params.StringsWatchResults
    26  	args := params.Entities{
    27  		Entities: []params.Entity{{Tag: m.tag.String()}},
    28  	}
    29  	err := m.st.facade.FacadeCall("WatchUnits", args, &results)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	if len(results.Results) != 1 {
    34  		return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
    35  	}
    36  	result := results.Results[0]
    37  	if result.Error != nil {
    38  		return nil, result.Error
    39  	}
    40  	w := watcher.NewStringsWatcher(m.st.facade.RawAPICaller(), result)
    41  	return w, nil
    42  }