NSX|P support init configuration by NSX tags
Like in the v3 plugin, the user can configure the main resource IDs by searching their tags. If the config has init_objects_by_tags = True, the object id givven in the config will be search on the NSX Policy manager as the tag, where the scope is the value configured in search_objects_scope. Change-Id: I9aa62b675a5be80b62eb260d9d61d9c00b20f5c6
This commit is contained in:
parent
2f61af4101
commit
e8677ec2cf
@ -391,6 +391,17 @@ nsx_v3_and_p = [
|
|||||||
help=_("List of transit networks used by NSX tier0 routers. "
|
help=_("List of transit networks used by NSX tier0 routers. "
|
||||||
"Neutron subnets will not be allowed to use those "
|
"Neutron subnets will not be allowed to use those "
|
||||||
"cidrs")),
|
"cidrs")),
|
||||||
|
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.")),
|
||||||
]
|
]
|
||||||
|
|
||||||
nsx_v3_opts = nsx_v3_and_p + [
|
nsx_v3_opts = nsx_v3_and_p + [
|
||||||
@ -451,17 +462,6 @@ nsx_v3_opts = nsx_v3_and_p + [
|
|||||||
cfg.IntOpt('dhcp_lease_time',
|
cfg.IntOpt('dhcp_lease_time',
|
||||||
default=86400,
|
default=86400,
|
||||||
help=_("DHCP default lease time.")),
|
help=_("DHCP default lease time.")),
|
||||||
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.")),
|
|
||||||
cfg.ListOpt('switching_profiles',
|
cfg.ListOpt('switching_profiles',
|
||||||
default=[],
|
default=[],
|
||||||
help=_("Optional parameter defining a list switching profiles "
|
help=_("Optional parameter defining a list switching profiles "
|
||||||
|
@ -43,10 +43,11 @@ class NsxPAvailabilityZone(v3_az.NsxV3AvailabilityZone):
|
|||||||
self.dns_domain = cfg.CONF.nsx_p.dns_domain
|
self.dns_domain = cfg.CONF.nsx_p.dns_domain
|
||||||
self.nameservers = cfg.CONF.nsx_p.nameservers
|
self.nameservers = cfg.CONF.nsx_p.nameservers
|
||||||
|
|
||||||
def _init_default_resource(self, resource_api, config_name,
|
def _init_default_resource(self, nsxpolicy, resource_api, config_name,
|
||||||
filter_list_results=None,
|
filter_list_results=None,
|
||||||
auto_config=False,
|
auto_config=False,
|
||||||
is_mandatory=True):
|
is_mandatory=True,
|
||||||
|
search_scope=None):
|
||||||
# NOTE(annak): we may need to generalize this for API calls
|
# NOTE(annak): we may need to generalize this for API calls
|
||||||
# requiring path ids
|
# requiring path ids
|
||||||
name_or_id = getattr(self, config_name)
|
name_or_id = getattr(self, config_name)
|
||||||
@ -77,11 +78,22 @@ class NsxPAvailabilityZone(v3_az.NsxV3AvailabilityZone):
|
|||||||
resource_api.get(name_or_id, silent=True)
|
resource_api.get(name_or_id, silent=True)
|
||||||
return name_or_id
|
return name_or_id
|
||||||
except nsx_lib_exc.ResourceNotFound:
|
except nsx_lib_exc.ResourceNotFound:
|
||||||
|
# Search by tags
|
||||||
|
if search_scope:
|
||||||
|
resource_type = resource_api.entry_def.resource_type()
|
||||||
|
resource_id = nsxpolicy.get_id_by_resource_and_tag(
|
||||||
|
resource_type,
|
||||||
|
search_scope,
|
||||||
|
name_or_id)
|
||||||
|
if resource_id:
|
||||||
|
return resource_id
|
||||||
|
|
||||||
# Check if the configured value is the name
|
# Check if the configured value is the name
|
||||||
resource = resource_api.get_by_name(name_or_id)
|
resource = resource_api.get_by_name(name_or_id)
|
||||||
if resource:
|
if resource:
|
||||||
return resource['id']
|
return resource['id']
|
||||||
else:
|
|
||||||
|
# Resource not found
|
||||||
if self.is_default():
|
if self.is_default():
|
||||||
raise cfg.RequiredOptError(config_name,
|
raise cfg.RequiredOptError(config_name,
|
||||||
group=cfg.OptGroup('nsx_p'))
|
group=cfg.OptGroup('nsx_p'))
|
||||||
@ -93,33 +105,36 @@ class NsxPAvailabilityZone(v3_az.NsxV3AvailabilityZone):
|
|||||||
'az': self.name})
|
'az': self.name})
|
||||||
raise nsx_exc.NsxPluginException(err_msg=msg)
|
raise nsx_exc.NsxPluginException(err_msg=msg)
|
||||||
|
|
||||||
def translate_configured_names_to_uuids(self, nsxpolicy, nsxlib=None):
|
def translate_configured_names_to_uuids(self, nsxpolicy, nsxlib=None,
|
||||||
|
search_scope=None):
|
||||||
super(NsxPAvailabilityZone, self).translate_configured_names_to_uuids(
|
super(NsxPAvailabilityZone, self).translate_configured_names_to_uuids(
|
||||||
nsxpolicy)
|
nsxpolicy)
|
||||||
|
|
||||||
# TODO(asarfaty): add support for init_objects_by_tags
|
|
||||||
self._default_overlay_tz_uuid = self._init_default_resource(
|
self._default_overlay_tz_uuid = self._init_default_resource(
|
||||||
nsxpolicy.transport_zone, 'default_overlay_tz',
|
nsxpolicy, nsxpolicy.transport_zone, 'default_overlay_tz',
|
||||||
auto_config=True, is_mandatory=True,
|
auto_config=True, is_mandatory=True,
|
||||||
filter_list_results=lambda tzs: [
|
filter_list_results=lambda tzs: [
|
||||||
tz for tz in tzs if tz['tz_type'].startswith('OVERLAY')])
|
tz for tz in tzs if tz['tz_type'].startswith('OVERLAY')],
|
||||||
|
search_scope=search_scope)
|
||||||
|
|
||||||
self._default_vlan_tz_uuid = self._init_default_resource(
|
self._default_vlan_tz_uuid = self._init_default_resource(
|
||||||
nsxpolicy.transport_zone, 'default_vlan_tz',
|
nsxpolicy, nsxpolicy.transport_zone, 'default_vlan_tz',
|
||||||
auto_config=True, is_mandatory=False,
|
auto_config=True, is_mandatory=False,
|
||||||
filter_list_results=lambda tzs: [
|
filter_list_results=lambda tzs: [
|
||||||
tz for tz in tzs if tz['tz_type'].startswith('VLAN')])
|
tz for tz in tzs if tz['tz_type'].startswith('VLAN')],
|
||||||
|
search_scope=search_scope)
|
||||||
|
|
||||||
self._default_tier0_router = self._init_default_resource(
|
self._default_tier0_router = self._init_default_resource(
|
||||||
nsxpolicy.tier0, 'default_tier0_router',
|
nsxpolicy, nsxpolicy.tier0, 'default_tier0_router',
|
||||||
auto_config=True, is_mandatory=True)
|
auto_config=True, is_mandatory=True,
|
||||||
|
search_scope=search_scope)
|
||||||
|
|
||||||
self.dhcp_relay_service = cfg.CONF.nsx_p.dhcp_relay_service
|
self.dhcp_relay_service = cfg.CONF.nsx_p.dhcp_relay_service
|
||||||
|
|
||||||
# If passthrough api is supported, also initialize those NSX objects
|
# If passthrough api is supported, also initialize those NSX objects
|
||||||
if nsxlib:
|
if nsxlib:
|
||||||
self._translate_dhcp_profile(nsxlib)
|
self._translate_dhcp_profile(nsxlib, search_scope=search_scope)
|
||||||
self._translate_metadata_proxy(nsxlib)
|
self._translate_metadata_proxy(nsxlib, search_scope=search_scope)
|
||||||
else:
|
else:
|
||||||
self._native_dhcp_profile_uuid = None
|
self._native_dhcp_profile_uuid = None
|
||||||
self._native_md_proxy_uuid = None
|
self._native_md_proxy_uuid = None
|
||||||
|
@ -176,7 +176,6 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
|
|||||||
self._init_default_config()
|
self._init_default_config()
|
||||||
self._prepare_default_rules()
|
self._prepare_default_rules()
|
||||||
self._init_segment_profiles()
|
self._init_segment_profiles()
|
||||||
|
|
||||||
self._init_dhcp_metadata()
|
self._init_dhcp_metadata()
|
||||||
|
|
||||||
# Init QoS
|
# Init QoS
|
||||||
@ -201,10 +200,18 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
|
|||||||
raise cfg.RequiredOptError("metadata_proxy",
|
raise cfg.RequiredOptError("metadata_proxy",
|
||||||
group=cfg.OptGroup('nsx_p'))
|
group=cfg.OptGroup('nsx_p'))
|
||||||
|
|
||||||
|
# If using tags to find the objects, make sure tag scope is configured
|
||||||
|
if (cfg.CONF.nsx_p.init_objects_by_tags and
|
||||||
|
not cfg.CONF.nsx_p.search_objects_scope):
|
||||||
|
raise cfg.RequiredOptError("search_objects_scope",
|
||||||
|
group=cfg.OptGroup('nsx_p'))
|
||||||
|
|
||||||
# Init AZ resources
|
# Init AZ resources
|
||||||
|
search_scope = (cfg.CONF.nsx_p.search_objects_scope
|
||||||
|
if cfg.CONF.nsx_p.init_objects_by_tags else None)
|
||||||
for az in self.get_azs_list():
|
for az in self.get_azs_list():
|
||||||
az.translate_configured_names_to_uuids(
|
az.translate_configured_names_to_uuids(
|
||||||
self.nsxpolicy, nsxlib=self.nsxlib)
|
self.nsxpolicy, nsxlib=self.nsxlib, search_scope=search_scope)
|
||||||
|
|
||||||
def _init_dhcp_metadata(self):
|
def _init_dhcp_metadata(self):
|
||||||
if (cfg.CONF.dhcp_agent_notification and
|
if (cfg.CONF.dhcp_agent_notification and
|
||||||
|
Loading…
Reference in New Issue
Block a user