]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add hosted agents list to dhcp agent scheduler
authorHirofumi Ichihara <ichihara.hirofumi@lab.ntt.co.jp>
Tue, 17 Nov 2015 02:29:07 +0000 (11:29 +0900)
committerHirofumi Ichihara <ichihara.hirofumi@lab.ntt.co.jp>
Thu, 19 Nov 2015 01:39:28 +0000 (10:39 +0900)
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
neutron/scheduler/dhcp_agent_scheduler.py

index 9ed9b806ff1262a94293ab2699c27cd0e36a104c..9a7b1b7d0f1f2730bf19625028cef355c0ca4fa9 100644 (file)
@@ -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
index 6a149440dde41f58f076fa72c30ac761f79b76cc..4dab4f058e7dbe54cec990d1a2db22458c0a3967 100644 (file)
@@ -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}