Sort multiple macs in port lookup

Sorting makes the usage more predictable.

Change-Id: Id88a0f8b5a6c5d0f411803d8618b8aac32165c99
This commit is contained in:
Sumit Naiksatam 2016-10-14 01:49:36 -07:00
parent 2d5067aeb7
commit 0dd42fbaed
1 changed files with 14 additions and 0 deletions

View File

@ -16,7 +16,12 @@ from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import constants as l3_constants
from neutron.db import l3_db
from neutron.db import models_v2
from neutron.db import securitygroups_db
from neutron.plugins.ml2 import db as ml2_db
from oslo_log import log
LOG = log.getLogger(__name__)
# Monkey patch create floatingip to allow subnet_id to be specified.
@ -167,3 +172,12 @@ def _get_security_groups_on_port(self, context, port):
securitygroups_db.SecurityGroupDbMixin._get_security_groups_on_port = (
_get_security_groups_on_port)
def get_port_from_device_mac(context, device_mac):
LOG.debug("get_port_from_device_mac() called for mac %s", device_mac)
qry = context.session.query(models_v2.Port).filter_by(
mac_address=device_mac).order_by(models_v2.Port.device_owner.desc())
return qry.first()
ml2_db.get_port_from_device_mac = get_port_from_device_mac