Example #1
0
 def __init__(self, uri, target_device, image_format, container, size=None):
     # uri is something like
     # http://host:port/path/to/image.img or
     # file:///tmp/image.img
     self.uri = uri
     self.target_device = target_device
     # this must be one of 'iso9660', 'ext[234]', 'xfs'
     self.image_format = image_format
     if container not in self.SUPPORTED_CONTAINERS:
         raise errors.WrongImageDataError(
             'Error while image initialization: '
             'unsupported image container')
     self.container = container
     self.size = size
Example #2
0
def containerize(filename, container, chunk_size=1048576):
    if container == 'gzip':
        output_file = filename + '.gz'
        with open(filename, 'rb') as f:
            # NOTE(agordeev): gzip in python2.6 doesn't have context manager
            # support
            g = gzip.open(output_file, 'wb')
            for chunk in iter(lambda: f.read(chunk_size), ''):
                g.write(chunk)
            g.close()
        os.remove(filename)
        return output_file
    raise errors.WrongImageDataError(
        'Error while image initialization: '
        'unsupported image container: {container}'.format(container=container))