Fix for issue 3740. Make docker_service more resilient when targeting older API versions.
This commit is contained in:
parent
f6690828af
commit
d0da544aef
1 changed files with 47 additions and 18 deletions
|
@ -599,25 +599,54 @@ class ContainerManager(DockerBaseClass):
|
||||||
for container in service.containers(stopped=True):
|
for container in service.containers(stopped=True):
|
||||||
inspection = container.inspect()
|
inspection = container.inspect()
|
||||||
# pare down the inspection data to the most useful bits
|
# pare down the inspection data to the most useful bits
|
||||||
facts = dict()
|
facts = dict(
|
||||||
|
cmd=[],
|
||||||
|
labels=dict(),
|
||||||
|
image=None,
|
||||||
|
state=dict(
|
||||||
|
running=None,
|
||||||
|
status=None
|
||||||
|
),
|
||||||
|
networks=dict()
|
||||||
|
)
|
||||||
|
if inspection['Config'].get('Cmd', None) is not None:
|
||||||
facts['cmd'] = inspection['Config']['Cmd']
|
facts['cmd'] = inspection['Config']['Cmd']
|
||||||
|
if inspection['Config'].get('Labels', None) is not None:
|
||||||
facts['labels'] = inspection['Config']['Labels']
|
facts['labels'] = inspection['Config']['Labels']
|
||||||
|
if inspection['Config'].get('Image', None) is not None:
|
||||||
facts['image'] = inspection['Config']['Image']
|
facts['image'] = inspection['Config']['Image']
|
||||||
facts['state'] = dict(
|
if inspection['State'].get('Running', None) is not None:
|
||||||
running=inspection['State']['Running'],
|
facts['state']['running'] = inspection['State']['Running']
|
||||||
status=inspection['State']['Status'],
|
if inspection['State'].get('Status', None) is not None:
|
||||||
)
|
facts['state']['status'] = inspection['State']['Status']
|
||||||
facts['networks'] = dict()
|
|
||||||
for key, value in inspection['NetworkSettings']['Networks'].items():
|
if inspection.get('NetworkSettings') and inspection['NetworkSettings'].get('Networks'):
|
||||||
|
networks = inspection['NetworkSettings']['Networks']
|
||||||
|
for key in networks:
|
||||||
facts['networks'][key] = dict(
|
facts['networks'][key] = dict(
|
||||||
aliases=inspection['NetworkSettings']['Networks'][key]['Aliases'],
|
aliases=[],
|
||||||
globalIPv6=inspection['NetworkSettings']['Networks'][key]['GlobalIPv6Address'],
|
globalIPv6=None,
|
||||||
globalIPv6PrefixLen=inspection['NetworkSettings']['Networks'][key]['GlobalIPv6PrefixLen'],
|
globalIPv6PrefixLen=0,
|
||||||
IPAddress=inspection['NetworkSettings']['Networks'][key]['IPAddress'],
|
IPAddress=None,
|
||||||
IPPrefixLen=inspection['NetworkSettings']['Networks'][key]['IPPrefixLen'],
|
IPPrefixLen=0,
|
||||||
links=inspection['NetworkSettings']['Networks'][key]['Links'],
|
links=None,
|
||||||
macAddress=inspection['NetworkSettings']['Networks'][key]['MacAddress'],
|
macAddress=None,
|
||||||
)
|
)
|
||||||
|
if networks[key].get('Aliases', None) is not None:
|
||||||
|
facts['networks'][key]['aliases'] = networks[key]['Aliases']
|
||||||
|
if networks[key].get('GlobalIPv6Address', None) is not None:
|
||||||
|
facts['networks'][key]['globalIPv6'] = networks[key]['GlobalIPv6Address']
|
||||||
|
if networks[key].get('GlobalIPv6PrefixLen', None) is not None:
|
||||||
|
facts['networks'][key]['globalIPv6PrefixLen'] = networks[key]['GlobalIPv6PrefixLen']
|
||||||
|
if networks[key].get('IPAddress', None) is not None:
|
||||||
|
facts['networks'][key]['IPAddress'] = networks[key]['IPAddress']
|
||||||
|
if networks[key].get('IPPrefixLen', None) is not None:
|
||||||
|
facts['networks'][key]['IPPrefixLen'] = networks[key]['IPPrefixLen']
|
||||||
|
if networks[key].get('Links', None) is not None:
|
||||||
|
facts['networks'][key]['links'] = networks[key]['Links']
|
||||||
|
if networks[key].get('MacAddress', None) is not None:
|
||||||
|
facts['networks'][key]['macAddress'] = networks[key]['MacAddress']
|
||||||
|
|
||||||
result['ansible_facts'][service.name][container.name] = facts
|
result['ansible_facts'][service.name][container.name] = facts
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue