[2.7] Fixes #33045: get existing containers in a network via inspect_network (Rebased #33048) (#47472)

* Fix #33045: get existing network via inspect_network (Rebased #33048) (#43997)


(cherry picked from commit 2939f68897)

* Add changelog.
This commit is contained in:
Felix Fontein 2018-10-23 15:43:48 +02:00 committed by Toshio Kuratomi
parent f4081c2d97
commit cb347c2096
2 changed files with 6 additions and 7 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "docker_network - fixes idempotency issues (https://github.com/ansible/ansible/issues/33045) and name substring issue (https://github.com/ansible/ansible/issues/32926)."

View file

@ -161,6 +161,7 @@ from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseCl
try:
from docker import utils
from docker.errors import NotFound
if HAS_DOCKER_PY_2 or HAS_DOCKER_PY_3:
from docker.types import IPAMPool, IPAMConfig
except Exception as dummy:
@ -215,14 +216,10 @@ class DockerNetworkManager(object):
self.absent()
def get_existing_network(self):
networks = self.client.networks(names=[self.parameters.network_name])
# check if a user is trying to find network by its Id
if not networks:
networks = self.client.networks(ids=[self.parameters.network_name])
if not networks:
try:
return self.client.inspect_network(self.parameters.network_name)
except NotFound:
return None
else:
return networks[0]
def has_different_config(self, net):
'''