[virt-tools-list] [virt-bootstrap] [PATCH v6 07/26] Get layer size if not provided

Cedric Bosdonnat cbosdonnat at suse.com
Sat Aug 19 12:32:59 UTC 2017


On Thu, 2017-08-17 at 10:39 +0100, Radostin Stoyanov wrote:
> Docker registry with Manifest v1 does not require the size of layers to
> be included. However, when this information is not provided we can use
> os.path.getsize() to get and show the size of tarball. We can also
> use this function for FileSource to provide consistent output messages.
> ---
>  src/virtBootstrap/sources/docker_source.py | 8 +++++---
>  src/virtBootstrap/sources/file_source.py   | 3 ++-
>  src/virtBootstrap/utils.py                 | 9 +++++----
>  3 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/src/virtBootstrap/sources/docker_source.py b/src/virtBootstrap/sources/docker_source.py
> index 246356a..58e30ce 100644
> --- a/src/virtBootstrap/sources/docker_source.py
> +++ b/src/virtBootstrap/sources/docker_source.py
> @@ -92,15 +92,17 @@ class DockerSource(object):
>              raise ValueError('Unsupported manifest schema.')
>  
>          for layer in layers_list:
> -            layer_digest = layer[digest_field]
> -            layer_size = layer['size'] if 'size' in layer else None
> -
>              # Store checksums of layers
> +            layer_digest = layer[digest_field]
>              sum_type, layer_sum = layer_digest.split(':')
>              self.checksums.append([sum_type, layer_sum])
>  
>              # Store file path and size of each layer
>              file_path = os.path.join(self.images_dir, layer_sum + '.tar')
> +            if 'size' in layer:
> +                layer_size = layer['size']
> +            else:
> +                layer_size = os.path.getsize(file_path)
>              self.layers.append([file_path, layer_size])
>  
>      def gen_valid_uri(self, uri):
> diff --git a/src/virtBootstrap/sources/file_source.py b/src/virtBootstrap/sources/file_source.py
> index c02f735..412db8a 100644
> --- a/src/virtBootstrap/sources/file_source.py
> +++ b/src/virtBootstrap/sources/file_source.py
> @@ -57,10 +57,11 @@ class FileSource(object):
>          if not os.path.isfile(self.path):
>              raise Exception('Invalid file source "%s"' % self.path)
>  
> +        layer = [[self.path, os.path.getsize(self.path)]]
>          if self.output_format == 'dir':
>              self.progress("Extracting files into destination directory",
>                            value=0, logger=logger)
> -            utils.safe_untar(self.path, dest)
> +            utils.untar_layers(layer, dest, self.progress)
>  
>          elif self.output_format == 'qcow2':
>              # Remove the old path
> diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
> index 730f939..48a931e 100644
> --- a/src/virtBootstrap/utils.py
> +++ b/src/virtBootstrap/utils.py
> @@ -147,10 +147,11 @@ def log_layer_extract(tar_file, tar_size, current, total, progress):
>      """
>      Create log message on layer extract.
>      """
> -    msg = 'Extracting layer (%s/%s)' % (current, total)
> -
> -    if tar_size:
> -        msg += " with size: %s" % bytes_to_size(tar_size)
> +    msg = 'Extracting layer (%s/%s) with size: %s' % (
> +        current,
> +        total,
> +        bytes_to_size(tar_size)
> +    )
>      progress(msg, logger=logger)
>      logger.debug('Untar layer: %s', tar_file)
>  

ACK

--
Cedric




More information about the virt-tools-list mailing list