github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/api/machiner/machine.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package machiner 5 6 import ( 7 "github.com/juju/names" 8 9 "github.com/juju/juju/api/common" 10 "github.com/juju/juju/api/watcher" 11 "github.com/juju/juju/apiserver/params" 12 "github.com/juju/juju/network" 13 ) 14 15 // Machine represents a juju machine as seen by a machiner worker. 16 type Machine struct { 17 tag names.MachineTag 18 life params.Life 19 st *State 20 } 21 22 // Tag returns the machine's tag. 23 func (m *Machine) Tag() names.Tag { 24 return m.tag 25 } 26 27 // Life returns the machine's lifecycle value. 28 func (m *Machine) Life() params.Life { 29 return m.life 30 } 31 32 // Refresh updates the cached local copy of the machine's data. 33 func (m *Machine) Refresh() error { 34 life, err := m.st.machineLife(m.tag) 35 if err != nil { 36 return err 37 } 38 m.life = life 39 return nil 40 } 41 42 // SetStatus sets the status of the machine. 43 func (m *Machine) SetStatus(status params.Status, info string, data map[string]interface{}) error { 44 var result params.ErrorResults 45 args := params.SetStatus{ 46 Entities: []params.EntityStatus{ 47 {Tag: m.tag.String(), Status: status, Info: info, Data: data}, 48 }, 49 } 50 err := m.st.facade.FacadeCall("SetStatus", args, &result) 51 if err != nil { 52 return err 53 } 54 return result.OneError() 55 } 56 57 // SetMachineAddresses sets the machine determined addresses of the machine. 58 func (m *Machine) SetMachineAddresses(addresses []network.Address) error { 59 var result params.ErrorResults 60 args := params.SetMachinesAddresses{ 61 MachineAddresses: []params.MachineAddresses{ 62 {Tag: m.Tag().String(), Addresses: addresses}, 63 }, 64 } 65 err := m.st.facade.FacadeCall("SetMachineAddresses", args, &result) 66 if err != nil { 67 return err 68 } 69 return result.OneError() 70 } 71 72 // EnsureDead sets the machine lifecycle to Dead if it is Alive or 73 // Dying. It does nothing otherwise. 74 func (m *Machine) EnsureDead() error { 75 var result params.ErrorResults 76 args := params.Entities{ 77 Entities: []params.Entity{{Tag: m.tag.String()}}, 78 } 79 err := m.st.facade.FacadeCall("EnsureDead", args, &result) 80 if err != nil { 81 return err 82 } 83 return result.OneError() 84 } 85 86 // Watch returns a watcher for observing changes to the machine. 87 func (m *Machine) Watch() (watcher.NotifyWatcher, error) { 88 return common.Watch(m.st.facade, m.tag) 89 }