Example #1
0
    def get_size(self, location, context=None):
        """
        Takes a `glance_store.location.Location` object that indicates
        where to find the image file, and returns the size

        :param location `glance_store.location.Location` object, supplied
                        from glance_store.location.get_location_from_uri()
        :retval int: size of image file in bytes
        """
        ami_id = location.get_store_uri().split('/')[2]
        ec2_resource = self._get_ec2_resource()
        image = ec2_resource.Image(ami_id)
        size = 0
        try:
            image.load()
            # no size info for instance-store volumes, so return 0 in that case
            if image.root_device_type == 'ebs':
                for bdm in image.block_device_mappings:
                    if 'Ebs' in bdm and 'VolumeSize' in bdm['Ebs']:
                        LOG.debug('ebs info: %s', bdm['Ebs'])
                        size += bdm['Ebs']['VolumeSize']
                # convert size in gb to bytes
                size *= 1073741824
        except botocore.exceptions.ClientError as ce:
            if ce.response['Error']['Code'] == 'InvalidAMIID.NotFound':
                raise exceptions.ImageDataNotFound()
            else:
                raise exceptions.GlanceStoreException(
                    ce.response['Error']['Code'])
        return size
Example #2
0
    def delete(self, location, context=None):
        """Takes a `glance_store.location.Location` object that indicates
        where to find the image file to delete

        :param location: `glance_store.location.Location` object, supplied
                  from glance_store.location.get_location_from_uri()
        :raises NotFound if image does not exist
        """
        LOG.info("Delete image %s" % location.get_store_uri())
Example #3
0
 def delete(self, location, context=None):
     """Takes a `glance_store.location.Location` object that indicates
     where to find the image file to delete
     :param location: `glance_store.location.Location` object, supplied
               from glance_store.location.get_location_from_uri()
     :raises NotFound if image does not exist
     """
     # This method works for Azure public images as we just need to delete
     # entry from glance catalog.
     # For Private images we will need extra handling here.
     LOG.info("Delete image %s" % location.get_store_uri())
Example #4
0
    def delete(self, location, context=None):
        """Takes a `glance_store.location.Location` object that indicates
        where to find the image file to delete

        :param location: `glance_store.location.Location` object, supplied
                  from glance_store.location.get_location_from_uri()
        :raises NotFound if image does not exist
        """
        ami_id = location.get_store_uri().split('/')[2]
        aws_client = self._get_ec2_client()
        aws_imgs = aws_client.describe_images(Owners=['self'])['Images']
        for img in aws_imgs:
            if ami_id == img.get('ImageId'):
                LOG.warn('**** ID of ami being deleted: {}'.format(ami_id))
                aws_client.deregister_image(ImageId=ami_id)