NSX|V3: Configure TZ, router and profiles using tags

New configuration option for the transport zones, tier0 router, dhcp
profile and md-proxy in the nsx ini file.
If init_objects_by_tags is True, the user should add a tag with a scope
(whose name will be set in search_objects_by_tags) to the overlay
transportzone, vlan transportzone and tier0 router on the nsx.
In the nsx ini file the user should configure the value of this tag for
each object instead of the object name or uuid.

Example:
[nsx_v3]
init_objects_by_tags = True
search_objects_scope = ini-scope
default_overlay_tz = ini-tag-tz
default_vlan_tz = ini-tag-tz2
default_tier0_router = ini-tag-rtr
metadata_proxy = ini-tag-md
dhcp_profile = ini-tag-dhcp

Depends-on: If05390d3b58b84290e1f306f03c5ba3654bd1fad
Change-Id: Icb66f42939e41eb32c8485f80f4e5d24cf172023
This commit is contained in:
Adit Sarfaty 2017-07-05 11:18:45 +03:00
parent 66935845a3
commit 28e2c22939
4 changed files with 91 additions and 12 deletions

View File

@ -0,0 +1,10 @@
---
prelude: >
NSX-V3 plugin supports a new configuration option for the transport zones,
tier-0 router, dhcp profile and md-proxy in the nsx ini file using NSX
Tags insead of names or IDs.
features:
- |
NSX-V3 plugin supports a new configuration option for the transport zones,
tier-0 router, dhcp profile and md-proxy in the nsx ini file using NSX
Tags insead of names or IDs.

View File

@ -423,6 +423,18 @@ nsx_v3_opts = [
'zones names for the native dhcp configuration. The ' 'zones names for the native dhcp configuration. The '
'configuration of each zone will be under a group ' 'configuration of each zone will be under a group '
'names [az:<name>]')), 'names [az:<name>]')),
cfg.BoolOpt('init_objects_by_tags',
default=False,
help=_("When True, the configured transport zones, router and "
"profiles will be found by tags on the NSX. The scope "
"of the tag will be the value of search_objects_"
"scope. The value of the search tag will be the name "
"configured in each respective configuration.")),
cfg.StrOpt('search_objects_scope',
help=_("This is the scope of the tag that will be used for "
"finding the objects uuids on the NSX during plugin "
"init.")),
] ]
DEFAULT_STATUS_CHECK_INTERVAL = 2000 DEFAULT_STATUS_CHECK_INTERVAL = 2000

View File

@ -88,6 +88,14 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone):
# Mandatory configurations (in AZ or inherited from global values) # Mandatory configurations (in AZ or inherited from global values)
# Unless this is the default AZ, and metadata is disabled. # Unless this is the default AZ, and metadata is disabled.
if self.dhcp_profile: if self.dhcp_profile:
dhcp_id = None
if cfg.CONF.nsx_v3.init_objects_by_tags:
# Find the TZ by its tag
dhcp_id = nsxlib.get_id_by_resource_and_tag(
nsxlib.native_dhcp_profile.resource_type,
cfg.CONF.nsx_v3.search_objects_scope,
self.dhcp_profile)
if not dhcp_id:
dhcp_id = nsxlib.native_dhcp_profile.get_id_by_name_or_id( dhcp_id = nsxlib.native_dhcp_profile.get_id_by_name_or_id(
self.dhcp_profile) self.dhcp_profile)
self._native_dhcp_profile_uuid = dhcp_id self._native_dhcp_profile_uuid = dhcp_id
@ -95,6 +103,14 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone):
self._native_dhcp_profile_uuid = None self._native_dhcp_profile_uuid = None
if self.metadata_proxy: if self.metadata_proxy:
proxy_id = None
if cfg.CONF.nsx_v3.init_objects_by_tags:
# Find the TZ by its tag
proxy_id = nsxlib.get_id_by_resource_and_tag(
nsxlib.native_md_proxy.resource_type,
cfg.CONF.nsx_v3.search_objects_scope,
self.metadata_proxy)
if not proxy_id:
proxy_id = nsxlib.native_md_proxy.get_id_by_name_or_id( proxy_id = nsxlib.native_md_proxy.get_id_by_name_or_id(
self.metadata_proxy) self.metadata_proxy)
self._native_md_proxy_uuid = proxy_id self._native_md_proxy_uuid = proxy_id
@ -102,6 +118,17 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone):
self._native_md_proxy_uuid = None self._native_md_proxy_uuid = None
if self.default_overlay_tz: if self.default_overlay_tz:
tz_id = None
if cfg.CONF.nsx_v3.init_objects_by_tags:
# Find the TZ by its tag
resource_type = (nsxlib.transport_zone.resource_type +
' AND transport_type:OVERLAY')
tz_id = nsxlib.get_id_by_resource_and_tag(
resource_type,
cfg.CONF.nsx_v3.search_objects_scope,
self.default_overlay_tz)
if not tz_id:
# Find the TZ by its name or id
tz_id = nsxlib.transport_zone.get_id_by_name_or_id( tz_id = nsxlib.transport_zone.get_id_by_name_or_id(
self.default_overlay_tz) self.default_overlay_tz)
self._default_overlay_tz_uuid = tz_id self._default_overlay_tz_uuid = tz_id
@ -110,6 +137,17 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone):
# Optional configurations (may be None) # Optional configurations (may be None)
if self.default_vlan_tz: if self.default_vlan_tz:
tz_id = None
if cfg.CONF.nsx_v3.init_objects_by_tags:
# Find the TZ by its tag
resource_type = (nsxlib.transport_zone.resource_type +
' AND transport_type:VLAN')
tz_id = nsxlib.get_id_by_resource_and_tag(
resource_type,
cfg.CONF.nsx_v3.search_objects_scope,
self.default_vlan_tz)
if not tz_id:
# Find the TZ by its name or id
tz_id = nsxlib.transport_zone.get_id_by_name_or_id( tz_id = nsxlib.transport_zone.get_id_by_name_or_id(
self.default_vlan_tz) self.default_vlan_tz)
self._default_vlan_tz_uuid = tz_id self._default_vlan_tz_uuid = tz_id

View File

@ -298,9 +298,26 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
'reason': e}) 'reason': e})
def _translate_configured_names_to_uuids(self): def _translate_configured_names_to_uuids(self):
# If using tags to find the objects, make sure tag scope is configured
if (cfg.CONF.nsx_v3.init_objects_by_tags and
not cfg.CONF.nsx_v3.search_objects_scope):
raise cfg.RequiredOptError("search_objects_scope",
group=cfg.OptGroup('nsx_v3'))
# default tier0 router # default tier0 router
self._default_tier0_router = None self._default_tier0_router = None
if cfg.CONF.nsx_v3.default_tier0_router: if cfg.CONF.nsx_v3.default_tier0_router:
rtr_id = None
if cfg.CONF.nsx_v3.init_objects_by_tags:
# Find the router by its tag
resource_type = (self.nsxlib.logical_router.resource_type +
' AND router_type:TIER0')
rtr_id = self.nsxlib.get_id_by_resource_and_tag(
resource_type,
cfg.CONF.nsx_v3.search_objects_scope,
cfg.CONF.nsx_v3.default_tier0_router)
if not rtr_id:
# find the router by name or id
rtr_id = self.nsxlib.logical_router.get_id_by_name_or_id( rtr_id = self.nsxlib.logical_router.get_id_by_name_or_id(
cfg.CONF.nsx_v3.default_tier0_router) cfg.CONF.nsx_v3.default_tier0_router)
self._default_tier0_router = rtr_id self._default_tier0_router = rtr_id
@ -308,10 +325,12 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
# Validate and translate native dhcp profiles per az # Validate and translate native dhcp profiles per az
if cfg.CONF.nsx_v3.native_dhcp_metadata: if cfg.CONF.nsx_v3.native_dhcp_metadata:
if not cfg.CONF.nsx_v3.dhcp_profile: if not cfg.CONF.nsx_v3.dhcp_profile:
raise cfg.RequiredOptError("dhcp_profile") raise cfg.RequiredOptError("dhcp_profile",
group=cfg.OptGroup('nsx_v3'))
if not cfg.CONF.nsx_v3.metadata_proxy: if not cfg.CONF.nsx_v3.metadata_proxy:
raise cfg.RequiredOptError("metadata_proxy") raise cfg.RequiredOptError("metadata_proxy",
group=cfg.OptGroup('nsx_v3'))
# Translate all the uuids in each of the availability # Translate all the uuids in each of the availability
for az in self.get_azs_list(): for az in self.get_azs_list():