Skip to content

Commit

Permalink
Support compute reservation resize (#3308) (#181)
Browse files Browse the repository at this point in the history
* support compute reservations resize

* remove if custom encoder

* review comments

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 27, 2020
1 parent 947007d commit 872d3da
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions plugins/modules/gcp_compute_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module))
update(module, self_link(module), fetch)
fetch = fetch_resource(module, self_link(module))
changed = True
else:
Expand All @@ -434,9 +434,22 @@ def create(module, link):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))


def update(module, link):
delete(module, self_link(module))
create(module, collection(module))
def update(module, link, fetch):
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module))


def update_fields(module, request, response):
if response.get('specificReservation') != request.get('specificReservation'):
specific_reservation_update(module, request, response)


def specific_reservation_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/zones/{zone}/reservations/{name}/resize"]).format(**module.params),
{u'specificReservation': ReservationSpecificreservation(module.params.get('specific_reservation', {}), module).to_request()},
)


def delete(module, link):
Expand Down Expand Up @@ -582,7 +595,7 @@ def from_response(self):
return remove_nones_from_dict(
{
u'count': self.request.get(u'count'),
u'instanceProperties': ReservationInstanceproperties(self.request.get(u'instanceProperties', {}), self.module).from_response(),
u'instanceProperties': ReservationInstanceproperties(self.module.params.get('instance_properties', {}), self.module).to_request(),
}
)

Expand Down

0 comments on commit 872d3da

Please sign in to comment.