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):