Use a joined relationship for AZ info on networks
The previous code was doing a DB lookup for each network's availability zone which was significantly impacting the performance of network listings. This patch adjusts the network model to be automatically joined to the DHCP agents table that the AZ code uses to populate the AZs for the network. Change-Id: I908ceb1a68e0eed7c304e3ff82279ad6fa406167 Closes-Bug: #1525740
This commit is contained in:
parent
dbc541be54
commit
57964df5c6
neutron
db
extensions
@ -464,15 +464,9 @@ class AZDhcpAgentSchedulerDbMixin(DhcpAgentSchedulerDbMixin,
|
||||
network_az.NetworkAvailabilityZoneMixin):
|
||||
"""Mixin class to add availability_zone supported DHCP agent scheduler."""
|
||||
|
||||
def get_network_availability_zones(self, network_id):
|
||||
context = ncontext.get_admin_context()
|
||||
with context.session.begin():
|
||||
query = context.session.query(agents_db.Agent.availability_zone)
|
||||
query = query.join(NetworkDhcpAgentBinding)
|
||||
query = query.filter(
|
||||
NetworkDhcpAgentBinding.network_id == network_id)
|
||||
query = query.group_by(agents_db.Agent.availability_zone)
|
||||
return [item[0] for item in query]
|
||||
def get_network_availability_zones(self, network):
|
||||
zones = {agent.availability_zone for agent in network.dhcp_agents}
|
||||
return list(zones)
|
||||
|
||||
|
||||
# helper functions for readability.
|
||||
|
@ -29,7 +29,7 @@ class NetworkAvailabilityZoneMixin(net_az.NetworkAvailabilityZonePluginBase):
|
||||
net_res[az_ext.AZ_HINTS] = az_ext.convert_az_string_to_list(
|
||||
net_db[az_ext.AZ_HINTS])
|
||||
net_res[az_ext.AVAILABILITY_ZONES] = (
|
||||
self.get_network_availability_zones(net_db['id']))
|
||||
self.get_network_availability_zones(net_db))
|
||||
|
||||
common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
|
||||
attributes.NETWORKS, ['_extend_availability_zone'])
|
||||
|
@ -267,3 +267,5 @@ class Network(model_base.HasStandardAttributes, model_base.BASEV2,
|
||||
backref='network', lazy='joined',
|
||||
cascade='all, delete, delete-orphan')
|
||||
availability_zone_hints = sa.Column(sa.String(255))
|
||||
dhcp_agents = orm.relationship('Agent', lazy='joined', viewonly=True,
|
||||
secondary='networkdhcpagentbindings')
|
||||
|
@ -64,5 +64,5 @@ class Network_availability_zone(extensions.ExtensionDescriptor):
|
||||
class NetworkAvailabilityZonePluginBase(object):
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_network_availability_zones(self, network_id):
|
||||
def get_network_availability_zones(self, network):
|
||||
"""Return availability zones which a network belongs to"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user