mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-07-26 22:51:30 -07:00
Bug fixes for GCP modules (as of 2019-01-22T12:43:52-08:00) (#51245)
This commit is contained in:
parent
a81d110422
commit
6c246c99d6
24 changed files with 660 additions and 869 deletions
|
@ -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 = '''
|
||||
---
|
||||
|
@ -238,15 +237,12 @@ def main():
|
|||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||
description=dict(type='str'),
|
||||
name=dict(type='str'),
|
||||
named_ports=dict(type='list', elements='dict', options=dict(
|
||||
name=dict(type='str'),
|
||||
port=dict(type='int')
|
||||
)),
|
||||
named_ports=dict(type='list', elements='dict', options=dict(name=dict(type='str'), port=dict(type='int'))),
|
||||
network=dict(),
|
||||
region=dict(type='str'),
|
||||
subnetwork=dict(),
|
||||
zone=dict(required=True, type='str'),
|
||||
instances=dict(type='list')
|
||||
instances=dict(type='list'),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -308,7 +304,7 @@ def resource_to_request(module):
|
|||
u'namedPorts': InstanceGroupNamedportsArray(module.params.get('named_ports', []), module).to_request(),
|
||||
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
|
||||
u'region': region_selflink(module.params.get('region'), module.params),
|
||||
u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink')
|
||||
u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink'),
|
||||
}
|
||||
return_vals = {}
|
||||
for k, v in request.items():
|
||||
|
@ -343,8 +339,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']))
|
||||
|
@ -381,7 +377,7 @@ def response_to_hash(module, response):
|
|||
u'namedPorts': InstanceGroupNamedportsArray(response.get(u'namedPorts', []), module).from_response(),
|
||||
u'network': response.get(u'network'),
|
||||
u'region': response.get(u'region'),
|
||||
u'subnetwork': response.get(u'subnetwork')
|
||||
u'subnetwork': response.get(u'subnetwork'),
|
||||
}
|
||||
|
||||
|
||||
|
@ -416,7 +412,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'])
|
||||
|
@ -454,8 +450,7 @@ class InstanceLogic(object):
|
|||
|
||||
def list_instances(self):
|
||||
auth = GcpSession(self.module, 'compute')
|
||||
response = return_if_object(self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}),
|
||||
'compute#instanceGroupsListInstances')
|
||||
response = return_if_object(self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}), 'compute#instanceGroupsListInstances')
|
||||
|
||||
# Transform instance list into a list of selfLinks for diffing with module parameters
|
||||
instances = []
|
||||
|
@ -481,9 +476,7 @@ class InstanceLogic(object):
|
|||
return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroups/{name}/addInstances".format(**self.module.params)
|
||||
|
||||
def _build_request(self, instances):
|
||||
request = {
|
||||
'instances': []
|
||||
}
|
||||
request = {'instances': []}
|
||||
for instance in instances:
|
||||
request['instances'].append({'instance': instance})
|
||||
return request
|
||||
|
@ -510,16 +503,10 @@ class InstanceGroupNamedportsArray(object):
|
|||
return items
|
||||
|
||||
def _request_for_item(self, item):
|
||||
return remove_nones_from_dict({
|
||||
u'name': item.get('name'),
|
||||
u'port': item.get('port')
|
||||
})
|
||||
return remove_nones_from_dict({u'name': item.get('name'), u'port': item.get('port')})
|
||||
|
||||
def _response_from_item(self, item):
|
||||
return remove_nones_from_dict({
|
||||
u'name': item.get(u'name'),
|
||||
u'port': item.get(u'port')
|
||||
})
|
||||
return remove_nones_from_dict({u'name': item.get(u'name'), u'port': item.get(u'port')})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue