Skip to content

Commit a0c51ac

Browse files
author
chaoyiwang
authored
Merge pull request #48 from ccl0326/clchen_dev
Use network inspect instead of network ls in docker_network_exists
2 parents a55d6cf + cb6a819 commit a0c51ac

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

apis/utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,14 @@ class CalicoException(Exception):
211211

212212
def docker_network_exists(name):
213213
cli = get_docker_client(DOCKER_BASE_URL)
214-
if len(cli.networks(names=[name])) == 0:
215-
return False
216-
else:
217-
return True
214+
try:
215+
cli.inspect_network(name)
216+
except docker.errors.APIError as e:
217+
# Forward compatibility for some exceptions raise.
218+
if e.status_code == 404:
219+
return False
220+
raise e
221+
return True
218222

219223

220224
def docker_network_add(name):

0 commit comments

Comments
 (0)