NSX-V+V3: Fix network availability zones extend func

In order for network availability zone field to have the right value
in the |TVD plugin, we need to separate the az-hints code from the az code.
the az hints is the same for v&v3 plugins and updated using a registered
extend method.
the az field logic is different in each plugin and updated direction by
get_network_availability_zones

Change-Id: Ife423b92d8861d8cde9a7ae265f86382505d2541
This commit is contained in:
Adit Sarfaty 2017-12-28 14:28:52 +02:00
parent 84da10cf22
commit a0456d9990
3 changed files with 16 additions and 16 deletions

View File

@ -23,10 +23,12 @@ from neutron.db import db_base_plugin_v2
from neutron.db import l3_db
from neutron.db import models_v2
from neutron_lib.api.definitions import address_scope as ext_address_scope
from neutron_lib.api.definitions import availability_zone as az_def
from neutron_lib.api.definitions import network as net_def
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import subnet as subnet_def
from neutron_lib.api import validators
from neutron_lib.api.validators import availability_zone as az_validator
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
@ -329,6 +331,12 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
msg = _("Cannot set a default route using static routes")
raise n_exc.BadRequest(resource='router', msg=msg)
@staticmethod
@resource_extend.extends([net_def.COLLECTION_NAME])
def _extend_availability_zone_hints(net_res, net_db):
net_res[az_def.AZ_HINTS] = az_validator.convert_az_string_to_list(
net_db[az_def.AZ_HINTS])
# Register the callback
def _validate_network_has_subnet(resource, event, trigger, **kwargs):

View File

@ -23,7 +23,6 @@ from neutron_lib.api.definitions import availability_zone as az_def
from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import network as net_def
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import provider_net as pnet
@ -3277,12 +3276,6 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
super(NsxVPluginV2, self).delete_router(context, id)
router_driver.delete_router(context, id)
@staticmethod
@resource_extend.extends([net_def.COLLECTION_NAME])
def _extend_availability_zone_hints(net_res, net_db):
net_res[az_def.AZ_HINTS] = az_validator.convert_az_string_to_list(
net_db[az_def.AZ_HINTS])
def get_availability_zone_name_by_edge(self, context, edge_id):
az_name = nsxv_db.get_edge_availability_zone(
context.session, edge_id)

View File

@ -18,7 +18,6 @@ from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib.api.definitions import availability_zone as az_def
from neutron_lib.api.definitions import external_net as extnet_apidef
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib.api.definitions import network as net_def
from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api import faults
from neutron_lib.api.validators import availability_zone as az_validator
@ -4385,21 +4384,21 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
# Validate against the configured AZs
return self.validate_obj_azs(availability_zones)
@staticmethod
@resource_extend.extends([net_def.COLLECTION_NAME])
def _extend_availability_zone_hints(net_res, net_db):
net_res[az_def.AZ_HINTS] = az_validator.convert_az_string_to_list(
net_db[az_def.AZ_HINTS])
def get_network_availability_zones(self, net_db):
if cfg.CONF.nsx_v3.native_dhcp_metadata:
hints = az_validator.convert_az_string_to_list(
net_db[az_def.AZ_HINTS])
# When using the configured AZs, the az will always be the same
# as the hint (or default if none)
if net_res[az_def.AZ_HINTS]:
az_name = net_res[az_def.AZ_HINTS][0]
if hints:
az_name = hints[0]
elif cfg.CONF.default_availability_zones:
az_name = cfg.CONF.default_availability_zones[0]
else:
az_name = nsx_az.DEFAULT_NAME
net_res[az_def.COLLECTION_NAME] = [az_name]
return [az_name]
else:
return []
def recalculate_snat_rules_for_router(self, context, router, subnets):
"""Recalculate router snat rules for specific subnets.