From b3532f837894a9df20d9b0ba50cff5612d011421 Mon Sep 17 00:00:00 2001 From: Janet Yu Date: Mon, 14 Dec 2015 14:24:27 -0800 Subject: [PATCH] Set logical switch os_neutron_id tag The os_neutron_id tag in logical switches had been omitted since the neutron id is the same as the UUID on the backend. However, users might perceive the blank space as missing information. Make an extra call to set the tag once the switch has been created. Closes-bug: #1527152 Change-Id: I800cb0736bc5e555e2b094458efb180eb7790db5 --- vmware_nsx/nsxlib/v3/__init__.py | 4 +++- vmware_nsx/plugins/nsx_v3/plugin.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/nsxlib/v3/__init__.py b/vmware_nsx/nsxlib/v3/__init__.py index 352c3b771a..7bce8453d4 100644 --- a/vmware_nsx/nsxlib/v3/__init__.py +++ b/vmware_nsx/nsxlib/v3/__init__.py @@ -102,7 +102,7 @@ def get_logical_switch(logical_switch_id): @utils.retry_upon_exception_nsxv3(nsx_exc.StaleRevision, max_attempts=cfg.CONF.nsx_v3.retries) -def update_logical_switch(lswitch_id, name=None, admin_state=None): +def update_logical_switch(lswitch_id, name=None, admin_state=None, tags=None): resource = "logical-switches/%s" % lswitch_id lswitch = get_logical_switch(lswitch_id) if name is not None: @@ -112,6 +112,8 @@ def update_logical_switch(lswitch_id, name=None, admin_state=None): lswitch['admin_state'] = nsx_constants.ADMIN_STATE_UP else: lswitch['admin_state'] = nsx_constants.ADMIN_STATE_DOWN + if tags is not None: + lswitch['tags'] = tags return client.update_resource(resource, lswitch) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 0b83205c08..a9ecefedc3 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -367,8 +367,22 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, result = nsxlib.create_logical_switch(net_name, physical_net, tags, admin_state=admin_state, vlan_id=vlan_id) + + # The logical switch's UUID is used as the id for the neutron network + # (via net_data, which is used below, in create_network). Now that we + # have a UUID for the logical switch, set that as the neutron network + # id in the switch's tags. Note errors but no rollback is needed here. network_id = result['id'] net_data['id'] = network_id + network_tags = result['tags'] + for tag in network_tags: + if tag['scope'] == 'os-neutron-id': + tag['tag'] = network_id + try: + nsxlib.update_logical_switch(network_id, tags=network_tags) + except nsx_exc.ManagerError: + LOG.exception(_LE("Unable to update network tags on NSX backend")) + return (is_provider_net, net_type, physical_net, vlan_id) def _extend_network_dict_provider(self, context, network, bindings=None):