From bfb2114f39fbe861eaa89f65fadec8fb79f4ffff Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Thu, 14 Jun 2018 18:29:50 +0000 Subject: [PATCH] Add description field to Route resource, make non-updateable. --- plugins/modules/gcp_compute_route.py | 77 +++++++++++++++------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/plugins/modules/gcp_compute_route.py b/plugins/modules/gcp_compute_route.py index 0053d8c..baa2b74 100644 --- a/plugins/modules/gcp_compute_route.py +++ b/plugins/modules/gcp_compute_route.py @@ -86,9 +86,10 @@ options: description: - The network that this route applies to. - 'This field represents a link to a Network resource in GCP. It can be specified - in two ways. First, you can place in the selfLink of the resource here as a - string Alternatively, you can add `register: name-of-resource` to a gcp_compute_network - task and then set this network field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''selfLink'' and value + of your resource''s selfLink Alternatively, you can add `register: name-of-resource` + to a gcp_compute_network task and then set this network field to "{{ name-of-resource + }}"' required: true priority: description: @@ -117,9 +118,10 @@ options: instances/instance * projects/project/zones/zone/instances/instance * zones/zone/instances/instance .' - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. First, you can place in the selfLink of the resource here as a - string Alternatively, you can add `register: name-of-resource` to a gcp_compute_instance - task and then set this next_hop_instance field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''selfLink'' and value + of your resource''s selfLink Alternatively, you can add `register: name-of-resource` + to a gcp_compute_instance task and then set this next_hop_instance field to + "{{ name-of-resource }}"' required: false next_hop_ip: description: @@ -129,9 +131,10 @@ options: description: - URL to a VpnTunnel that should handle matching packets. - 'This field represents a link to a VpnTunnel resource in GCP. It can be specified - in two ways. First, you can place in the selfLink of the resource here as a - string Alternatively, you can add `register: name-of-resource` to a gcp_compute_vpn_tunnel - task and then set this next_hop_vpn_tunnel field to "{{ name-of-resource }}"' + in two ways. First, you can place a dictionary with key ''selfLink'' and value + of your resource''s selfLink Alternatively, you can add `register: name-of-resource` + to a gcp_compute_vpn_tunnel task and then set this next_hop_vpn_tunnel field + to "{{ name-of-resource }}"' required: false extends_documentation_fragment: gcp notes: @@ -142,26 +145,26 @@ notes: EXAMPLES = ''' - name: create a network gcp_compute_network: - name: "network-route" - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: present + name: network-route + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present register: network - name: create a route gcp_compute_route: - name: "test_object" - dest_range: 192.168.6.0/24 - next_hop_gateway: global/gateways/default-internet-gateway - network: "{{ network }}" - tags: - - backends - - databases - project: "test_project" - auth_kind: "serviceaccount" - service_account_file: "/tmp/auth.pem" - state: present + name: test_object + dest_range: 192.168.6.0/24 + next_hop_gateway: global/gateways/default-internet-gateway + network: "{{ network }}" + tags: + - backends + - databases + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" + state: present ''' RETURN = ''' @@ -191,7 +194,7 @@ network: description: - The network that this route applies to. returned: success - type: str + type: dict priority: description: - The priority of this route. Priority is used to break ties in cases where there @@ -222,7 +225,7 @@ nextHopInstance: instances/instance * projects/project/zones/zone/instances/instance * zones/zone/instances/instance .' returned: success - type: str + type: dict nextHopIp: description: - Network IP address of an instance that should handle matching packets. @@ -232,7 +235,7 @@ nextHopVpnTunnel: description: - URL to a VpnTunnel that should handle matching packets. returned: success - type: str + type: dict nextHopNetwork: description: - URL to a Network that should handle matching packets. @@ -262,13 +265,13 @@ def main(): dest_range=dict(required=True, type='str'), description=dict(type='str'), name=dict(required=True, type='str'), - network=dict(required=True), + network=dict(required=True, type='dict'), priority=dict(type='int'), tags=dict(type='list', elements='str'), next_hop_gateway=dict(type='str'), - next_hop_instance=dict(), + next_hop_instance=dict(type='dict'), next_hop_ip=dict(type='str'), - next_hop_vpn_tunnel=dict(), + next_hop_vpn_tunnel=dict(type='dict'), ) ) @@ -284,11 +287,10 @@ def main(): if fetch: if state == 'present': if is_different(module, fetch): - update(module, self_link(module), kind) - fetch = fetch_resource(module, self_link(module), kind) + fetch = update(module, self_link(module), kind, fetch) changed = True else: - delete(module, self_link(module), kind) + delete(module, self_link(module), kind, fetch) fetch = {} changed = True else: @@ -308,11 +310,12 @@ def create(module, link, kind): return wait_for_operation(module, auth.post(link, resource_to_request(module))) -def update(module, link, kind): - module.fail_json(msg="Route cannot be edited") +def update(module, link, kind, fetch): + auth = GcpSession(module, 'compute') + return wait_for_operation(module, auth.put(link, resource_to_request(module))) -def delete(module, link, kind): +def delete(module, link, kind, fetch): auth = GcpSession(module, 'compute') return wait_for_operation(module, auth.delete(link))