NSX|v: call backend scoping objects only once during init
The call to get the NSX backend scoping objets is called multiple times during plugin init (2-3 times per availability zone) to validate the configuration. The result of this call is a big xml data, which needs to be parsed. This patch makes sure that we will call the backend only once during init and used the cached results for the rest of the times. Later calls (after init) should not use the cache since the backend configuration might have changed. Change-Id: Ib5ed8f0d75aed98963e1deff9c123ee01afc875c
This commit is contained in:
parent
b76d3ad6de
commit
1320922703
@ -4216,23 +4216,27 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
|
||||
# Validate the global & per-AZ validate_datacenter_moid
|
||||
if not self.nsx_v.vcns.validate_datacenter_moid(
|
||||
cfg.CONF.nsxv.datacenter_moid):
|
||||
cfg.CONF.nsxv.datacenter_moid,
|
||||
during_init=True):
|
||||
raise nsx_exc.NsxResourceNotFound(
|
||||
res_name='datacenter_moid',
|
||||
res_id=cfg.CONF.nsxv.datacenter_moid)
|
||||
for dc in self._availability_zones_data.get_additional_datacenter():
|
||||
if not self.nsx_v.vcns.validate_datacenter_moid(dc):
|
||||
if not self.nsx_v.vcns.validate_datacenter_moid(
|
||||
dc, during_init=True):
|
||||
raise nsx_exc.NsxAZResourceNotFound(
|
||||
res_name='datacenter_moid', res_id=dc)
|
||||
|
||||
# Validate the global & per-AZ external_network
|
||||
if not self.nsx_v.vcns.validate_network(
|
||||
cfg.CONF.nsxv.external_network):
|
||||
cfg.CONF.nsxv.external_network,
|
||||
during_init=True):
|
||||
raise nsx_exc.NsxResourceNotFound(
|
||||
res_name='external_network',
|
||||
res_id=cfg.CONF.nsxv.external_network)
|
||||
for ext_net in self._availability_zones_data.get_additional_ext_net():
|
||||
if not self.nsx_v.vcns.validate_network(ext_net):
|
||||
if not self.nsx_v.vcns.validate_network(
|
||||
ext_net, during_init=True):
|
||||
raise nsx_exc.NsxAZResourceNotFound(
|
||||
res_name='external_network', res_id=ext_net)
|
||||
|
||||
|
@ -122,6 +122,7 @@ class Vcns(object):
|
||||
ca_file=ca_file,
|
||||
insecure=insecure)
|
||||
self._nsx_version = None
|
||||
self._normalized_scoping_objects = None
|
||||
|
||||
def _log_request(self, method, uri, body, format):
|
||||
if format == 'json':
|
||||
@ -877,11 +878,23 @@ class Vcns(object):
|
||||
format='xml')
|
||||
return scoping_objects
|
||||
|
||||
def _scopingobjects_lookup(self, type_names, object_id, name=None):
|
||||
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
|
||||
h, so_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
root = utils.normalize_xml(so_list)
|
||||
def _scopingobjects_lookup(self, type_names, object_id, name=None,
|
||||
use_cache=False):
|
||||
"""Look for a specific object in the NSX scoping objects."""
|
||||
# used cached scoping objects during plugin init since it is
|
||||
# a big structure to retrieve and parse each time.
|
||||
if use_cache and self._normalized_scoping_objects is not None:
|
||||
# Use the cached data
|
||||
root = self._normalized_scoping_objects
|
||||
else:
|
||||
# Not using cache, or we do want to use it,
|
||||
# but it was not saved yet:
|
||||
# So get the data from the NSX and parse it
|
||||
so_list = self.get_scoping_objects()
|
||||
root = utils.normalize_xml(so_list)
|
||||
# Save it for possible usage next time (even if not using cache)
|
||||
self._normalized_scoping_objects = root
|
||||
|
||||
for obj in root.iter('object'):
|
||||
if (obj.find('objectTypeName').text in type_names and
|
||||
obj.find('objectId').text == object_id and
|
||||
@ -890,14 +903,17 @@ class Vcns(object):
|
||||
|
||||
return False
|
||||
|
||||
def validate_datacenter_moid(self, object_id):
|
||||
return self._scopingobjects_lookup(['Datacenter'], object_id)
|
||||
def validate_datacenter_moid(self, object_id, during_init=False):
|
||||
return self._scopingobjects_lookup(['Datacenter'], object_id,
|
||||
use_cache=during_init)
|
||||
|
||||
def validate_network(self, object_id):
|
||||
return self._scopingobjects_lookup(NETWORK_TYPES, object_id)
|
||||
def validate_network(self, object_id, during_init=False):
|
||||
return self._scopingobjects_lookup(NETWORK_TYPES, object_id,
|
||||
use_cache=during_init)
|
||||
|
||||
def validate_network_name(self, object_id, name):
|
||||
return self._scopingobjects_lookup(NETWORK_TYPES, object_id, name)
|
||||
def validate_network_name(self, object_id, name, during_init=False):
|
||||
return self._scopingobjects_lookup(NETWORK_TYPES, object_id,
|
||||
use_cache=during_init)
|
||||
|
||||
def validate_vdn_scope(self, object_id):
|
||||
uri = '%s/scopes' % VDN_PREFIX
|
||||
|
@ -1173,13 +1173,13 @@ class FakeVcns(object):
|
||||
self._dhcp_bindings = {}
|
||||
self._ipam_pools = {}
|
||||
|
||||
def validate_datacenter_moid(self, object_id):
|
||||
def validate_datacenter_moid(self, object_id, during_init=False):
|
||||
return True
|
||||
|
||||
def validate_network(self, object_id):
|
||||
def validate_network(self, object_id, during_init=False):
|
||||
return True
|
||||
|
||||
def validate_network_name(self, object_id, name):
|
||||
def validate_network_name(self, object_id, name, during_init=False):
|
||||
return True
|
||||
|
||||
def validate_vdn_scope(self, object_id):
|
||||
|
Loading…
x
Reference in New Issue
Block a user