diff options
author | Jhon Honce <jhonce@redhat.com> | 2018-06-05 12:40:35 -0700 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-05 21:23:54 +0000 |
commit | 93c1722caab372f873765041d2bd2b710de3c5c4 (patch) | |
tree | 3c2b5020db1e68092bbd25888a90f6ef145d0d00 /contrib/python/podman | |
parent | 3901ecc7b6b08b7555ccf0e8a05b278b05a9629c (diff) | |
download | podman-93c1722caab372f873765041d2bd2b710de3c5c4.tar.gz podman-93c1722caab372f873765041d2bd2b710de3c5c4.tar.bz2 podman-93c1722caab372f873765041d2bd2b710de3c5c4.zip |
Add support for BuildImage
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Closes: #908
Approved by: baude
Diffstat (limited to 'contrib/python/podman')
-rw-r--r-- | contrib/python/podman/client.py | 2 | ||||
-rw-r--r-- | contrib/python/podman/libs/images.py | 34 |
2 files changed, 22 insertions, 14 deletions
diff --git a/contrib/python/podman/client.py b/contrib/python/podman/client.py index c6112aae8..89fcf5c15 100644 --- a/contrib/python/podman/client.py +++ b/contrib/python/podman/client.py @@ -38,7 +38,7 @@ class Client(object): @contextlib.contextmanager def _podman(uri, interface): - """Context manager for API children to access varlink.""" + """Context manager for API workers to access varlink.""" client = VarlinkClient(address=uri) try: iface = client.open(interface) diff --git a/contrib/python/podman/libs/images.py b/contrib/python/podman/libs/images.py index f28cb64aa..3beadec1d 100644 --- a/contrib/python/podman/libs/images.py +++ b/contrib/python/podman/libs/images.py @@ -30,23 +30,18 @@ class Image(collections.UserDict): return super().__getitem__(key) def _split_token(self, values=None, sep='='): - mapped = {} - if values: - for var in values: - k, v = var.split(sep, 1) - mapped[k] = v - return mapped + return dict([v.split(sep, 1) for v in values if values]) def create(self, *args, **kwargs): """Create container from image. Pulls defaults from image.inspect() """ - # Inialize config from parameters with self._client() as podman: details = self.inspect() # TODO: remove network settings once defaults implemented in service + # Inialize config from parameters, then add image information config = Config(image_id=self.id, **kwargs) config['command'] = details.containerconfig['cmd'] config['env'] = self._split_token(details.containerconfig['env']) @@ -75,9 +70,8 @@ class Image(collections.UserDict): for r in podman.HistoryImage(self.id)['history']: yield collections.namedtuple('HistoryDetail', r.keys())(**r) + # Convert all keys to lowercase. def _lower_hook(self): - """Convert all keys to lowercase.""" - @functools.wraps(self._lower_hook) def wrapped(input): return {k.lower(): v for (k, v) in input.items()} @@ -127,14 +121,26 @@ class Images(object): for img in results['images']: yield Image(self._client, img['id'], img) - def build(self, *args, **kwargs): + def build(self, dockerfile=None, tags=None, **kwargs): """Build container from image. See podman-build.1.md for kwargs details. """ + if dockerfile is None: + raise ValueError('"dockerfile" is a required argument.') + elif not hasattr(dockerfile, '__iter__'): + raise ValueError('"dockerfile" is required to be an iter.') + + if tags is None: + raise ValueError('"tags" is a required argument.') + elif not hasattr(tags, '__iter__'): + raise ValueError('"tags" is required to be an iter.') + + config = Config(dockerfile=dockerfile, tags=tags, **kwargs) with self._client() as podman: - # TODO: Need arguments - podman.BuildImage() + result = podman.BuildImage(config) + return self.get(result['image']['id']), \ + (line for line in result['image']['logs']) def delete_unused(self): """Delete Images not associated with a container.""" @@ -163,4 +169,6 @@ class Images(object): def get(self, id): """Get Image from id.""" - return next((i for i in self.list() if i.id == id), None) + with self._client() as podman: + result = podman.GetImage(id) + return Image(self._client, result['image']['id'], result['image']) |