mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix dockerng.network_* name matching
Updating the states so that they loop through the list of networks returned from `dockerng.networks` to check that one of the networks returned fully matches the name of the network that needs to be ensured to be present or absent. Another option would be to add an argument to the `dockerng.networks` execution module to enable strict matching. This would probably be preferable to repeating the logic in the states, but I didn't want to meddle too much as the execution module is currently just wrapping the docker-py library. Fixes #41982
This commit is contained in:
parent
82b1eb28ab
commit
515c612808
1 changed files with 21 additions and 2 deletions
|
@ -2242,8 +2242,17 @@ def network_present(name, driver=None, containers=None):
|
|||
# map containers to container's Ids.
|
||||
containers = [__salt__['dockerng.inspect_container'](c)['Id'] for c in containers]
|
||||
networks = __salt__['dockerng.networks'](names=[name])
|
||||
|
||||
# networks will contain all Docker networks which partially match 'name'.
|
||||
# We need to loop through to find the matching network, if there is one.
|
||||
network = None
|
||||
if networks:
|
||||
network = networks[0] # we expect network's name to be unique
|
||||
for network_iter in networks:
|
||||
if network_iter['Name'] == name:
|
||||
network = network_iter
|
||||
break
|
||||
|
||||
if network is not None:
|
||||
if all(c in network['Containers'] for c in containers):
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Network \'{0}\' already exists.'.format(name)
|
||||
|
@ -2302,7 +2311,17 @@ def network_absent(name, driver=None):
|
|||
'comment': ''}
|
||||
|
||||
networks = __salt__['dockerng.networks'](names=[name])
|
||||
if not networks:
|
||||
|
||||
# networks will contain all Docker networks which partially match 'name'.
|
||||
# We need to loop through to find the matching network, if there is one.
|
||||
network = None
|
||||
if networks:
|
||||
for network_iter in networks:
|
||||
if network_iter['Name'] == name:
|
||||
network = network_iter
|
||||
break
|
||||
|
||||
if network is None:
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Network \'{0}\' already absent'.format(name)
|
||||
return ret
|
||||
|
|
Loading…
Add table
Reference in a new issue