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