~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/service.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import inspect
23
23
import os
 
24
import random
 
25
import signal
24
26
 
25
27
import eventlet
26
28
import greenlet
27
29
 
 
30
from nova.common import eventlet_backdoor
28
31
from nova import context
29
32
from nova import db
30
33
from nova import exception
31
34
from nova import flags
32
35
from nova import log as logging
33
36
from nova.openstack.common import cfg
 
37
from nova.openstack.common import importutils
34
38
from nova import rpc
35
39
from nova import utils
36
40
from nova import version
46
50
    cfg.IntOpt('periodic_interval',
47
51
               default=60,
48
52
               help='seconds between running periodic tasks'),
 
53
    cfg.IntOpt('periodic_fuzzy_delay',
 
54
               default=60,
 
55
               help='range of seconds to randomly delay when starting the'
 
56
                    ' periodic task scheduler to reduce stampeding.'
 
57
                    ' (Disable by setting to 0)'),
49
58
    cfg.StrOpt('ec2_listen',
50
59
               default="0.0.0.0",
51
60
               help='IP address for EC2 API to listen'),
72
81
               help='IP address for OpenStack Volume API to listen'),
73
82
    cfg.IntOpt('osapi_volume_listen_port',
74
83
               default=8776,
75
 
               help='port for os volume api to listen'),
 
84
               help='port for os volume api to listen')
76
85
    ]
77
86
 
78
87
FLAGS = flags.FLAGS
126
135
        :returns: None
127
136
 
128
137
        """
 
138
        def sigterm(sig, frame):
 
139
            LOG.audit(_("SIGTERM received"))
 
140
            # NOTE(jk0): Raise a ^C which is caught by the caller and cleanly
 
141
            # shuts down the service. This does not yet handle eventlet
 
142
            # threads.
 
143
            raise KeyboardInterrupt
 
144
 
 
145
        signal.signal(signal.SIGTERM, sigterm)
 
146
 
129
147
        for service in self._services:
130
148
            try:
131
149
                service.wait()
141
159
    it state to the database services table."""
142
160
 
143
161
    def __init__(self, host, binary, topic, manager, report_interval=None,
144
 
                 periodic_interval=None, *args, **kwargs):
 
162
                 periodic_interval=None, periodic_fuzzy_delay=None,
 
163
                 *args, **kwargs):
145
164
        self.host = host
146
165
        self.binary = binary
147
166
        self.topic = topic
148
167
        self.manager_class_name = manager
149
 
        manager_class = utils.import_class(self.manager_class_name)
 
168
        manager_class = importutils.import_class(self.manager_class_name)
150
169
        self.manager = manager_class(host=self.host, *args, **kwargs)
151
170
        self.report_interval = report_interval
152
171
        self.periodic_interval = periodic_interval
 
172
        self.periodic_fuzzy_delay = periodic_fuzzy_delay
153
173
        super(Service, self).__init__(*args, **kwargs)
154
174
        self.saved_args, self.saved_kwargs = args, kwargs
155
175
        self.timers = []
159
179
        LOG.audit(_('Starting %(topic)s node (version %(vcs_string)s)'),
160
180
                  {'topic': self.topic, 'vcs_string': vcs_string})
161
181
        utils.cleanup_file_locks()
 
182
        rpc.register_opts(FLAGS)
162
183
        self.manager.init_host()
163
184
        self.model_disconnected = False
164
185
        ctxt = context.get_admin_context()
177
198
        LOG.debug(_("Creating Consumer connection for Service %s") %
178
199
                  self.topic)
179
200
 
 
201
        rpc_dispatcher = self.manager.create_rpc_dispatcher()
 
202
 
180
203
        # Share this same connection for these Consumers
181
 
        self.conn.create_consumer(self.topic, self, fanout=False)
 
204
        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=False)
182
205
 
183
206
        node_topic = '%s.%s' % (self.topic, self.host)
184
 
        self.conn.create_consumer(node_topic, self, fanout=False)
 
207
        self.conn.create_consumer(node_topic, rpc_dispatcher, fanout=False)
185
208
 
186
 
        self.conn.create_consumer(self.topic, self, fanout=True)
 
209
        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=True)
187
210
 
188
211
        # Consume from all consumers in a thread
189
212
        self.conn.consume_in_thread()
190
213
 
191
214
        if self.report_interval:
192
215
            pulse = utils.LoopingCall(self.report_state)
193
 
            pulse.start(interval=self.report_interval, now=False)
 
216
            pulse.start(interval=self.report_interval,
 
217
                        initial_delay=self.report_interval)
194
218
            self.timers.append(pulse)
195
219
 
196
220
        if self.periodic_interval:
 
221
            if self.periodic_fuzzy_delay:
 
222
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
 
223
            else:
 
224
                initial_delay = None
 
225
 
197
226
            periodic = utils.LoopingCall(self.periodic_tasks)
198
 
            periodic.start(interval=self.periodic_interval, now=False)
 
227
            periodic.start(interval=self.periodic_interval,
 
228
                           initial_delay=initial_delay)
199
229
            self.timers.append(periodic)
200
230
 
201
231
    def _create_service_ref(self, context):
214
244
 
215
245
    @classmethod
216
246
    def create(cls, host=None, binary=None, topic=None, manager=None,
217
 
               report_interval=None, periodic_interval=None):
 
247
               report_interval=None, periodic_interval=None,
 
248
               periodic_fuzzy_delay=None):
218
249
        """Instantiates class and passes back application object.
219
250
 
220
251
        :param host: defaults to FLAGS.host
223
254
        :param manager: defaults to FLAGS.<topic>_manager
224
255
        :param report_interval: defaults to FLAGS.report_interval
225
256
        :param periodic_interval: defaults to FLAGS.periodic_interval
 
257
        :param periodic_fuzzy_delay: defaults to FLAGS.periodic_fuzzy_delay
226
258
 
227
259
        """
228
260
        if not host:
233
265
            topic = binary.rpartition('nova-')[2]
234
266
        if not manager:
235
267
            manager = FLAGS.get('%s_manager' % topic, None)
236
 
        if not report_interval:
 
268
        if report_interval is None:
237
269
            report_interval = FLAGS.report_interval
238
 
        if not periodic_interval:
 
270
        if periodic_interval is None:
239
271
            periodic_interval = FLAGS.periodic_interval
 
272
        if periodic_fuzzy_delay is None:
 
273
            periodic_fuzzy_delay = FLAGS.periodic_fuzzy_delay
240
274
        service_obj = cls(host, binary, topic, manager,
241
 
                          report_interval, periodic_interval)
 
275
                          report_interval=report_interval,
 
276
                          periodic_interval=periodic_interval,
 
277
                          periodic_fuzzy_delay=periodic_fuzzy_delay)
242
278
 
243
279
        return service_obj
244
280
 
349
385
        if not manager_class_name:
350
386
            return None
351
387
 
352
 
        manager_class = utils.import_class(manager_class_name)
 
388
        manager_class = importutils.import_class(manager_class_name)
353
389
        return manager_class()
354
390
 
355
391
    def start(self):
362
398
 
363
399
        """
364
400
        utils.cleanup_file_locks()
 
401
        rpc.register_opts(FLAGS)
365
402
        if self.manager:
366
403
            self.manager.init_host()
367
404
        self.server.start()
397
434
    for server in servers:
398
435
        _launcher.launch_server(server)
399
436
 
 
437
    eventlet_backdoor.initialize_if_enabled()
 
438
 
400
439
 
401
440
def wait():
402
441
    LOG.debug(_('Full set of FLAGS:'))
 
442
    rpc.register_opts(FLAGS)
403
443
    for flag in FLAGS:
404
444
        flag_get = FLAGS.get(flag, None)
405
445
        # hide flag contents from log if contains a password