mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-09-29 21:13:30 -07:00
Partial updates (#63)
This commit is contained in:
parent
3382f7f7b2
commit
2837b2f836
13 changed files with 1165 additions and 877 deletions
|
@ -298,8 +298,7 @@ def main():
|
|||
if fetch:
|
||||
if state == 'present':
|
||||
if is_different(module, fetch):
|
||||
update(module, self_link(module), kind, fetch)
|
||||
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)
|
||||
|
@ -322,8 +321,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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue