本文整理匯總了Python中oslo_service.loopingcall.FixedIntervalLoopingCall方法的典型用法代碼示例。如果您正苦於以下問題:Python loopingcall.FixedIntervalLoopingCall方法的具體用法?Python loopingcall.FixedIntervalLoopingCall怎麽用?Python loopingcall.FixedIntervalLoopingCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oslo_service.loopingcall
的用法示例。
在下文中一共展示了loopingcall.FixedIntervalLoopingCall方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def __init__(self, vpn_service, host):
# TODO(pc_m) Replace vpn_service with config arg, once all driver
# implementations no longer need vpn_service.
self.conf = vpn_service.conf
self.host = host
self.conn = n_rpc.Connection()
self.context = context.get_admin_context_without_session()
self.topic = topics.IPSEC_AGENT_TOPIC
node_topic = '%s.%s' % (self.topic, self.host)
self.processes = {}
self.routers = {}
self.process_status_cache = {}
self.endpoints = [self]
self.conn.create_consumer(node_topic, self.endpoints, fanout=False)
self.conn.consume_in_threads()
self.agent_rpc = IPsecVpnDriverApi(topics.IPSEC_DRIVER_TOPIC)
self.process_status_cache_check = loopingcall.FixedIntervalLoopingCall(
self.report_status, self.context)
self.process_status_cache_check.start(
interval=self.conf.ipsec.ipsec_status_check_interval)
示例2: __init__
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def __init__(self, host, conf=None):
super(BgpDrAgentWithStateReport,
self).__init__(host, conf)
self.state_rpc = agent_rpc.PluginReportStateAPI(topics.REPORTS)
self.agent_state = {
'agent_type': bgp_consts.AGENT_TYPE_BGP_ROUTING,
'binary': 'neutron-bgp-dragent',
'configurations': {},
'host': host,
'topic': bgp_consts.BGP_DRAGENT,
'start_flag': True}
report_interval = cfg.CONF.AGENT.report_interval
if report_interval:
self.heartbeat = loopingcall.FixedIntervalLoopingCall(
self._report_state)
self.heartbeat.start(interval=report_interval)
示例3: _wait_for_image_state
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def _wait_for_image_state(self, ami_id, desired_state):
"""Timer to wait for the image/snapshot to reach a desired state
:params:ami_id: correspoding image id in Amazon
:params:desired_state: the desired new state of the image to be in.
"""
def _wait_for_state():
"""Called at an interval until the AMI image is available."""
try:
images = self.ec2_conn.get_all_images(image_ids=[ami_id], owners=None,
executable_by=None, filters=None, dry_run=None)
state = images[0].state
if state == desired_state:
LOG.info("Image has changed state to %s." % desired_state)
raise loopingcall.LoopingCallDone()
except boto_exc.EC2ResponseError:
pass
timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state)
timer.start(interval=0.5).wait()
示例4: _create_sec_grp_rules
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def _create_sec_grp_rules(self, secgrp, rules):
ingress, egress = self._convert_openstack_rules_to_vpc(rules)
def _wait_for_state(start_time):
current_time = time.time()
if current_time - start_time > self._wait_time_sec:
raise loopingcall.LoopingCallDone(False)
try:
self._refresh_sec_grp_rules(secgrp, ingress, egress)
except Exception as ex:
LOG.exception('Error creating security group rules. Retrying.')
return
raise loopingcall.LoopingCallDone(True)
timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state,
time.time())
return timer.start(interval=5).wait()
示例5: _start_periodic_tasks
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def _start_periodic_tasks(self):
# Run the task once in the current thread so prevent a race with
# the first invocation of get_share_stats.
self._update_ssc_info()
# Start the task that updates the slow-changing storage service catalog
ssc_periodic_task = loopingcall.FixedIntervalLoopingCall(
self._update_ssc_info)
ssc_periodic_task.start(interval=self.SSC_UPDATE_INTERVAL_SECONDS,
initial_delay=self.SSC_UPDATE_INTERVAL_SECONDS)
# Start the task that logs autosupport (EMS) data to the controller
ems_periodic_task = loopingcall.FixedIntervalLoopingCall(
self._handle_ems_logging)
ems_periodic_task.start(interval=self.AUTOSUPPORT_INTERVAL_SECONDS,
initial_delay=0)
# Start the task that runs other housekeeping tasks, such as deletion
# of previously soft-deleted storage artifacts.
housekeeping_periodic_task = loopingcall.FixedIntervalLoopingCall(
self._handle_housekeeping_tasks)
housekeeping_periodic_task.start(
interval=self.HOUSEKEEPING_INTERVAL_SECONDS, initial_delay=0)
示例6: test_interval_adjustment
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def test_interval_adjustment(self, elapsed_mock, sleep_mock):
"""Ensure the interval is adjusted to account for task duration."""
self.num_runs = 3
second = 1
smidgen = 0.01
elapsed_mock.side_effect = [second - smidgen,
second + second,
second + smidgen,
]
timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_zero)
timer.start(interval=1.01).wait()
expected_calls = [0.02, 0.00, 0.00]
for i, call in enumerate(sleep_mock.call_args_list):
expected = expected_calls[i]
args, kwargs = call
actual = args[0]
message = ('Call #%d, expected: %s, actual: %s' %
(i, expected, actual))
self.assertAlmostEqual(expected, actual, message=message)
示例7: start
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def start(self):
self.manager.start()
self.manager.init_host()
super(Service, self).start()
if self.report_interval:
pulse = loopingcall.FixedIntervalLoopingCall(self.report_state)
pulse.start(interval=self.report_interval,
initial_delay=self.report_interval)
self.timers.append(pulse)
if self.periodic_interval:
if self.periodic_fuzzy_delay:
initial_delay = random.randint(0, self.periodic_fuzzy_delay)
else:
initial_delay = None
periodic = loopingcall.FixedIntervalLoopingCall(
self.periodic_tasks)
periodic.start(interval=self.periodic_interval,
initial_delay=initial_delay)
self.timers.append(periodic)
self.manager.after_start()
示例8: __init__
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def __init__(self, trigger_id, trigger_property, executor):
super(TimeTrigger, self).__init__(
trigger_id, trigger_property, executor)
self._trigger_property = self.check_trigger_definition(
trigger_property)
timer = self._get_timer(self._trigger_property)
first_run_time = self._compute_next_run_time(
datetime.utcnow(), self._trigger_property['end_time'], timer)
LOG.debug("first_run_time: %s", first_run_time)
self._trigger_execution_new(self._id, first_run_time)
if not self.__class__._loopingcall:
self.__class__._loopingcall = loopingcall.FixedIntervalLoopingCall(
self._loop)
self.__class__._loopingcall.start(
interval=CONF.trigger_poll_interval,
stop_on_exception=False,
)
self._register()
示例9: connection
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def connection(self):
if not self._connection:
_connection = self._setup_connection()
# create container
try:
_connection.put_container(self.bank_object_container)
_connection.put_container(self.bank_leases_container)
except SwiftConnectionFailed as err:
LOG.error("bank plugin create container failed.")
raise exception.CreateContainerFailed(reason=err)
self._connection = _connection
# acquire lease
try:
self.acquire_lease()
except exception.AcquireLeaseFailed:
LOG.error("bank plugin acquire lease failed.")
raise
# start renew lease
renew_lease_loop = loopingcall.FixedIntervalLoopingCall(
self.renew_lease)
renew_lease_loop.start(interval=self.lease_renew_window,
initial_delay=self.lease_renew_window)
return self._connection
示例10: status_poll
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def status_poll(get_status_func, interval, success_statuses=set(),
failure_statuses=set(), ignore_statuses=set(),
ignore_unexpected=False):
def _poll():
status = get_status_func()
if status in success_statuses:
raise loopingcall.LoopingCallDone(retvalue=True)
if status in failure_statuses:
raise loopingcall.LoopingCallDone(retvalue=False)
if status in ignore_statuses:
return
if ignore_unexpected is False:
raise loopingcall.LoopingCallDone(retvalue=False)
loop = loopingcall.FixedIntervalLoopingCall(_poll)
return loop.start(interval=interval, initial_delay=interval).wait()
示例11: __init__
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def __init__(self):
self._vrouter_semaphore = eventlet.semaphore.Semaphore()
self._vrouter_client = ContrailVRouterApi(
doconnect=True, semaphore=self._vrouter_semaphore)
timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
timer.start(interval=2)
示例12: __init__
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def __init__(self, service_name, **kwargs):
super(HeartbeatEmitter, self).__init__()
self._status = 'UP'
self._stats = {}
self._capabilities = {}
self._service_name = service_name
self._hostname = CONF.host
self._timer = loopingcall.FixedIntervalLoopingCall(
self._emit_heartbeat
)
示例13: _wait_for_power_off
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def _wait_for_power_off(self, instance_name, time_limit):
"""Waiting for a VM to be in a disabled state.
:return: True if the instance is shutdown within time_limit,
False otherwise.
"""
desired_vm_states = [os_win_const.HYPERV_VM_STATE_DISABLED]
def _check_vm_status(instance_name):
if self._get_vm_state(instance_name) in desired_vm_states:
raise loopingcall.LoopingCallDone()
periodic_call = loopingcall.FixedIntervalLoopingCall(_check_vm_status,
instance_name)
try:
# add a timeout to the periodic call.
periodic_call.start(interval=SHUTDOWN_TIME_INCREMENT)
etimeout.with_timeout(time_limit, periodic_call.wait)
except etimeout.Timeout:
# VM did not shutdown in the expected time_limit.
return False
finally:
# stop the periodic call, in case of exceptions or Timeout.
periodic_call.stop()
return True
示例14: __init__
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def __init__(self, conf=None):
super(OVSDBManager, self).__init__(conf)
self._extract_ovsdb_config(conf)
self.enable_manager = cfg.CONF.ovsdb.enable_manager
periodic_interval = self.conf.ovsdb.periodic_interval
if self.enable_manager:
self.ovsdb_fd = None
self._sock_open_connection()
self.looping_task_ovsdb_states = (
loopingcall.FixedIntervalLoopingCall(self._send_ovsdb_states))
self.looping_task_ovsdb_states.start(interval=periodic_interval)
else:
self.looping_task = loopingcall.FixedIntervalLoopingCall(
self._connect_to_ovsdb_server)
self.looping_task.start(interval=periodic_interval)
示例15: _setup_state_rpc
# 需要導入模塊: from oslo_service import loopingcall [as 別名]
# 或者: from oslo_service.loopingcall import FixedIntervalLoopingCall [as 別名]
def _setup_state_rpc(self):
self.state_rpc = agent_rpc.PluginReportStateAPI(
topics.L2GATEWAY_PLUGIN)
report_interval = self.conf.AGENT.report_interval
if report_interval:
heartbeat = loopingcall.FixedIntervalLoopingCall(
self._report_state)
heartbeat.start(interval=report_interval)