Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Partial updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rambleraptor authored and modular-magician committed Aug 17, 2018
1 parent faf7194 commit d5cfd99
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 29 deletions.
49 changes: 46 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_compute_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@
'''

RETURN = '''
label_fingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally during
updates.
returned: success
type: str
creation_timestamp:
description:
- Creation timestamp in RFC3339 text format.
Expand Down Expand Up @@ -427,7 +433,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
fetch = update(module, self_link(module), kind, fetch)
changed = True
else:
delete(module, self_link(module), kind)
Expand All @@ -450,8 +456,44 @@ 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="Disk cannot be edited")
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
if response.get('labels') != request.get('labels'):
label_fingerprint_update(module, request, response)
if response.get('sizeGb') != request.get('sizeGb'):
size_gb_update(module, request, response)


def label_fingerprint_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/zones/{zone}/disks/{name}/setLabels"
]).format(**module.params),
{
u'labelFingerprint': response.get('labelFingerprint'),
u'labels': module.params.get('labels')
}
)


def size_gb_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/zones/{zone}/disks/{name}/resize"
]).format(**module.params),
{
u'sizeGb': module.params.get('size_gb')
}
)


def delete(module, link, kind):
Expand Down Expand Up @@ -539,6 +581,7 @@ def is_different(module, response):
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'labelFingerprint': response.get(u'labelFingerprint'),
u'creationTimestamp': response.get(u'creationTimestamp'),
u'description': response.get(u'description'),
u'id': response.get(u'id'),
Expand Down
6 changes: 6 additions & 0 deletions lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
returned: always
type: complex
contains:
label_fingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally during
updates.
returned: success
type: str
creation_timestamp:
description:
- Creation timestamp in RFC3339 text format.
Expand Down
48 changes: 44 additions & 4 deletions lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@
- This field is not used for internal load balancing.
returned: success
type: dict
label_fingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally during
updates.
returned: success
type: str
region:
description:
- A reference to the region where the regional forwarding rule resides.
Expand Down Expand Up @@ -386,7 +392,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
fetch = update(module, self_link(module), kind, fetch)
changed = True
else:
delete(module, self_link(module), kind)
Expand All @@ -409,8 +415,41 @@ 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="ForwardingRule cannot be edited")
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
if response.get('target') != request.get('target'):
target_update(module, request, response)


def target_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/regions/{region}/forwardingRules/{name}/setTarget"
]).format(**module.params),
{
u'target': replace_resource_dict(module.params.get(u'target', {}), 'selfLink')
}
)


def label_fingerprint_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/regions/{region}/forwardingRules/{name}/setLabels"
]).format(**module.params),
{
u'labelFingerprint': response.get('labelFingerprint')
}
)


def delete(module, link, kind):
Expand Down Expand Up @@ -513,7 +552,8 @@ def response_to_hash(module, response):
u'portRange': response.get(u'portRange'),
u'ports': response.get(u'ports'),
u'subnetwork': response.get(u'subnetwork'),
u'target': response.get(u'target')
u'target': response.get(u'target'),
u'labelFingerprint': response.get(u'labelFingerprint')
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@
- This field is not used for internal load balancing.
returned: success
type: dict
label_fingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally during
updates.
returned: success
type: str
region:
description:
- A reference to the region where the regional forwarding rule resides.
Expand Down
32 changes: 29 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_compute_global_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
be a dash.
returned: success
type: str
label_fingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally during
updates.
returned: success
type: str
ip_version:
description:
- The IP Version that will be used by this address. Valid options are IPV4 or IPV6.
Expand Down Expand Up @@ -166,7 +172,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
fetch = update(module, self_link(module), kind, fetch)
changed = True
else:
delete(module, self_link(module), kind)
Expand All @@ -189,8 +195,27 @@ 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="GlobalAddress cannot be edited")
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
pass


def label_fingerprint_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/global/addresses/{name}/setLabels"
]).format(**module.params),
{
u'labelFingerprint': response.get('labelFingerprint')
}
)


def delete(module, link, kind):
Expand Down Expand Up @@ -276,6 +301,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'labelFingerprint': response.get(u'labelFingerprint'),
u'ipVersion': response.get(u'ipVersion'),
u'region': response.get(u'region')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
be a dash.
returned: success
type: str
label_fingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally during
updates.
returned: success
type: str
ip_version:
description:
- The IP Version that will be used by this address. Valid options are IPV4 or IPV6.
Expand Down
41 changes: 38 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
fetch = update(module, self_link(module), kind, fetch)
changed = True
else:
delete(module, self_link(module), kind)
Expand All @@ -251,8 +251,43 @@ 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="Subnetwork cannot be edited")
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
if response.get('ipCidrRange') != request.get('ipCidrRange'):
ip_cidr_range_update(module, request, response)
if response.get('privateIpGoogleAccess') != request.get('privateIpGoogleAccess'):
private_ip_google_access_update(module, request, response)


def ip_cidr_range_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/regions/{region}/subnetworks/{name}/expandIpCidrRange"
]).format(**module.params),
{
u'ipCidrRange': module.params.get('ip_cidr_range')
}
)


def private_ip_google_access_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/regions/{region}/subnetworks/{name}/setPrivateIpGoogleAccess"
]).format(**module.params),
{
u'privateIpGoogleAccess': module.params.get('private_ip_google_access')
}
)


def delete(module, link, kind):
Expand Down
26 changes: 23 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
fetch = update(module, self_link(module), kind, fetch)
changed = True
else:
delete(module, self_link(module), kind)
Expand All @@ -221,8 +221,28 @@ 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="TargetHttpProxy cannot be edited")
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
if response.get('urlMap') != request.get('urlMap'):
url_map_update(module, request, response)


def url_map_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/targetHttpProxies/{name}/setUrlMap"
]).format(**module.params),
{
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')
}
)


def delete(module, link, kind):
Expand Down
Loading

0 comments on commit d5cfd99

Please sign in to comment.