Merge "Fix subnet use vdr dhcp edge for dhcp service"

This commit is contained in:
Jenkins 2015-09-06 12:09:42 +00:00 committed by Gerrit Code Review
commit af18b4ed70
2 changed files with 20 additions and 11 deletions

View File

@ -516,6 +516,15 @@ def add_vdr_dhcp_binding(session, vdr_router_id, dhcp_router_id, dhcp_edge_id):
return binding
def update_vdr_dhcp_binding(session, vdr_router_id, **kwargs):
with session.begin(subtransactions=True):
binding = (session.query(nsxv_models.NsxvVdrDhcpBinding).
filter_by(vdr_router_id=vdr_router_id).one())
for key, value in six.iteritems(kwargs):
binding[key] = value
return binding
def get_vdr_dhcp_bindings(session):
try:
bindings = session.query(nsxv_models.NsxvVdrDhcpBinding).all()

View File

@ -695,22 +695,20 @@ class EdgeManager(object):
nsxv_db.create_edge_dhcp_static_binding(context.session, edge_id,
mac_address, binding_id)
def _get_vdr_dhcp_edges(self, context):
bindings = nsxv_db.get_vdr_dhcp_bindings(context.session)
edges = [binding['dhcp_edge_id'] for binding in bindings]
return edges
def _get_available_edges(self, context, network_id, conflicting_nets):
if conflicting_nets is None:
conflicting_nets = []
conflict_edge_ids = []
available_edge_ids = []
router_bindings = nsxv_db.get_nsxv_router_bindings(context.session)
vdr_dhcp_bindings = nsxv_db.get_vdr_dhcp_bindings(context.session)
vdr_dhcp_router_ids = [
binding['dhcp_router_id'] for binding in vdr_dhcp_bindings]
all_dhcp_edges = {binding['router_id']: binding['edge_id'] for
binding in router_bindings if (binding['router_id'].
startswith(vcns_const.DHCP_EDGE_PREFIX) and
binding['status'] == plugin_const.ACTIVE)}
vdr_dhcp_edges = self._get_vdr_dhcp_edges(context)
binding['status'] == plugin_const.ACTIVE and
binding['router_id'] not in vdr_dhcp_router_ids)}
if all_dhcp_edges:
for dhcp_edge_id in set(all_dhcp_edges.values()):
@ -731,8 +729,7 @@ class EdgeManager(object):
for x in all_dhcp_edges.values():
if (x not in conflict_edge_ids and
x not in available_edge_ids and
x not in vdr_dhcp_edges):
x not in available_edge_ids):
available_edge_ids.append(x)
return (conflict_edge_ids, available_edge_ids)
@ -975,6 +972,9 @@ class EdgeManager(object):
self.reuse_existing_dhcp_edge(
context, dhcp_edge_id, resource_id, network_id)
else:
temp_edge_id = ("fake_id_" + _uuid())[:36]
nsxv_db.add_vdr_dhcp_binding(context.session, vdr_router_id,
str(resource_id), temp_edge_id)
# Attach to DHCP Edge
dhcp_edge_id = self.allocate_new_dhcp_edge(
context, network_id, resource_id)
@ -992,8 +992,8 @@ class EdgeManager(object):
dhcp_edge_id,
[RP_FILTER_PROPERTY_OFF_TEMPLATE % ('all', '0')])
nsxv_db.add_vdr_dhcp_binding(context.session, vdr_router_id,
str(resource_id), dhcp_edge_id)
nsxv_db.update_vdr_dhcp_binding(context.session, vdr_router_id,
dhcp_edge_id=dhcp_edge_id)
address_groups = self.plugin._create_network_dhcp_address_group(
context, network_id)