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