Exemplo n.º 1
0
    def install(self):
        """Process image installation."""
        url_fn = self._extract_url_fn()
        if not url_fn:
            raise IOError("Can not determine file name from url: %r" %
                          self._url)

        if self._cache.is_valid:
            LOG.info("Found valid cached image+metadata at: %s",
                     colorizer.quote(self._cache.path))
            image_details = self._cache.load_details()
        else:
            sh.mkdir(self._cache.path)
            if not self._is_url_local():
                fetched_fn, bytes_down = down.UrlLibDownloader(
                    self._url,
                    sh.joinpths(self._cache.path, url_fn)).download()
                LOG.debug("For url %s we downloaded %s bytes to %s", self._url,
                          bytes_down, fetched_fn)
            else:
                fetched_fn = self._url
            image_details = Unpacker().unpack(url_fn, fetched_fn,
                                              self._cache.path)
            self._cache.save_details(image_details)

        image_name = self._generate_image_name(url_fn)
        image_id = self._register(image_name, image_details)
        return image_name, image_id
Exemplo n.º 2
0
 def install(self):
     url_fn = self._extract_url_fn()
     if not url_fn:
         raise IOError("Can not determine file name from url: %r" %
                       (self.url))
     (cache_path, details_path) = self._cached_paths()
     use_cached = self._validate_cache(cache_path, details_path)
     if use_cached:
         LOG.info("Found valid cached image + metadata at: %s",
                  colorizer.quote(cache_path))
         unpack_info = utils.load_yaml_text(sh.load_file(details_path))
     else:
         sh.mkdir(cache_path)
         if not self._is_url_local():
             (fetched_fn, bytes_down) = down.UrlLibDownloader(
                 self.url, sh.joinpths(cache_path, url_fn)).download()
             LOG.debug("For url %s we downloaded %s bytes to %s", self.url,
                       bytes_down, fetched_fn)
         else:
             fetched_fn = self.url
         unpack_info = Unpacker().unpack(url_fn, fetched_fn, cache_path)
         sh.write_file(details_path, utils.prettify_yaml(unpack_info))
     tgt_image_name = self._generate_img_name(url_fn)
     img_id = self._register(tgt_image_name, unpack_info)
     return (tgt_image_name, img_id)
Exemplo n.º 3
0
 def install(self):
     url_fn = self._extract_url_fn()
     if not url_fn:
         raise IOError("Can not determine file name from url: %r" %
                       (self.url))
     with utils.tempdir() as tdir:
         if not self._is_url_local():
             (fetched_fn, bytes_down) = down.UrlLibDownloader(
                 self.url, sh.joinpths(tdir, url_fn)).download()
             LOG.debug("For url %s we downloaded %s bytes to %s", self.url,
                       bytes_down, fetched_fn)
         else:
             fetched_fn = self.url
         unpack_info = Unpacker().unpack(url_fn, fetched_fn, tdir)
         tgt_image_name = self._generate_img_name(url_fn)
         img_id = self._register(tgt_image_name, unpack_info)
         return (tgt_image_name, img_id)