diff options
| author | Frank Sachsenheim <funkyfuture@riseup.net> | 2017-03-04 01:04:20 +0100 |
|---|---|---|
| committer | Frank Sachsenheim <funkyfuture@riseup.net> | 2017-04-15 15:46:52 +0200 |
| commit | 659090fc99b87bc9bb4fb5533b09d7ba781ac28d (patch) | |
| tree | 062f3e6dc7fc29e1028d908a0b02cfc7bc3e1fef | |
| parent | b585ec59a8a3e7f6f7252d106df0a027eb0b5ab6 (diff) | |
| download | docker-py-659090fc99b87bc9bb4fb5533b09d7ba781ac28d.tar.gz | |
Adds an 'image' property to the container model
Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
| -rw-r--r-- | docker/models/containers.py | 10 | ||||
| -rw-r--r-- | docs/containers.rst | 1 | ||||
| -rw-r--r-- | tests/unit/models_containers_test.py | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py index 493f180..93f6372 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -19,6 +19,16 @@ class Container(Model): return self.attrs['Name'].lstrip('/') @property + def image(self): + """ + The image of the container. + """ + image_id = self.attrs['Image'] + if image_id is None: + return None + return self.client.images.get(image_id.split(':')[1]) + + @property def labels(self): """ The labels of a container as dictionary. diff --git a/docs/containers.rst b/docs/containers.rst index b67a066..9ea64ad 100644 --- a/docs/containers.rst +++ b/docs/containers.rst @@ -25,6 +25,7 @@ Container objects .. autoattribute:: short_id .. autoattribute:: name .. autoattribute:: status + .. autoattribute:: image .. autoattribute:: labels .. py:attribute:: attrs diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index a5ef4a1..c594606 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -384,6 +384,11 @@ class ContainerTest(unittest.TestCase): container.get_archive('foo') client.api.get_archive.assert_called_with(FAKE_CONTAINER_ID, 'foo') + def test_image(self): + client = make_fake_client() + container = client.containers.get(FAKE_CONTAINER_ID) + assert container.image.id == FAKE_IMAGE_ID + def test_kill(self): client = make_fake_client() container = client.containers.get(FAKE_CONTAINER_ID) |
