NSX|V: Call NSX backend once for dvs validations
When validation the DVS-IDs upon plugin init or provider network creation, we can first get all teh dVS IDs from teh NSX backend, and then validate that all the requested IDs are in the list. Change-Id: Ie03da6c4149c215f7037586cb443d2c5d6e417db
This commit is contained in:
parent
e8b2397926
commit
775031e5c4
@ -589,8 +589,10 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
|
||||
def _validate_physical_network(self, physical_network, default_dvs):
|
||||
dvs_ids = self._get_dvs_ids(physical_network, default_dvs)
|
||||
existing_dvs = self.nsx_v.vcns.get_dvs_list()
|
||||
for dvs_id in dvs_ids:
|
||||
if not self.nsx_v.vcns.validate_dvs(dvs_id):
|
||||
if not self.nsx_v.vcns.validate_dvs(
|
||||
dvs_id, dvs_list=existing_dvs):
|
||||
raise nsx_exc.NsxResourceNotFound(res_name='dvs_id',
|
||||
res_id=dvs_id)
|
||||
|
||||
@ -4214,13 +4216,16 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
LOG.info("Unable to configure edge reservations")
|
||||
|
||||
def _validate_config(self):
|
||||
existing_dvs = self.nsx_v.vcns.get_dvs_list()
|
||||
if (cfg.CONF.nsxv.dvs_id and
|
||||
not self.nsx_v.vcns.validate_dvs(cfg.CONF.nsxv.dvs_id)):
|
||||
not self.nsx_v.vcns.validate_dvs(cfg.CONF.nsxv.dvs_id,
|
||||
dvs_list=existing_dvs)):
|
||||
raise nsx_exc.NsxResourceNotFound(
|
||||
res_name='dvs_id',
|
||||
res_id=cfg.CONF.nsxv.dvs_id)
|
||||
for dvs_id in self._availability_zones_data.get_additional_dvs_ids():
|
||||
if not self.nsx_v.vcns.validate_dvs(dvs_id):
|
||||
if not self.nsx_v.vcns.validate_dvs(dvs_id,
|
||||
dvs_list=existing_dvs):
|
||||
raise nsx_exc.NsxAZResourceNotFound(
|
||||
res_name='dvs_id', res_id=dvs_id)
|
||||
|
||||
|
@ -926,13 +926,23 @@ class Vcns(object):
|
||||
|
||||
return False
|
||||
|
||||
def validate_dvs(self, object_id):
|
||||
def get_dvs_list(self):
|
||||
uri = '%s/switches' % VDN_PREFIX
|
||||
h, dvs_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
root = utils.normalize_xml(dvs_list)
|
||||
dvs_list = []
|
||||
for obj_id in root.iter('objectId'):
|
||||
if obj_id.text == object_id:
|
||||
if obj_id.text:
|
||||
dvs_list.append(obj_id.text)
|
||||
|
||||
return dvs_list
|
||||
|
||||
def validate_dvs(self, object_id, dvs_list=None):
|
||||
if not dvs_list:
|
||||
dvs_list = self.get_dvs_list()
|
||||
for dvs in dvs_list:
|
||||
if dvs == object_id:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -1185,7 +1185,10 @@ class FakeVcns(object):
|
||||
def validate_vdn_scope(self, object_id):
|
||||
return True
|
||||
|
||||
def validate_dvs(self, object_id):
|
||||
def get_dvs_list(self):
|
||||
return []
|
||||
|
||||
def validate_dvs(self, object_id, dvs_list=None):
|
||||
return True
|
||||
|
||||
def edges_lock_operation(self):
|
||||
|
Loading…
Reference in New Issue
Block a user