Kaydet (Commit) 64f4ba90 authored tarafından Maxime Petazzoni's avatar Maxime Petazzoni

Support remote API v1.8 (and make it the default)

Signed-off-by: 's avatarMaxime Petazzoni <max@signalfuse.com>
üst 417d6912
......@@ -28,6 +28,7 @@ from .utils import utils
if not six.PY3:
import websocket
DEFAULT_DOCKER_API_VERSION = '1.8'
DEFAULT_TIMEOUT_SECONDS = 60
STREAM_HEADER_SIZE_BYTES = 8
......@@ -65,7 +66,7 @@ class APIError(requests.exceptions.HTTPError):
class Client(requests.Session):
def __init__(self, base_url=None, version="1.6",
def __init__(self, base_url=None, version=DEFAULT_DOCKER_API_VERSION,
timeout=DEFAULT_TIMEOUT_SECONDS):
super(Client, self).__init__()
if base_url is None:
......@@ -363,7 +364,7 @@ class Client(requests.Session):
if context is not None:
context.close()
if stream:
if stream or utils.compare_version('1.8', self._version) >= 0:
return self._stream_result(response)
else:
output = self._result(response)
......@@ -473,6 +474,8 @@ class Client(requests.Session):
def images(self, name=None, quiet=False, all=False, viz=False):
if viz:
if utils.compare_version('1.7', self._version) >= 0:
raise Exception('Viz output is not supported in API >= 1.7!')
return self._result(self._get(self._url("images/viz")))
params = {
'filter': name,
......
......@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
CURRENT_VERSION = 'v1.6'
CURRENT_VERSION = 'v1.8'
FAKE_CONTAINER_ID = '3cc2351ab11b'
FAKE_IMAGE_ID = 'e9aa60c60128'
......@@ -30,13 +30,16 @@ FAKE_PATH = '/path'
def get_fake_version():
status_code = 200
response = {'GoVersion': '1', 'Version': '1.1.1'}
response = {'GoVersion': '1', 'Version': '1.1.1',
'GitCommit': 'deadbeef+CHANGES'}
return status_code, response
def get_fake_info():
status_code = 200
response = {'Containers': 1, 'Images': 1, 'Debug': ''}
response = {'Containers': 1, 'Images': 1, 'Debug': False,
'MemoryLimit': False, 'SwapLimit': False,
'IPv4Forwarding': True}
return status_code, response
......@@ -52,7 +55,7 @@ def get_fake_images():
'Id': FAKE_IMAGE_ID,
'Created': '2 days ago',
'Repository': 'busybox',
'Tag': 'latest'
'RepoTags': ['busybox:latest', 'busybox:1.0'],
}]
return status_code, response
......
......@@ -55,7 +55,8 @@ def fake_resp(url, data=None, **kwargs):
return response(status_code=status_code, content=content)
fake_request = mock.Mock(side_effect=fake_resp)
url_prefix = 'http+unix://var/run/docker.sock/v1.6/'
url_prefix = 'http+unix://var/run/docker.sock/v{0}/'.format(
docker.client.DEFAULT_DOCKER_API_VERSION)
@mock.patch.multiple('docker.Client', get=fake_request, post=fake_request,
......@@ -103,6 +104,13 @@ class DockerClientTest(unittest.TestCase):
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
)
def test_image_viz(self):
try:
self.client.images('busybox', viz=True)
self.fail('Viz output should not be supported!')
except Exception:
pass
###################
## LISTING TESTS ##
###################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment