Exemplo n.º 1
0
    def create(self, volume_id, size=None, backup_source_volume_id=None,
               backup_id=None, image_id=None, callback=None, lock=None,
               account=None, cinder=None, scrub_callback=None):

        op_start = time()

        size_str = self._get_size_str(size)
        tmp_vol = None
        snet_glance = None

        if image_id:
            mgmt_glance = get_glance_conn(self.conf, tenant_id=account,
                                          glance_urls=self.glance_mgmt_urls)
            snet_glance = get_glance_conn(self.conf, tenant_id=account)
            try:
                glance_start = time()
                image = mgmt_glance.head(image_id)
                logger.info('STAT: glance.head %r. Time: %r' %
                            (image_id, time() - glance_start))
                status = getattr(image, 'status', 'ACTIVE')
                if status.upper() != 'ACTIVE':
                    raise InvalidImage("Non-active image status: %s" % status)
                min_disk = getattr(image, 'min_disk', 0)
                if min_disk > 127:
                    raise InvalidImage("Image > 127GB: %s" % image_id)
                if min_disk:
                    multiplier = self._get_scratch_multiplier(image)
                    convert_gbs = int(min_disk * multiplier)
                else:
                    convert_gbs = self.convert_gbs
                tmp_vol = self.create_convert_scratch(image, convert_gbs)
            except GlanceError, e:
                logger.warning("Error fetching glance image: %s" % e)
                raise InvalidImage("Error fetching image: %s" % image_id)
Exemplo n.º 2
0
            try:
                log_duration()
            finally:
                if callback:
                    return callback(*args, **kwargs)

        if any((backup_source_volume_id, backup_id)):
            # TODO: clean up this volume if the spawn fails
            dest_volume = self.get(volume_id)
            size = (dest_volume['size'] / 1024 / 1024 / 1024)
            spawn(lock, self.restore, dest_volume,
                  backup_source_volume_id, backup_id, size, cinder,
                  callback=callback_wrap, skip_fork=self.skip_fork)
        elif image_id:
            # TODO: clean up this volume if the spawn fails
            snet_glance = get_glance_conn(self.conf, tenant_id=account)
            dest_volume = self.get(volume_id)
            spawn(lock, self.copy_image, dest_volume, image, snet_glance,
                  tmp_vol, scrub_callback, callback=callback_wrap,
                  skip_fork=self.skip_fork)
        else:
            log_duration()

    def _max_snapshot_size(self, bytes):
        chunk_size = 4096
        exception_size = 16
        origin_chunks = ((bytes - 1) // chunk_size) + 1
        exceptions_per_chunk = ((chunk_size - 1) // exception_size) + 1
        # +1 for rounding up, +1 for the last allocated (unused) chunk
        exception_chunks = ((origin_chunks - 1) // exceptions_per_chunk) + 2
        # +1 for the header chunk
Exemplo n.º 3
0
        if any((backup_source_volume_id, backup_id)):
            # TODO: clean up this volume if the spawn fails
            dest_volume = self.get(volume_id)
            size = (dest_volume['size'] / 1024 / 1024 / 1024)
            spawn(lock,
                  self.restore,
                  dest_volume,
                  backup_source_volume_id,
                  backup_id,
                  size,
                  cinder,
                  callback=callback_wrap,
                  skip_fork=self.skip_fork)
        elif image_id:
            # TODO: clean up this volume if the spawn fails
            snet_glance = get_glance_conn(self.conf, tenant_id=account)
            dest_volume = self.get(volume_id)
            spawn(lock,
                  self.copy_image,
                  dest_volume,
                  image,
                  snet_glance,
                  tmp_vol,
                  scrub_callback,
                  callback=callback_wrap,
                  skip_fork=self.skip_fork)
        else:
            log_duration()

    def _max_snapshot_size(self, bytes):
        chunk_size = 4096