Example #1
0
    def create_volume_from_image(self, image_id):
        """Create cinder volume

        :param image_id: ID of amphora image

        :return volume id
        """
        volume = self.manager.create(
            size=CONF.cinder.volume_size,
            volume_type=CONF.cinder.volume_type,
            availability_zone=CONF.cinder.availability_zone,
            imageRef=image_id)
        resource_status = self.manager.get(volume.id).status

        status = constants.CINDER_STATUS_AVAILABLE
        start = int(time.time())

        while resource_status != status:
            time.sleep(CONF.cinder.volume_create_retry_interval)
            instance_volume = self.manager.get(volume.id)
            resource_status = instance_volume.status
            if resource_status == constants.CINDER_STATUS_ERROR:
                LOG.error('Error creating %s', instance_volume.id)
                instance_volume.delete()
                raise cinder_exceptions.ResourceInErrorState(
                    obj=volume, fault_msg='Cannot create volume')
            if int(time.time()) - start >= CONF.cinder.volume_create_timeout:
                LOG.error('Timed out waiting to create cinder volume %s',
                          instance_volume.id)
                instance_volume.delete()
                raise cinder_exceptions.TimeoutException(
                    obj=volume, action=constants.CINDER_ACTION_CREATE_VOLUME)
        return volume.id
Example #2
0
def _poll_for_status(poll_fn, obj_id, info, action, final_ok_states,
                     timeout_period, global_request_id=None, messages=None,
                     poll_period=2, status_field="status"):
    """Block while an action is being performed."""
    time_elapsed = 0
    while True:
        time.sleep(poll_period)
        time_elapsed += poll_period
        obj = poll_fn(obj_id)
        status = getattr(obj, status_field)
        info[status_field] = status
        if status:
            status = status.lower()

        if status in final_ok_states:
            break
        elif status == "error":
            utils.print_dict(info)
            if global_request_id:
                search_opts = {
                    'request_id': global_request_id
                    }
                message_list = messages.list(search_opts=search_opts)
                try:
                    fault_msg = message_list[0].user_message
                except IndexError:
                    fault_msg = "Unknown error. Operation failed."
                raise exceptions.ResourceInErrorState(obj, fault_msg)
        elif time_elapsed == timeout_period:
            utils.print_dict(info)
            raise exceptions.TimeoutException(obj, action)