github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/api/common/environwatcher.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import ( 7 "github.com/juju/juju/api/base" 8 "github.com/juju/juju/api/watcher" 9 "github.com/juju/juju/apiserver/params" 10 "github.com/juju/juju/environs/config" 11 ) 12 13 // EnvironWatcher provides common client-side API functions 14 // to call into apiserver.common.EnvironWatcher. 15 type EnvironWatcher struct { 16 facade base.FacadeCaller 17 } 18 19 // NewEnvironWatcher creates a EnvironWatcher on the specified facade, 20 // and uses this name when calling through the caller. 21 func NewEnvironWatcher(facade base.FacadeCaller) *EnvironWatcher { 22 return &EnvironWatcher{facade} 23 } 24 25 // WatchForEnvironConfigChanges return a NotifyWatcher waiting for the 26 // environment configuration to change. 27 func (e *EnvironWatcher) WatchForEnvironConfigChanges() (watcher.NotifyWatcher, error) { 28 var result params.NotifyWatchResult 29 err := e.facade.FacadeCall("WatchForEnvironConfigChanges", nil, &result) 30 if err != nil { 31 return nil, err 32 } 33 return watcher.NewNotifyWatcher(e.facade.RawAPICaller(), result), nil 34 } 35 36 // EnvironConfig returns the current environment configuration. 37 func (e *EnvironWatcher) EnvironConfig() (*config.Config, error) { 38 var result params.EnvironConfigResult 39 err := e.facade.FacadeCall("EnvironConfig", nil, &result) 40 if err != nil { 41 return nil, err 42 } 43 conf, err := config.New(config.NoDefaults, result.Config) 44 if err != nil { 45 return nil, err 46 } 47 return conf, nil 48 }