NSXv: add timeout parameter for backend calls

Change-Id: I0eac75ebc9b6d18a3020685e9bd5744c98edab0e
This commit is contained in:
Kobi Samoray 2017-09-10 14:31:00 +03:00
parent 25211bdd3e
commit 123f92b45a
3 changed files with 20 additions and 16 deletions

View File

@ -688,6 +688,9 @@ nsxv_opts = [
"specifying DVS MoRef ID usable for VLAN provider "
"networks, as well as ranges of VLAN tags on each "
"available for allocation to networks.")),
cfg.IntOpt('nsx_transaction_timeout',
default=120,
help=_("Timeout interval for NSX backend transactions.")),
]
# define the configuration of each NSX-V availability zone.

View File

@ -85,12 +85,13 @@ class VcnsApiHelper(object):
}
def __init__(self, address, user, password, format='json', ca_file=None,
insecure=True):
insecure=True, timeout=None):
self.authToken = base64.encodestring(six.b("%s:%s" % (user, password)))
self.user = user
self.passwd = password
self.address = address
self.format = format
self.timeout = timeout
if format == 'json':
self.encode = jsonutils.dumps
else:
@ -135,11 +136,15 @@ class VcnsApiHelper(object):
else:
data = None
response = requests.request(method,
uri,
verify=self.verify_cert,
data=data,
headers=headers)
try:
response = requests.request(method,
uri,
verify=self.verify_cert,
data=data,
headers=headers,
timeout=self.timeout)
except requests.exceptions.Timeout:
raise exceptions.VcnsApiException(uri=uri)
status = response.status_code

View File

@ -111,16 +111,12 @@ class Vcns(object):
self.password = password
self.ca_file = ca_file
self.insecure = insecure
self.jsonapi_client = VcnsApiClient.VcnsApiHelper(address, user,
password,
format='json',
ca_file=ca_file,
insecure=insecure)
self.xmlapi_client = VcnsApiClient.VcnsApiHelper(address, user,
password,
format='xml',
ca_file=ca_file,
insecure=insecure)
self.jsonapi_client = VcnsApiClient.VcnsApiHelper(
address, user, password, format='json', ca_file=ca_file,
insecure=insecure, timeout=cfg.CONF.nsxv.nsx_transaction_timeout)
self.xmlapi_client = VcnsApiClient.VcnsApiHelper(
address, user, password, format='xml', ca_file=ca_file,
insecure=insecure, timeout=cfg.CONF.nsxv.nsx_transaction_timeout)
self._nsx_version = None
self._normalized_scoping_objects = None