Repository: ansible/ansible

Issue:
docker_network failes with 'endpoint with name x already exists in network y'
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
docker_network

##### ANSIBLE VERSION
```
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]
```
###### Docker-Py Version
1.10.6
###### Docker Version
Docker version 17.09.0-ce

##### CONFIGURATION
```
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = [u'/etc/ansible/environments/dev']
```

##### OS / ENVIRONMENT
Vagrant/Debian-Jessie

##### SUMMARY
docker_network taks fails, if container is already added to network.
Underlying reason: docker.Client.networks calls the docker API without explictly specifying verbose mode. For docker API 1.24 the containers are included in the response, for docker API 1.32 this is not the case anymore.  

##### STEPS TO REPRODUCE
Define a docker_network task as follows: 

```yaml
- name: create network
  docker_network:
    name: myNetwork
    appends:
      yes
    connected:
      - machine1
```

##### EXPECTED RESULTS
Subsequent runs should not try to add the container to the network, if already connected.

##### ACTUAL RESULTS
The docker_network command does not detect, that container is already added to network and tries to add it again, which results in the following failure:

```
Traceback (most recent call last):
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 393, in <module>
    main()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 388, in main
    cm = DockerNetworkManager(client)
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 206, in __init__
    self.present()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 353, in present
    self.connect_containers()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 314, in connect_containers
    self.client.connect_container_to_network(name, self.parameters.network_name)
  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 21, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 35, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/api/network.py", line 96, in connect_container_to_network
    self._raise_for_status(res)
  File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 174, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
docker.errors.APIError: 403 Client Error: Forbidden ("{"message":"endpoint with name machine1 already exists in network myNetwork"}")

fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 393, in <mod
ule>\n    main()\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 388, in main\n    cm = DockerNetworkManager(client)\
n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 206, in __init__\n    self.present()\n  File \"/tmp/ansible_Ao0G0J/an
sible_module_docker_network.py\", line 353, in present\n    self.connect_containers()\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_ne
twork.py\", line 314, in connect_containers\n    self.client.connect_container_to_network(name, self.parameters.network_name)\n  File \"/usr
/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 21, in wrapped\n    return f(self, resource_id, *args, **kwargs)\n  Fi
le \"/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 35, in wrapper\n    return f(self, *args, **kwargs)\n  File \
"/usr/local/lib/python2.7/dist-packages/docker/api/network.py\", line 96, in connect_container_to_network\n    self._raise_for_status(res)\n
  File \"/usr/local/lib/python2.7/dist-packages/docker/client.py\", line 174, in _raise_for_status\n    raise errors.APIError(e, response, e
xplanation=explanation)\ndocker.errors.APIError: 403 Client Error: Forbidden (\"{\"message\":\"endpoint with name machine1 already exists i
n network myNetwork\"}\")\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 0
```
Ansible docker_network calls http+docker://localunixsocket/v1.32/networks with {'filters': '{"name": ["myNetwork"]}'} resulting in
```
[{u'Ingress': False, u'Name': u'myNetwork', u'Created': u'2017-11-17T11:47:10.788848271Z', u'EnableIPv6': False, u'Labels': {}, u'Driver': u'bridge', u'Attachable': False, u'ConfigOnly': False, u'Internal': False, u'ConfigFrom': {u'Network': u''}, u'Options': {}, u'IPAM': {u'Config': [{u'Subnet': u'172.18.0.0/16', u'Gateway': u'172.18.0.1'}], u'Driver': u'default', u'Options': None}, u'Scope': u'local', u'Id': u'5875c64c4d4db12a675a7ca188e676150befcde817823b11ec9e1765b9d53b10', u'Containers': {}}]
```
Using docker client directly calls http+docker://localunixsocket/v1.24/networks with {'filters': '{"name": ["myNetwork"]}'} resulting in
```
[{u'Ingress': False, u'Name': u'myNetwork', u'Created': u'2017-11-17T11:47:10.788848271Z', u'EnableIPv6': False, u'Labels': {}, u'Driver': u'bridge', u'Attachable': False, u'ConfigOnly': False, u'Internal': False, u'ConfigFrom': {u'Network': u''}, u'Options': {}, u'IPAM': {u'Config': [{u'Subnet': u'172.18.0.0/16', u'Gateway': u'172.18.0.1'}], u'Driver': u'default', u'Options': None}, u'Scope': u'local', u'Id': u'5875c64c4d4db12a675a7ca188e676150befcde817823b11ec9e1765b9d53b10', u'Containers': {u'7a3815a8bd541ecb48b03642952ff9b479d8cf29eabaae673580eb1cb0538df7': {u'IPv4Address': u'172.18.0.3/16', u'MacAddress': u'02:42:ac:00:00:00', u'Name': u'machine1', u'EndpointID': u'6c719552d507e208b25c3655c2a0d8fea9e8ad6b87be82115c870fa7b67e9f39', u'IPv6Address': u''}}}]
```
docker_network failes with 'endpoint with name x already exists in network y'
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
docker_network

##### ANSIBLE VERSION
```
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]
```
###### Docker-Py Version
1.10.6
###### Docker Version
Docker version 17.09.0-ce

##### CONFIGURATION
```
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = [u'/etc/ansible/environments/dev']
```

##### OS / ENVIRONMENT
Vagrant/Debian-Jessie

##### SUMMARY
docker_network taks fails, if container is already added to network.
Underlying reason: docker.Client.networks calls the docker API without explictly specifying verbose mode. For docker API 1.24 the containers are included in the response, for docker API 1.32 this is not the case anymore.  

##### STEPS TO REPRODUCE
Define a docker_network task as follows: 

```yaml
- name: create network
  docker_network:
    name: myNetwork
    appends:
      yes
    connected:
      - machine1
```

##### EXPECTED RESULTS
Subsequent runs should not try to add the container to the network, if already connected.

##### ACTUAL RESULTS
The docker_network command does not detect, that container is already added to network and tries to add it again, which results in the following failure:

```
Traceback (most recent call last):
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 393, in <module>
    main()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 388, in main
    cm = DockerNetworkManager(client)
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 206, in __init__
    self.present()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 353, in present
    self.connect_containers()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 314, in connect_containers
    self.client.connect_container_to_network(name, self.parameters.network_name)
  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 21, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 35, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/api/network.py", line 96, in connect_container_to_network
    self._raise_for_status(res)
  File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 174, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
docker.errors.APIError: 403 Client Error: Forbidden ("{"message":"endpoint with name machine1 already exists in network myNetwork"}")

fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 393, in <mod
ule>\n    main()\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 388, in main\n    cm = DockerNetworkManager(client)\
n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 206, in __init__\n    self.present()\n  File \"/tmp/ansible_Ao0G0J/an
sible_module_docker_network.py\", line 353, in present\n    self.connect_containers()\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_ne
twork.py\", line 314, in connect_containers\n    self.client.connect_container_to_network(name, self.parameters.network_name)\n  File \"/usr
/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 21, in wrapped\n    return f(self, resource_id, *args, **kwargs)\n  Fi
le \"/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 35, in wrapper\n    return f(self, *args, **kwargs)\n  File \
"/usr/local/lib/python2.7/dist-packages/docker/api/network.py\", line 96, in connect_container_to_network\n    self._raise_for_status(res)\n
  File \"/usr/local/lib/python2.7/dist-packages/docker/client.py\", line 174, in _raise_for_status\n    raise errors.APIError(e, response, e
xplanation=explanation)\ndocker.errors.APIError: 403 Client Error: Forbidden (\"{\"message\":\"endpoint with name machine1 already exists i
n network myNetwork\"}\")\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 0
```
Ansible docker_network calls http+docker://localunixsocket/v1.32/networks with {'filters': '{"name": ["myNetwork"]}'} resulting in
```
[{u'Ingress': False, u'Name': u'myNetwork', u'Created': u'2017-11-17T11:47:10.788848271Z', u'EnableIPv6': False, u'Labels': {}, u'Driver': u'bridge', u'Attachable': False, u'ConfigOnly': False, u'Internal': False, u'ConfigFrom': {u'Network': u''}, u'Options': {}, u'IPAM': {u'Config': [{u'Subnet': u'172.18.0.0/16', u'Gateway': u'172.18.0.1'}], u'Driver': u'default', u'Options': None}, u'Scope': u'local', u'Id': u'5875c64c4d4db12a675a7ca188e676150befcde817823b11ec9e1765b9d53b10', u'Containers': {}}]
```
Using docker client directly calls http+docker://localunixsocket/v1.24/networks with {'filters': '{"name": ["myNetwork"]}'} resulting in
```
[{u'Ingress': False, u'Name': u'myNetwork', u'Created': u'2017-11-17T11:47:10.788848271Z', u'EnableIPv6': False, u'Labels': {}, u'Driver': u'bridge', u'Attachable': False, u'ConfigOnly': False, u'Internal': False, u'ConfigFrom': {u'Network': u''}, u'Options': {}, u'IPAM': {u'Config': [{u'Subnet': u'172.18.0.0/16', u'Gateway': u'172.18.0.1'}], u'Driver': u'default', u'Options': None}, u'Scope': u'local', u'Id': u'5875c64c4d4db12a675a7ca188e676150befcde817823b11ec9e1765b9d53b10', u'Containers': {u'7a3815a8bd541ecb48b03642952ff9b479d8cf29eabaae673580eb1cb0538df7': {u'IPv4Address': u'172.18.0.3/16', u'MacAddress': u'02:42:ac:00:00:00', u'Name': u'machine1', u'EndpointID': u'6c719552d507e208b25c3655c2a0d8fea9e8ad6b87be82115c870fa7b67e9f39', u'IPv6Address': u''}}}]
```
docker_network failes with 'endpoint with name x already exists in network y'
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
docker_network

##### ANSIBLE VERSION
```
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]
```
###### Docker-Py Version
1.10.6
###### Docker Version
Docker version 17.09.0-ce

##### CONFIGURATION
```
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = [u'/etc/ansible/environments/dev']
```

##### OS / ENVIRONMENT
Vagrant/Debian-Jessie

##### SUMMARY
docker_network taks fails, if container is already added to network.
Underlying reason: docker.Client.networks calls the docker API without explictly specifying verbose mode. For docker API 1.24 the containers are included in the response, for docker API 1.32 this is not the case anymore.  

##### STEPS TO REPRODUCE
Define a docker_network task as follows: 

```yaml
- name: create network
  docker_network:
    name: myNetwork
    appends:
      yes
    connected:
      - machine1
```

##### EXPECTED RESULTS
Subsequent runs should not try to add the container to the network, if already connected.

##### ACTUAL RESULTS
The docker_network command does not detect, that container is already added to network and tries to add it again, which results in the following failure:

```
Traceback (most recent call last):
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 393, in <module>
    main()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 388, in main
    cm = DockerNetworkManager(client)
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 206, in __init__
    self.present()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 353, in present
    self.connect_containers()
  File "/tmp/ansible_Ao0G0J/ansible_module_docker_network.py", line 314, in connect_containers
    self.client.connect_container_to_network(name, self.parameters.network_name)
  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 21, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 35, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/api/network.py", line 96, in connect_container_to_network
    self._raise_for_status(res)
  File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 174, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
docker.errors.APIError: 403 Client Error: Forbidden ("{"message":"endpoint with name machine1 already exists in network myNetwork"}")

fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 393, in <mod
ule>\n    main()\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 388, in main\n    cm = DockerNetworkManager(client)\
n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_network.py\", line 206, in __init__\n    self.present()\n  File \"/tmp/ansible_Ao0G0J/an
sible_module_docker_network.py\", line 353, in present\n    self.connect_containers()\n  File \"/tmp/ansible_Ao0G0J/ansible_module_docker_ne
twork.py\", line 314, in connect_containers\n    self.client.connect_container_to_network(name, self.parameters.network_name)\n  File \"/usr
/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 21, in wrapped\n    return f(self, resource_id, *args, **kwargs)\n  Fi
le \"/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py\", line 35, in wrapper\n    return f(self, *args, **kwargs)\n  File \
"/usr/local/lib/python2.7/dist-packages/docker/api/network.py\", line 96, in connect_container_to_network\n    self._raise_for_status(res)\n
  File \"/usr/local/lib/python2.7/dist-packages/docker/client.py\", line 174, in _raise_for_status\n    raise errors.APIError(e, response, e
xplanation=explanation)\ndocker.errors.APIError: 403 Client Error: Forbidden (\"{\"message\":\"endpoint with name machine1 already exists i
n network myNetwork\"}\")\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 0
```
Ansible docker_network calls http+docker://localunixsocket/v1.32/networks with {'filters': '{"name": ["myNetwork"]}'} resulting in
```
[{u'Ingress': False, u'Name': u'myNetwork', u'Created': u'2017-11-17T11:47:10.788848271Z', u'EnableIPv6': False, u'Labels': {}, u'Driver': u'bridge', u'Attachable': False, u'ConfigOnly': False, u'Internal': False, u'ConfigFrom': {u'Network': u''}, u'Options': {}, u'IPAM': {u'Config': [{u'Subnet': u'172.18.0.0/16', u'Gateway': u'172.18.0.1'}], u'Driver': u'default', u'Options': None}, u'Scope': u'local', u'Id': u'5875c64c4d4db12a675a7ca188e676150befcde817823b11ec9e1765b9d53b10', u'Containers': {}}]
```
Using docker client directly calls http+docker://localunixsocket/v1.24/networks with {'filters': '{"name": ["myNetwork"]}'} resulting in
```
[{u'Ingress': False, u'Name': u'myNetwork', u'Created': u'2017-11-17T11:47:10.788848271Z', u'EnableIPv6': False, u'Labels': {}, u'Driver': u'bridge', u'Attachable': False, u'ConfigOnly': False, u'Internal': False, u'ConfigFrom': {u'Network': u''}, u'Options': {}, u'IPAM': {u'Config': [{u'Subnet': u'172.18.0.0/16', u'Gateway': u'172.18.0.1'}], u'Driver': u'default', u'Options': None}, u'Scope': u'local', u'Id': u'5875c64c4d4db12a675a7ca188e676150befcde817823b11ec9e1765b9d53b10', u'Containers': {u'7a3815a8bd541ecb48b03642952ff9b479d8cf29eabaae673580eb1cb0538df7': {u'IPv4Address': u'172.18.0.3/16', u'MacAddress': u'02:42:ac:00:00:00', u'Name': u'machine1', u'EndpointID': u'6c719552d507e208b25c3655c2a0d8fea9e8ad6b87be82115c870fa7b67e9f39', u'IPv6Address': u''}}}]
```


Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/docker/docker_network.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/docker/docker_network.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @chouseknecht @keitwb @olsaki
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
From docker API doc for the [List Networks endpoint](https://docs.docker.com/engine/api/v1.32/#operation/NetworkList):

> Note that it uses a different, smaller representation of a network than inspecting a single network. For example, the list of containers attached to the network is not propagated in API versions 1.28 and up.
I'm using `state: present force:yes` as a workaround so my scripts at least finish. This removes and recreates the entire network on every run. It works, but is quite slow.
Shouldn't this be idempotent? The module should check existing containers on the network before trying to re-add them.
Yes, it does already. See #33048 which fixes this check for docker api version >=1.28.
As long as this is not merged officially, you may place the patched docker_network.py in the library folder.

Files identified in the description:
* [lib/ansible/modules/cloud/docker/docker_network.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/docker/docker_network.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @chouseknecht @keitwb @olsaki
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
From docker API doc for the [List Networks endpoint](https://docs.docker.com/engine/api/v1.32/#operation/NetworkList):

> Note that it uses a different, smaller representation of a network than inspecting a single network. For example, the list of containers attached to the network is not propagated in API versions 1.28 and up.
I'm using `state: present force:yes` as a workaround so my scripts at least finish. This removes and recreates the entire network on every run. It works, but is quite slow.
Shouldn't this be idempotent? The module should check existing containers on the network before trying to re-add them.
Yes, it does already. See #33048 which fixes this check for docker api version >=1.28.
As long as this is not merged officially, you may place the patched docker_network.py in the library folder.

Files identified in the description:
* [lib/ansible/modules/cloud/docker/docker_network.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/docker/docker_network.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @chouseknecht @keitwb @olsaki
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
From docker API doc for the [List Networks endpoint](https://docs.docker.com/engine/api/v1.32/#operation/NetworkList):

> Note that it uses a different, smaller representation of a network than inspecting a single network. For example, the list of containers attached to the network is not propagated in API versions 1.28 and up.
I'm using `state: present force:yes` as a workaround so my scripts at least finish. This removes and recreates the entire network on every run. It works, but is quite slow.
Shouldn't this be idempotent? The module should check existing containers on the network before trying to re-add them.
Yes, it does already. See #33048 which fixes this check for docker api version >=1.28.
As long as this is not merged officially, you may place the patched docker_network.py in the library folder.


Resolving patch:
diff --git a/lib/ansible/modules/cloud/docker/docker_network.py b/lib/ansible/modules/cloud/docker/docker_network.py
--- a/lib/ansible/modules/cloud/docker/docker_network.py
+++ b/lib/ansible/modules/cloud/docker/docker_network.py
@@ -161,6 +161,7 @@
 
 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 @@ def __init__(self, client):
             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):
         '''


Test patch: