Merge "NSX-V| improve AZ validation"
This commit is contained in:
commit
e3e85f0eb6
@ -83,12 +83,6 @@ class ConfiguredAvailabilityZones(object):
|
||||
obj = az_class(None)
|
||||
self.availability_zones[obj.name] = obj
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_resources(self):
|
||||
"""Return a list of all the resources in all the availability zones
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_availability_zone(self, name):
|
||||
"""Return an availability zone object by its name
|
||||
"""
|
||||
|
@ -150,6 +150,11 @@ class NsxResourceNotFound(n_exc.NotFound):
|
||||
message = _("%(res_name)s %(res_id)s not found on the backend.")
|
||||
|
||||
|
||||
class NsxAZResourceNotFound(NsxResourceNotFound):
|
||||
message = _("Availability zone %(res_name)s %(res_id)s not found on the "
|
||||
"backend.")
|
||||
|
||||
|
||||
class NsxQosPolicyMappingNotFound(n_exc.NotFound):
|
||||
message = _('Unable to find mapping for QoS policy: %(policy)s')
|
||||
|
||||
|
@ -202,23 +202,44 @@ class NsxVAvailabilityZones(common_az.ConfiguredAvailabilityZones):
|
||||
cfg.CONF.nsxv.availability_zones,
|
||||
NsxVAvailabilityZone)
|
||||
|
||||
def get_resources(self):
|
||||
"""Return a list of all the resources in all the availability zones
|
||||
def get_inventory(self):
|
||||
"""Return a set of relevant resources in all the availability zones
|
||||
"""
|
||||
resources = []
|
||||
resources = set()
|
||||
for az in self.list_availability_zones_objects():
|
||||
resources.append(az.resource_pool)
|
||||
resources.append(az.datastore_id)
|
||||
resources.add(az.resource_pool)
|
||||
resources.add(az.datastore_id)
|
||||
if az.ha_datastore_id:
|
||||
resources.append(az.ha_datastore_id)
|
||||
if az.mgt_net_moid:
|
||||
resources.append(az.mgt_net_moid)
|
||||
if az.external_network:
|
||||
resources.append(az.external_network)
|
||||
if az.vdn_scope_id:
|
||||
resources.append(az.vdn_scope_id)
|
||||
if az.mgt_net_moid:
|
||||
resources.append(az.mgt_net_moid)
|
||||
if az.datacenter_moid:
|
||||
resources.append(az.datacenter_moid)
|
||||
resources.add(az.ha_datastore_id)
|
||||
|
||||
return resources
|
||||
|
||||
def get_unique_non_default_param(self, param_name):
|
||||
"""Return a set of all configured values of one of az params
|
||||
|
||||
Ignore the value of the default AZ
|
||||
"""
|
||||
resources = set()
|
||||
default_val = None
|
||||
for az in self.list_availability_zones_objects():
|
||||
az_val = getattr(az, param_name)
|
||||
if az.is_default():
|
||||
default_val = az_val
|
||||
elif az_val:
|
||||
resources.add(az_val)
|
||||
# remove the default value
|
||||
if default_val:
|
||||
resources.discard(default_val)
|
||||
return resources
|
||||
|
||||
def get_additional_vdn_scope(self):
|
||||
return self.get_unique_non_default_param("vdn_scope_id")
|
||||
|
||||
def get_additional_mgt_net(self):
|
||||
return self.get_unique_non_default_param("mgt_net_moid")
|
||||
|
||||
def get_additional_ext_net(self):
|
||||
return self.get_unique_non_default_param("external_network")
|
||||
|
||||
def get_additional_datacenter(self):
|
||||
return self.get_unique_non_default_param("datacenter_moid")
|
||||
|
@ -4045,29 +4045,49 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
res_name='dvs_id',
|
||||
res_id=cfg.CONF.nsxv.dvs_id)
|
||||
|
||||
# Validate the global & per-AZ validate_datacenter_moid
|
||||
if not self.nsx_v.vcns.validate_datacenter_moid(
|
||||
cfg.CONF.nsxv.datacenter_moid):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
raise nsx_exc.NsxAZResourceNotFound(
|
||||
res_name='external_network', res_id=ext_net)
|
||||
|
||||
# Validate the global & per-AZ vdn_scope_id
|
||||
if not self.nsx_v.vcns.validate_vdn_scope(cfg.CONF.nsxv.vdn_scope_id):
|
||||
raise nsx_exc.NsxResourceNotFound(
|
||||
res_name='vdn_scope_id',
|
||||
res_id=cfg.CONF.nsxv.vdn_scope_id)
|
||||
for vdns in self._availability_zones_data.get_additional_vdn_scope():
|
||||
if not self.nsx_v.vcns.validate_vdn_scope(vdns):
|
||||
raise nsx_exc.NsxAZResourceNotFound(
|
||||
res_name='vdn_scope_id', res_id=vdns)
|
||||
|
||||
# Validate the global & per-AZ mgt_net_moid
|
||||
if (cfg.CONF.nsxv.mgt_net_moid
|
||||
and not self.nsx_v.vcns.validate_network(
|
||||
cfg.CONF.nsxv.mgt_net_moid)):
|
||||
raise nsx_exc.NsxResourceNotFound(
|
||||
res_name='mgt_net_moid',
|
||||
res_id=cfg.CONF.nsxv.mgt_net_moid)
|
||||
for mgmt_net in self._availability_zones_data.get_additional_mgt_net():
|
||||
if not self.nsx_v.vcns.validate_network(mgmt_net):
|
||||
raise nsx_exc.NsxAZResourceNotFound(
|
||||
res_name='mgt_net_moid', res_id=mgmt_net)
|
||||
|
||||
ver = self.nsx_v.vcns.get_version()
|
||||
if version.LooseVersion(ver) < version.LooseVersion('6.2.0'):
|
||||
@ -4095,7 +4115,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
inventory.append((cluster, 'cluster_moid'))
|
||||
|
||||
# Add the availability zones resources
|
||||
az_resources = self._availability_zones_data.get_resources()
|
||||
az_resources = self._availability_zones_data.get_inventory()
|
||||
for res in az_resources:
|
||||
inventory.append((res, 'availability_zones'))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user