mirror of https://github.com/docker/docker-py.git
Merge branch 'feature/image-import' of github.com:tarnfeld/docker-py into tarnfeld-feature/image-import
This commit is contained in:
commit
8a5cd6ae65
|
@ -453,27 +453,35 @@ class Client(requests.Session):
|
||||||
return [x['Id'] for x in res]
|
return [x['Id'] for x in res]
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def import_image(self, src, data=None, repository=None, tag=None):
|
def import_image(self, src=None, data=None, repository=None, tag=None,
|
||||||
|
image=None):
|
||||||
u = self._url("/images/create")
|
u = self._url("/images/create")
|
||||||
params = {
|
params = {
|
||||||
'repo': repository,
|
'repo': repository,
|
||||||
'tag': tag
|
'tag': tag
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
# XXX: this is ways not optimal but the only way
|
|
||||||
# for now to import tarballs through the API
|
|
||||||
fic = open(src)
|
|
||||||
data = fic.read()
|
|
||||||
fic.close()
|
|
||||||
src = "-"
|
|
||||||
except IOError:
|
|
||||||
# file does not exists or not a file (URL)
|
|
||||||
data = None
|
|
||||||
if isinstance(src, six.string_types):
|
|
||||||
params['fromSrc'] = src
|
|
||||||
return self._result(self._post(u, data=data, params=params))
|
|
||||||
|
|
||||||
return self._result(self._post(u, data=src, params=params))
|
if src:
|
||||||
|
try:
|
||||||
|
# XXX: this is ways not optimal but the only way
|
||||||
|
# for now to import tarballs through the API
|
||||||
|
fic = open(src)
|
||||||
|
data = fic.read()
|
||||||
|
fic.close()
|
||||||
|
src = "-"
|
||||||
|
except IOError:
|
||||||
|
# file does not exists or not a file (URL)
|
||||||
|
data = None
|
||||||
|
if isinstance(src, six.string_types):
|
||||||
|
params['fromSrc'] = src
|
||||||
|
return self._result(self._post(u, data=data, params=params))
|
||||||
|
return self._result(self._post(u, data=src, params=params))
|
||||||
|
|
||||||
|
if image:
|
||||||
|
params['fromImage'] = image
|
||||||
|
return self._result(self._post(u, data=None, params=params))
|
||||||
|
|
||||||
|
raise Exception("Must specify a src or image")
|
||||||
|
|
||||||
def info(self):
|
def info(self):
|
||||||
return self._result(self._get(self._url("/info")),
|
return self._result(self._get(self._url("/info")),
|
||||||
|
|
|
@ -868,6 +868,27 @@ class DockerClientTest(unittest.TestCase):
|
||||||
buf.close()
|
buf.close()
|
||||||
os.remove(buf.name)
|
os.remove(buf.name)
|
||||||
|
|
||||||
|
def test_import_image_from_image(self):
|
||||||
|
try:
|
||||||
|
self.client.import_image(
|
||||||
|
image=fake_api.FAKE_IMAGE_NAME,
|
||||||
|
repository=fake_api.FAKE_REPO_NAME,
|
||||||
|
tag=fake_api.FAKE_TAG_NAME
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
|
fake_request.assert_called_with(
|
||||||
|
'unix://var/run/docker.sock/v1.6/images/create',
|
||||||
|
params={
|
||||||
|
'repo': fake_api.FAKE_REPO_NAME,
|
||||||
|
'tag': fake_api.FAKE_TAG_NAME,
|
||||||
|
'fromImage': fake_api.FAKE_IMAGE_NAME
|
||||||
|
},
|
||||||
|
data=None,
|
||||||
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
|
)
|
||||||
|
|
||||||
def test_inspect_image(self):
|
def test_inspect_image(self):
|
||||||
try:
|
try:
|
||||||
self.client.inspect_image(fake_api.FAKE_IMAGE_NAME)
|
self.client.inspect_image(fake_api.FAKE_IMAGE_NAME)
|
||||||
|
|
Loading…
Reference in New Issue