mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
apache2_mod_proxy - minor improvements/fixes (#2142)
* minor improvements/fixes - moved imports from the bottom of the code to the top (ansible-style). - pythonified/simplified get_member_status()/set_member_status() - reduced clutter in Balancer.__init__() * added changelog fragment
This commit is contained in:
parent
f1dbef4143
commit
1d1cbc4f56
2 changed files with 14 additions and 18 deletions
2
changelogs/fragments/2142-apache2_mod_proxy-cleanup.yml
Normal file
2
changelogs/fragments/2142-apache2_mod_proxy-cleanup.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- apache2_mod_proxy - refactored/cleaned-up part of the code (https://github.com/ansible-collections/community.general/pull/2142).
|
|
@ -198,6 +198,10 @@ members:
|
|||
import re
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
BEAUTIFUL_SOUP_IMP_ERR = None
|
||||
try:
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
|
@ -273,13 +277,8 @@ class BalancerMember(object):
|
|||
'drained': 'Drn',
|
||||
'hot_standby': 'Stby',
|
||||
'ignore_errors': 'Ign'}
|
||||
status = {}
|
||||
actual_status = str(self.attributes['Status'])
|
||||
for mode in status_mapping.keys():
|
||||
if re.search(pattern=status_mapping[mode], string=actual_status):
|
||||
status[mode] = True
|
||||
else:
|
||||
status[mode] = False
|
||||
status = dict((mode, patt in actual_status) for mode, patt in iteritems(status_mapping))
|
||||
return status
|
||||
|
||||
def set_member_status(self, values):
|
||||
|
@ -290,13 +289,10 @@ class BalancerMember(object):
|
|||
'ignore_errors': '&w_status_I'}
|
||||
|
||||
request_body = regexp_extraction(self.management_url, EXPRESSION, 1)
|
||||
for k in values_mapping.keys():
|
||||
if values[str(k)]:
|
||||
request_body = request_body + str(values_mapping[k]) + '=1'
|
||||
else:
|
||||
request_body = request_body + str(values_mapping[k]) + '=0'
|
||||
values_url = "".join("{0}={1}".format(url_param, 1 if values[mode] else 0) for mode, url_param in iteritems(values_mapping))
|
||||
request_body = "{0}{1}".format(request_body, values_url)
|
||||
|
||||
response = fetch_url(self.module, self.management_url, data=str(request_body))
|
||||
response = fetch_url(self.module, self.management_url, data=request_body)
|
||||
if response[1]['status'] != 200:
|
||||
self.module.fail_json(msg="Could not set the member status! " + self.host + " " + response[1]['status'])
|
||||
|
||||
|
@ -309,11 +305,11 @@ class Balancer(object):
|
|||
|
||||
def __init__(self, host, suffix, module, members=None, tls=False):
|
||||
if tls:
|
||||
self.base_url = str(str('https://') + str(host))
|
||||
self.url = str(str('https://') + str(host) + str(suffix))
|
||||
self.base_url = 'https://' + str(host)
|
||||
self.url = 'https://' + str(host) + str(suffix)
|
||||
else:
|
||||
self.base_url = str(str('http://') + str(host))
|
||||
self.url = str(str('http://') + str(host) + str(suffix))
|
||||
self.base_url = 'http://' + str(host)
|
||||
self.url = 'http://' + str(host) + str(suffix)
|
||||
self.module = module
|
||||
self.page = self.fetch_balancer_page()
|
||||
if members is None:
|
||||
|
@ -444,7 +440,5 @@ def main():
|
|||
module.fail_json(msg=str(module.params['member_host']) + ' is not a member of the balancer ' + str(module.params['balancer_vhost']) + '!')
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue