示例#1
0
    def Main(self):
        """The main method for the DockerExplorerTool class.

    It instantiates the Storage Object and Handles arguments parsing.

    Raises:
      ValueError: If the arguments couldn't be parsed.
    """
        options = self.ParseArguments()

        self._SetLogging(debug=options.debug)

        self._explorer = explorer.Explorer()

        if options.command == 'download':
            try:
                dl = downloader.DockerImageDownloader(options.image_name)
                if options.what == 'all':
                    dl.DownloadPseudoDockerfile()
                    dl.DownloadLayers()
                if options.what == 'dockerfile':
                    dl.DownloadPseudoDockerfile()
                if options.what == 'layers':
                    dl.DownloadLayers()
            except errors.DownloaderException as exc:
                logger.debug(exc.message)
                logger.debug(exc.http_message)
                logger.error(
                    'Make sure the image \'{0:s}:{1:s}\' exists in the public Docker '
                    'Hub registry: https://hub.docker.com/r/{2:s}/tags'.format(
                        dl.repository, dl.tag, dl.repository))
            return

        self._explorer.SetDockerDirectory(options.docker_directory)
        self._explorer.DetectDockerStorageVersion()

        if not options.command:
            self.ShowContainers()

        elif options.command == 'mount':
            self.Mount(options.container_id, options.mountpoint)

        elif options.command == 'history':
            self.ShowHistory(options.container_id,
                             show_empty_layers=options.show_empty)

        elif options.command == 'list':
            if options.what == 'all_containers':
                self.ShowContainers()
            elif options.what == 'running_containers':
                self.ShowContainers(only_running=True)
            elif options.what == 'repositories':
                print(self._explorer.GetRepositoriesString())
        else:
            raise ValueError('Unhandled command %s' % options.command)
示例#2
0
    def testDetectStorageFail(self):
        """Tests that the DockerExplorerTool.DetectStorage function fails on
    Docker directory."""
        explorer_object = explorer.Explorer()
        explorer_object.docker_directory = 'this_dir_shouldnt_exist'

        expected_error_message = (
            'this_dir_shouldnt_exist is not a Docker directory')
        with self.assertRaises(errors.BadStorageException) as err:
            explorer_object.SetDockerDirectory('this_dir_shouldnt_exist')
        self.assertEqual(expected_error_message, err.exception.message)
示例#3
0
 def setUpClass(cls):
     # We setup one overlay2 backed Docker root folder for all the following
     # tests.
     cls.driver = 'overlay2'
     cls.docker_directory_path = os.path.join('test_data', 'docker')
     if not os.path.isdir(cls.docker_directory_path):
         docker_tar = os.path.join('test_data', 'overlay2.v2.tgz')
         with tarfile.open(docker_tar, 'r:gz') as tar:
             tar.extractall('test_data')
     cls.explorer_object = explorer.Explorer()
     cls.explorer_object.SetDockerDirectory(cls.docker_directory_path)
     cls.explorer_object.DetectDockerStorageVersion()
示例#4
0
  def setUpClass(cls):
    """Internal method to set up the TestCase on a specific storage."""
    cls.driver = 'overlay2'
    cls.docker_directory_path = os.path.join('test_data', 'docker')
    if not os.path.isdir(cls.docker_directory_path):
      docker_tar = os.path.join('test_data', 'vols.v2.tgz')
      tar = tarfile.open(docker_tar, 'r:gz')
      tar.extractall('test_data')
      tar.close()
    cls.explorer_object = explorer.Explorer()
    cls.explorer_object.SetDockerDirectory(cls.docker_directory_path)

    cls.driver_class = storage.Overlay2Storage
    cls.storage_version = 2
示例#5
0
  def _setup(cls, driver, driver_class, storage_version=2):
    """Internal method to set up the TestCase on a specific storage."""
    cls.driver = driver
    docker_directory_path = os.path.join('test_data', 'docker')
    if not os.path.isdir(docker_directory_path):
      docker_tar = os.path.join(
          'test_data', '{0:s}.v{1:d}.tgz'.format(driver, storage_version))
      tar = tarfile.open(docker_tar, 'r:gz')
      tar.extractall('test_data')
      tar.close()
    cls.explorer_object = explorer.Explorer()
    cls.explorer_object.SetDockerDirectory(docker_directory_path)
    cls.explorer_object.DetectDockerStorageVersion()

    cls.driver_class = driver_class
    cls.storage_version = storage_version