From ca5f9aab1ea530ee686c30a504f0490a97aa30f7 Mon Sep 17 00:00:00 2001 From: Kevin Breit Date: Mon, 9 Jul 2018 04:13:38 -0500 Subject: [PATCH] Meraki module utility - get_net() downloads networks if data isn't provided (#41423) * Enable get_net() to download nets if data isn't provided - Currently, get_net() requires data to be passed to it - PR enables get_net() to download all networks if data isn't passed - Slightly simpler code - Best practice is to download nets early in execution * Apply fixes related to get_net() * Removed extra code from the rebase --- .../module_utils/network/meraki/meraki.py | 25 ++++++++----------- .../modules/network/meraki/meraki_network.py | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/ansible/module_utils/network/meraki/meraki.py b/lib/ansible/module_utils/network/meraki/meraki.py index 7499f64da2..684063c5c0 100644 --- a/lib/ansible/module_utils/network/meraki/meraki.py +++ b/lib/ansible/module_utils/network/meraki/meraki.py @@ -211,20 +211,17 @@ class MerakiModule(object): self.nets.append(t) return self.nets - def get_net(self, org_name, net_name, data=None): - """Return network information about a particular network.""" - # TODO: Allow method to download data on its own - # if not data: - # org_id = self.get_org_id(org_name) - # path = '/organizations/{org_id}/networks/{net_id}'.format( - # org_id=org_id, - # net_id=self.get_net_id( - # org_name=org_name, - # net_name=net_name, - # data=data) - # ) - # return json.loads(self.request('GET', path)) - # else: + # def get_net(self, org_name, net_name, data=None): + # path = self.construct_path('get_all', function='network', org_id=org_id) + # r = self.request(path, method='GET') + # return r + + def get_net(self, org_name, net_name, org_id=None, data=None): + ''' Return network information ''' + if not data: + if not org_id: + org_id = self.get_org_id(org_name) + data = self.get_nets(org_id=org_id) for n in data: if n['name'] == net_name: return n diff --git a/lib/ansible/modules/network/meraki/meraki_network.py b/lib/ansible/modules/network/meraki/meraki_network.py index 7d979f37a4..8d16be2c8f 100644 --- a/lib/ansible/modules/network/meraki/meraki_network.py +++ b/lib/ansible/modules/network/meraki/meraki_network.py @@ -206,7 +206,7 @@ def main(): elif meraki.params['net_name'] or meraki.params['net_id'] is not None: meraki.result['data'] = meraki.get_net(meraki.params['org_name'], meraki.params['net_name'], - nets + data=nets ) elif meraki.params['state'] == 'present': if meraki.params['net_name']: # FIXME: Idempotency check is ugly here, improve