github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/api/common/apiaddresser.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 apiwatcher "github.com/juju/juju/api/watcher" 9 "github.com/juju/juju/apiserver/params" 10 "github.com/juju/juju/network" 11 "github.com/juju/juju/watcher" 12 ) 13 14 // APIAddresser provides common client-side API 15 // functions to call into apiserver.common.APIAddresser 16 type APIAddresser struct { 17 facade base.FacadeCaller 18 } 19 20 // NewAPIAddresser returns a new APIAddresser that makes API calls 21 // using caller and the specified facade name. 22 func NewAPIAddresser(facade base.FacadeCaller) *APIAddresser { 23 return &APIAddresser{ 24 facade: facade, 25 } 26 } 27 28 // APIAddresses returns the list of addresses used to connect to the API. 29 func (a *APIAddresser) APIAddresses() ([]string, error) { 30 var result params.StringsResult 31 err := a.facade.FacadeCall("APIAddresses", nil, &result) 32 if err != nil { 33 return nil, err 34 } 35 36 if err := result.Error; err != nil { 37 return nil, err 38 } 39 return result.Result, nil 40 } 41 42 // ModelUUID returns the model UUID to connect to the model 43 // that the current connection is for. 44 func (a *APIAddresser) ModelUUID() (string, error) { 45 var result params.StringResult 46 err := a.facade.FacadeCall("ModelUUID", nil, &result) 47 if err != nil { 48 return "", err 49 } 50 return result.Result, nil 51 } 52 53 // CACert returns the certificate used to validate the API and state connections. 54 func (a *APIAddresser) CACert() (string, error) { 55 var result params.BytesResult 56 err := a.facade.FacadeCall("CACert", nil, &result) 57 if err != nil { 58 return "", err 59 } 60 return string(result.Result), nil 61 } 62 63 // APIHostPorts returns the host/port addresses of the API servers. 64 func (a *APIAddresser) APIHostPorts() ([][]network.HostPort, error) { 65 var result params.APIHostPortsResult 66 err := a.facade.FacadeCall("APIHostPorts", nil, &result) 67 if err != nil { 68 return nil, err 69 } 70 return result.NetworkHostsPorts(), nil 71 } 72 73 // WatchAPIHostPorts watches the host/port addresses of the API servers. 74 func (a *APIAddresser) WatchAPIHostPorts() (watcher.NotifyWatcher, error) { 75 var result params.NotifyWatchResult 76 err := a.facade.FacadeCall("WatchAPIHostPorts", nil, &result) 77 if err != nil { 78 return nil, err 79 } 80 return apiwatcher.NewNotifyWatcher(a.facade.RawAPICaller(), result), nil 81 }