[NSXv3] Add os-project-name tag
Add a new tag for the name of the project (tenant) that owns the resource. Change-Id: I3b554cc40bc10ce058c16d83a564d7d0b80d189e
This commit is contained in:
@@ -100,21 +100,25 @@ def build_v3_api_version_tag():
|
|||||||
'tag': version.version_info.release_string()}]
|
'tag': version.version_info.release_string()}]
|
||||||
|
|
||||||
|
|
||||||
def build_v3_tags_payload(resource, resource_type):
|
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 os-project-id:<tenant-id>, os-api-version:<neutron-api-version>,
|
||||||
os-neutron-id:<resource-id>
|
<resoutce>:<resource-id>, os-project-name:<project-name>
|
||||||
"""
|
"""
|
||||||
# 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) > 20:
|
||||||
raise exceptions.InvalidInput(
|
raise exceptions.InvalidInput(
|
||||||
error_message=_('scope cannot exceed 20 characters'))
|
error_message=_('scope cannot exceed 20 characters'))
|
||||||
|
# There may be cases when the plugin creates the port, for example DHCP
|
||||||
|
if not project_name:
|
||||||
|
project_name = 'NSX neutron plug-in'
|
||||||
return [{'scope': resource_type,
|
return [{'scope': resource_type,
|
||||||
'tag': resource.get('id', '')},
|
'tag': resource.get('id', '')},
|
||||||
{'scope': 'os-project-id',
|
{'scope': 'os-project-id',
|
||||||
'tag': resource.get('tenant_id', '')},
|
'tag': resource.get('tenant_id', '')},
|
||||||
|
{'scope': 'os-project-name',
|
||||||
|
'tag': project_name},
|
||||||
{'scope': 'os-api-version',
|
{'scope': 'os-api-version',
|
||||||
'tag': version.version_info.release_string()}]
|
'tag': version.version_info.release_string()}]
|
||||||
|
|
||||||
|
|||||||
@@ -350,7 +350,8 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
context, net_data)
|
context, net_data)
|
||||||
net_name = net_data['name']
|
net_name = net_data['name']
|
||||||
tags = utils.build_v3_tags_payload(
|
tags = utils.build_v3_tags_payload(
|
||||||
net_data, resource_type='os-neutron-net-id')
|
net_data, resource_type='os-neutron-net-id',
|
||||||
|
project_name=context.tenant_name)
|
||||||
admin_state = net_data.get('admin_state_up', True)
|
admin_state = net_data.get('admin_state_up', True)
|
||||||
|
|
||||||
# Create network on the backend
|
# Create network on the backend
|
||||||
@@ -575,7 +576,8 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
port_data, l2gw_port_check,
|
port_data, l2gw_port_check,
|
||||||
psec_is_on):
|
psec_is_on):
|
||||||
tags = utils.build_v3_tags_payload(
|
tags = utils.build_v3_tags_payload(
|
||||||
port_data, resource_type='os-neutron-port-id')
|
port_data, resource_type='os-neutron-port-id',
|
||||||
|
project_name=context.tenant_name)
|
||||||
parent_name, tag = self._get_data_from_binding_profile(
|
parent_name, tag = self._get_data_from_binding_profile(
|
||||||
context, port_data)
|
context, port_data)
|
||||||
address_bindings = self._build_address_bindings(port_data)
|
address_bindings = self._build_address_bindings(port_data)
|
||||||
@@ -1000,7 +1002,8 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
gw_info = self._extract_external_gw(context, router, is_extract=True)
|
gw_info = self._extract_external_gw(context, router, is_extract=True)
|
||||||
router['router']['id'] = uuidutils.generate_uuid()
|
router['router']['id'] = uuidutils.generate_uuid()
|
||||||
tags = utils.build_v3_tags_payload(
|
tags = utils.build_v3_tags_payload(
|
||||||
router['router'], resource_type='os-neutron-router-id')
|
router['router'], resource_type='os-neutron-router-id',
|
||||||
|
project_name=context.tenant_name)
|
||||||
result = self._router_client.create(
|
result = self._router_client.create(
|
||||||
display_name=router['router'].get('name'),
|
display_name=router['router'].get('name'),
|
||||||
tags=tags)
|
tags=tags)
|
||||||
@@ -1396,7 +1399,8 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
secgroup['id'] = uuidutils.generate_uuid()
|
secgroup['id'] = uuidutils.generate_uuid()
|
||||||
|
|
||||||
tags = utils.build_v3_tags_payload(
|
tags = utils.build_v3_tags_payload(
|
||||||
secgroup, resource_type='os-neutron-secgr-id')
|
secgroup, resource_type='os-neutron-secgr-id',
|
||||||
|
project_name=context.tenant_name)
|
||||||
name = security.get_nsgroup_name(secgroup)
|
name = security.get_nsgroup_name(secgroup)
|
||||||
ns_group = None
|
ns_group = None
|
||||||
firewall_section = None
|
firewall_section = None
|
||||||
|
|||||||
@@ -174,7 +174,8 @@ class NsxV3Driver(l2gateway_db.L2GatewayMixin):
|
|||||||
self._validate_segment_id(seg_id)
|
self._validate_segment_id(seg_id)
|
||||||
try:
|
try:
|
||||||
tags = nsx_utils.build_v3_tags_payload(
|
tags = nsx_utils.build_v3_tags_payload(
|
||||||
gw_connection, resource_type='os-neutron-l2gw-id')
|
gw_connection, resource_type='os-neutron-l2gw-id',
|
||||||
|
project_name=context.tenant_name)
|
||||||
bridge_endpoint = nsxlib.create_bridge_endpoint(
|
bridge_endpoint = nsxlib.create_bridge_endpoint(
|
||||||
device_name=device_name,
|
device_name=device_name,
|
||||||
seg_id=seg_id,
|
seg_id=seg_id,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ 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']:
|
||||||
|
policy['policy']['tenant_name'] = context.tenant_name
|
||||||
tags = utils.build_v3_tags_payload(policy['policy'])
|
tags = utils.build_v3_tags_payload(policy['policy'])
|
||||||
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"),
|
||||||
|
|||||||
@@ -388,9 +388,24 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin):
|
|||||||
result = utils.build_v3_tags_payload(
|
result = utils.build_v3_tags_payload(
|
||||||
{'id': 'fake_id',
|
{'id': 'fake_id',
|
||||||
'tenant_id': 'fake_tenant_id'},
|
'tenant_id': 'fake_tenant_id'},
|
||||||
resource_type='os-neutron-net-id')
|
resource_type='os-neutron-net-id',
|
||||||
|
project_name='fake_tenant_name')
|
||||||
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': 'fake_tenant_name'},
|
||||||
|
{'scope': 'os-api-version',
|
||||||
|
'tag': version.version_info.release_string()}]
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
def test_build_v3_tags_payload_internal(self):
|
||||||
|
result = utils.build_v3_tags_payload(
|
||||||
|
{'id': 'fake_id',
|
||||||
|
'tenant_id': 'fake_tenant_id'},
|
||||||
|
resource_type='os-neutron-net-id',
|
||||||
|
project_name=None)
|
||||||
|
expected = [{'scope': 'os-neutron-net-id', 'tag': 'fake_id'},
|
||||||
|
{'scope': 'os-project-id', 'tag': 'fake_tenant_id'},
|
||||||
|
{'scope': 'os-project-name', 'tag': 'NSX neutron plug-in'},
|
||||||
{'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)
|
||||||
@@ -400,7 +415,8 @@ class TestNsxV3Utils(NsxV3PluginTestCaseMixin):
|
|||||||
utils.build_v3_tags_payload,
|
utils.build_v3_tags_payload,
|
||||||
{'id': 'fake_id',
|
{'id': 'fake_id',
|
||||||
'tenant_id': 'fake_tenant_id'},
|
'tenant_id': 'fake_tenant_id'},
|
||||||
resource_type='os-neutron-maldini-rocks-id')
|
resource_type='os-neutron-maldini-rocks-id',
|
||||||
|
project_name='fake')
|
||||||
|
|
||||||
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user