From 42290044bec5f28c15cc1f21e46f849e1db02bfb Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Tue, 18 Jul 2017 10:12:53 +0100 Subject: DockerSource: Encapsulate URI generation This change makes it easier to test the code. --- src/virtBootstrap/sources.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py index eaf3f8f..77aa15f 100644 --- a/src/virtBootstrap/sources.py +++ b/src/virtBootstrap/sources.py @@ -102,32 +102,20 @@ class DockerSource(object): @param progress: Instance of the progress module """ + self.url = self.gen_valid_uri(kwargs['uri']) self.username = kwargs['username'] self.password = kwargs['password'] self.output_format = kwargs['fmt'] self.insecure = kwargs['not_secure'] self.no_cache = kwargs['no_cache'] self.progress = kwargs['progress'].update_progress + self.images_dir = utils.get_image_dir(self.no_cache) self.manifest = None self.layers = [] if self.username and not self.password: self.password = getpass.getpass() - registry = kwargs['uri'].netloc - image = kwargs['uri'].path - - # Convert "docker:///" to "docker://" - if not registry and image.startswith('/'): - image = image[1:] - - # Convert "docker:///" to "docker://" - elif image.endswith('/'): - image = image[:-1] - - self.url = "docker://" + registry + image - self.images_dir = utils.get_image_dir(self.no_cache) - self.retrieve_layers_info() def retrieve_layers_info(self): @@ -145,6 +133,23 @@ class DockerSource(object): file_path = os.path.join(self.images_dir, layer_sum + '.tar') self.layers.append([sum_type, layer_sum, file_path, layer['size']]) + def gen_valid_uri(self, uri): + """ + Generate Docker URI in format accepted by skopeo. + """ + registry = uri.netloc + image = uri.path + + # Convert "docker:///" to "docker://" + if not registry and image.startswith('/'): + image = image[1:] + + # Convert "docker:///" to "docker://" + elif image.endswith('/'): + image = image[:-1] + + return "docker://" + registry + image + def download_image(self): """ Download image layers using "skopeo copy". -- cgit