Fix undefined variables, basestring usage, and some associated python3 issues

This commit is contained in:
Toshio Kuratomi
2017-07-22 18:15:46 -07:00
parent 9f7b0dfc30
commit 225fa5d092
84 changed files with 652 additions and 963 deletions

View File

@@ -242,6 +242,8 @@ try:
except ImportError:
python_consul_installed = False
from ansible.module_utils.basic import AnsibleModule
def register_with_consul(module):
state = module.params.get('state')
@@ -285,7 +287,7 @@ def add_check(module, check):
retrieve the full metadata of an existing check through the consul api.
Without this we can't compare to the supplied check and so we must assume
a change. '''
if not check.name and not service_id:
if not check.name and not check.service_id:
module.fail_json(msg='a check name is required for a node level check, one not attached to a service')
consul_api = get_consul_api(module)
@@ -425,7 +427,7 @@ class ConsulService():
optional['port'] = self.port
if len(self.checks) > 0:
optional['check'] = checks[0].check
optional['check'] = self.checks[0].check
consul_api.agent.service.register(
self.name,
@@ -464,7 +466,7 @@ class ConsulService():
return data
class ConsulCheck():
class ConsulCheck(object):
def __init__(self, check_id, name, node=None, host='localhost',
script=None, interval=None, ttl=None, notes=None, http=None, timeout=None, service_id=None):
@@ -513,8 +515,8 @@ class ConsulCheck():
self.check_id == other.check_id and
self.service_id == other.service_id and
self.name == other.name and
self.script == script and
self.interval == interval)
self.script == other.script and
self.interval == other.interval)
def __ne__(self, other):
return not self.__eq__(other)
@@ -586,7 +588,6 @@ def main():
except Exception as e:
module.fail_json(msg=str(e))
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

View File

@@ -140,6 +140,10 @@ except ImportError:
from requests.exceptions import ConnectionError
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes
def execute(module):
state = module.params.get('state')
@@ -216,22 +220,17 @@ def load_rules_for_token(module, consul_api, token):
rules = Rules()
info = consul_api.acl.info(token)
if info and info['Rules']:
rule_set = hcl.loads(to_ascii(info['Rules']))
rule_set = hcl.loads(to_bytes(info['Rules'], errors='ignore', nonstring='passthru'))
for rule_type in rule_set:
for pattern, policy in rule_set[rule_type].items():
rules.add_rule(rule_type, Rule(pattern, policy['policy']))
return rules
except Exception as e:
module.fail_json(
msg="Could not load rule list from retrieved rule data %s, %s" % (
token, e))
return json_to_rules(module, loaded)
return rules
def to_ascii(unicode_string):
if isinstance(unicode_string, unicode):
return unicode_string.encode('ascii', 'ignore')
return unicode_string
def yml_to_rules(module, yml_rules):
rules = Rules()
@@ -275,7 +274,7 @@ class Rules:
for rule_type in RULE_TYPES:
for pattern, rule in self.rules[rule_type].items():
rules += template % (rule_type, pattern, rule.policy)
return to_ascii(rules)
return to_bytes(rules, errors='ignore', nonstring='passthru')
def __len__(self):
count = 0
@@ -362,7 +361,6 @@ def main():
except Exception as e:
module.fail_json(msg=str(e))
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()