Multiple port binding for ML2

Functionality is added to the ML2 plugin to handle multiple port
bindings

Co-Authored-By: Anindita Das <anindita.das@intel.com>
Co-Authored-By: Miguel Lavalle <miguel.lavalle@huawei.com>

Partial-Bug: #1580880

Change-Id: Ie31d4e27e3f55edfe334c4029ca9ed685e684c39
This commit is contained in:
Jakub Libosvar
2017-07-27 14:15:11 +00:00
committed by Miguel Lavalle
parent e8168345ef
commit f7b62a7f29
18 changed files with 870 additions and 64 deletions

View File

@@ -33,6 +33,7 @@ import uuid
import eventlet
from eventlet.green import subprocess
import netaddr
from neutron_lib.api.definitions import portbindings_extended as pb_ext
from neutron_lib import constants as n_const
from neutron_lib.utils import helpers
from oslo_config import cfg
@@ -43,6 +44,7 @@ import six
import neutron
from neutron._i18n import _
from neutron.common import exceptions
from neutron.db import api as db_api
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
@@ -783,3 +785,36 @@ def bytes_to_bits(value):
def bits_to_kilobits(value, base):
# NOTE(slaweq): round up that even 1 bit will give 1 kbit as a result
return int((value + (base - 1)) / base)
def get_port_binding_by_status_and_host(bindings, status, host='',
raise_if_not_found=False,
port_id=None):
"""Returns from an iterable the binding with the specified status and host.
The input iterable can contain zero or one binding in status ACTIVE
and zero or many bindings in status INACTIVE. As a consequence, to
unequivocally retrieve an inactive binding, the caller must specify a non
empty value for host. If host is the empty string, the first binding
satisfying the specified status will be returned. If no binding is found
with the specified status and host, None is returned or PortBindingNotFound
is raised if raise_if_not_found is True
:param bindings: An iterable containing port bindings
:param status: The status of the port binding to return. Possible values
are ACTIVE or INACTIVE as defined in
:file:`neutron_lib/constants.py`.
:param host: str representing the host of the binding to return.
:param raise_if_not_found: If a binding is not found and this parameter is
True, a PortBindingNotFound exception is raised
:param port_id: The id of the binding's port
:returns: The searched for port binding or None if it is not found
:raises: PortBindingNotFound if the binding is not found and
raise_if_not_found is True
"""
for binding in bindings:
if binding[pb_ext.STATUS] == status:
if not host or binding[pb_ext.HOST] == host:
return binding
if raise_if_not_found:
raise exceptions.PortBindingNotFound(port_id=port_id, host=host)