当前位置: 首页>>代码示例>>Python>>正文


Python loopingcall.LoopingCallDone方法代码示例

本文整理汇总了Python中oslo_service.loopingcall.LoopingCallDone方法的典型用法代码示例。如果您正苦于以下问题:Python loopingcall.LoopingCallDone方法的具体用法?Python loopingcall.LoopingCallDone怎么用?Python loopingcall.LoopingCallDone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_service.loopingcall的用法示例。


在下文中一共展示了loopingcall.LoopingCallDone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _wait_for_image_state

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [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() 
开发者ID:platform9,项目名称:openstack-omni,代码行数:21,代码来源:ec2driver.py

示例2: _create_sec_grp_rules

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [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() 
开发者ID:platform9,项目名称:openstack-omni,代码行数:18,代码来源:aws_utils.py

示例3: check_notification_status

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def check_notification_status(self, notification, wait_interval,
                                  wait_period):
        def wait_for_notification_status_finished():
            result = self.admin_conn.ha.get_notification(
                notification.notification_uuid)
            if result.status == fields.NotificationStatus.FINISHED:
                raise loopingcall.LoopingCallDone()

        timer = loopingcall.FixedIntervalWithTimeoutLoopingCall(
            wait_for_notification_status_finished)

        try:
            timer.start(interval=wait_interval, initial_delay=1,
                        timeout=wait_period).wait()
        except loopingcall.LoopingCallTimeOut:
            self.fail("Timed out: Notification is not processed and "
                      "it's not in the finished status") 
开发者ID:openstack,项目名称:masakari,代码行数:19,代码来源:notification_base.py

示例4: check_server_status

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def check_server_status(self, server, status):

        def wait_for_server_status_change():
            instance = self.admin_conn.compute.get_server(server.id)
            if instance.status == status:
                raise loopingcall.LoopingCallDone()

        timer = loopingcall.FixedIntervalWithTimeoutLoopingCall(
            wait_for_server_status_change)

        try:
            timer.start(interval=self.SERVER_WAIT_INTERVAL,
                        timeout=self.SERVER_WAIT_PERIOD).wait()
        except loopingcall.LoopingCallTimeOut:
            self.fail("Timed out: Instance is not in the expected"
                      " status: %s" % status) 
开发者ID:openstack,项目名称:masakari,代码行数:18,代码来源:notification_base.py

示例5: test_no_double_start

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def test_no_double_start(self):
        wait_ev = greenthreading.Event()

        def _run_forever_until_set():
            if wait_ev.is_set():
                raise loopingcall.LoopingCallDone(True)
            else:
                return 0.01

        timer = loopingcall.DynamicLoopingCall(_run_forever_until_set)
        timer.start()

        self.assertRaises(RuntimeError, timer.start)

        wait_ev.set()
        timer.wait() 
开发者ID:openstack,项目名称:oslo.service,代码行数:18,代码来源:test_loopingcall.py

示例6: status_poll

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [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() 
开发者ID:openstack,项目名称:karbor,代码行数:18,代码来源:utils.py

示例7: _wait_for_power_off

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [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 
开发者ID:openstack,项目名称:compute-hyperv,代码行数:30,代码来源:vmops.py

示例8: _wait_for_state

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def _wait_for_state(self, instance, ec2_id, desired_state, desired_power_state):
        """Wait for the state of the corrosponding ec2 instance to be in completely available state.
        :params:ec2_id: the instance's corrosponding ec2 id.
        :params:desired_state: the desired state of the instance to be in.
        """
        def _wait_for_power_state():
            """Called at an interval until the VM is running again.
            """
            ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id])

            state = ec2_instance[0].state
            if state == desired_state:
                LOG.info("Instance has changed state to %s." % desired_state)
                raise loopingcall.LoopingCallDone()

        def _wait_for_status_check():
            """Power state of a machine might be ON, but status check is the one which gives the real
            """
            ec2_instance = self.ec2_conn.get_all_instance_status(instance_ids=[ec2_id])[0]
            if ec2_instance.system_status.status == 'ok':
                LOG.info("Instance status check is %s / %s" %
                         (ec2_instance.system_status.status, ec2_instance.instance_status.status))
                raise loopingcall.LoopingCallDone()

        #waiting for the power state to change
        timer = loopingcall.FixedIntervalLoopingCall(_wait_for_power_state)
        timer.start(interval=1).wait() 
开发者ID:platform9,项目名称:openstack-omni,代码行数:29,代码来源:ec2driver.py

示例9: test_volume_create_fails

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def test_volume_create_fails(self, mock_wait):
        def wait(*args):
            def _wait():
                raise loopingcall.LoopingCallDone(False)
            timer = loopingcall.FixedIntervalLoopingCall(_wait)
            return timer.start(interval=1).wait()

        mock_wait.side_effect = wait
        self.assertRaises(APITimeout, self._driver.create_volume, self._stub_volume()) 
开发者ID:platform9,项目名称:openstack-omni,代码行数:11,代码来源:test_ebs.py

示例10: test_snapshot_create_fails

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def test_snapshot_create_fails(self, mock_wait):
        def wait(*args):
            def _wait():
                raise loopingcall.LoopingCallDone(False)

            timer = loopingcall.FixedIntervalLoopingCall(_wait)
            return timer.start(interval=1).wait()
        mock_wait.side_effect = wait
        ss = self._stub_snapshot()
        self._driver.create_volume(ss['volume'])
        self.assertRaises(APITimeout, self._driver.create_snapshot, ss) 
开发者ID:platform9,项目名称:openstack-omni,代码行数:13,代码来源:test_ebs.py

示例11: _wait_for_create

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def _wait_for_create(self, id, final_state):
        def _wait_for_status(start_time):
            current_time = time.time()

            if current_time - start_time > self._wait_time_sec:
                raise loopingcall.LoopingCallDone(False)

            obj = self._conn.get_all_volumes([id])[0]
            if obj.status == final_state:
                raise loopingcall.LoopingCallDone(True)

        timer = loopingcall.FixedIntervalLoopingCall(_wait_for_status, time.time())
        return timer.start(interval=5).wait() 
开发者ID:platform9,项目名称:openstack-omni,代码行数:15,代码来源:ebs.py

示例12: _create_sec_grp_tags

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def _create_sec_grp_tags(self, secgrp, tags):
        def _wait_for_state(start_time):
            current_time = time.time()
            if current_time - start_time > self._wait_time_sec:
                raise loopingcall.LoopingCallDone(False)
            try:
                secgrp.reload()
                secgrp.create_tags(Tags=tags)
            except Exception as ex:
                LOG.exception('Exception when adding tags to security groups.'
                              ' Retrying.')
                return
            raise loopingcall.LoopingCallDone(True)
        timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state, time.time())
        return timer.start(interval=5).wait() 
开发者ID:platform9,项目名称:openstack-omni,代码行数:17,代码来源:aws_utils.py

示例13: update_status

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def update_status(self):
        LOG.debug("Updating status for cluster %s", self.cluster.id)
        # get the driver for the cluster
        cdriver = driver.Driver.get_driver_for_cluster(self.ctx, self.cluster)
        # ask the driver to sync status
        cdriver.update_cluster_status(self.ctx, self.cluster)
        LOG.debug("Status for cluster %s updated to %s (%s)",
                  self.cluster.id, self.cluster.status,
                  self.cluster.status_reason)
        # status update notifications
        if self.cluster.status.endswith("_COMPLETE"):
            conductor_utils.notify_about_cluster_operation(
                self.ctx, self.status_to_event[self.cluster.status],
                taxonomy.OUTCOME_SUCCESS, self.cluster)
        if self.cluster.status.endswith("_FAILED"):
            conductor_utils.notify_about_cluster_operation(
                self.ctx, self.status_to_event[self.cluster.status],
                taxonomy.OUTCOME_FAILURE, self.cluster)
        # if we're done with it, delete it
        if self.cluster.status == objects.fields.ClusterStatus.DELETE_COMPLETE:
            # delete all the nodegroups that belong to this cluster
            for ng in objects.NodeGroup.list(self.ctx, self.cluster.uuid):
                ng.destroy()
            self.cluster.destroy()
        # end the "loop"
        raise loopingcall.LoopingCallDone() 
开发者ID:openstack,项目名称:magnum,代码行数:28,代码来源:periodic.py

示例14: update_health_status

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def update_health_status(self):
        LOG.debug("Updating health status for cluster %s", self.cluster.id)
        self._update_health_status()
        LOG.debug("Status for cluster %s updated to %s (%s)",
                  self.cluster.id, self.cluster.health_status,
                  self.cluster.health_status_reason)
        # TODO(flwang): Health status update notifications?
        # end the "loop"
        raise loopingcall.LoopingCallDone() 
开发者ID:openstack,项目名称:magnum,代码行数:11,代码来源:periodic.py

示例15: start

# 需要导入模块: from oslo_service import loopingcall [as 别名]
# 或者: from oslo_service.loopingcall import LoopingCallDone [as 别名]
def start(self, interval, **kwargs):
        initial_delay = kwargs.pop("initial_delay", 0)
        stop_on_exception = kwargs.pop("stop_on_exception", True)
        if initial_delay:
            time.sleep(initial_delay)
        while True:
            try:
                self.call_func()
            except loopingcall.LoopingCallDone:
                return 0
            except Exception as exc:
                if stop_on_exception:
                    raise exc
            if interval:
                time.sleep(interval) 
开发者ID:openstack,项目名称:magnum,代码行数:17,代码来源:fakes.py


注:本文中的oslo_service.loopingcall.LoopingCallDone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。