Exemplo n.º 1
0
    def ReadFromDisk(cls, path=None):
        """Reads configuration file and meta-data from default Docker location.

    Reads configuration file and meta-data from default Docker location. Returns
    a Configuration object containing the full contents of the configuration
    file, the configuration file path and Docker version.

    Args:
      path: string, path to look for the Docker config file. If empty will
      attempt to read from the new config location (default).

    Returns:
      A Configuration object

    Raises:
      ValueError: path or is_new_format are not set.
      InvalidDockerConfigError: config file could not be read as JSON.
    """
        path = path or client_utils.GetDockerConfigPath(True)[0]
        try:
            version = str(client_utils.GetDockerVersion())
            content = client_utils.ReadConfigurationFile(path)
        except (ValueError, client_utils.DockerError) as err:
            raise client_utils.InvalidDockerConfigError(
                ('Docker configuration file [{}] could not be read as JSON: {}'
                 ).format(path, str(err)))

        return cls(content, version, path)
Exemplo n.º 2
0
def _EmailFlagDeprecatedForDockerVersion():
    """Checks to see if --email flag is deprecated.

  Returns:
    True if the installed Docker client version has deprecated the
    --email flag during 'docker login,' False otherwise.
  """
    try:
        version = client_lib.GetDockerVersion()

    except exceptions.Error:
        # Docker doesn't exist or doesn't like the modern version query format.
        # Assume that --email is not deprecated, return False.
        return False

    return version >= _EMAIL_FLAG_DEPRECATED_VERSION
Exemplo n.º 3
0
 def DockerVersion(self):
     if not self._version:
         version_str = str(client_utils.GetDockerVersion())
         self._version = distutils_version.LooseVersion(version_str)
     return self._version
 def DockerVersion(self):
     if not self._version:
         version_str = six.text_type(client_utils.GetDockerVersion())
         self._version = semver.LooseVersion(version_str)
     return self._version
Exemplo n.º 5
0
 def testGetDockerVersionNotFound(self):
     self.process_mock.returncode = 1
     with self.assertRaisesRegex(
             client_lib.DockerError,
             'could not retrieve Docker client version'):
         client_lib.GetDockerVersion()
Exemplo n.º 6
0
 def testGetDockerVersion(self):
     self.process_mock.communicate.return_value = ("'1.13'",
                                                   "'stderr value'")
     result = client_lib.GetDockerVersion()
     self.assertEqual(_TEST_DOCKER_VERSION, result)