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