Skip to content

Commit

Permalink
Pep8 fixes for ha_proxy module (ansible#24090)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored and sivel committed Apr 28, 2017
1 parent 3d4523f commit ca7616b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
28 changes: 11 additions & 17 deletions lib/ansible/modules/net_tools/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,18 @@
from string import Template


DEFAULT_SOCKET_LOCATION="/var/run/haproxy.sock"
DEFAULT_SOCKET_LOCATION = "/var/run/haproxy.sock"
RECV_SIZE = 1024
ACTION_CHOICES = ['enabled', 'disabled']
WAIT_RETRIES=25
WAIT_INTERVAL=5
WAIT_RETRIES = 25
WAIT_INTERVAL = 5


######################################################################
class TimeoutException(Exception):
pass


class HAProxy(object):
"""
Used for communicating with HAProxy through its local UNIX socket interface.
Expand Down Expand Up @@ -237,7 +239,6 @@ def execute(self, cmd, timeout=200, capture_output=True):
self.client.close()
return result


def capture_command_output(self, cmd, output):
"""
Capture the output for a command
Expand All @@ -249,7 +250,6 @@ def capture_command_output(self, cmd, output):
self.command_results['output'] = []
self.command_results['output'].append(output)


def discover_all_backends(self):
"""
Discover all entries with svname = 'BACKEND' and return a list of their corresponding
Expand All @@ -259,8 +259,7 @@ def discover_all_backends(self):
r = csv.DictReader(data.splitlines())
return tuple(map(lambda d: d['pxname'], filter(lambda d: d['svname'] == 'BACKEND', r)))


def execute_for_backends(self, cmd, pxname, svname, wait_for_status = None):
def execute_for_backends(self, cmd, pxname, svname, wait_for_status=None):
"""
Run some command on the specified backends. If no backends are provided they will
be discovered automatically (all backends)
Expand All @@ -278,11 +277,10 @@ def execute_for_backends(self, cmd, pxname, svname, wait_for_status = None):
if (self.fail_on_not_found or self.wait) and state is None:
self.module.fail_json(msg="The specified backend '%s/%s' was not found!" % (backend, svname))

self.execute(Template(cmd).substitute(pxname = backend, svname = svname))
self.execute(Template(cmd).substitute(pxname=backend, svname=svname))
if self.wait:
self.wait_until_status(backend, svname, wait_for_status)


def get_state_for(self, pxname, svname):
"""
Find the state of specific services. When pxname is not set, get all backends for a specific host.
Expand All @@ -298,7 +296,6 @@ def get_state_for(self, pxname, svname):
)
return state or None


def wait_until_status(self, pxname, svname, status):
"""
Wait for a service to reach the specified status. Try RETRIES times
Expand All @@ -317,7 +314,6 @@ def wait_until_status(self, pxname, svname, status):

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):
"""
Enabled action, marks server to UP and checks are re-enabled,
Expand All @@ -329,7 +325,6 @@ def enabled(self, host, backend, weight):
cmd += "; set weight $pxname/$svname %s" % weight
self.execute_for_backends(cmd, backend, host, 'UP')


def disabled(self, host, backend, shutdown_sessions):
"""
Disabled action, marks server to DOWN for maintenance. In this mode, no more checks will be
Expand All @@ -341,7 +336,6 @@ def disabled(self, host, backend, shutdown_sessions):
cmd += "; shutdown sessions server $pxname/$svname"
self.execute_for_backends(cmd, backend, host, 'MAINT')


def act(self):
"""
Figure out what you want to do from ansible, and then do it.
Expand Down Expand Up @@ -375,12 +369,12 @@ def main():

# load ansible module object
module = AnsibleModule(
argument_spec = dict(
state = dict(required=True, default=None, choices=ACTION_CHOICES),
argument_spec=dict(
state=dict(required=True, default=None, choices=ACTION_CHOICES),
host=dict(required=True, default=None),
backend=dict(required=False, default=None),
weight=dict(required=False, default=None),
socket = dict(required=False, default=DEFAULT_SOCKET_LOCATION),
socket=dict(required=False, default=DEFAULT_SOCKET_LOCATION),
shutdown_sessions=dict(required=False, default=False, type='bool'),
fail_on_not_found=dict(required=False, default=False, type='bool'),
wait=dict(required=False, default=False, type='bool'),
Expand All @@ -396,7 +390,7 @@ def main():
ansible_haproxy.act()

# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.basic import AnsibleModule

if __name__ == '__main__':
main()
1 change: 0 additions & 1 deletion test/sanity/pep8/legacy-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py
lib/ansible/modules/network/f5/bigip_virtual_server.py
lib/ansible/modules/network/fortios/fortios_config.py
lib/ansible/modules/network/fortios/fortios_ipv4_policy.py
lib/ansible/modules/net_tools/haproxy.py
lib/ansible/modules/network/illumos/dladm_iptun.py
lib/ansible/modules/network/illumos/dladm_linkprop.py
lib/ansible/modules/network/ios/_ios_template.py
Expand Down

0 comments on commit ca7616b

Please sign in to comment.