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 (
ProviderName = "openstack"
AvailabilityZone = "availability_zone"
defaultTimeOut = 60 * time.Second
)
var ErrNotFound = errors.New("Failed to find object")
@ -102,6 +103,7 @@ type RouterOpts struct {
type MetadataOpts struct {
SearchOrder string `gcfg:"search-order"`
RequestTimeout MyDuration `gcfg:"request-timeout"`
}
// OpenStack is an implementation of cloud provider Interface for OpenStack.
@ -290,6 +292,12 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
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{
provider: provider,
region: cfg.Global.Region,