[virt-bootstrap] [PATCH v7 07/26] Get layer size if not provided

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 | 5 ++---
 src/virtBootstrap/utils.py                 | 9 +++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/virtBootstrap/sources/docker_source.py b/src/virtBootstrap/sources/docker_source.py
index 246356a..2dadb42 100644
--- a/src/virtBootstrap/sources/docker_source.py
+++ b/src/virtBootstrap/sources/docker_source.py
@@ -92,15 +92,14 @@ 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')
+            layer_size = layer.get('size', None)
             self.layers.append([file_path, layer_size])
 
     def gen_valid_uri(self, uri):
diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
index a04627e..267963f 100644
--- a/src/virtBootstrap/utils.py
+++ b/src/virtBootstrap/utils.py
@@ -150,10 +150,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 or os.path.getsize(tar_file))
+    )
     progress(msg, logger=logger)
     logger.debug('Untar layer: %s', tar_file)
 
-- 
2.13.5

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux