mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-05 18:30:27 -07:00
Spanner Fixes (#301)
Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
parent
a29f611cf6
commit
72e4cc7214
7 changed files with 47 additions and 14 deletions
|
@ -1139,7 +1139,7 @@ def wait_for_operation(module, response):
|
|||
return {}
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
wait_done = wait_for_completion(status, op_result, module)
|
||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instance')
|
||||
return decode_response(fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instance'), module)
|
||||
|
||||
|
||||
def wait_for_completion(status, op_result, module):
|
||||
|
|
|
@ -1058,7 +1058,7 @@ def wait_for_operation(module, response):
|
|||
return {}
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
wait_done = wait_for_completion(status, op_result, module)
|
||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instanceTemplate')
|
||||
return decode_response(fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instanceTemplate'), module)
|
||||
|
||||
|
||||
def wait_for_completion(status, op_result, module):
|
||||
|
|
|
@ -410,7 +410,7 @@ def wait_for_operation(module, response):
|
|||
return {}
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
wait_done = wait_for_completion(status, op_result, module)
|
||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetPool')
|
||||
return decode_response(fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetPool'), module)
|
||||
|
||||
|
||||
def wait_for_completion(status, op_result, module):
|
||||
|
|
|
@ -127,6 +127,7 @@ instance:
|
|||
|
||||
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict
|
||||
import json
|
||||
import time
|
||||
|
||||
################################################################################
|
||||
# Main
|
||||
|
@ -177,7 +178,7 @@ def main():
|
|||
|
||||
def create(module, link):
|
||||
auth = GcpSession(module, 'spanner')
|
||||
return return_if_object(module, auth.post(link, resource_to_request(module)))
|
||||
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||
|
||||
|
||||
def update(module, link):
|
||||
|
@ -191,11 +192,7 @@ def delete(module, link):
|
|||
|
||||
|
||||
def resource_to_request(module):
|
||||
request = {
|
||||
u'instance': replace_resource_dict(module.params.get(u'instance', {}), 'name'),
|
||||
u'name': module.params.get('name'),
|
||||
u'extraStatements': module.params.get('extra_statements'),
|
||||
}
|
||||
request = {u'name': module.params.get('name'), u'extraStatements': module.params.get('extra_statements')}
|
||||
request = encode_request(request, module)
|
||||
return_vals = {}
|
||||
for k, v in request.items():
|
||||
|
@ -268,6 +265,42 @@ def response_to_hash(module, response):
|
|||
return {u'name': module.params.get('name'), u'extraStatements': module.params.get('extra_statements')}
|
||||
|
||||
|
||||
def async_op_url(module, extra_data=None):
|
||||
if extra_data is None:
|
||||
extra_data = {}
|
||||
url = "https://spanner.googleapis.com/v1/{op_id}"
|
||||
combined = extra_data.copy()
|
||||
combined.update(module.params)
|
||||
return url.format(**combined)
|
||||
|
||||
|
||||
def wait_for_operation(module, response):
|
||||
op_result = return_if_object(module, response)
|
||||
if op_result is None:
|
||||
return {}
|
||||
status = navigate_hash(op_result, ['done'])
|
||||
wait_done = wait_for_completion(status, op_result, module)
|
||||
raise_if_errors(op_result, ['error'], module)
|
||||
return navigate_hash(wait_done, ['response'])
|
||||
|
||||
|
||||
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 not status:
|
||||
raise_if_errors(op_result, ['error'], module)
|
||||
time.sleep(1.0)
|
||||
op_result = fetch_resource(module, op_uri, False)
|
||||
status = navigate_hash(op_result, ['done'])
|
||||
return op_result
|
||||
|
||||
|
||||
def raise_if_errors(response, err_path, module):
|
||||
errors = navigate_hash(response, err_path)
|
||||
if errors is not None:
|
||||
module.fail_json(msg=errors)
|
||||
|
||||
|
||||
def decode_response(response, module):
|
||||
if not response:
|
||||
return response
|
||||
|
|
|
@ -202,7 +202,7 @@ def update(module, link):
|
|||
|
||||
def delete(module, link):
|
||||
auth = GcpSession(module, 'spanner')
|
||||
return wait_for_operation(module, auth.delete(link))
|
||||
return return_if_object(module, auth.delete(link))
|
||||
|
||||
|
||||
def resource_to_request(module):
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'webstore' in \"{{ results['resources'] | map(attribute='name') | list }}\""
|
||||
- results['resources'] | map(attribute='name') | select("match", ".*webstore.*") | list | length == 1
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: create a database that already exists
|
||||
gcp_spanner_database:
|
||||
|
@ -101,7 +101,7 @@
|
|||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'webstore' not in \"{{ results['resources'] | map(attribute='name') | list }}\""
|
||||
- results['resources'] | map(attribute='name') | select("match", ".*webstore.*") | list | length == 0
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: delete a database that does not exist
|
||||
gcp_spanner_database:
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- "\"{{resource_name}}\" in \"{{ results['resources'] | map(attribute='name') | list }}\""
|
||||
- results['resources'] | map(attribute='name') | select("match", ".*testinstance.*") | list | length == 1
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: create a instance that already exists
|
||||
gcp_spanner_instance:
|
||||
|
@ -102,7 +102,7 @@
|
|||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- "\"{{resource_name}}\" not in \"{{ results['resources'] | map(attribute='name') | list }}\""
|
||||
- results['resources'] | map(attribute='name') | select("match", ".*testinstance.*") | list | length == 0
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: delete a instance that does not exist
|
||||
gcp_spanner_instance:
|
||||
|
|
Loading…
Add table
Reference in a new issue