Ignore containers that don't have a name

If a container is in the process of being removed, or removal has
failed, it can sometimes appear in the output of GET /containers/json
but not have a 'Name' key. In that case, rather than crashing, we can
ignore it.

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2015-08-10 16:00:45 +01:00
commit dfa4bf4452
6 changed files with 64 additions and 11 deletions

View file

@ -22,10 +22,14 @@ class Container(object):
"""
Construct a container object from the output of GET /containers/json.
"""
name = get_container_name(dictionary)
if name is None:
return None
new_dictionary = {
'Id': dictionary['Id'],
'Image': dictionary['Image'],
'Name': '/' + get_container_name(dictionary),
'Name': '/' + name,
}
return cls(client, new_dictionary, **kwargs)