|
|
|
@ -18,12 +18,15 @@ from oslo_db import exception as db_exc
|
|
|
|
|
from oslo_log import helpers as log_helpers
|
|
|
|
|
from oslo_log import log as logging
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
from sqlalchemy import or_
|
|
|
|
|
from sqlalchemy.orm import exc
|
|
|
|
|
|
|
|
|
|
from neutron._i18n import _, _LE
|
|
|
|
|
from neutron.common import constants
|
|
|
|
|
from neutron.common import exceptions as n_exc
|
|
|
|
|
from neutron.common import utils
|
|
|
|
|
from neutron.db import model_base
|
|
|
|
|
from neutron.db import models_v2
|
|
|
|
|
from neutron.extensions import dvr as ext_dvr
|
|
|
|
|
from neutron.extensions import portbindings
|
|
|
|
|
from neutron import manager
|
|
|
|
@ -134,26 +137,24 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
|
|
|
|
:param subnet: subnet id to match and extract ports of interest
|
|
|
|
|
:returns list -- Ports on the given subnet in the input host
|
|
|
|
|
"""
|
|
|
|
|
# FIXME(vivek, salv-orlando): improve this query by adding the
|
|
|
|
|
# capability of filtering by binding:host_id
|
|
|
|
|
ports_by_host = []
|
|
|
|
|
filter = {'fixed_ips': {'subnet_id': [subnet]}}
|
|
|
|
|
ports = self.plugin.get_ports(context, filters=filter)
|
|
|
|
|
LOG.debug("List of Ports on subnet %(subnet)s at host %(host)s "
|
|
|
|
|
"received as %(ports)s",
|
|
|
|
|
{'subnet': subnet, 'host': host, 'ports': ports})
|
|
|
|
|
for port in ports:
|
|
|
|
|
device_owner = port['device_owner']
|
|
|
|
|
if (utils.is_dvr_serviced(device_owner)):
|
|
|
|
|
if port[portbindings.HOST_ID] == host:
|
|
|
|
|
port_dict = self.plugin._make_port_dict(port,
|
|
|
|
|
process_extensions=False)
|
|
|
|
|
ports_by_host.append(port_dict)
|
|
|
|
|
filters = {'fixed_ips': {'subnet_id': [subnet]},
|
|
|
|
|
portbindings.HOST_ID: [host]}
|
|
|
|
|
ports_query = self.plugin._get_ports_query(context, filters=filters)
|
|
|
|
|
owner_filter = or_(
|
|
|
|
|
models_v2.Port.device_owner.startswith(
|
|
|
|
|
constants.DEVICE_OWNER_COMPUTE_PREFIX),
|
|
|
|
|
models_v2.Port.device_owner.in_(
|
|
|
|
|
utils.get_other_dvr_serviced_device_owners()))
|
|
|
|
|
ports_query = ports_query.filter(owner_filter)
|
|
|
|
|
ports = [
|
|
|
|
|
self.plugin._make_port_dict(port, process_extensions=False)
|
|
|
|
|
for port in ports_query.all()
|
|
|
|
|
]
|
|
|
|
|
LOG.debug("Returning list of dvr serviced ports on host %(host)s"
|
|
|
|
|
" for subnet %(subnet)s ports %(ports)s",
|
|
|
|
|
{'host': host, 'subnet': subnet,
|
|
|
|
|
'ports': ports_by_host})
|
|
|
|
|
return ports_by_host
|
|
|
|
|
'ports': ports})
|
|
|
|
|
return ports
|
|
|
|
|
|
|
|
|
|
@log_helpers.log_method_call
|
|
|
|
|
def get_subnet_for_dvr(self, context, subnet, fixed_ips=None):
|
|
|
|
|