]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
DB: Only ask for MAC instead of entire port
authorKevin Benton <blak111@gmail.com>
Fri, 17 Oct 2014 04:24:07 +0000 (21:24 -0700)
committerKevin Benton <blak111@gmail.com>
Fri, 17 Oct 2014 04:25:38 +0000 (21:25 -0700)
Optimize a query in _get_lla_gateway_ip_for_subnet
to only grab the column used instead of every column
in the port table.

Partial-Bug: #1373851
Change-Id: I5257e1e22645f3df9a77c0967b09a0ad0cf8b251

neutron/db/securitygroups_rpc_base.py

index 1dda6bb46982325494e504fe61dc7a072f0b7802..e73b2f6142e498cc28d693bc680108b9d7e95ed9 100644 (file)
@@ -330,7 +330,7 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin):
         return ips
 
     def _get_lla_gateway_ip_for_subnet(self, context, subnet):
-        query = context.session.query(models_v2.Port)
+        query = context.session.query(models_v2.Port.mac_address)
         query = query.join(models_v2.IPAllocation)
         query = query.filter(
             models_v2.IPAllocation.subnet_id == subnet['id'])
@@ -339,12 +339,11 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin):
         query = query.filter(models_v2.Port.device_owner ==
                              q_const.DEVICE_OWNER_ROUTER_INTF)
         try:
-            gateway_port = query.one()
+            mac_address = query.one()[0]
         except (exc.NoResultFound, exc.MultipleResultsFound):
             LOG.warn(_('No valid gateway port on subnet %s is '
                        'found for IPv6 RA'), subnet['id'])
             return
-        mac_address = gateway_port['mac_address']
         lla_ip = str(ipv6.get_ipv6_addr_by_EUI64(
             q_const.IPV6_LLA_PREFIX,
             mac_address))