Esempio n. 1
0
 def load_image(self):
     '''Load image metadata using docker commands'''
     try:
         container.extract_image_metadata(self.repotag)
         self._manifest = self.get_image_manifest()
         self.__repotags = self.get_image_repotags(self._manifest)
         self._config = self.get_image_config(self._manifest)
         self.__history = self.get_image_history(self._config)
         layer_paths = self.get_image_layers(self._manifest)
         layer_diffs = self.get_diff_ids(self._config)
         checksum_type = self.get_diff_checksum_type(self._config)
         layer_count = 1
         while layer_diffs and layer_paths:
             layer = ImageLayer(layer_diffs.pop(0), layer_paths.pop(0))
             layer.set_checksum(checksum_type, layer.diff_id)
             layer.gen_fs_hash()
             layer.layer_index = layer_count
             layer_count = layer_count + 1
             self._layers.append(layer)
         self.set_layer_created_by()
     except NameError as e:
         raise NameError(e)
     except subprocess.CalledProcessError as e:
         raise subprocess.CalledProcessError(
             e.returncode, cmd=e.cmd, output=e.output, stderr=e.stderr)
     except IOError as e:
         raise IOError(e)
Esempio n. 2
0
 def load_image(self):
     """Load metadata from an extracted docker image. This assumes the
     image has already been downloaded and extracted into the working
     directory"""
     try:
         self._manifest = self.get_image_manifest()
         self.__repotags = self.get_image_repotags(self._manifest)
         self._config = self.get_image_config(self._manifest)
         self.__history = self.get_image_history(self._config)
         layer_paths = self.get_image_layers(self._manifest)
         layer_diffs = self.get_diff_ids(self._config)
         checksum_type = self.get_diff_checksum_type(self._config)
         layer_count = 1
         while layer_diffs and layer_paths:
             layer = ImageLayer(layer_diffs.pop(0), layer_paths.pop(0))
             layer.set_checksum(checksum_type, layer.diff_id)
             layer.gen_fs_hash()
             layer.layer_index = layer_count
             layer_count = layer_count + 1
             self._layers.append(layer)
         self.set_layer_created_by()
     except NameError as e:
         raise NameError(e)
     except subprocess.CalledProcessError as e:
         raise subprocess.CalledProcessError(e.returncode,
                                             cmd=e.cmd,
                                             output=e.output,
                                             stderr=e.stderr)
     except IOError as e:
         raise IOError(e)
Esempio n. 3
0
 def load_image(self):
     '''Load image metadata using docker commands'''
     try:
         option = self.get_image_option()
         container.extract_image_metadata(option)
         self._manifest = self.get_image_manifest()
         self._image_id = self.get_image_id(self._manifest)
         self.__repotags = self.get_image_repotags(self._manifest)
         self._config = self.get_image_config(self._manifest)
         self.__history = self.get_image_history(self._config)
         layer_paths = self.get_image_layers(self._manifest)
         layer_diffs = self.get_diff_ids(self._config)
         checksum_type = self.get_diff_checksum_type(self._config)
         while layer_diffs and layer_paths:
             layer = ImageLayer(layer_diffs.pop(0), layer_paths.pop(0))
             layer.set_checksum(checksum_type, layer.diff_id)
             layer.gen_fs_hash()
             self._layers.append(layer)
         self.set_layer_created_by()
     except NameError:  # pylint: disable=try-except-raise
         raise
     except subprocess.CalledProcessError:  # pylint: disable=try-except-raise
         raise
     except IOError:  # pylint: disable=try-except-raise
         raise
Esempio n. 4
0
 def load_image(self, load_until_layer=0):
     """Load metadata from an extracted docker image. This assumes the
     image has already been downloaded and extracted into the working
     directory"""
     if load_until_layer > 0:
         self._load_until_layer = load_until_layer
     # else defaults to 0 - handles negative load_until_layer
     try:
         self._manifest = self.get_image_manifest()
         self.__repotags = self.get_image_repotags(self._manifest)
         self._config = self.get_image_config(self._manifest)
         self.__history = self.get_image_history(self._config)
         layer_paths = self.get_image_layers(self._manifest)
         layer_diffs = self.get_diff_ids(self._config)
         checksum_type = self.get_diff_checksum_type(self._config)
         layer_count = 1
         while layer_diffs and layer_paths:
             layer = ImageLayer(layer_diffs.pop(0), layer_paths.pop(0))
             # Only load metadata for the layers we need to report on according to the --layers command line option
             # If  --layers option is not present, load all the layers
             if self.load_until_layer >= layer_count or self.load_until_layer == 0:
                 layer.set_checksum(checksum_type, layer.diff_id)
                 layer.gen_fs_hash()
                 layer.layer_index = layer_count
                 self._layers.append(layer)
             layer_count = layer_count + 1
         self._total_layers = layer_count - 1
         if self.load_until_layer > self.total_layers:
             # if user asked to analyze more layers than image has
             # turn off the load_until_layer feature
             self._load_until_layer = 0
         self.set_layer_created_by()
     except NameError as e:
         raise NameError(e)
     except subprocess.CalledProcessError as e:
         raise subprocess.CalledProcessError(e.returncode,
                                             cmd=e.cmd,
                                             output=e.output,
                                             stderr=e.stderr)
     except IOError as e:
         raise IOError(e)