Bug fixes for GCP modules (as of 2019-01-22T12:43:52-08:00) (#51245)

This commit is contained in:
Alex Stephen 2019-01-23 13:45:40 -08:00
parent a81d110422
commit 6c246c99d6
24 changed files with 660 additions and 869 deletions

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -216,11 +215,9 @@ def main():
ipv4_range=dict(type='str'),
name=dict(required=True, type='str'),
auto_create_subnetworks=dict(type='bool'),
routing_config=dict(type='dict', options=dict(
routing_mode=dict(required=True, type='str', choices=['REGIONAL', 'GLOBAL'])
))
routing_config=dict(type='dict', options=dict(routing_mode=dict(required=True, type='str', choices=['REGIONAL', 'GLOBAL']))),
),
mutually_exclusive=[['auto_create_subnetworks', 'ipv4_range']]
mutually_exclusive=[['auto_create_subnetworks', 'ipv4_range']],
)
if not module.params['scopes']:
@ -276,7 +273,7 @@ def resource_to_request(module):
u'IPv4Range': module.params.get('ipv4_range'),
u'name': module.params.get('name'),
u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'),
u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request()
u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request(),
}
return_vals = {}
for k, v in request.items():
@ -311,8 +308,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -350,7 +347,7 @@ def response_to_hash(module, response):
u'subnetworks': response.get(u'subnetworks'),
u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'),
u'creationTimestamp': response.get(u'creationTimestamp'),
u'routingConfig': NetworkRoutingconfig(response.get(u'routingConfig', {}), module).from_response()
u'routingConfig': NetworkRoutingconfig(response.get(u'routingConfig', {}), module).from_response(),
}
@ -376,7 +373,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -398,14 +395,10 @@ class NetworkRoutingconfig(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'routingMode': self.request.get('routing_mode')
})
return remove_nones_from_dict({u'routingMode': self.request.get('routing_mode')})
def from_response(self):
return remove_nones_from_dict({
u'routingMode': self.request.get(u'routingMode')
})
return remove_nones_from_dict({u'routingMode': self.request.get(u'routingMode')})
if __name__ == '__main__':