Adds an 'image' property to the container model

Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
This commit is contained in:
Frank Sachsenheim 2017-03-04 01:04:20 +01:00
parent b585ec59a8
commit 659090fc99
3 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,16 @@ class Container(Model):
if self.attrs.get('Name') is not None:
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):
"""

View File

@ -25,6 +25,7 @@ Container objects
.. autoattribute:: short_id
.. autoattribute:: name
.. autoattribute:: status
.. autoattribute:: image
.. autoattribute:: labels
.. py:attribute:: attrs

View File

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