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

Fix bad type for Network routing_config.routing_mode #136

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions lib/ansible/modules/cloud/google/gcp_compute_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def main():
ipv4_range=dict(type='str'),
name=dict(required=True, type='str'),
auto_create_subnetworks=dict(type='bool'),
routing_config=dict(type='list', elements='dict', options=dict(
routing_config=dict(type='dict', options=dict(
routing_mode=dict(required=True, type='str', choices=['REGIONAL', 'GLOBAL'])
))
)
Expand Down Expand Up @@ -275,7 +275,7 @@ def resource_to_request(module):
u'IPv4Range': module.params.get('ipv4_range'),
u'name': module.params.get('name'),
u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'),
u'routingConfig': NetworkRoutingconfigArray(module.params.get('routing_config', []), module).to_request()
u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request()
}
return_vals = {}
for k, v in request.items():
Expand Down Expand Up @@ -349,7 +349,7 @@ def response_to_hash(module, response):
u'subnetworks': response.get(u'subnetworks'),
u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'),
u'creationTimestamp': response.get(u'creationTimestamp'),
u'routingConfig': NetworkRoutingconfigArray(response.get(u'routingConfig', []), module).from_response()
u'routingConfig': NetworkRoutingconfig(response.get(u'routingConfig', {}), module).from_response()
}


Expand Down Expand Up @@ -388,34 +388,22 @@ def raise_if_errors(response, err_path, module):
module.fail_json(msg=errors)


class NetworkRoutingconfigArray(object):
class NetworkRoutingconfig(object):
def __init__(self, request, module):
self.module = module
if request:
self.request = request
else:
self.request = []
self.request = {}

def to_request(self):
items = []
for item in self.request:
items.append(self._request_for_item(item))
return items

def from_response(self):
items = []
for item in self.request:
items.append(self._response_from_item(item))
return items

def _request_for_item(self, item):
return remove_nones_from_dict({
u'routingMode': item.get('routing_mode')
u'routingMode': self.request.get('routing_mode')
})

def _response_from_item(self, item):
def from_response(self):
return remove_nones_from_dict({
u'routingMode': item.get(u'routingMode')
u'routingMode': self.request.get(u'routingMode')
})


Expand Down