Merge "Optimize get_ports with trunk extension"
This commit is contained in:
commit
e968620adc
neutron
@ -223,7 +223,8 @@ class DbBasePluginCommon(object):
|
||||
|
||||
def _make_port_dict(self, port, fields=None,
|
||||
process_extensions=True,
|
||||
with_fixed_ips=True):
|
||||
with_fixed_ips=True,
|
||||
bulk=False):
|
||||
if isinstance(port, port_obj.Port):
|
||||
port_data = port.db_obj
|
||||
standard_attr_id = port.db_obj.standard_attr.id
|
||||
@ -252,8 +253,10 @@ class DbBasePluginCommon(object):
|
||||
ip["ip_address"])} for ip in port["fixed_ips"]]
|
||||
# Call auxiliary extend functions, if any
|
||||
if process_extensions:
|
||||
res['bulk'] = bulk
|
||||
resource_extend.apply_funcs(
|
||||
port_def.COLLECTION_NAME, res, port_data)
|
||||
res.pop('bulk')
|
||||
return db_utils.resource_fields(res, fields)
|
||||
|
||||
def _get_network(self, context, id):
|
||||
|
@ -1563,7 +1563,9 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
sorts=sorts, limit=limit,
|
||||
marker_obj=marker_obj,
|
||||
page_reverse=page_reverse)
|
||||
items = [self._make_port_dict(c, fields) for c in query]
|
||||
items = [self._make_port_dict(c, fields, bulk=True) for c in query]
|
||||
# TODO(obondarev): use neutron_lib constant
|
||||
resource_extend.apply_funcs('ports_bulk', items, None)
|
||||
if limit and page_reverse:
|
||||
items.reverse()
|
||||
return items
|
||||
|
@ -79,17 +79,44 @@ class TrunkPlugin(service_base.ServicePluginBase):
|
||||
'port_id': x.port_id}
|
||||
for x in port_db.trunk_port.sub_ports
|
||||
}
|
||||
core_plugin = directory.get_plugin()
|
||||
ports = core_plugin.get_ports(
|
||||
context.get_admin_context(), filters={'id': subports})
|
||||
for port in ports:
|
||||
subports[port['id']]['mac_address'] = port['mac_address']
|
||||
if not port_res.get('bulk'):
|
||||
core_plugin = directory.get_plugin()
|
||||
ports = core_plugin.get_ports(
|
||||
context.get_admin_context(), filters={'id': subports})
|
||||
for port in ports:
|
||||
subports[port['id']]['mac_address'] = port['mac_address']
|
||||
trunk_details = {'trunk_id': port_db.trunk_port.id,
|
||||
'sub_ports': list(subports.values())}
|
||||
port_res['trunk_details'] = trunk_details
|
||||
|
||||
return port_res
|
||||
|
||||
@staticmethod
|
||||
# TODO(obondarev): use neutron_lib constant
|
||||
@resource_extend.extends(['ports_bulk'])
|
||||
def _extend_port_trunk_details_bulk(ports_res, noop):
|
||||
"""Add trunk subport details to a list of ports."""
|
||||
subport_ids = []
|
||||
trunk_ports = []
|
||||
for p in ports_res:
|
||||
if 'trunk_details' in p and 'subports' in p['trunk_details']:
|
||||
trunk_ports.append(p)
|
||||
for subp in p['trunk_details']['subports']:
|
||||
subport_ids.append(subp['port_id'])
|
||||
if not subport_ids:
|
||||
return ports_res
|
||||
|
||||
core_plugin = directory.get_plugin()
|
||||
subports = core_plugin.get_ports(
|
||||
context.get_admin_context(), filters={'id': subport_ids})
|
||||
subport_macs = {p['id']: p['mac_address'] for p in subports}
|
||||
|
||||
for tp in trunk_ports:
|
||||
for subp in tp['trunk_details']['subports']:
|
||||
subp['mac_address'] = subport_macs[subp['port_id']]
|
||||
|
||||
return ports_res
|
||||
|
||||
def check_compatibility(self):
|
||||
"""Verify the plugin can load correctly and fail otherwise."""
|
||||
self.check_driver_compatibility()
|
||||
|
Loading…
x
Reference in New Issue
Block a user