NSX|V improve validate_network performance
validate_network calls may have called the backend up to 3 times, while 1 time is enough Change-Id: Ifbfb7adbb2fd53d279667c163a3e0da03a43293f
This commit is contained in:
parent
c7f26cb926
commit
0d3106062e
@ -81,6 +81,8 @@ IPAM_POOL_SERVICE = "ipam/pools"
|
|||||||
CSR = "csr"
|
CSR = "csr"
|
||||||
CERTIFICATE = "certificate"
|
CERTIFICATE = "certificate"
|
||||||
|
|
||||||
|
NETWORK_TYPES = ['Network', 'VirtualWire', 'DistributedVirtualPortgroup']
|
||||||
|
|
||||||
|
|
||||||
def retry_upon_exception(exc, delay=500, max_delay=4000,
|
def retry_upon_exception(exc, delay=500, max_delay=4000,
|
||||||
max_attempts=cfg.CONF.nsxv.retries):
|
max_attempts=cfg.CONF.nsxv.retries):
|
||||||
@ -791,14 +793,14 @@ class Vcns(object):
|
|||||||
format='xml')
|
format='xml')
|
||||||
return scoping_objects
|
return scoping_objects
|
||||||
|
|
||||||
def _scopingobjects_lookup(self, type_name, object_id, name=None):
|
def _scopingobjects_lookup(self, type_names, object_id, name=None):
|
||||||
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
|
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
|
||||||
h, so_list = self.do_request(HTTP_GET, uri, decode=False,
|
h, so_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||||
format='xml')
|
format='xml')
|
||||||
|
|
||||||
root = et.fromstring(so_list)
|
root = et.fromstring(so_list)
|
||||||
for obj in root.iter('object'):
|
for obj in root.iter('object'):
|
||||||
if (obj.find('objectTypeName').text == type_name and
|
if (obj.find('objectTypeName').text in type_names and
|
||||||
obj.find('objectId').text == object_id and
|
obj.find('objectId').text == object_id and
|
||||||
(name is None or obj.find('name').text == name)):
|
(name is None or obj.find('name').text == name)):
|
||||||
return True
|
return True
|
||||||
@ -806,19 +808,13 @@ class Vcns(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def validate_datacenter_moid(self, object_id):
|
def validate_datacenter_moid(self, object_id):
|
||||||
return self._scopingobjects_lookup('Datacenter', object_id)
|
return self._scopingobjects_lookup(['Datacenter'], object_id)
|
||||||
|
|
||||||
def validate_network(self, object_id):
|
def validate_network(self, object_id):
|
||||||
return (self._scopingobjects_lookup('Network', object_id) or
|
return self._scopingobjects_lookup(NETWORK_TYPES, object_id)
|
||||||
self._scopingobjects_lookup('DistributedVirtualPortgroup',
|
|
||||||
object_id) or
|
|
||||||
self._scopingobjects_lookup('VirtualWire', object_id))
|
|
||||||
|
|
||||||
def validate_network_name(self, object_id, name):
|
def validate_network_name(self, object_id, name):
|
||||||
return (self._scopingobjects_lookup('Network', object_id, name) or
|
return self._scopingobjects_lookup(NETWORK_TYPES, object_id, name)
|
||||||
self._scopingobjects_lookup('DistributedVirtualPortgroup',
|
|
||||||
object_id, name) or
|
|
||||||
self._scopingobjects_lookup('VirtualWire', object_id, name))
|
|
||||||
|
|
||||||
def validate_vdn_scope(self, object_id):
|
def validate_vdn_scope(self, object_id):
|
||||||
uri = '%s/scopes' % VDN_PREFIX
|
uri = '%s/scopes' % VDN_PREFIX
|
||||||
|
Loading…
x
Reference in New Issue
Block a user