Bug fixes for GCP modules (#51574)
This commit is contained in:
parent
6a79468acf
commit
2b0f16443c
10 changed files with 69 additions and 62 deletions
|
@ -40,17 +40,21 @@ requirements:
|
|||
- requests >= 2.18.4
|
||||
- google-auth >= 1.3.0
|
||||
options:
|
||||
zone:
|
||||
location:
|
||||
description:
|
||||
- The zone where the cluster is deployed.
|
||||
- The location where the cluster is deployed.
|
||||
required: true
|
||||
aliases:
|
||||
- region
|
||||
- zone
|
||||
version_added: 2.8
|
||||
extends_documentation_fragment: gcp
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: a cluster facts
|
||||
gcp_container_cluster_facts:
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: test_project
|
||||
auth_kind: serviceaccount
|
||||
service_account_file: "/tmp/auth.pem"
|
||||
|
@ -65,7 +69,7 @@ items:
|
|||
name:
|
||||
description:
|
||||
- The name of this cluster. The name must be unique within this project and
|
||||
zone, and can be up to 40 characters. Must be Lowercase letters, numbers,
|
||||
location, and can be up to 40 characters. Must be Lowercase letters, numbers,
|
||||
and hyphens only. Must start with a letter. Must end with a number or a letter.
|
||||
returned: success
|
||||
type: str
|
||||
|
@ -288,12 +292,6 @@ items:
|
|||
- The name of the Google Compute Engine subnetwork to which the cluster is connected.
|
||||
returned: success
|
||||
type: str
|
||||
location:
|
||||
description:
|
||||
- The list of Google Compute Engine locations in which the cluster's nodes should
|
||||
be located.
|
||||
returned: success
|
||||
type: list
|
||||
endpoint:
|
||||
description:
|
||||
- The IP address of this cluster's master endpoint.
|
||||
|
@ -347,9 +345,9 @@ items:
|
|||
- The time the cluster will be automatically deleted in RFC3339 text format.
|
||||
returned: success
|
||||
type: str
|
||||
zone:
|
||||
location:
|
||||
description:
|
||||
- The zone where the cluster is deployed.
|
||||
- The location where the cluster is deployed.
|
||||
returned: success
|
||||
type: str
|
||||
'''
|
||||
|
@ -366,7 +364,7 @@ import json
|
|||
|
||||
|
||||
def main():
|
||||
module = GcpModule(argument_spec=dict(zone=dict(required=True, type='str')))
|
||||
module = GcpModule(argument_spec=dict(location=dict(required=True, type='str', aliases=['region', 'zone'])))
|
||||
|
||||
if not module.params['scopes']:
|
||||
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||
|
@ -381,7 +379,7 @@ def main():
|
|||
|
||||
|
||||
def collection(module):
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters".format(**module.params)
|
||||
return "https://container.googleapis.com/v1/projects/{project}/locations/{location}/clusters".format(**module.params)
|
||||
|
||||
|
||||
def fetch_list(module, link):
|
||||
|
|
|
@ -207,10 +207,14 @@ options:
|
|||
Alternatively, you can add `register: name-of-resource` to a gcp_container_cluster
|
||||
task and then set this cluster field to "{{ name-of-resource }}"'
|
||||
required: true
|
||||
zone:
|
||||
location:
|
||||
description:
|
||||
- The zone where the node pool is deployed.
|
||||
- The location where the node pool is deployed.
|
||||
required: true
|
||||
aliases:
|
||||
- region
|
||||
- zone
|
||||
version_added: 2.8
|
||||
extends_documentation_fragment: gcp
|
||||
'''
|
||||
|
||||
|
@ -219,7 +223,7 @@ EXAMPLES = '''
|
|||
gcp_container_cluster:
|
||||
name: "cluster-nodepool"
|
||||
initial_node_count: 4
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -231,7 +235,7 @@ EXAMPLES = '''
|
|||
name: my-pool
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "test_project"
|
||||
auth_kind: "serviceaccount"
|
||||
service_account_file: "/tmp/auth.pem"
|
||||
|
@ -415,9 +419,9 @@ cluster:
|
|||
- The cluster this node pool belongs to.
|
||||
returned: success
|
||||
type: str
|
||||
zone:
|
||||
location:
|
||||
description:
|
||||
- The zone where the node pool is deployed.
|
||||
- The location where the node pool is deployed.
|
||||
returned: success
|
||||
type: str
|
||||
'''
|
||||
|
@ -468,7 +472,7 @@ def main():
|
|||
),
|
||||
),
|
||||
cluster=dict(required=True),
|
||||
zone=dict(required=True, type='str'),
|
||||
location=dict(required=True, type='str', aliases=['region', 'zone']),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -542,16 +546,16 @@ def fetch_resource(module, link, allow_not_found=True):
|
|||
def self_link(module):
|
||||
res = {
|
||||
'project': module.params['project'],
|
||||
'zone': module.params['zone'],
|
||||
'location': module.params['location'],
|
||||
'cluster': replace_resource_dict(module.params['cluster'], 'name'),
|
||||
'name': module.params['name'],
|
||||
}
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools/{name}".format(**res)
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{location}/clusters/{cluster}/nodePools/{name}".format(**res)
|
||||
|
||||
|
||||
def collection(module):
|
||||
res = {'project': module.params['project'], 'zone': module.params['zone'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')}
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res)
|
||||
res = {'project': module.params['project'], 'location': module.params['location'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')}
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{location}/clusters/{cluster}/nodePools".format(**res)
|
||||
|
||||
|
||||
def return_if_object(module, response, allow_not_found=False):
|
||||
|
@ -630,7 +634,7 @@ def wait_for_completion(status, op_result, module):
|
|||
while status != 'DONE':
|
||||
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||
time.sleep(1.0)
|
||||
op_result = fetch_resource(module, op_uri)
|
||||
op_result = fetch_resource(module, op_uri, False)
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
return op_result
|
||||
|
||||
|
|
|
@ -40,10 +40,14 @@ requirements:
|
|||
- requests >= 2.18.4
|
||||
- google-auth >= 1.3.0
|
||||
options:
|
||||
zone:
|
||||
location:
|
||||
description:
|
||||
- The zone where the node pool is deployed.
|
||||
- The location where the node pool is deployed.
|
||||
required: true
|
||||
aliases:
|
||||
- region
|
||||
- zone
|
||||
version_added: 2.8
|
||||
cluster:
|
||||
description:
|
||||
- The cluster this node pool belongs to.
|
||||
|
@ -59,7 +63,7 @@ EXAMPLES = '''
|
|||
- name: a node pool facts
|
||||
gcp_container_node_pool_facts:
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: test_project
|
||||
auth_kind: serviceaccount
|
||||
service_account_file: "/tmp/auth.pem"
|
||||
|
@ -248,9 +252,9 @@ items:
|
|||
- The cluster this node pool belongs to.
|
||||
returned: success
|
||||
type: str
|
||||
zone:
|
||||
location:
|
||||
description:
|
||||
- The zone where the node pool is deployed.
|
||||
- The location where the node pool is deployed.
|
||||
returned: success
|
||||
type: str
|
||||
'''
|
||||
|
@ -267,7 +271,7 @@ import json
|
|||
|
||||
|
||||
def main():
|
||||
module = GcpModule(argument_spec=dict(zone=dict(required=True, type='str'), cluster=dict(required=True)))
|
||||
module = GcpModule(argument_spec=dict(location=dict(required=True, type='str', aliases=['region', 'zone']), cluster=dict(required=True)))
|
||||
|
||||
if not module.params['scopes']:
|
||||
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||
|
@ -282,8 +286,8 @@ def main():
|
|||
|
||||
|
||||
def collection(module):
|
||||
res = {'project': module.params['project'], 'zone': module.params['zone'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')}
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res)
|
||||
res = {'project': module.params['project'], 'location': module.params['location'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')}
|
||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{location}/clusters/{cluster}/nodePools".format(**res)
|
||||
|
||||
|
||||
def fetch_list(module, link):
|
||||
|
|
|
@ -123,7 +123,7 @@ def main():
|
|||
|
||||
def collection(module):
|
||||
res = {'project': module.params['project'], 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')}
|
||||
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets".format(**res)
|
||||
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**res)
|
||||
|
||||
|
||||
def fetch_list(module, link):
|
||||
|
|
|
@ -320,7 +320,7 @@ def decode_request(response, module):
|
|||
|
||||
|
||||
def encode_request(request, module):
|
||||
request['topic'] = '/'.join(['projects', module.params['project'], 'topics', module.params['topic']['name']])
|
||||
request['topic'] = '/'.join(['projects', module.params['project'], 'topics', request['topic']])
|
||||
request['name'] = '/'.join(['projects', module.params['project'], 'subscriptions', module.params['name']])
|
||||
|
||||
return request
|
||||
|
|
|
@ -305,7 +305,7 @@ def is_different(module, response):
|
|||
# This is for doing comparisons with Ansible's current parameters.
|
||||
def response_to_hash(module, response):
|
||||
return {
|
||||
u'projectNumber': response.get(u'number'),
|
||||
u'projectNumber': response.get(u'projectNumber'),
|
||||
u'lifecycleState': response.get(u'lifecycleState'),
|
||||
u'name': response.get(u'name'),
|
||||
u'createTime': response.get(u'createTime'),
|
||||
|
@ -336,10 +336,10 @@ def wait_for_operation(module, 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})
|
||||
if not status:
|
||||
while not status:
|
||||
raise_if_errors(op_result, ['error'], module)
|
||||
time.sleep(1.0)
|
||||
op_result = fetch_resource(module, op_uri)
|
||||
op_result = fetch_resource(module, op_uri, False)
|
||||
status = navigate_hash(op_result, ['done'])
|
||||
return op_result
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ notes:
|
|||
EXAMPLES = '''
|
||||
- name: create a instance
|
||||
gcp_spanner_instance:
|
||||
name: "test_object"
|
||||
name: testinstance
|
||||
display_name: My Spanner Instance
|
||||
node_count: 2
|
||||
labels:
|
||||
|
@ -291,7 +291,7 @@ def response_to_hash(module, response):
|
|||
def async_op_url(module, extra_data=None):
|
||||
if extra_data is None:
|
||||
extra_data = {}
|
||||
url = "https://spanner.googleapis.com/v1/projects/{project}/global/operations/{op_id}"
|
||||
url = "https://spanner.googleapis.com/v1/{op_id}"
|
||||
combined = extra_data.copy()
|
||||
combined.update(module.params)
|
||||
return url.format(**combined)
|
||||
|
@ -301,19 +301,20 @@ def wait_for_operation(module, response):
|
|||
op_result = return_if_object(module, response)
|
||||
if op_result is None:
|
||||
return {}
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
status = navigate_hash(op_result, ['done'])
|
||||
wait_done = wait_for_completion(status, op_result, module)
|
||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']))
|
||||
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 status != 'DONE':
|
||||
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||
while not status:
|
||||
raise_if_errors(op_result, ['error'], module)
|
||||
time.sleep(1.0)
|
||||
op_result = fetch_resource(module, op_uri)
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
op_result = fetch_resource(module, op_uri, False)
|
||||
status = navigate_hash(op_result, ['done'])
|
||||
return op_result
|
||||
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ def wait_for_completion(status, op_result, module):
|
|||
while status != 'DONE':
|
||||
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||
time.sleep(1.0)
|
||||
op_result = fetch_resource(module, op_uri, 'sql#operation')
|
||||
op_result = fetch_resource(module, op_uri, 'sql#operation', False)
|
||||
status = navigate_hash(op_result, ['status'])
|
||||
return op_result
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
gcp_container_cluster:
|
||||
name: "cluster-nodepool"
|
||||
initial_node_count: 4
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -28,7 +28,7 @@
|
|||
name: my-pool
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -39,7 +39,7 @@
|
|||
name: my-pool
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -52,7 +52,7 @@
|
|||
- name: verify that node_pool was created
|
||||
gcp_container_node_pool_facts:
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -69,7 +69,7 @@
|
|||
name: my-pool
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -85,7 +85,7 @@
|
|||
name: my-pool
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -98,7 +98,7 @@
|
|||
- name: verify that node_pool was deleted
|
||||
gcp_container_node_pool_facts:
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -115,7 +115,7 @@
|
|||
name: my-pool
|
||||
initial_node_count: 4
|
||||
cluster: "{{ cluster }}"
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -132,7 +132,7 @@
|
|||
gcp_container_cluster:
|
||||
name: "cluster-nodepool"
|
||||
initial_node_count: 4
|
||||
zone: us-central1-a
|
||||
location: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# Pre-test setup
|
||||
- name: delete a instance
|
||||
gcp_spanner_instance:
|
||||
name: "{{ resource_name }}"
|
||||
name: testinstance
|
||||
display_name: My Spanner Instance
|
||||
node_count: 2
|
||||
labels:
|
||||
|
@ -28,7 +28,7 @@
|
|||
#----------------------------------------------------------
|
||||
- name: create a instance
|
||||
gcp_spanner_instance:
|
||||
name: "{{ resource_name }}"
|
||||
name: testinstance
|
||||
display_name: My Spanner Instance
|
||||
node_count: 2
|
||||
labels:
|
||||
|
@ -58,7 +58,7 @@
|
|||
# ----------------------------------------------------------------------------
|
||||
- name: create a instance that already exists
|
||||
gcp_spanner_instance:
|
||||
name: "{{ resource_name }}"
|
||||
name: testinstance
|
||||
display_name: My Spanner Instance
|
||||
node_count: 2
|
||||
labels:
|
||||
|
@ -76,7 +76,7 @@
|
|||
#----------------------------------------------------------
|
||||
- name: delete a instance
|
||||
gcp_spanner_instance:
|
||||
name: "{{ resource_name }}"
|
||||
name: testinstance
|
||||
display_name: My Spanner Instance
|
||||
node_count: 2
|
||||
labels:
|
||||
|
@ -106,7 +106,7 @@
|
|||
# ----------------------------------------------------------------------------
|
||||
- name: delete a instance that does not exist
|
||||
gcp_spanner_instance:
|
||||
name: "{{ resource_name }}"
|
||||
name: testinstance
|
||||
display_name: My Spanner Instance
|
||||
node_count: 2
|
||||
labels:
|
||||
|
|
Loading…
Reference in a new issue