github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/state/api/firewaller/firewaller.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package firewaller 5 6 import ( 7 "launchpad.net/juju-core/environs/config" 8 "launchpad.net/juju-core/state/api/base" 9 "launchpad.net/juju-core/state/api/common" 10 "launchpad.net/juju-core/state/api/params" 11 "launchpad.net/juju-core/state/api/watcher" 12 ) 13 14 // State provides access to the Firewaller API facade. 15 type State struct { 16 caller base.Caller 17 } 18 19 // NewState creates a new client-side Firewaller facade. 20 func NewState(caller base.Caller) *State { 21 return &State{caller} 22 } 23 24 // life requests the life cycle of the given entity from the server. 25 func (st *State) life(tag string) (params.Life, error) { 26 return common.Life(st.caller, "Firewaller", tag) 27 } 28 29 // Unit provides access to methods of a state.Unit through the facade. 30 func (st *State) Unit(tag string) (*Unit, error) { 31 life, err := st.life(tag) 32 if err != nil { 33 return nil, err 34 } 35 return &Unit{ 36 tag: tag, 37 life: life, 38 st: st, 39 }, nil 40 } 41 42 // Machine provides access to methods of a state.Machine through the 43 // facade. 44 func (st *State) Machine(tag string) (*Machine, error) { 45 life, err := st.life(tag) 46 if err != nil { 47 return nil, err 48 } 49 return &Machine{ 50 tag: tag, 51 life: life, 52 st: st, 53 }, nil 54 } 55 56 // WatchForEnvironConfigChanges return a NotifyWatcher waiting for the 57 // environment configuration to change. 58 func (st *State) WatchForEnvironConfigChanges() (watcher.NotifyWatcher, error) { 59 var result params.NotifyWatchResult 60 err := st.caller.Call("Firewaller", "", "WatchForEnvironConfigChanges", nil, &result) 61 if err != nil { 62 return nil, err 63 } 64 if err := result.Error; err != nil { 65 return nil, result.Error 66 } 67 w := watcher.NewNotifyWatcher(st.caller, result) 68 return w, nil 69 } 70 71 // EnvironConfig returns the current environment configuration. 72 func (st *State) EnvironConfig() (*config.Config, error) { 73 var result params.EnvironConfigResult 74 err := st.caller.Call("Firewaller", "", "EnvironConfig", nil, &result) 75 if err != nil { 76 return nil, err 77 } 78 if err := result.Error; err != nil { 79 return nil, err 80 } 81 conf, err := config.New(config.NoDefaults, result.Config) 82 if err != nil { 83 return nil, err 84 } 85 return conf, nil 86 } 87 88 // WatchEnvironMachines returns a StringsWatcher that notifies of 89 // changes to the life cycles of the top level machines in the current 90 // environment. 91 func (st *State) WatchEnvironMachines() (watcher.StringsWatcher, error) { 92 var result params.StringsWatchResult 93 err := st.caller.Call("Firewaller", "", "WatchEnvironMachines", nil, &result) 94 if err != nil { 95 return nil, err 96 } 97 if err := result.Error; err != nil { 98 return nil, result.Error 99 } 100 w := watcher.NewStringsWatcher(st.caller, result) 101 return w, nil 102 }