mirror of https://github.com/docker/docker-py.git
Adds a 'labels' property to the image model
Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
This commit is contained in:
parent
1cd56b9f0c
commit
b585ec59a8
|
@ -15,6 +15,14 @@ class Image(Model):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: '%s'>" % (self.__class__.__name__, "', '".join(self.tags))
|
return "<%s: '%s'>" % (self.__class__.__name__, "', '".join(self.tags))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def labels(self):
|
||||||
|
"""
|
||||||
|
The labels of an image as dictionary.
|
||||||
|
"""
|
||||||
|
result = self.attrs['Config'].get('Labels')
|
||||||
|
return result or {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def short_id(self):
|
def short_id(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -29,6 +29,7 @@ Image objects
|
||||||
.. autoattribute:: id
|
.. autoattribute:: id
|
||||||
.. autoattribute:: short_id
|
.. autoattribute:: short_id
|
||||||
.. autoattribute:: tags
|
.. autoattribute:: tags
|
||||||
|
.. autoattribute:: labels
|
||||||
.. py:attribute:: attrs
|
.. py:attribute:: attrs
|
||||||
|
|
||||||
The raw representation of this object from the server.
|
The raw representation of this object from the server.
|
||||||
|
|
|
@ -158,6 +158,7 @@ def get_fake_inspect_image():
|
||||||
'Parent': "27cf784147099545",
|
'Parent': "27cf784147099545",
|
||||||
'Created': "2013-03-23T22:24:18.818426-07:00",
|
'Created': "2013-03-23T22:24:18.818426-07:00",
|
||||||
'Container': FAKE_CONTAINER_ID,
|
'Container': FAKE_CONTAINER_ID,
|
||||||
|
'Config': {'Labels': {'bar': 'foo'}},
|
||||||
'ContainerConfig':
|
'ContainerConfig':
|
||||||
{
|
{
|
||||||
"Hostname": "",
|
"Hostname": "",
|
||||||
|
|
|
@ -21,6 +21,11 @@ class ImageCollectionTest(unittest.TestCase):
|
||||||
assert isinstance(image, Image)
|
assert isinstance(image, Image)
|
||||||
assert image.id == FAKE_IMAGE_ID
|
assert image.id == FAKE_IMAGE_ID
|
||||||
|
|
||||||
|
def test_labels(self):
|
||||||
|
client = make_fake_client()
|
||||||
|
image = client.images.get(FAKE_IMAGE_ID)
|
||||||
|
assert image.labels == {'bar': 'foo'}
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
images = client.images.list(all=True)
|
images = client.images.list(all=True)
|
||||||
|
|
Loading…
Reference in New Issue