@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):
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
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
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
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):
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(
]
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}