Merge pull request #56 from kiorky/import_image_tarball

support tarball imports
This commit is contained in:
Joffrey F 2013-09-30 09:04:07 -07:00
commit fadc6f2f42
2 changed files with 17 additions and 2 deletions

View File

@ -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.

View File

@ -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))