add timeout for Openstack cloud provider

pull/6/head
Di Xu 2017-09-28 17:38:11 +08:00
parent 3eb5ba805c
commit fe92a55425
1 changed files with 9 additions and 1 deletions

View File

@ -52,6 +52,7 @@ import (
const ( const (
ProviderName = "openstack" ProviderName = "openstack"
AvailabilityZone = "availability_zone" AvailabilityZone = "availability_zone"
defaultTimeOut = 60 * time.Second
) )
var ErrNotFound = errors.New("Failed to find object") var ErrNotFound = errors.New("Failed to find object")
@ -101,7 +102,8 @@ type RouterOpts struct {
} }
type MetadataOpts struct { type MetadataOpts struct {
SearchOrder string `gcfg:"search-order"` SearchOrder string `gcfg:"search-order"`
RequestTimeout MyDuration `gcfg:"request-timeout"`
} }
// OpenStack is an implementation of cloud provider Interface for OpenStack. // OpenStack is an implementation of cloud provider Interface for OpenStack.
@ -290,6 +292,12 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
return nil, err return nil, err
} }
emptyDuration := MyDuration{}
if cfg.Metadata.RequestTimeout == emptyDuration {
cfg.Metadata.RequestTimeout.Duration = time.Duration(defaultTimeOut)
}
provider.HTTPClient.Timeout = cfg.Metadata.RequestTimeout.Duration
os := OpenStack{ os := OpenStack{
provider: provider, provider: provider,
region: cfg.Global.Region, region: cfg.Global.Region,