mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-06 02:40:29 -07:00
Converting names from short-name to partial URIs (#277)
Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
parent
5f262e2eb2
commit
71accbf571
11 changed files with 33 additions and 20 deletions
|
@ -615,7 +615,7 @@ def response_to_hash(module, response):
|
|||
def disk_type_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/[a-z1-9\-]*/diskTypes/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/.*/diskTypes/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/diskTypes/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -309,7 +309,7 @@ def response_to_hash(module, response):
|
|||
def region_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/regions/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -617,7 +617,7 @@ def response_to_hash(module, response):
|
|||
def license_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1//projects/.*/global/licenses/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1//projects/.*/global/licenses/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1//projects/{project}/global/licenses/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -1109,7 +1109,7 @@ def response_to_hash(module, response):
|
|||
def disk_type_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/[a-z1-9\-]*/diskTypes/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/.*/diskTypes/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/diskTypes/%s".format(**params) % name
|
||||
return name
|
||||
|
@ -1118,7 +1118,7 @@ def disk_type_selflink(name, params):
|
|||
def machine_type_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/[a-z1-9\-]*/machineTypes/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/.*/machineTypes/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/machineTypes/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -386,7 +386,7 @@ def response_to_hash(module, response):
|
|||
def region_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/regions/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -487,7 +487,7 @@ def response_to_hash(module, response):
|
|||
def region_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/regions/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -1037,7 +1037,7 @@ def response_to_hash(module, response):
|
|||
def disk_type_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/[a-z1-9\-]*/diskTypes/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/.*/diskTypes/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/diskTypes/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -435,7 +435,7 @@ def response_to_hash(module, response):
|
|||
def region_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/regions/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -527,7 +527,7 @@ def response_to_hash(module, response):
|
|||
def zone_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/zones/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/zones/%s".format(**params) % name
|
||||
return name
|
||||
|
@ -536,7 +536,7 @@ def zone_selflink(name, params):
|
|||
def region_disk_type_selflink(name, params):
|
||||
if name is None:
|
||||
return
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/{region}/diskTypes/[a-z1-9\-]*"
|
||||
url = r"https://www.googleapis.com/compute/v1/projects/.*/regions/.*/diskTypes/.*"
|
||||
if not re.match(url, name):
|
||||
name = "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/diskTypes/%s".format(**params) % name
|
||||
return name
|
||||
|
|
|
@ -62,7 +62,7 @@ notes:
|
|||
EXAMPLES = '''
|
||||
- name: create a repository
|
||||
gcp_sourcerepo_repository:
|
||||
name: projects/test_project/repos/test_object
|
||||
name: test_object
|
||||
project: test_project
|
||||
auth_kind: serviceaccount
|
||||
service_account_file: "/tmp/auth.pem"
|
||||
|
@ -95,6 +95,7 @@ size:
|
|||
|
||||
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict
|
||||
import json
|
||||
import re
|
||||
|
||||
################################################################################
|
||||
# Main
|
||||
|
@ -152,7 +153,7 @@ def delete(module, link):
|
|||
|
||||
|
||||
def resource_to_request(module):
|
||||
request = {u'name': module.params.get('name')}
|
||||
request = {u'name': name_partial_to_full(module.params.get('name'), module.params)}
|
||||
return_vals = {}
|
||||
for k, v in request.items():
|
||||
if v or v is False:
|
||||
|
@ -167,7 +168,7 @@ def fetch_resource(module, link, allow_not_found=True):
|
|||
|
||||
|
||||
def self_link(module):
|
||||
return "https://sourcerepo.googleapis.com/v1/{name}".format(**module.params)
|
||||
return "https://sourcerepo.googleapis.com/v1/projects/{project}/repos/{name}".format(**module.params)
|
||||
|
||||
|
||||
def collection(module):
|
||||
|
@ -216,7 +217,19 @@ def is_different(module, response):
|
|||
# Remove unnecessary properties from the response.
|
||||
# This is for doing comparisons with Ansible's current parameters.
|
||||
def response_to_hash(module, response):
|
||||
return {u'name': module.params.get('name'), u'url': response.get(u'url'), u'size': response.get(u'size')}
|
||||
return {u'name': name_partial_to_full(module.params.get('name'), module.params), u'url': response.get(u'url'), u'size': response.get(u'size')}
|
||||
|
||||
|
||||
def name_partial_to_full(name, params):
|
||||
if name is None:
|
||||
return
|
||||
|
||||
url = r"projects/.*/repos/.*"
|
||||
|
||||
if not re.match(url, name):
|
||||
name = "projects/{project}/repos/{name}".format(**params)
|
||||
|
||||
return name
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# Pre-test setup
|
||||
- name: delete a repository
|
||||
gcp_sourcerepo_repository:
|
||||
name: projects/{{ gcp_project }}/repos/{{ resource_name }}
|
||||
name: "{{ resource_name }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -23,7 +23,7 @@
|
|||
#----------------------------------------------------------
|
||||
- name: create a repository
|
||||
gcp_sourcerepo_repository:
|
||||
name: projects/{{ gcp_project }}/repos/{{ resource_name }}
|
||||
name: "{{ resource_name }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -48,7 +48,7 @@
|
|||
# ----------------------------------------------------------------------------
|
||||
- name: create a repository that already exists
|
||||
gcp_sourcerepo_repository:
|
||||
name: projects/{{ gcp_project }}/repos/{{ resource_name }}
|
||||
name: "{{ resource_name }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -61,7 +61,7 @@
|
|||
#----------------------------------------------------------
|
||||
- name: delete a repository
|
||||
gcp_sourcerepo_repository:
|
||||
name: projects/{{ gcp_project }}/repos/{{ resource_name }}
|
||||
name: "{{ resource_name }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
@ -86,7 +86,7 @@
|
|||
# ----------------------------------------------------------------------------
|
||||
- name: delete a repository that does not exist
|
||||
gcp_sourcerepo_repository:
|
||||
name: projects/{{ gcp_project }}/repos/{{ resource_name }}
|
||||
name: "{{ resource_name }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
|
|
Loading…
Add table
Reference in a new issue