Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 78 changed files with 2,452 additions and 1,095 deletions.
45 changes: 33 additions & 12 deletions lib/ansible/modules/cloud/google/gcp_compute_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,24 @@
letter, and all following characters must be a dash, lowercase letter, or digit,
except the last character, which cannot be a dash.
required: true
network_tier:
description:
- 'The networking tier used for configuring this address. This field can take the
following values: PREMIUM or STANDARD. If this field is not specified, it is assumed
to be PREMIUM.'
required: false
version_added: 2.8
choices: ['PREMIUM', 'STANDARD']
subnetwork:
description:
- The URL of the subnetwork in which to reserve the address. If an IP address is specified,
it must be within the subnetwork's IP range.
- This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER purposes.
- 'This field represents a link to a Subnetwork resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_subnetwork
task and then set this subnetwork field to "{{ name-of-resource }}" Alternatively,
you can set this subnetwork to a dictionary with the selfLink key where the value
is the selfLink of your Subnetwork.'
required: false
version_added: 2.7
region:
Expand All @@ -106,7 +119,7 @@
name: test-address1
region: us-west1
project: "test_project"
auth_kind: "service_account"
auth_kind: "serviceaccount"
service_account_file: "/tmp/auth.pem"
state: present
'''
Expand All @@ -119,13 +132,13 @@
be inside the specified subnetwork, if any.
returned: success
type: str
address_type:
addressType:
description:
- The type of address to reserve, either INTERNAL or EXTERNAL.
- If unspecified, defaults to EXTERNAL.
returned: success
type: str
creation_timestamp:
creationTimestamp:
description:
- Creation timestamp in RFC3339 text format.
returned: success
Expand All @@ -149,6 +162,13 @@
except the last character, which cannot be a dash.
returned: success
type: str
networkTier:
description:
- 'The networking tier used for configuring this address. This field can take the
following values: PREMIUM or STANDARD. If this field is not specified, it is assumed
to be PREMIUM.'
returned: success
type: str
subnetwork:
description:
- The URL of the subnetwork in which to reserve the address. If an IP address is specified,
Expand Down Expand Up @@ -192,6 +212,7 @@ def main():
address_type=dict(default='EXTERNAL', type='str', choices=['INTERNAL', 'EXTERNAL']),
description=dict(type='str'),
name=dict(required=True, type='str'),
network_tier=dict(type='str', choices=['PREMIUM', 'STANDARD']),
subnetwork=dict(type='dict'),
region=dict(required=True, type='str')
)
Expand All @@ -209,7 +230,8 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
update(module, self_link(module), kind)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
delete(module, self_link(module), kind)
Expand All @@ -233,8 +255,7 @@ def create(module, link, kind):


def update(module, link, kind):
auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
module.fail_json(msg="Address cannot be edited")


def delete(module, link, kind):
Expand All @@ -249,6 +270,7 @@ def resource_to_request(module):
u'addressType': module.params.get('address_type'),
u'description': module.params.get('description'),
u'name': module.params.get('name'),
u'networkTier': module.params.get('network_tier'),
u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink')
}
return_vals = {}
Expand All @@ -259,9 +281,9 @@ def resource_to_request(module):
return return_vals


def fetch_resource(module, link, kind):
def fetch_resource(module, link, kind, allow_not_found=True):
auth = GcpSession(module, 'compute')
return return_if_object(module, auth.get(link), kind)
return return_if_object(module, auth.get(link), kind, allow_not_found)


def self_link(module):
Expand All @@ -272,9 +294,9 @@ def collection(module):
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/addresses".format(**module.params)


def return_if_object(module, response, kind):
def return_if_object(module, response, kind, allow_not_found=False):
# If not found, return nothing.
if response.status_code == 404:
if allow_not_found and response.status_code == 404:
return None

# If no content, return nothing.
Expand All @@ -289,8 +311,6 @@ def return_if_object(module, response, kind):

if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
if result['kind'] != kind:
module.fail_json(msg="Incorrect result: {kind}".format(**result))

return result

Expand Down Expand Up @@ -323,6 +343,7 @@ def response_to_hash(module, response):
u'description': response.get(u'description'),
u'id': response.get(u'id'),
u'name': response.get(u'name'),
u'networkTier': response.get(u'networkTier'),
u'subnetwork': response.get(u'subnetwork'),
u'users': response.get(u'users')
}
Expand Down
13 changes: 10 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_compute_address_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
filters:
- name = test_object
project: test_project
auth_kind: service_account
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
'''

Expand All @@ -79,13 +79,13 @@
be inside the specified subnetwork, if any.
returned: success
type: str
address_type:
addressType:
description:
- The type of address to reserve, either INTERNAL or EXTERNAL.
- If unspecified, defaults to EXTERNAL.
returned: success
type: str
creation_timestamp:
creationTimestamp:
description:
- Creation timestamp in RFC3339 text format.
returned: success
Expand All @@ -109,6 +109,13 @@
except the last character, which cannot be a dash.
returned: success
type: str
networkTier:
description:
- 'The networking tier used for configuring this address. This field can take the
following values: PREMIUM or STANDARD. If this field is not specified, it is assumed
to be PREMIUM.'
returned: success
type: str
subnetwork:
description:
- The URL of the subnetwork in which to reserve the address. If an IP address is specified,
Expand Down
21 changes: 10 additions & 11 deletions lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@
description: A BackendBucket to connect LNB w/ Storage Bucket
enable_cdn: true
project: "test_project"
auth_kind: "service_account"
auth_kind: "serviceaccount"
service_account_file: "/tmp/auth.pem"
state: present
'''

RETURN = '''
bucket_name:
bucketName:
description:
- Cloud Storage bucket name.
returned: success
type: str
creation_timestamp:
creationTimestamp:
description:
- Creation timestamp in RFC3339 text format.
returned: success
Expand All @@ -118,7 +118,7 @@
resource is created.
returned: success
type: str
enable_cdn:
enableCdn:
description:
- If true, enable Cloud CDN for this BackendBucket.
returned: success
Expand Down Expand Up @@ -178,7 +178,8 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
update(module, self_link(module), kind)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
delete(module, self_link(module), kind)
Expand Down Expand Up @@ -227,9 +228,9 @@ def resource_to_request(module):
return return_vals


def fetch_resource(module, link, kind):
def fetch_resource(module, link, kind, allow_not_found=True):
auth = GcpSession(module, 'compute')
return return_if_object(module, auth.get(link), kind)
return return_if_object(module, auth.get(link), kind, allow_not_found)


def self_link(module):
Expand All @@ -240,9 +241,9 @@ def collection(module):
return "https://www.googleapis.com/compute/v1/projects/{project}/global/backendBuckets".format(**module.params)


def return_if_object(module, response, kind):
def return_if_object(module, response, kind, allow_not_found=False):
# If not found, return nothing.
if response.status_code == 404:
if allow_not_found and response.status_code == 404:
return None

# If no content, return nothing.
Expand All @@ -257,8 +258,6 @@ def return_if_object(module, response, kind):

if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
if result['kind'] != kind:
module.fail_json(msg="Incorrect result: {kind}".format(**result))

return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
filters:
- name = test_object
project: test_project
auth_kind: service_account
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
'''

Expand All @@ -66,12 +66,12 @@
returned: always
type: complex
contains:
bucket_name:
bucketName:
description:
- Cloud Storage bucket name.
returned: success
type: str
creation_timestamp:
creationTimestamp:
description:
- Creation timestamp in RFC3339 text format.
returned: success
Expand All @@ -82,7 +82,7 @@
resource is created.
returned: success
type: str
enable_cdn:
enableCdn:
description:
- If true, enable Cloud CDN for this BackendBucket.
returned: success
Expand Down Expand Up @@ -118,7 +118,7 @@
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
filters=dict(type='list', elements='str')
)
)

Expand Down
Loading

0 comments on commit 18a088c

Please sign in to comment.