mirror of https://github.com/docker/docker-py.git
Merge pull request #56 from kiorky/import_image_tarball
support tarball imports
This commit is contained in:
commit
fadc6f2f42
|
@ -46,6 +46,8 @@ Identical to the `docker import` command. If `src` is a string or unicode
|
|||
string, it will be treated as a URL to fetch the image from. To import an image
|
||||
from the local machine, `src` needs to be a file-like object or bytes
|
||||
collection.
|
||||
To import from a tarball use your absolute path to your tarball.
|
||||
To load arbitrary data as tarball use whatever you want as src and your tarball content in data.
|
||||
|
||||
* `c.info()`
|
||||
Identical to the `docker info` command.
|
||||
|
|
|
@ -275,15 +275,28 @@ class Client(requests.Session):
|
|||
return [x['Id'] for x in res]
|
||||
return res
|
||||
|
||||
def import_image(self, src, repository=None, tag=None):
|
||||
def import_image(self, src, data=None, repository=None, tag=None):
|
||||
'''
|
||||
To import from a local tarball, use the absolute path to the file
|
||||
'''
|
||||
u = self._url("/images/create")
|
||||
params = {
|
||||
'repo': repository,
|
||||
'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, None, params=params))
|
||||
return self._result(self.post(u, data, params=params))
|
||||
|
||||
return self._result(self.post(u, src, params=params))
|
||||
|
||||
|
|
Loading…
Reference in New Issue