parent
4c7bb32c1f
commit
4376417743
1 changed files with 9 additions and 6 deletions
|
@ -233,7 +233,7 @@ class HAProxy(object):
|
|||
self.wait = self.module.params['wait']
|
||||
self.wait_retries = self.module.params['wait_retries']
|
||||
self.wait_interval = self.module.params['wait_interval']
|
||||
self.drain = self.module.params['drain']
|
||||
self._drain = self.module.params['drain']
|
||||
self.command_results = {}
|
||||
|
||||
def execute(self, cmd, timeout=200, capture_output=True):
|
||||
|
@ -310,7 +310,8 @@ class HAProxy(object):
|
|||
# Fail when backends were not found
|
||||
state = self.get_state_for(backend, svname)
|
||||
if (self.fail_on_not_found) and state is None:
|
||||
self.module.fail_json(msg="The specified backend '%s/%s' was not found!" % (backend, svname))
|
||||
self.module.fail_json(
|
||||
msg="The specified backend '%s/%s' was not found!" % (backend, svname))
|
||||
|
||||
if state is not None:
|
||||
self.execute(Template(cmd).substitute(pxname=backend, svname=svname))
|
||||
|
@ -327,7 +328,8 @@ class HAProxy(object):
|
|||
state = tuple(
|
||||
map(
|
||||
lambda d: {'status': d['status'], 'weight': d['weight'], 'scur': d['scur']},
|
||||
filter(lambda d: (pxname is None or d['pxname'] == pxname) and d['svname'] == svname, r)
|
||||
filter(lambda d: (pxname is None or d['pxname']
|
||||
== pxname) and d['svname'] == svname, r)
|
||||
)
|
||||
)
|
||||
return state or None
|
||||
|
@ -344,12 +346,13 @@ class HAProxy(object):
|
|||
|
||||
# We can assume there will only be 1 element in state because both svname and pxname are always set when we get here
|
||||
if state[0]['status'] == status:
|
||||
if not self.drain or (state[0]['scur'] == '0' and state == 'MAINT'):
|
||||
if not self._drain or (state[0]['scur'] == '0' and state == 'MAINT'):
|
||||
return True
|
||||
else:
|
||||
time.sleep(self.wait_interval)
|
||||
|
||||
self.module.fail_json(msg="server %s/%s not status '%s' after %d retries. Aborting." % (pxname, svname, status, self.wait_retries))
|
||||
self.module.fail_json(msg="server %s/%s not status '%s' after %d retries. Aborting." %
|
||||
(pxname, svname, status, self.wait_retries))
|
||||
|
||||
def enabled(self, host, backend, weight):
|
||||
"""
|
||||
|
@ -397,7 +400,7 @@ class HAProxy(object):
|
|||
# toggle enable/disbale server
|
||||
if self.state == 'enabled':
|
||||
self.enabled(self.host, self.backend, self.weight)
|
||||
elif self.state == 'disabled' and self.drain:
|
||||
elif self.state == 'disabled' and self._drain:
|
||||
self.drain(self.host, self.backend, status='MAINT')
|
||||
elif self.state == 'disabled':
|
||||
self.disabled(self.host, self.backend, self.shutdown_sessions)
|
||||
|
|
Loading…
Reference in a new issue