use auto reauth when access token is expired

pull/6/head
Masahiro Sano 2015-04-18 18:41:54 +09:00
parent ff59f316f6
commit b2d68c79b7
1 changed files with 2 additions and 19 deletions

View File

@ -76,7 +76,6 @@ type LoadBalancerOpts struct {
// OpenStack is an implementation of cloud provider Interface for OpenStack.
type OpenStack struct {
provider *gophercloud.ProviderClient
authOpts gophercloud.AuthOptions
region string
lbOpts LoadBalancerOpts
}
@ -117,11 +116,7 @@ func (cfg Config) toAuthOptions() gophercloud.AuthOptions {
TenantID: cfg.Global.TenantId,
TenantName: cfg.Global.TenantName,
// Persistent service, so we need to be able to renew
// tokens.
// (gophercloud doesn't appear to actually reauth yet,
// hence the explicit openstack.Authenticate() calls
// below)
// Persistent service, so we need to be able to renew tokens.
AllowReauth: true,
}
}
@ -138,15 +133,13 @@ func readConfig(config io.Reader) (Config, error) {
}
func newOpenStack(cfg Config) (*OpenStack, error) {
authOpts := cfg.toAuthOptions()
provider, err := openstack.AuthenticatedClient(authOpts)
provider, err := openstack.AuthenticatedClient(cfg.toAuthOptions())
if err != nil {
return nil, err
}
os := OpenStack{
provider: provider,
authOpts: authOpts,
region: cfg.Global.Region,
lbOpts: cfg.LoadBalancer,
}
@ -162,11 +155,6 @@ type Instances struct {
func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
glog.V(4).Info("openstack.Instances() called")
if err := openstack.Authenticate(os.provider, os.authOpts); err != nil {
glog.Warningf("Failed to reauthenticate: %v", err)
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
@ -413,11 +401,6 @@ type LoadBalancer struct {
func (os *OpenStack) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
glog.V(4).Info("openstack.TCPLoadBalancer() called")
if err := openstack.Authenticate(os.provider, os.authOpts); err != nil {
glog.Warningf("Failed to reauthenticate: %v", err)
return nil, false
}
// TODO: Search for and support Rackspace loadbalancer API, and others.
network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,