Merge "NSX|V refactor create_dhcp_edge_service to avoid code duplication"

This commit is contained in:
Jenkins 2016-08-04 06:50:36 +00:00 committed by Gerrit Code Review
commit 4588ff4722

View File

@ -1065,62 +1065,46 @@ class EdgeManager(object):
dhcp_edge_binding = nsxv_db.get_nsxv_router_binding(context.session, dhcp_edge_binding = nsxv_db.get_nsxv_router_binding(context.session,
resource_id) resource_id)
allocate_new_edge = False allocate_new_edge = False
# case 1: update a subnet to an existing dhcp edge with locking.LockManager.get_lock('nsx-edge-pool'):
if dhcp_edge_binding: (conflict_edge_ids,
with locking.LockManager.get_lock('nsx-edge-pool'): available_edge_ids) = self._get_used_edges(context, subnet,
availability_zone)
LOG.debug("The available edges %s, the conflict edges %s ",
available_edge_ids, conflict_edge_ids)
edge_id = None
# Check if the network can stay on the existing DHCP edge
if dhcp_edge_binding:
edge_id = dhcp_edge_binding['edge_id'] edge_id = dhcp_edge_binding['edge_id']
(conflict_edge_ids, LOG.debug("At present network %s is using edge %s",
available_edge_ids) = self._get_used_edges(context, subnet, network_id, edge_id)
availability_zone)
LOG.debug("The available edges %s, the conflict edges %s "
"at present is using edge %s",
available_edge_ids, conflict_edge_ids, edge_id)
with locking.LockManager.get_lock(str(edge_id)): with locking.LockManager.get_lock(str(edge_id)):
# Delete the existing vnic interface if there is # Delete the existing vnic interface if there is
# an overlapping subnet or the binding is in ERROR status # an overlapping subnet or the binding is in ERROR status
if (edge_id in conflict_edge_ids or if (edge_id in conflict_edge_ids or
dhcp_edge_binding['status'] == plugin_const.ERROR): dhcp_edge_binding['status'] == plugin_const.ERROR):
LOG.debug("Removing network %s from dhcp edge %s",
network_id, edge_id)
self.remove_network_from_dhcp_edge(context, self.remove_network_from_dhcp_edge(context,
network_id, edge_id) network_id, edge_id)
#Move the network to anther Edge and update vnic: edge_id = None
#1. Find an available existing edge or create a new one
#2. For the existing one, cut off the old port group if not edge_id:
# connection #Attach the network to a new Edge and update vnic:
#3. Create the new port group connection to an existing #1. Find an available existing edge or create a new one
# one #2. For the existing one, cut off the old port group
#4. Update the address groups to the vnic # connection
if available_edge_ids: #3. Create the new port group connection to an existing one
new_id = self._get_random_available_edge( #4. Update the address groups to the vnic
available_edge_ids)
if new_id:
LOG.debug("Select edge %s to support dhcp for "
"network %s", new_id, network_id)
self.reuse_existing_dhcp_edge(
context, new_id, resource_id, network_id,
availability_zone)
else:
allocate_new_edge = True
else:
allocate_new_edge = True
# case 2: attach the subnet to a new edge and update vnic
else:
with locking.LockManager.get_lock('nsx-edge-pool'):
(conflict_edge_ids,
available_edge_ids) = self._get_used_edges(context, subnet,
availability_zone)
LOG.debug('The available edges %s, the conflict edges %s',
available_edge_ids, conflict_edge_ids)
# There is available one
if available_edge_ids: if available_edge_ids:
new_id = self._get_random_available_edge( new_id = self._get_random_available_edge(
available_edge_ids) available_edge_ids)
if new_id: if new_id:
LOG.debug("Select edge %s to support dhcp for network " LOG.debug("Select edge %s to support dhcp for "
"%s", new_id, network_id) "network %s", new_id, network_id)
with locking.LockManager.get_lock(str(new_id)): self.reuse_existing_dhcp_edge(
self.reuse_existing_dhcp_edge( context, new_id, resource_id, network_id,
context, new_id, resource_id, network_id, availability_zone)
availability_zone)
else: else:
allocate_new_edge = True allocate_new_edge = True
else: else: