mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
docker_swarm update to use shared Swarm library (#52886)
* docker_swarm: Update code to use AnsibleDockerSwarmClient instead of AnsibleDockerClient * docker_swarm: Update check_if_swarm_node_is_down() with repetitive attempts to check node status to reflect original method implementation * docker_swarm: Add information that `state: inspect` will be removed in future release * docker_swarm: Fix sanity error * docker_swarm: Check_mode conditional for failing during the swarm init * docker_swarm: Small cleanup of a code * docker_swarm: Moving the warning message before dispatching * Commit to solve problems with Shippable
This commit is contained in:
parent
c6ae23062b
commit
72bdcdfff2
2 changed files with 35 additions and 53 deletions
|
@ -3,6 +3,7 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
import json
|
||||
from time import sleep
|
||||
|
||||
try:
|
||||
from docker.errors import APIError
|
||||
|
@ -108,23 +109,29 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
|||
return True
|
||||
return False
|
||||
|
||||
def check_if_swarm_node_is_down(self, node_id=None):
|
||||
def check_if_swarm_node_is_down(self, node_id=None, repeat_check=1):
|
||||
"""
|
||||
Checks if node status on Swarm manager is 'down'. If node_id is provided it query manager about
|
||||
node specified in parameter, otherwise it query manager itself. If run on Swarm Worker node or
|
||||
host that is not part of Swarm it will fail the playbook
|
||||
|
||||
:param repeat_check: number of check attempts with 5 seconds delay between them, by default check only once
|
||||
:param node_id: node ID or name, if None then method will try to get node_id of host module run on
|
||||
:return:
|
||||
True if node is part of swarm but its state is down, False otherwise
|
||||
"""
|
||||
|
||||
if repeat_check < 1:
|
||||
repeat_check = 1
|
||||
|
||||
if node_id is None:
|
||||
node_id = self.get_swarm_node_id()
|
||||
|
||||
node_info = self.get_node_inspect(node_id=node_id)
|
||||
if node_info['Status']['State'] == 'down':
|
||||
return True
|
||||
for retry in range(0, repeat_check):
|
||||
node_info = self.get_node_inspect(node_id=node_id)
|
||||
if node_info['Status']['State'] == 'down':
|
||||
return True
|
||||
sleep(5)
|
||||
return False
|
||||
|
||||
def get_node_inspect(self, node_id=None, skip_missing=False):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue