[NSXv3] Add tags to qos switching profile
Add resource type and project name tags to qos switching profile. Make maximum length of resource type name a constant. Fix some typos. Change-Id: Ibd793894ca65320fa5fcf49e5dfa1872f534b7fe
This commit is contained in:
parent
5488dd47f8
commit
32d1b92f18
@ -27,6 +27,7 @@ from vmware_nsx._i18n import _, _LE
|
|||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
MAX_DISPLAY_NAME_LEN = 40
|
MAX_DISPLAY_NAME_LEN = 40
|
||||||
|
MAX_RESOURCE_TYPE_LEN = 20
|
||||||
NEUTRON_VERSION = version.version_info.release_string()
|
NEUTRON_VERSION = version.version_info.release_string()
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ def build_v3_api_version_tag():
|
|||||||
Neutron resource.
|
Neutron resource.
|
||||||
"""
|
"""
|
||||||
return [{'scope': 'os-neutron-id',
|
return [{'scope': 'os-neutron-id',
|
||||||
'tag': 'NSX neutron plug-in'},
|
'tag': 'NSX Neutron plugin'},
|
||||||
{'scope': "os-api-version",
|
{'scope': "os-api-version",
|
||||||
'tag': version.version_info.release_string()}]
|
'tag': version.version_info.release_string()}]
|
||||||
|
|
||||||
@ -103,16 +104,19 @@ def build_v3_api_version_tag():
|
|||||||
def build_v3_tags_payload(resource, resource_type, project_name):
|
def build_v3_tags_payload(resource, resource_type, project_name):
|
||||||
"""
|
"""
|
||||||
Construct the tags payload that will be pushed to NSX-v3
|
Construct the tags payload that will be pushed to NSX-v3
|
||||||
Add os-project-id:<tenant-id>, os-api-version:<neutron-api-version>,
|
Add <resource_type>:<resource-id>, os-project-id:<tenant-id>,
|
||||||
<resoutce>:<resource-id>, os-project-name:<project-name>
|
os-project-name:<project_name> os-api-version:<neutron-api-version>
|
||||||
"""
|
"""
|
||||||
# Add in a validation to ensure that we catch this at build time
|
# Add in a validation to ensure that we catch this at build time
|
||||||
if len(resource_type) > 20:
|
if len(resource_type) > MAX_RESOURCE_TYPE_LEN:
|
||||||
raise exceptions.InvalidInput(
|
raise exceptions.InvalidInput(
|
||||||
error_message=_('scope cannot exceed 20 characters'))
|
error_message=(_('Tag scope name cannot exceed %(max_len)s '
|
||||||
|
'characters: %(scope)s') %
|
||||||
|
{'max_len': MAX_RESOURCE_TYPE_LEN,
|
||||||
|
'scope': resource_type}))
|
||||||
# There may be cases when the plugin creates the port, for example DHCP
|
# There may be cases when the plugin creates the port, for example DHCP
|
||||||
if not project_name:
|
if not project_name:
|
||||||
project_name = 'NSX neutron plug-in'
|
project_name = 'NSX Neutron plugin'
|
||||||
return [{'scope': resource_type,
|
return [{'scope': resource_type,
|
||||||
'tag': resource.get('id', '')},
|
'tag': resource.get('id', '')},
|
||||||
{'scope': 'os-project-id',
|
{'scope': 'os-project-id',
|
||||||
|
@ -40,9 +40,9 @@ class NsxQosPlugin(qos_plugin.QoSPlugin):
|
|||||||
|
|
||||||
@db_base_plugin_common.convert_result_to_dict
|
@db_base_plugin_common.convert_result_to_dict
|
||||||
def create_policy(self, context, policy):
|
def create_policy(self, context, policy):
|
||||||
if 'tenant_name' not in policy['policy']:
|
tags = utils.build_v3_tags_payload(
|
||||||
policy['policy']['tenant_name'] = context.tenant_name
|
policy['policy'], resource_type='os-neutron-qos-id',
|
||||||
tags = utils.build_v3_tags_payload(policy['policy'])
|
project_name=context.tenant_name)
|
||||||
result = nsxlib.create_qos_switching_profile(
|
result = nsxlib.create_qos_switching_profile(
|
||||||
tags=tags, name=policy['policy'].get("name"),
|
tags=tags, name=policy['policy'].get("name"),
|
||||||
description=policy['policy'].get("description"))
|
description=policy['policy'].get("description"))
|
||||||
|
@ -405,12 +405,12 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin):
|
|||||||
project_name=None)
|
project_name=None)
|
||||||
expected = [{'scope': 'os-neutron-net-id', 'tag': 'fake_id'},
|
expected = [{'scope': 'os-neutron-net-id', 'tag': 'fake_id'},
|
||||||
{'scope': 'os-project-id', 'tag': 'fake_tenant_id'},
|
{'scope': 'os-project-id', 'tag': 'fake_tenant_id'},
|
||||||
{'scope': 'os-project-name', 'tag': 'NSX neutron plug-in'},
|
{'scope': 'os-project-name', 'tag': 'NSX Neutron plugin'},
|
||||||
{'scope': 'os-api-version',
|
{'scope': 'os-api-version',
|
||||||
'tag': version.version_info.release_string()}]
|
'tag': version.version_info.release_string()}]
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
def test_build_v3_tags_payloadi_invalid_length(self):
|
def test_build_v3_tags_payload_invalid_length(self):
|
||||||
self.assertRaises(n_exc.InvalidInput,
|
self.assertRaises(n_exc.InvalidInput,
|
||||||
utils.build_v3_tags_payload,
|
utils.build_v3_tags_payload,
|
||||||
{'id': 'fake_id',
|
{'id': 'fake_id',
|
||||||
@ -421,7 +421,7 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin):
|
|||||||
def test_build_v3_api_version_tag(self):
|
def test_build_v3_api_version_tag(self):
|
||||||
result = utils.build_v3_api_version_tag()
|
result = utils.build_v3_api_version_tag()
|
||||||
expected = [{'scope': 'os-neutron-id',
|
expected = [{'scope': 'os-neutron-id',
|
||||||
'tag': 'NSX neutron plug-in'},
|
'tag': 'NSX Neutron plugin'},
|
||||||
{'scope': 'os-api-version',
|
{'scope': 'os-api-version',
|
||||||
'tag': version.version_info.release_string()}]
|
'tag': version.version_info.release_string()}]
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user