diff --git a/vmware_nsx/common/availability_zones.py b/vmware_nsx/common/availability_zones.py index 2be7771828..d566a1d4ce 100644 --- a/vmware_nsx/common/availability_zones.py +++ b/vmware_nsx/common/availability_zones.py @@ -29,6 +29,7 @@ class ConfiguredAvailabilityZone(object): def __init__(self, config_line, default_name=DEFAULT_NAME): self.name = "" + self.init_defaults() self._is_default = False if config_line and ':' in config_line: # Older configuration - each line contains all the relevant @@ -47,7 +48,6 @@ class ConfiguredAvailabilityZone(object): # Default zone configuration self.name = default_name self._is_default = True - self.init_default_az() def is_default(self): return self._is_default @@ -68,7 +68,7 @@ class ConfiguredAvailabilityZone(object): pass @abc.abstractmethod - def init_default_az(self): + def init_defaults(self): pass diff --git a/vmware_nsx/common/config.py b/vmware_nsx/common/config.py index 6a7b281c3f..ec831d48f7 100644 --- a/vmware_nsx/common/config.py +++ b/vmware_nsx/common/config.py @@ -350,6 +350,34 @@ nsx_v3_and_p = [ "specifying Transport Zone UUID usable for VLAN " "provider networks, as well as ranges of VLAN " "tags on each available for allocation to networks.")), + cfg.ListOpt('availability_zones', + default=[], + help=_('Optional parameter defining the networks availability ' + 'zones names for the native dhcp configuration. The ' + 'configuration of each zone will be under a group ' + 'names [az:]')), + cfg.StrOpt('metadata_proxy', + help=_("This is the name or UUID of the NSX Metadata Proxy " + "that will be used to enable native metadata service. " + "It needs to be created in NSX before starting Neutron " + "with the NSX plugin.")), + cfg.StrOpt('dhcp_profile', + help=_("This is the name or UUID of the NSX DHCP Profile " + "that will be used to enable native DHCP service. It " + "needs to be created in NSX before starting Neutron " + "with the NSX plugin")), + cfg.StrOpt('native_metadata_route', + default="169.254.169.254/31", + help=_("The metadata route used for native metadata proxy " + "service.")), + cfg.StrOpt('dns_domain', + default='openstacklocal', + help=_("Domain to use for building the hostnames.")), + cfg.ListOpt('nameservers', + default=[], + help=_("List of nameservers to configure for the DHCP " + "binding entries. These will be used if there are no " + "nameservers defined on the subnet.")), ] nsx_v3_opts = nsx_v3_and_p + [ @@ -407,41 +435,13 @@ nsx_v3_opts = nsx_v3_and_p + [ default=True, help=_("If true, DHCP and metadata proxy services will be " "provided by NSX backend.")), - cfg.StrOpt('native_metadata_route', - default="169.254.169.254/31", - help=_("The metadata route used for native metadata proxy " - "service.")), - cfg.StrOpt('dhcp_profile', - help=_("This is the name or UUID of the NSX DHCP Profile " - "that will be used to enable native DHCP service. It " - "needs to be created in NSX before starting Neutron " - "with the NSX plugin")), cfg.IntOpt('dhcp_lease_time', default=86400, help=_("DHCP default lease time.")), - cfg.StrOpt('dns_domain', - default='openstacklocal', - help=_("Domain to use for building the hostnames.")), - cfg.ListOpt('nameservers', - default=[], - help=_("List of nameservers to configure for the DHCP " - "binding entries. These will be used if there are no " - "nameservers defined on the subnet.")), - cfg.StrOpt('metadata_proxy', - help=_("This is the name or UUID of the NSX Metadata Proxy " - "that will be used to enable native metadata service. " - "It needs to be created in NSX before starting Neutron " - "with the NSX plugin.")), cfg.StrOpt('dhcp_relay_service', help=_("(Optional) This is the name or UUID of the NSX dhcp " "relay service that will be used to enable DHCP relay " "on router ports.")), - cfg.ListOpt('availability_zones', - default=[], - help=_('Optional parameter defining the networks availability ' - 'zones names for the native dhcp configuration. The ' - 'configuration of each zone will be under a group ' - 'names [az:]')), cfg.BoolOpt('init_objects_by_tags', default=False, help=_("When True, the configured transport zones, router and " diff --git a/vmware_nsx/plugins/common_v3/availability_zones.py b/vmware_nsx/plugins/common_v3/availability_zones.py new file mode 100644 index 0000000000..d80081d1b6 --- /dev/null +++ b/vmware_nsx/plugins/common_v3/availability_zones.py @@ -0,0 +1,100 @@ +# Copyright 2017 VMware, Inc. +# All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from vmware_nsx._i18n import _ +from vmware_nsx.common import availability_zones as common_az +from vmware_nsx.common import config +from vmware_nsx.common import exceptions as nsx_exc + +DEFAULT_NAME = common_az.DEFAULT_NAME + 'v3' + + +class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone): + + def init_from_config_line(self, config_line): + # Not supported for nsx_v3 (old configuration) + raise nsx_exc.NsxInvalidConfiguration( + opt_name="availability_zones", + opt_value=config_line, + reason=_("Expected a list of names")) + + def _has_native_dhcp_metadata(self): + # May be overriden by children + return True + + def init_from_config_section(self, az_name): + az_info = config.get_nsxv3_az_opts(self.name) + + if self._has_native_dhcp_metadata(): + # The optional parameters will get the global values if not + # defined for this AZ + self.metadata_proxy = az_info.get('metadata_proxy') + if not self.metadata_proxy: + raise nsx_exc.NsxInvalidConfiguration( + opt_name="metadata_proxy", + opt_value='None', + reason=(_("metadata_proxy for availability zone %s " + "must be defined") % az_name)) + + self.dhcp_profile = az_info.get('dhcp_profile') + if not self.dhcp_profile: + raise nsx_exc.NsxInvalidConfiguration( + opt_name="dhcp_profile", + opt_value='None', + reason=(_("dhcp_profile for availability zone %s " + "must be defined") % az_name)) + + native_metadata_route = az_info.get('native_metadata_route') + if native_metadata_route: + self.native_metadata_route = native_metadata_route + else: + self.metadata_proxy = None + self.dhcp_profile = None + self.native_metadata_route = None + + default_overlay_tz = az_info.get('default_overlay_tz') + if default_overlay_tz: + self.default_overlay_tz = default_overlay_tz + + default_vlan_tz = az_info.get('default_vlan_tz') + if default_vlan_tz: + self.default_vlan_tz = default_vlan_tz + + default_tier0_router = az_info.get('default_tier0_router') + if default_tier0_router: + self.default_tier0_router = default_tier0_router + + dns_domain = az_info.get('dns_domain') + if dns_domain: + self.dns_domain = dns_domain + + nameservers = az_info.get('nameservers') + if nameservers: + self.nameservers = nameservers + + def init_defaults(self): + # Should be implemented by children + pass + + def translate_configured_names_to_uuids(self, nsxlib): + # May be overriden by children + # Default implementation assumes UUID is provided in config + # TODO(annak): refine this when we have a better picture + # what az config is relevant for policy + self._native_dhcp_profile_uuid = self.dhcp_profile + self._native_md_proxy_uuid = self.metadata_proxy + self._default_overlay_tz_uuid = self.default_overlay_tz + self._default_vlan_tz_uuid = self.default_vlan_tz + self._default_tier0_router = self.default_tier0_router diff --git a/vmware_nsx/plugins/nsx_p/availability_zones.py b/vmware_nsx/plugins/nsx_p/availability_zones.py new file mode 100644 index 0000000000..86b696c8f1 --- /dev/null +++ b/vmware_nsx/plugins/nsx_p/availability_zones.py @@ -0,0 +1,46 @@ +# Copyright 2017 VMware, Inc. +# All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_config import cfg + +from vmware_nsx.common import availability_zones as common_az +from vmware_nsx.plugins.common_v3 import availability_zones as v3_az + + +DEFAULT_NAME = common_az.DEFAULT_NAME + 'v3' + + +class NsxPAvailabilityZone(v3_az.NsxV3AvailabilityZone): + + def init_defaults(self): + # use the default configuration + self.metadata_proxy = cfg.CONF.nsx_p.metadata_proxy + self.dhcp_profile = cfg.CONF.nsx_p.dhcp_profile + self.native_metadata_route = cfg.CONF.nsx_p.native_metadata_route + self.default_overlay_tz = cfg.CONF.nsx_p.default_overlay_tz + self.default_vlan_tz = cfg.CONF.nsx_p.default_vlan_tz + self.default_tier0_router = cfg.CONF.nsx_p.default_tier0_router + + +class NsxPAvailabilityZones(common_az.ConfiguredAvailabilityZones): + + default_name = DEFAULT_NAME + + def __init__(self): + default_azs = cfg.CONF.default_availability_zones + super(NsxPAvailabilityZones, self).__init__( + cfg.CONF.nsx_p.availability_zones, + NsxPAvailabilityZone, + default_availability_zones=default_azs) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index b0143074d2..3ecc6c2ad6 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -73,6 +73,7 @@ from vmware_nsx.extensions import providersecuritygroup as provider_sg from vmware_nsx.extensions import secgroup_rule_local_ip_prefix as sg_prefix from vmware_nsx.extensions import securitygrouplogging as sg_logging from vmware_nsx.plugins.common_v3 import plugin as nsx_plugin_common +from vmware_nsx.plugins.nsx_p import availability_zones as nsxp_az from vmware_nsx.plugins.nsx_v3 import utils as v3_utils from vmware_nsxlib.v3 import exceptions as nsx_lib_exc @@ -154,6 +155,8 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, self._extension_manager = managers.ExtensionManager( extension_drivers=extension_drivers) self.cfg_group = 'nsx_p' # group name for nsx_p section in nsx.ini + self.init_availability_zones() + super(NsxPolicyPlugin, self).__init__() # Bind the dummy L3 notifications self.l3_rpc_notifier = l3_rpc_agent_api.L3NotifyAPI() @@ -229,6 +232,9 @@ class NsxPolicyPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, filter_list_results=lambda tzs: [ tz for tz in tzs if tz['tz_type'].startswith('VLAN')]) + def init_availability_zones(self): + self._availability_zones_data = nsxp_az.NsxPAvailabilityZones() + def _validate_nsx_policy_version(self): self._nsx_version = self.nsxpolicy.get_version() LOG.info("NSX Version: %s", self._nsx_version) diff --git a/vmware_nsx/plugins/nsx_v/availability_zones.py b/vmware_nsx/plugins/nsx_v/availability_zones.py index 83c6ce4efb..2fbfdd2973 100644 --- a/vmware_nsx/plugins/nsx_v/availability_zones.py +++ b/vmware_nsx/plugins/nsx_v/availability_zones.py @@ -179,7 +179,7 @@ class NsxVAvailabilityZone(common_az.ConfiguredAvailabilityZone): self.mgt_net_proxy_netmask = None self.mgt_net_default_gateway = None - def init_default_az(self): + def init_defaults(self): # use the default configuration self.resource_pool = cfg.CONF.nsxv.resource_pool_id self.datastore_id = cfg.CONF.nsxv.datastore_id diff --git a/vmware_nsx/plugins/nsx_v3/availability_zones.py b/vmware_nsx/plugins/nsx_v3/availability_zones.py index 37170012b5..f1dabc68d8 100644 --- a/vmware_nsx/plugins/nsx_v3/availability_zones.py +++ b/vmware_nsx/plugins/nsx_v3/availability_zones.py @@ -12,88 +12,35 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - from oslo_config import cfg -from vmware_nsx._i18n import _ from vmware_nsx.common import availability_zones as common_az from vmware_nsx.common import config -from vmware_nsx.common import exceptions as nsx_exc +from vmware_nsx.plugins.common_v3 import availability_zones as v3_az + from vmware_nsxlib.v3 import core_resources from vmware_nsxlib.v3 import nsx_constants as nsxlib_consts -DEFAULT_NAME = common_az.DEFAULT_NAME + 'v3' +class NsxV3AvailabilityZone(v3_az.NsxV3AvailabilityZone): -class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone): - - def init_from_config_line(self, config_line): - # Not supported for nsx_v3 (old configuration) - raise nsx_exc.NsxInvalidConfiguration( - opt_name="availability_zones", - opt_value=config_line, - reason=_("Expected a list of names")) + def _has_native_dhcp_metadata(self): + return cfg.CONF.nsx_v3.native_dhcp_metadata def init_from_config_section(self, az_name): + super(NsxV3AvailabilityZone, self).init_from_config_section(az_name) + az_info = config.get_nsxv3_az_opts(self.name) - if cfg.CONF.nsx_v3.native_dhcp_metadata: - # The optional parameters will get the global values if not - # defined for this AZ - self.metadata_proxy = az_info.get('metadata_proxy') - if not self.metadata_proxy: - raise nsx_exc.NsxInvalidConfiguration( - opt_name="metadata_proxy", - opt_value='None', - reason=(_("metadata_proxy for availability zone %s " - "must be defined") % az_name)) + switching_profiles = az_info.get('switching_profiles') + if switching_profiles: + self.switching_profiles = switching_profiles - self.dhcp_profile = az_info.get('dhcp_profile') - if not self.dhcp_profile: - raise nsx_exc.NsxInvalidConfiguration( - opt_name="dhcp_profile", - opt_value='None', - reason=(_("dhcp_profile for availability zone %s " - "must be defined") % az_name)) + dhcp_relay_service = az_info.get('dhcp_relay_service') + if dhcp_relay_service: + self.dhcp_relay_service = dhcp_relay_service - self.native_metadata_route = az_info.get('native_metadata_route') - if self.native_metadata_route is None: - nmr = cfg.CONF.nsx_v3.native_metadata_route - self.native_metadata_route = nmr - else: - self.metadata_proxy = None - self.dhcp_profile = None - self.native_metadata_route = None - - self.dns_domain = az_info.get('dns_domain') - if self.dns_domain is None: - self.dns_domain = cfg.CONF.nsx_v3.dns_domain - - self.nameservers = az_info.get('nameservers') - if self.nameservers is None: - self.nameservers = cfg.CONF.nsx_v3.nameservers - - self.default_overlay_tz = az_info.get('default_overlay_tz') - if self.default_overlay_tz is None: - self.default_overlay_tz = cfg.CONF.nsx_v3.default_overlay_tz - - self.default_vlan_tz = az_info.get('default_vlan_tz') - if self.default_vlan_tz is None: - self.default_vlan_tz = cfg.CONF.nsx_v3.default_vlan_tz - - self.switching_profiles = az_info.get('switching_profiles') - if self.switching_profiles is None: - self.switching_profiles = cfg.CONF.nsx_v3.switching_profiles - - self.dhcp_relay_service = az_info.get('dhcp_relay_service') - if self.dhcp_relay_service is None: - self.dhcp_relay_service = cfg.CONF.nsx_v3.dhcp_relay_service - - self.default_tier0_router = az_info.get('default_tier0_router') - if self.default_tier0_router is None: - self.default_tier0_router = cfg.CONF.nsx_v3.default_tier0_router - - def init_default_az(self): + def init_defaults(self): # use the default configuration self.metadata_proxy = cfg.CONF.nsx_v3.metadata_proxy self.dhcp_profile = cfg.CONF.nsx_v3.dhcp_profile @@ -231,7 +178,7 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone): class NsxV3AvailabilityZones(common_az.ConfiguredAvailabilityZones): - default_name = DEFAULT_NAME + default_name = v3_az.DEFAULT_NAME def __init__(self, use_tvd_config=False): if use_tvd_config: diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py index 3be3cb8e52..38e05c16bf 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py @@ -24,7 +24,7 @@ from oslo_log import log as logging from vmware_nsx.common import config # noqa from vmware_nsx.common import utils as nsx_utils from vmware_nsx.dhcp_meta import rpc as nsx_rpc -from vmware_nsx.plugins.nsx_v3 import availability_zones as nsx_az +from vmware_nsx.plugins.common_v3 import availability_zones as nsx_az from vmware_nsx.shell.admin.plugins.common import constants from vmware_nsx.shell.admin.plugins.common import formatters from vmware_nsx.shell.admin.plugins.common import utils as admin_utils diff --git a/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py b/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py index e2838ff228..d9f0fa77ab 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py @@ -31,7 +31,7 @@ from vmware_nsx.common import exceptions as nsx_exc from vmware_nsx.common import utils from vmware_nsx.db import db as nsx_db from vmware_nsx.extensions import advancedserviceproviders as as_providers -from vmware_nsx.plugins.nsx_v3 import availability_zones as nsx_az +from vmware_nsx.plugins.common_v3 import availability_zones as nsx_az from vmware_nsx.tests.unit.nsx_v3 import test_plugin from vmware_nsxlib.v3 import core_resources from vmware_nsxlib.v3 import nsx_constants