예제 #1
0
    def _get_network_hostable_dhcp_agents(self, plugin, context, 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': [], 'hosted_agents': []}
        n_agents = cfg.CONF.dhcp_agents_per_network - len(hosted_agents)
        az_hints = (network.get(az_def.AZ_HINTS) or
                    cfg.CONF.default_availability_zones)
        active_dhcp_agents = self._get_active_agents(plugin, context, az_hints)
        hosted_agent_ids = [agent['id'] for agent in hosted_agents]
        if not active_dhcp_agents:
            return {'n_agents': 0, 'hostable_agents': [],
                    'hosted_agents': hosted_agents}
        hostable_dhcp_agents = [
            agent for agent in active_dhcp_agents
            if agent.id not in hosted_agent_ids and plugin.is_eligible_agent(
                context, True, agent)]
        hostable_dhcp_agents = self._filter_agents_with_network_access(
            plugin, context, network, hostable_dhcp_agents)

        if not hostable_dhcp_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,
                'hosted_agents': hosted_agents}
예제 #2
0
    def _get_network_hostable_dhcp_agents(self, plugin, context, 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': [], 'hosted_agents': []}
        n_agents = cfg.CONF.dhcp_agents_per_network - len(hosted_agents)
        az_hints = (network.get(az_def.AZ_HINTS) or
                    cfg.CONF.default_availability_zones)
        active_dhcp_agents = self._get_active_agents(plugin, context, az_hints)
        hosted_agent_ids = [agent['id'] for agent in hosted_agents]
        if not active_dhcp_agents:
            return {'n_agents': 0, 'hostable_agents': [],
                    'hosted_agents': hosted_agents}
        hostable_dhcp_agents = [
            agent for agent in active_dhcp_agents
            if agent.id not in hosted_agent_ids and plugin.is_eligible_agent(
                context, True, agent)]
        hostable_dhcp_agents = self._filter_agents_with_network_access(
            plugin, context, network, hostable_dhcp_agents)

        if not hostable_dhcp_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,
                'hosted_agents': hosted_agents}
 def _get_dhcp_agents_hosting_network(self, plugin, context, network):
     """Return dhcp agents hosting the given network or None if a given
        network is already hosted by enough number of agents.
     """
     agents_per_network = cfg.CONF.dhcp_agents_per_network
     # TODO(gongysh) don't schedule the networks with only
     # subnets whose enable_dhcp is false
     with db_api.CONTEXT_READER.using(context):
         network_hosted_agents = plugin.get_dhcp_agents_hosting_networks(
             context, [network['id']], hosts=network.get('candidate_hosts'))
         if len(network_hosted_agents) >= agents_per_network:
             LOG.debug('Network %s is already hosted by enough agents.',
                       network['id'])
             return
     return network_hosted_agents
예제 #4
0
 def _get_dhcp_agents_hosting_network(self, plugin, context, network):
     """Return dhcp agents hosting the given network or None if a given
        network is already hosted by enough number of agents.
     """
     agents_per_network = cfg.CONF.dhcp_agents_per_network
     # TODO(gongysh) don't schedule the networks with only
     # subnets whose enable_dhcp is false
     with context.session.begin(subtransactions=True):
         network_hosted_agents = plugin.get_dhcp_agents_hosting_networks(
             context, [network['id']], hosts=network.get('candidate_hosts'))
         if len(network_hosted_agents) >= agents_per_network:
             LOG.debug('Network %s is already hosted by enough agents.',
                       network['id'])
             return
     return network_hosted_agents