minor cleanup, removing unused/redundant code, cleaned some comments, slight reformating in class to

remove kwargs
reviewable/pr18780/r1
Brian Coca 10 years ago
parent 82aaaa4152
commit a97d1016dc

@ -94,11 +94,8 @@ author: Ravi Bhure <ravibhure@gmail.com>
version_added: "1.9" version_added: "1.9"
''' '''
import logging
import socket import socket
import re
logger = logging.getLogger(__name__)
DEFAULT_SOCKET_LOCATION="/var/run/haproxy.sock" DEFAULT_SOCKET_LOCATION="/var/run/haproxy.sock"
RECV_SIZE = 1024 RECV_SIZE = 1024
@ -120,14 +117,15 @@ class HAProxy(object):
http://haproxy.1wt.eu/download/1.5/doc/configuration.txt#Unix Socket commands http://haproxy.1wt.eu/download/1.5/doc/configuration.txt#Unix Socket commands
""" """
def __init__(self, module, **kwargs): def __init__(self, module):
self.module = module self.module = module
self.state = kwargs['state']
self.host = kwargs['host'] self.state = self.module.params['state']
self.backend = kwargs['backend'] self.host = self.module.params['host']
self.weight = kwargs['weight'] self.backend = self.module.params['backend']
self.socket = kwargs['socket'] self.weight = self.module.params['weight']
self.shutdown_sessions = kwargs['shutdown_sessions'] self.socket = self.module.params['socket']
self.shutdown_sessions = self.module.params['shutdown_sessions']
self.command_results = [] self.command_results = []
@ -137,8 +135,6 @@ class HAProxy(object):
UNIX socket and waiting up to 'timeout' milliseconds for the response. UNIX socket and waiting up to 'timeout' milliseconds for the response.
""" """
buffer = ""
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.client.connect(self.socket) self.client.connect(self.socket)
self.client.sendall('%s\n' % cmd) self.client.sendall('%s\n' % cmd)
@ -214,8 +210,7 @@ class HAProxy(object):
def act(self): def act(self):
""" """
Figure out what you want to do from ansible, and then do the Figure out what you want to do from ansible, and then do it.
needful (at the earliest).
""" """
# toggle enable/disbale server # toggle enable/disbale server
@ -226,8 +221,7 @@ class HAProxy(object):
self.disabled(self.host, self.backend, self.shutdown_sessions) self.disabled(self.host, self.backend, self.shutdown_sessions)
else: else:
self.module.fail_json(msg="unknown state specified: '%s'" % \ self.module.fail_json(msg="unknown state specified: '%s'" % self.state)
self.state)
self.module.exit_json(stdout=self.command_results, changed=True) self.module.exit_json(stdout=self.command_results, changed=True)
@ -245,32 +239,12 @@ def main():
), ),
) )
state = module.params['state']
host = module.params['host']
backend = module.params['backend']
weight = module.params['weight']
socket = module.params['socket']
shutdown_sessions = module.params['shutdown_sessions']
##################################################################
# Required args per state:
# (enabled/disabled) = (host)
#
# AnsibleModule will verify most stuff, we need to verify
# 'socket' manually.
##################################################################
##################################################################
if not socket: if not socket:
module.fail_json(msg="unable to locate haproxy socket") module.fail_json(msg="unable to locate haproxy socket")
##################################################################
required_one_of=[['state', 'host']]
ansible_haproxy = HAProxy(module, **module.params) ansible_haproxy = HAProxy(module, **module.params)
ansible_haproxy.act() ansible_haproxy.act()
##################################################################
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

Loading…
Cancel
Save