14
14
# under the License.
16
16
from eventlet import greenthread
18
from oslo.config import cfg
19
from oslo.db import exception as db_exc
20
from oslo import messaging
21
from oslo.serialization import jsonutils
22
from oslo.utils import timeutils
17
from oslo_config import cfg
18
from oslo_db import exception as db_exc
19
from oslo_log import log as logging
21
from oslo_serialization import jsonutils
22
from oslo_utils import timeutils
23
23
import sqlalchemy as sa
24
24
from sqlalchemy.orm import exc
25
25
from sqlalchemy import sql
27
27
from neutron.api.v2 import attributes
28
from neutron.common import constants
28
29
from neutron.db import model_base
29
30
from neutron.db import models_v2
30
31
from neutron.extensions import agent as ext_agent
31
32
from neutron.i18n import _LW
32
33
from neutron import manager
33
from neutron.openstack.common import log as logging
35
35
LOG = logging.getLogger(__name__)
36
cfg.CONF.register_opt(
37
38
cfg.IntOpt('agent_down_time', default=75,
38
39
help=_("Seconds to regard the agent is down; should be at "
39
40
"least twice report_interval, to be sure the "
40
"agent is down for good.")))
41
"agent is down for good.")),
42
cfg.StrOpt('dhcp_load_type', default='networks',
43
choices=['networks', 'subnets', 'ports'],
44
help=_('Representing the resource type whose load is being '
45
'reported by the agent. This can be "networks", '
46
'"subnets" or "ports". '
47
'When specified (Default is networks), the server will '
48
'extract particular load sent as part of its agent '
49
'configuration object from the agent report state, '
50
'which is the number of resources being consumed, at '
51
'every report_interval.'
52
'dhcp_load_type can be used in combination with '
53
'network_scheduler_driver = '
54
'neutron.scheduler.dhcp_agent_scheduler.WeightScheduler '
55
'When the network_scheduler_driver is WeightScheduler, '
56
'dhcp_load_type can be configured to represent the '
57
'choice for the resource being balanced. '
58
'Example: dhcp_load_type=networks')),
60
cfg.CONF.register_opts(AGENT_OPTS)
43
63
class Agent(model_base.BASEV2, models_v2.HasId):
68
88
description = sa.Column(sa.String(255))
69
89
# configurations: a json dict string, I think 4095 is enough
70
90
configurations = sa.Column(sa.String(4095), nullable=False)
91
# load - number of resources hosted by the agent
92
load = sa.Column(sa.Integer, default=0, nullable=False)
73
95
def is_active(self):
142
def _get_agent_load(self, agent):
143
configs = agent.get('configurations', {})
146
if(agent['agent_type'] == constants.AGENT_TYPE_DHCP):
147
load_type = cfg.CONF.dhcp_load_type
149
load = int(configs.get(load_type, 0))
120
152
def _make_agent_dict(self, agent, fields=None):
121
153
attr = ext_agent.RESOURCE_ATTRIBUTE_MAP.get(
122
154
ext_agent.RESOURCE_NAME + 's')
222
255
class AgentExtRpcCallback(object):
223
"""Processes the rpc report in plugin implementations."""
225
target = messaging.Target(version='1.0')
256
"""Processes the rpc report in plugin implementations.
258
This class implements the server side of an rpc interface. The client side
259
can be found in neutron.agent.rpc.PluginReportStateAPI. For more
260
information on changing rpc interfaces, see doc/source/devref/rpc_api.rst.
263
target = oslo_messaging.Target(version='1.0',
264
namespace=constants.RPC_NAMESPACE_STATE)
226
265
START_TIME = timeutils.utcnow()
228
267
def __init__(self, plugin=None):