diff options
| author | Joffrey F <f.joffrey@gmail.com> | 2013-09-30 09:04:07 -0700 |
|---|---|---|
| committer | Joffrey F <f.joffrey@gmail.com> | 2013-09-30 09:04:07 -0700 |
| commit | fadc6f2f425288c7822a9774a7fe77dfce4b70c6 (patch) | |
| tree | b697ec9c3cfe91c286563ba575987774140debca | |
| parent | 3288e9f9b0dc99ba7f59b4bbfdc854be7c0219dc (diff) | |
| parent | 2ecc7990cbf3b8a258be72eff0924be42a36380b (diff) | |
| download | docker-py-fadc6f2f425288c7822a9774a7fe77dfce4b70c6.tar.gz | |
Merge pull request #56 from kiorky/import_image_tarball
support tarball imports
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | docker/client.py | 17 |
2 files changed, 17 insertions, 2 deletions
@@ -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. diff --git a/docker/client.py b/docker/client.py index 03f383b..4f7a1f9 100644 --- a/docker/client.py +++ b/docker/client.py @@ -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)) |
