From 57afbc75fff3aef5d1fb4f5e5dc4ad856a318100 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 31 Jan 2019 09:54:33 -0800 Subject: [PATCH] Changing NodePool from Zone to Location (#182) /cc @rambleraptor --- .../cloud/google/gcp_container_cluster.py | 5 +++- .../google/gcp_container_cluster_facts.py | 4 ++- .../cloud/google/gcp_container_node_pool.py | 26 +++++++++++-------- .../google/gcp_container_node_pool_facts.py | 20 ++++++++------ .../gcp_container_node_pool/tasks/main.yml | 18 ++++++------- 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster.py b/lib/ansible/modules/cloud/google/gcp_container_cluster.py index e0f8726ccc51a6..36e12dbbd45c72 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster.py @@ -256,6 +256,9 @@ description: - The location where the cluster is deployed. required: true + aliases: + - zone + version_added: 2.8 extends_documentation_fragment: gcp ''' @@ -622,7 +625,7 @@ def main(): ), ), subnetwork=dict(type='str'), - location=dict(required=True, type='str'), + location=dict(required=True, type='str', aliases=['zone']), ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py b/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py index 5f5f1d754fdf0c..67fe06fbff85a4 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py @@ -45,7 +45,9 @@ - The location where the cluster is deployed. required: true aliases: + - region - zone + version_added: 2.8 extends_documentation_fragment: gcp ''' @@ -362,7 +364,7 @@ def main(): - module = GcpModule(argument_spec=dict(location=dict(required=True, type='str', aliases=['zone']))) + 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'] diff --git a/lib/ansible/modules/cloud/google/gcp_container_node_pool.py b/lib/ansible/modules/cloud/google/gcp_container_node_pool.py index 1619ebbca7f9e8..a635a4bf0d123b 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_node_pool.py +++ b/lib/ansible/modules/cloud/google/gcp_container_node_pool.py @@ -207,10 +207,14 @@ 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 @@ 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 @@ 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 @@ - 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): diff --git a/lib/ansible/modules/cloud/google/gcp_container_node_pool_facts.py b/lib/ansible/modules/cloud/google/gcp_container_node_pool_facts.py index 1ab26232cc03f1..33d4593a09ff97 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_node_pool_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_container_node_pool_facts.py @@ -40,10 +40,14 @@ - 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 @@ - 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 @@ - 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 @@ 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): diff --git a/test/integration/targets/gcp_container_node_pool/tasks/main.yml b/test/integration/targets/gcp_container_node_pool/tasks/main.yml index 9047ac40f644dd..775d6a4ffb826e 100644 --- a/test/integration/targets/gcp_container_node_pool/tasks/main.yml +++ b/test/integration/targets/gcp_container_node_pool/tasks/main.yml @@ -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 }}"