summaryrefslogtreecommitdiff
path: root/vmware_nsx/plugins/nsx_v/plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'vmware_nsx/plugins/nsx_v/plugin.py')
-rw-r--r--vmware_nsx/plugins/nsx_v/plugin.py67
1 files changed, 34 insertions, 33 deletions
diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py
index 5a3a03d..b4c46b6 100644
--- a/vmware_nsx/plugins/nsx_v/plugin.py
+++ b/vmware_nsx/plugins/nsx_v/plugin.py
@@ -1768,6 +1768,13 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
1768 return self._update_port(context, id, port, original_port, 1768 return self._update_port(context, id, port, original_port,
1769 is_compute_port, device_id) 1769 is_compute_port, device_id)
1770 1770
1771 def _update_dhcp_adddress(self, context, network_id):
1772 with locking.LockManager.get_lock('dhcp-update-%s' % network_id):
1773 address_groups = self._create_network_dhcp_address_group(
1774 context, network_id)
1775 self._update_dhcp_edge_service(context, network_id,
1776 address_groups)
1777
1771 def _update_port(self, context, id, port, original_port, is_compute_port, 1778 def _update_port(self, context, id, port, original_port, is_compute_port,
1772 device_id): 1779 device_id):
1773 attrs = port[attr.PORT] 1780 attrs = port[attr.PORT]
@@ -1896,10 +1903,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
1896 self._create_dhcp_static_binding(context, ret_port) 1903 self._create_dhcp_static_binding(context, ret_port)
1897 elif owner == constants.DEVICE_OWNER_DHCP: 1904 elif owner == constants.DEVICE_OWNER_DHCP:
1898 # Update the ip of the dhcp port 1905 # Update the ip of the dhcp port
1899 address_groups = self._create_network_dhcp_address_group( 1906 self._update_dhcp_adddress(context,
1900 context, ret_port['network_id']) 1907 ret_port['network_id'])
1901 self._update_dhcp_edge_service(
1902 context, ret_port['network_id'], address_groups)
1903 elif (owner == constants.DEVICE_OWNER_ROUTER_GW or 1908 elif (owner == constants.DEVICE_OWNER_ROUTER_GW or
1904 owner == constants.DEVICE_OWNER_ROUTER_INTF): 1909 owner == constants.DEVICE_OWNER_ROUTER_INTF):
1905 # This is a router port - update the edge appliance 1910 # This is a router port - update the edge appliance
@@ -2116,33 +2121,33 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
2116 # and send update dhcp interface rest call before deleting subnet's 2121 # and send update dhcp interface rest call before deleting subnet's
2117 # corresponding dhcp interface rest call and lead to overlap response 2122 # corresponding dhcp interface rest call and lead to overlap response
2118 # from backend. 2123 # from backend.
2119 with locking.LockManager.get_lock('nsx-edge-pool'): 2124 network_id = subnet['network_id']
2120 with context.session.begin(subtransactions=True): 2125 with locking.LockManager.get_lock(network_id):
2121 super(NsxVPluginV2, self).delete_subnet(context, id) 2126 with locking.LockManager.get_lock('nsx-edge-pool'):
2127 with context.session.begin(subtransactions=True):
2128 super(NsxVPluginV2, self).delete_subnet(context, id)
2129
2122 if subnet['enable_dhcp']: 2130 if subnet['enable_dhcp']:
2123 # There is only DHCP port available 2131 # There is only DHCP port available
2124 if len(ports) == 1: 2132 if len(ports) == 1:
2125 port = ports.pop() 2133 port = ports.pop()
2134 # This is done out of the transaction as it invokes
2135 # update_port which interfaces with the NSX
2126 self.ipam.delete_port(context, port['id']) 2136 self.ipam.delete_port(context, port['id'])
2127 2137
2128 if subnet['enable_dhcp']: 2138 # Delete the DHCP edge service
2129 # Delete the DHCP edge service 2139 filters = {'network_id': [network_id]}
2130 network_id = subnet['network_id'] 2140 remaining_subnets = self.get_subnets(context,
2131 filters = {'network_id': [network_id]} 2141 filters=filters)
2132 remaining_subnets = self.get_subnets(context, 2142 if len(remaining_subnets) == 0:
2133 filters=filters) 2143 self._cleanup_dhcp_edge_before_deletion(
2134 if len(remaining_subnets) == 0: 2144 context, network_id)
2135 self._cleanup_dhcp_edge_before_deletion( 2145 LOG.debug("Delete the DHCP service for network %s",
2136 context, network_id) 2146 network_id)
2137 LOG.debug("Delete the DHCP service for network %s", 2147 self._delete_dhcp_edge_service(context, network_id)
2138 network_id) 2148 else:
2139 self._delete_dhcp_edge_service(context, network_id) 2149 # Update address group and delete the DHCP port only
2140 else: 2150 self._update_dhcp_adddress(context, network_id)
2141 # Update address group and delete the DHCP port only
2142 address_groups = self._create_network_dhcp_address_group(
2143 context, network_id)
2144 self._update_dhcp_edge_service(context, network_id,
2145 address_groups)
2146 2151
2147 def _is_overlapping_reserved_subnets(self, subnet): 2152 def _is_overlapping_reserved_subnets(self, subnet):
2148 """Return True if the subnet overlaps with reserved subnets. 2153 """Return True if the subnet overlaps with reserved subnets.
@@ -2265,7 +2270,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
2265 self._update_dhcp_service_with_subnet(context, s) 2270 self._update_dhcp_service_with_subnet(context, s)
2266 except Exception: 2271 except Exception:
2267 with excutils.save_and_reraise_exception(): 2272 with excutils.save_and_reraise_exception():
2268 self.delete_subnet(context, s['id']) 2273 super(NsxVPluginV2, self).delete_subnet(context,
2274 s['id'])
2269 return s 2275 return s
2270 2276
2271 def _process_subnet_ext_attr_create(self, session, subnet_db, 2277 def _process_subnet_ext_attr_create(self, session, subnet_db,
@@ -2467,9 +2473,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
2467 network_id) 2473 network_id)
2468 self._delete_dhcp_edge_service(context, network_id) 2474 self._delete_dhcp_edge_service(context, network_id)
2469 return 2475 return
2470 address_groups = self._create_network_dhcp_address_group(context, 2476 self._update_dhcp_adddress(context, network_id)
2471 network_id)
2472 self._update_dhcp_edge_service(context, network_id, address_groups)
2473 2477
2474 def _get_conflict_network_ids_by_overlapping(self, context, subnets): 2478 def _get_conflict_network_ids_by_overlapping(self, context, subnets):
2475 with locking.LockManager.get_lock('nsx-networking'): 2479 with locking.LockManager.get_lock('nsx-networking'):
@@ -2567,10 +2571,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
2567 self.edge_manager.create_dhcp_edge_service(context, network_id, 2571 self.edge_manager.create_dhcp_edge_service(context, network_id,
2568 subnet) 2572 subnet)
2569 # Create all dhcp ports within the network 2573 # Create all dhcp ports within the network
2570 address_groups = self._create_network_dhcp_address_group( 2574 self._update_dhcp_adddress(context, network_id)
2571 context, network_id)
2572 self.edge_manager.update_dhcp_edge_service(
2573 context, network_id, address_groups=address_groups)
2574 2575
2575 except Exception: 2576 except Exception:
2576 with excutils.save_and_reraise_exception(): 2577 with excutils.save_and_reraise_exception():