From a047d0ad7966e4ea9d5fc40888f2edde6d3d5248 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Wed, 23 Dec 2015 14:56:34 -0800 Subject: [PATCH] NSX|V3: Add tags for DownLink logical router port Add the following tags for a DownLink router port: - os-api-version - os-project-id - os-project-name - os-neutron-rport-id - os-subnet-id Change-Id: I3b4cf40d71a4923a5541e7c0156552033ff397fe --- vmware_nsx/nsxlib/v3/resources.py | 4 +++- vmware_nsx/nsxlib/v3/router.py | 6 ++++-- vmware_nsx/plugins/nsx_v3/plugin.py | 5 +++++ vmware_nsx/tests/unit/nsxlib/v3/test_resources.py | 4 +++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/vmware_nsx/nsxlib/v3/resources.py b/vmware_nsx/nsxlib/v3/resources.py index a4df085675..f1aa4ad859 100644 --- a/vmware_nsx/nsxlib/v3/resources.py +++ b/vmware_nsx/nsxlib/v3/resources.py @@ -317,13 +317,15 @@ class LogicalRouterPort(AbstractRESTResource): def create(self, logical_router_id, display_name, + tags, resource_type, logical_port_id, address_groups, edge_cluster_member_index=None): body = {'display_name': display_name, 'resource_type': resource_type, - 'logical_router_id': logical_router_id} + 'logical_router_id': logical_router_id, + 'tags': tags or []} if address_groups: body['subnets'] = address_groups if resource_type in [nsx_constants.LROUTERPORT_UPLINK, diff --git a/vmware_nsx/nsxlib/v3/router.py b/vmware_nsx/nsxlib/v3/router.py index 3c9fb7455f..e43d2a73a0 100644 --- a/vmware_nsx/nsxlib/v3/router.py +++ b/vmware_nsx/nsxlib/v3/router.py @@ -79,14 +79,14 @@ class RouterLib(object): def add_router_link_port(self, tier1_uuid, tier0_uuid, edge_members): # Create Tier0 logical router link port tier0_link_port = self._router_port_client.create( - tier0_uuid, display_name=TIER0_ROUTER_LINK_PORT_NAME, + tier0_uuid, display_name=TIER0_ROUTER_LINK_PORT_NAME, tags=None, resource_type=nsx_constants.LROUTERPORT_LINKONTIER0, logical_port_id=None, address_groups=None) linked_logical_port_id = tier0_link_port['id'] # Create Tier1 logical router link port self._router_port_client.create( - tier1_uuid, display_name=TIER1_ROUTER_LINK_PORT_NAME, + tier1_uuid, display_name=TIER1_ROUTER_LINK_PORT_NAME, tags=None, resource_type=nsx_constants.LROUTERPORT_LINKONTIER1, logical_port_id=linked_logical_port_id, address_groups=None) @@ -128,6 +128,7 @@ class RouterLib(object): def create_logical_router_intf_port_by_ls_id(self, logical_router_id, display_name, + tags, ls_id, logical_switch_port_id, address_groups): @@ -137,6 +138,7 @@ class RouterLib(object): return self._router_port_client.create( logical_router_id, display_name, + tags, nsx_constants.LROUTERPORT_DOWNLINK, logical_switch_port_id, address_groups) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index edc421a124..1fa8afa8c5 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -1201,9 +1201,14 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, context, router_id, network_id) display_name = utils.get_name_and_uuid( subnet['name'], subnet['id']) + tags = utils.build_v3_tags_payload( + port, resource_type='os-neutron-rport-id', + project_name=context.tenant_name) + tags.append({'scope': 'os-subnet-id', 'tag': subnet['id']}) self._routerlib.create_logical_router_intf_port_by_ls_id( logical_router_id=nsx_router_id, display_name=display_name, + tags=tags, ls_id=nsx_net_id, logical_switch_port_id=nsx_port_id, address_groups=address_groups) diff --git a/vmware_nsx/tests/unit/nsxlib/v3/test_resources.py b/vmware_nsx/tests/unit/nsxlib/v3/test_resources.py index ceea677a2c..0b16f54bdc 100644 --- a/vmware_nsx/tests/unit/nsxlib/v3/test_resources.py +++ b/vmware_nsx/tests/unit/nsxlib/v3/test_resources.py @@ -329,13 +329,15 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase): lrport.create(fake_router_port['logical_router_id'], fake_router_port['display_name'], + None, fake_router_port['resource_type'], None, None, None) data = { 'display_name': fake_router_port['display_name'], 'logical_router_id': fake_router_port['logical_router_id'], - 'resource_type': fake_router_port['resource_type'] + 'resource_type': fake_router_port['resource_type'], + 'tags': [] } test_client.assert_json_call(