From 65aea5d57728a7dcf9ad9665693305f97fd1918d Mon Sep 17 00:00:00 2001 From: Hirofumi Ichihara Date: Tue, 17 Nov 2015 11:29:07 +0900 Subject: [PATCH] Add hosted agents list to dhcp agent scheduler Availability zone aware dhcp scheduler uses hosted agents list to schedule dhcp agent to proper availability zone. The scheduler can avoid scheduling the same availalibity zone as agents host a network which should be distributed for HA. Change-Id: Ib01f6d852956dc1e89b83321d657c0baf829e28a Partially-implements: blueprint add-availability-zone --- neutron/scheduler/base_scheduler.py | 9 ++++--- neutron/scheduler/dhcp_agent_scheduler.py | 32 ++++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/neutron/scheduler/base_scheduler.py b/neutron/scheduler/base_scheduler.py index 9ed9b806f..9a7b1b7d0 100644 --- a/neutron/scheduler/base_scheduler.py +++ b/neutron/scheduler/base_scheduler.py @@ -32,7 +32,7 @@ class BaseScheduler(object): @abc.abstractmethod def select(self, plugin, context, resource_hostable_agents, - num_agents_needed): + resource_hosted_agents, num_agents_needed): """Return a subset of agents based on the specific scheduling logic.""" def schedule(self, plugin, context, resource): @@ -44,8 +44,9 @@ class BaseScheduler(object): plugin, context, resource) num_agents = filtered_agents_dict['n_agents'] hostable_agents = filtered_agents_dict['hostable_agents'] + hosted_agents = filtered_agents_dict['hosted_agents'] chosen_agents = self.select(plugin, context, hostable_agents, - num_agents) + hosted_agents, num_agents) # bind the resource to the agents self.resource_filter.bind(context, chosen_agents, resource['id']) return chosen_agents @@ -58,7 +59,7 @@ class BaseChanceScheduler(BaseScheduler): self.resource_filter = resource_filter def select(self, plugin, context, resource_hostable_agents, - num_agents_needed): + resource_hosted_agents, num_agents_needed): chosen_agents = random.sample(resource_hostable_agents, num_agents_needed) return chosen_agents @@ -71,7 +72,7 @@ class BaseWeightScheduler(BaseScheduler): self.resource_filter = resource_filter def select(self, plugin, context, resource_hostable_agents, - num_agents_needed): + resource_hosted_agents, num_agents_needed): chosen_agents = sorted(resource_hostable_agents, key=attrgetter('load'))[0:num_agents_needed] return chosen_agents diff --git a/neutron/scheduler/dhcp_agent_scheduler.py b/neutron/scheduler/dhcp_agent_scheduler.py index 6a149440d..4dab4f058 100644 --- a/neutron/scheduler/dhcp_agent_scheduler.py +++ b/neutron/scheduler/dhcp_agent_scheduler.py @@ -115,11 +115,20 @@ class DhcpFilter(base_resource_filter.BaseResourceFilter): super(DhcpFilter, self).bind(context, bound_agents, network_id) def filter_agents(self, plugin, context, network): - """Return the agents that can host the network.""" + """Return the agents that can host the network. + + This function returns a dictionary which has 3 keys. + n_agents: The number of agents should be scheduled. If n_agents=0, + all networks are already scheduled or no more agent can host the + network. + hostable_agents: A list of agents which can host the network. + hosted_agents: A list of agents which already hosts the network. + """ agents_dict = self._get_network_hostable_dhcp_agents( plugin, context, network) if not agents_dict['hostable_agents'] or agents_dict['n_agents'] <= 0: - return {'n_agents': 0, 'hostable_agents': []} + return {'n_agents': 0, 'hostable_agents': [], + 'hosted_agents': agents_dict['hosted_agents']} return agents_dict def _get_dhcp_agents_hosting_network(self, plugin, context, network): @@ -151,17 +160,21 @@ class DhcpFilter(base_resource_filter.BaseResourceFilter): return active_dhcp_agents def _get_network_hostable_dhcp_agents(self, plugin, context, network): - """Return number of agents which will actually host the given network - and a list of dhcp agents which can host the given network + """Provide information on hostable DHCP agents for network. + + The returned value includes the number of agents that will actually + host the given network, a list of DHCP agents that can host the given + network, and a list of DHCP agents currently hosting the network. """ hosted_agents = self._get_dhcp_agents_hosting_network(plugin, context, network) if hosted_agents is None: - return {'n_agents': 0, 'hostable_agents': []} + return {'n_agents': 0, 'hostable_agents': [], 'hosted_agents': []} n_agents = cfg.CONF.dhcp_agents_per_network - len(hosted_agents) active_dhcp_agents = self._get_active_agents(plugin, context) if not active_dhcp_agents: - return {'n_agents': 0, 'hostable_agents': []} + return {'n_agents': 0, 'hostable_agents': [], + 'hosted_agents': hosted_agents} hostable_dhcp_agents = [ agent for agent in set(active_dhcp_agents) if agent not in hosted_agents and plugin.is_eligible_agent( @@ -169,7 +182,8 @@ class DhcpFilter(base_resource_filter.BaseResourceFilter): ] if not hostable_dhcp_agents: - return {'n_agents': 0, 'hostable_agents': []} + return {'n_agents': 0, 'hostable_agents': [], + 'hosted_agents': hosted_agents} n_agents = min(len(hostable_dhcp_agents), n_agents) - return {'n_agents': n_agents, 'hostable_agents': - hostable_dhcp_agents} + return {'n_agents': n_agents, 'hostable_agents': hostable_dhcp_agents, + 'hosted_agents': hosted_agents} -- 2.45.2