mirror of https://github.com/docker/docker-py.git
Adds an 'image' property to the container model
Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
This commit is contained in:
parent
b585ec59a8
commit
659090fc99
|
@ -18,6 +18,16 @@ class Container(Model):
|
||||||
if self.attrs.get('Name') is not None:
|
if self.attrs.get('Name') is not None:
|
||||||
return self.attrs['Name'].lstrip('/')
|
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
|
@property
|
||||||
def labels(self):
|
def labels(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -25,6 +25,7 @@ Container objects
|
||||||
.. autoattribute:: short_id
|
.. autoattribute:: short_id
|
||||||
.. autoattribute:: name
|
.. autoattribute:: name
|
||||||
.. autoattribute:: status
|
.. autoattribute:: status
|
||||||
|
.. autoattribute:: image
|
||||||
.. autoattribute:: labels
|
.. autoattribute:: labels
|
||||||
.. py:attribute:: attrs
|
.. py:attribute:: attrs
|
||||||
|
|
||||||
|
|
|
@ -384,6 +384,11 @@ class ContainerTest(unittest.TestCase):
|
||||||
container.get_archive('foo')
|
container.get_archive('foo')
|
||||||
client.api.get_archive.assert_called_with(FAKE_CONTAINER_ID, '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):
|
def test_kill(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
container = client.containers.get(FAKE_CONTAINER_ID)
|
container = client.containers.get(FAKE_CONTAINER_ID)
|
||||||
|
|
Loading…
Reference in New Issue