summaryrefslogtreecommitdiff
path: root/contrib/python/podman
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-05-17 11:57:59 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-18 21:08:21 +0000
commit4b804e85165a29f9d712f1ec4f289040f942f459 (patch)
tree39d689400151f9c9dc954c4f648fe2c3f01127e1 /contrib/python/podman
parent228c71b1dadaa8894648111982d09c76b066e3c9 (diff)
downloadpodman-4b804e85165a29f9d712f1ec4f289040f942f459.tar.gz
podman-4b804e85165a29f9d712f1ec4f289040f942f459.tar.bz2
podman-4b804e85165a29f9d712f1ec4f289040f942f459.zip
Implement podman.containers.commit()
- Add API support - Update tests - Make changes from reviews Signed-off-by: Jhon Honce <jhonce@redhat.com> Closes: #798 Approved by: mheon
Diffstat (limited to 'contrib/python/podman')
-rw-r--r--contrib/python/podman/libs/containers.py40
-rw-r--r--contrib/python/podman/libs/images.py11
2 files changed, 44 insertions, 7 deletions
diff --git a/contrib/python/podman/libs/containers.py b/contrib/python/podman/libs/containers.py
index cbbef23b1..0655010f1 100644
--- a/contrib/python/podman/libs/containers.py
+++ b/contrib/python/podman/libs/containers.py
@@ -1,6 +1,7 @@
"""Models for manipulating containers and storage."""
import collections
import functools
+import getpass
import json
import signal
@@ -93,6 +94,45 @@ class Container(collections.UserDict):
results = podman.ExportContainer(self.id, target)
return results['tarfile']
+ def commit(self,
+ image_name,
+ *args,
+ changes=[],
+ message='',
+ pause=True,
+ **kwargs):
+ """Create image from container.
+
+ All changes overwrite existing values.
+ See inspect() to obtain current settings.
+
+ Changes:
+ CMD=/usr/bin/zsh
+ ENTRYPOINT=/bin/sh date
+ ENV=TEST=test_containers.TestContainers.test_commit
+ EXPOSE=8888/tcp
+ LABEL=unittest=test_commit
+ USER=bozo:circus
+ VOLUME=/data
+ WORKDIR=/data/application
+ """
+ # TODO: Clean up *args, **kwargs after Commit() is complete
+ try:
+ author = kwargs.get('author', getpass.getuser())
+ except Exception:
+ author = ''
+
+ for c in changes:
+ if c.startswith('LABEL=') and c.count('=') < 2:
+ raise ValueError(
+ 'LABEL should have the format: LABEL=label=value, not {}'.
+ format(c))
+
+ with self._client() as podman:
+ results = podman.Commit(self.id, image_name, changes, author,
+ message, pause)
+ return results['image']
+
def start(self):
"""Start container, return id on success."""
with self._client() as podman:
diff --git a/contrib/python/podman/libs/images.py b/contrib/python/podman/libs/images.py
index 1d40984a7..d6fd7946d 100644
--- a/contrib/python/podman/libs/images.py
+++ b/contrib/python/podman/libs/images.py
@@ -95,13 +95,6 @@ class Images(object):
results = podman.CreateImage()
return results['image']
- def create_from(self, *args, **kwargs):
- """Create image from container."""
- # TODO: Should this be on container?
- with self._client() as podman:
- results = podman.CreateFromContainer()
- return results['image']
-
def build(self, *args, **kwargs):
"""Build container from image.
@@ -135,3 +128,7 @@ class Images(object):
results = podman.SearchImage(id)
for img in results['images']:
yield img
+
+ def get(self, id):
+ """Get Image from id."""
+ return next((i for i in self.list() if i.id == id), None)