Kaydet (Commit) 4b090441 authored tarafından Joffrey F's avatar Joffrey F

Merge pull request #161 from mpetazzoni/api-1.8

Support remote API v1.8 (and make it the default)
...@@ -28,6 +28,7 @@ from .utils import utils ...@@ -28,6 +28,7 @@ from .utils import utils
if not six.PY3: if not six.PY3:
import websocket import websocket
DEFAULT_DOCKER_API_VERSION = '1.8'
DEFAULT_TIMEOUT_SECONDS = 60 DEFAULT_TIMEOUT_SECONDS = 60
STREAM_HEADER_SIZE_BYTES = 8 STREAM_HEADER_SIZE_BYTES = 8
...@@ -65,7 +66,7 @@ class APIError(requests.exceptions.HTTPError): ...@@ -65,7 +66,7 @@ class APIError(requests.exceptions.HTTPError):
class Client(requests.Session): 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): timeout=DEFAULT_TIMEOUT_SECONDS):
super(Client, self).__init__() super(Client, self).__init__()
if base_url is None: if base_url is None:
...@@ -363,7 +364,7 @@ class Client(requests.Session): ...@@ -363,7 +364,7 @@ class Client(requests.Session):
if context is not None: if context is not None:
context.close() context.close()
if stream: if stream or utils.compare_version('1.8', self._version) >= 0:
return self._stream_result(response) return self._stream_result(response)
else: else:
output = self._result(response) output = self._result(response)
...@@ -473,6 +474,8 @@ class Client(requests.Session): ...@@ -473,6 +474,8 @@ class Client(requests.Session):
def images(self, name=None, quiet=False, all=False, viz=False): def images(self, name=None, quiet=False, all=False, viz=False):
if viz: 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"))) return self._result(self._get(self._url("images/viz")))
params = { params = {
'filter': name, 'filter': name,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
CURRENT_VERSION = 'v1.6' CURRENT_VERSION = 'v1.8'
FAKE_CONTAINER_ID = '3cc2351ab11b' FAKE_CONTAINER_ID = '3cc2351ab11b'
FAKE_IMAGE_ID = 'e9aa60c60128' FAKE_IMAGE_ID = 'e9aa60c60128'
...@@ -30,13 +30,16 @@ FAKE_PATH = '/path' ...@@ -30,13 +30,16 @@ FAKE_PATH = '/path'
def get_fake_version(): def get_fake_version():
status_code = 200 status_code = 200
response = {'GoVersion': '1', 'Version': '1.1.1'} response = {'GoVersion': '1', 'Version': '1.1.1',
'GitCommit': 'deadbeef+CHANGES'}
return status_code, response return status_code, response
def get_fake_info(): def get_fake_info():
status_code = 200 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 return status_code, response
...@@ -52,7 +55,7 @@ def get_fake_images(): ...@@ -52,7 +55,7 @@ def get_fake_images():
'Id': FAKE_IMAGE_ID, 'Id': FAKE_IMAGE_ID,
'Created': '2 days ago', 'Created': '2 days ago',
'Repository': 'busybox', 'Repository': 'busybox',
'Tag': 'latest' 'RepoTags': ['busybox:latest', 'busybox:1.0'],
}] }]
return status_code, response return status_code, response
......
...@@ -55,7 +55,8 @@ def fake_resp(url, data=None, **kwargs): ...@@ -55,7 +55,8 @@ def fake_resp(url, data=None, **kwargs):
return response(status_code=status_code, content=content) return response(status_code=status_code, content=content)
fake_request = mock.Mock(side_effect=fake_resp) 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, @mock.patch.multiple('docker.Client', get=fake_request, post=fake_request,
...@@ -103,6 +104,13 @@ class DockerClientTest(unittest.TestCase): ...@@ -103,6 +104,13 @@ class DockerClientTest(unittest.TestCase):
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS 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 ## ## 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