/
machine.go
42 lines (36 loc) · 1.06 KB
/
machine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package deployer
import (
"fmt"
"github.com/juju/names"
"github.com/juju/juju/api/watcher"
"github.com/juju/juju/apiserver/params"
)
// Machine represents a juju machine as seen by the deployer worker.
type Machine struct {
tag names.MachineTag
st *State
}
// WatchUnits starts a StringsWatcher to watch all units deployed to
// the machine, in order to track which ones should be deployed or
// recalled.
func (m *Machine) WatchUnits() (watcher.StringsWatcher, error) {
var results params.StringsWatchResults
args := params.Entities{
Entities: []params.Entity{{Tag: m.tag.String()}},
}
err := m.st.facade.FacadeCall("WatchUnits", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := watcher.NewStringsWatcher(m.st.facade.RawAPICaller(), result)
return w, nil
}