from cinder import exception
from cinder.openstack.common import importutils
from cinder.openstack.common import log as logging
+from cinder.openstack.common import loopingcall
from cinder.openstack.common import rpc
-from cinder import utils
from cinder import version
from cinder import wsgi
self.manager.init_host()
if self.report_interval:
- pulse = utils.LoopingCall(self.report_state)
+ pulse = loopingcall.LoopingCall(self.report_state)
pulse.start(interval=self.report_interval,
initial_delay=self.report_interval)
self.timers.append(pulse)
else:
initial_delay = None
- periodic = utils.LoopingCall(self.periodic_tasks)
+ periodic = loopingcall.LoopingCall(self.periodic_tasks)
periodic.start(interval=self.periodic_interval,
initial_delay=initial_delay)
self.timers.append(periodic)
import sys
import tempfile
-from eventlet import event
-from eventlet import greenthread
from eventlet import pools
from oslo.config import cfg
import paramiko
return getattr(backend, key)
-class LoopingCallDone(Exception):
- """Exception to break out and stop a LoopingCall.
-
- The poll-function passed to LoopingCall can raise this exception to
- break out of the loop normally. This is somewhat analogous to
- StopIteration.
-
- An optional return-value can be included as the argument to the exception;
- this return-value will be returned by LoopingCall.wait()
-
- """
-
- def __init__(self, retvalue=True):
- """:param retvalue: Value that LoopingCall.wait() should return."""
- self.retvalue = retvalue
-
-
-class LoopingCall(object):
- def __init__(self, f=None, *args, **kw):
- self.args = args
- self.kw = kw
- self.f = f
- self._running = False
-
- def start(self, interval, initial_delay=None):
- self._running = True
- done = event.Event()
-
- def _inner():
- if initial_delay:
- greenthread.sleep(initial_delay)
-
- try:
- while self._running:
- self.f(*self.args, **self.kw)
- if not self._running:
- break
- greenthread.sleep(interval)
- except LoopingCallDone as e:
- self.stop()
- done.send(e.retvalue)
- except Exception:
- LOG.exception(_('in looping call'))
- done.send_exception(*sys.exc_info())
- return
- else:
- done.send(True)
-
- self.done = done
-
- greenthread.spawn(_inner)
- return self.done
-
- def stop(self):
- self._running = False
-
- def wait(self):
- return self.done.wait()
-
-
class ProtectedExpatParser(expatreader.ExpatParser):
"""An expat parser which disables DTD's and entities by default."""