From 55ed4489e396129486e9580ad1eafdf7a7406cc1 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Sun, 31 Aug 2014 08:58:16 -0500 Subject: [PATCH] Perform region validation early to be more explicit about invalid region failures --- lib/ansible/module_utils/rax.py | 7 ++++--- library/cloud/rax_dns | 2 +- library/cloud/rax_dns_record | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/rax.py b/lib/ansible/module_utils/rax.py index db8b6c4f3a..a8f33208ca 100644 --- a/lib/ansible/module_utils/rax.py +++ b/lib/ansible/module_utils/rax.py @@ -212,7 +212,7 @@ def rax_required_together(): return [['api_key', 'username']] -def setup_rax_module(module, rax_module): +def setup_rax_module(module, rax_module, region_required=True): rax_module.USER_AGENT = 'ansible/%s %s' % (ANSIBLE_VERSION, rax_module.USER_AGENT) @@ -270,7 +270,8 @@ def setup_rax_module(module, rax_module): except Exception, e: module.fail_json(msg='%s' % e.message) - rax_module.USER_AGENT = 'ansible/%s %s' % (ANSIBLE_VERSION, - rax_module.USER_AGENT) + if region_required and region not in rax_module.regions: + module.fail_json(msg='%s is not a valid region, must be one of: %s' % + (region, ','.join(rax_module.regions))) return rax_module diff --git a/library/cloud/rax_dns b/library/cloud/rax_dns index e726851d60..dacc4c672f 100644 --- a/library/cloud/rax_dns +++ b/library/cloud/rax_dns @@ -160,7 +160,7 @@ def main(): state = module.params.get('state') ttl = module.params.get('ttl') - setup_rax_module(module, pyrax) + setup_rax_module(module, pyrax, False) rax_dns(module, comment, email, name, state, ttl) diff --git a/library/cloud/rax_dns_record b/library/cloud/rax_dns_record index 561758f4fd..a28f5b9a9b 100644 --- a/library/cloud/rax_dns_record +++ b/library/cloud/rax_dns_record @@ -312,7 +312,7 @@ def main(): ttl = module.params.get('ttl') record_type = module.params.get('type') - setup_rax_module(module, pyrax) + setup_rax_module(module, pyrax, False) if record_type.upper() == 'PTR': if not server and not loadbalancer: