~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/db/agents_db.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    under the License.
15
15
 
16
16
from eventlet import greenthread
17
 
 
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
 
20
import oslo_messaging
 
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
26
26
 
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
34
34
 
35
35
LOG = logging.getLogger(__name__)
36
 
cfg.CONF.register_opt(
 
36
 
 
37
AGENT_OPTS = [
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')),
 
59
]
 
60
cfg.CONF.register_opts(AGENT_OPTS)
41
61
 
42
62
 
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)
71
93
 
72
94
    @property
73
95
    def is_active(self):
117
139
            conf = {}
118
140
        return conf
119
141
 
 
142
    def _get_agent_load(self, agent):
 
143
        configs = agent.get('configurations', {})
 
144
        load_type = None
 
145
        load = 0
 
146
        if(agent['agent_type'] == constants.AGENT_TYPE_DHCP):
 
147
            load_type = cfg.CONF.dhcp_load_type
 
148
        if load_type:
 
149
            load = int(configs.get(load_type, 0))
 
150
        return load
 
151
 
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')
178
210
 
179
211
            configurations_dict = agent.get('configurations', {})
180
212
            res['configurations'] = jsonutils.dumps(configurations_dict)
 
213
            res['load'] = self._get_agent_load(agent)
181
214
            current_time = timeutils.utcnow()
182
215
            try:
183
216
                agent_db = self._get_agent_by_type_and_host(
220
253
 
221
254
 
222
255
class AgentExtRpcCallback(object):
223
 
    """Processes the rpc report in plugin implementations."""
224
 
 
225
 
    target = messaging.Target(version='1.0')
 
256
    """Processes the rpc report in plugin implementations.
 
257
 
 
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.
 
261
    """
 
262
 
 
263
    target = oslo_messaging.Target(version='1.0',
 
264
                                   namespace=constants.RPC_NAMESPACE_STATE)
226
265
    START_TIME = timeutils.utcnow()
227
266
 
228
267
    def __init__(self, plugin=None):