[GCE] Invalid zone reported through fail_json

* added new helper function for zones and regions.
* modified GCE module to use it

Fixes: ansible/ansible#20616
This commit is contained in:
Tom Melendez 2017-03-18 03:18:04 +00:00 committed by Brian Coca
parent cdb4d350b4
commit 1c38cba7ca
2 changed files with 27 additions and 12 deletions

View file

@ -400,3 +400,16 @@ def check_min_pkg_version(pkg_name, minimum_version):
def unexpected_error_msg(error):
"""Create an error string based on passed in error."""
return 'Unexpected response: (%s). Detail: %s' % (str(error), traceback.format_exc())
def get_valid_location(module, driver, location, location_type='zone'):
if location_type == 'zone':
l = driver.ex_get_zone(location)
else:
l = driver.ex_get_region(location)
if l is None:
link = 'https://cloud.google.com/compute/docs/regions-zones/regions-zones#available'
module.fail_json(msg=('%s %s is invalid. Please see the list of '
'available %s at %s' % (
location_type, location, location_type, link)),
changed=False)
return l