1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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

This commit is contained in:
Brian Coca 2014-12-09 09:06:04 -05:00 committed by Matt Clay
parent 7e83da3480
commit 3ef53f92eb

View file

@ -94,11 +94,8 @@ author: Ravi Bhure <ravibhure@gmail.com>
version_added: "1.9"
'''
import logging
import socket
import re
logger = logging.getLogger(__name__)
DEFAULT_SOCKET_LOCATION="/var/run/haproxy.sock"
RECV_SIZE = 1024
@ -120,14 +117,15 @@ class HAProxy(object):
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.state = kwargs['state']
self.host = kwargs['host']
self.backend = kwargs['backend']
self.weight = kwargs['weight']
self.socket = kwargs['socket']
self.shutdown_sessions = kwargs['shutdown_sessions']
self.state = self.module.params['state']
self.host = self.module.params['host']
self.backend = self.module.params['backend']
self.weight = self.module.params['weight']
self.socket = self.module.params['socket']
self.shutdown_sessions = self.module.params['shutdown_sessions']
self.command_results = []
@ -137,8 +135,6 @@ class HAProxy(object):
UNIX socket and waiting up to 'timeout' milliseconds for the response.
"""
buffer = ""
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.client.connect(self.socket)
self.client.sendall('%s\n' % cmd)
@ -214,8 +210,7 @@ class HAProxy(object):
def act(self):
"""
Figure out what you want to do from ansible, and then do the
needful (at the earliest).
Figure out what you want to do from ansible, and then do it.
"""
# toggle enable/disbale server
@ -226,8 +221,7 @@ class HAProxy(object):
self.disabled(self.host, self.backend, self.shutdown_sessions)
else:
self.module.fail_json(msg="unknown state specified: '%s'" % \
self.state)
self.module.fail_json(msg="unknown state specified: '%s'" % self.state)
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:
module.fail_json(msg="unable to locate haproxy socket")
##################################################################
required_one_of=[['state', 'host']]
ansible_haproxy = HAProxy(module, **module.params)
ansible_haproxy.act()
##################################################################
# import module snippets
from ansible.module_utils.basic import *