From 106e4b374a4eae78900c757b8faee503062b3fd4 Mon Sep 17 00:00:00 2001 From: Kevin Breit Date: Fri, 13 Jul 2018 19:26:37 -0500 Subject: [PATCH] Meraki utility - construct_path() now supports custom keys (#42286) * construct_path() now supports custom keys - Allows for much more flexible test substitution - Implemented functionality in meraki_vlan for test case * Fix comments for PEP8 --- lib/ansible/module_utils/network/meraki/meraki.py | 8 +++++--- lib/ansible/modules/network/meraki/meraki_vlan.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_utils/network/meraki/meraki.py b/lib/ansible/module_utils/network/meraki/meraki.py index 684063c5c06..4519f87a3f9 100644 --- a/lib/ansible/module_utils/network/meraki/meraki.py +++ b/lib/ansible/module_utils/network/meraki/meraki.py @@ -249,7 +249,7 @@ class MerakiModule(object): return template['id'] self.fail_json(msg='No configuration template named {0} found'.format(name)) - def construct_path(self, action, function=None, org_id=None, net_id=None, org_name=None): + def construct_path(self, action, function=None, org_id=None, net_id=None, org_name=None, custom=None): """Build a path from the URL catalog. Uses function property from class for catalog lookup. @@ -261,8 +261,10 @@ class MerakiModule(object): built_path = self.url_catalog[action][function] if org_name: org_id = self.get_org_id(org_name) - - built_path = built_path.format(org_id=org_id, net_id=net_id) + if custom: + built_path = built_path.format(org_id=org_id, net_id=net_id, **custom) + else: + built_path = built_path.format(org_id=org_id, net_id=net_id) return built_path def request(self, path, method=None, payload=None): diff --git a/lib/ansible/modules/network/meraki/meraki_vlan.py b/lib/ansible/modules/network/meraki/meraki_vlan.py index 02e0dfb8dcc..e20cfd78f68 100644 --- a/lib/ansible/modules/network/meraki/meraki_vlan.py +++ b/lib/ansible/modules/network/meraki/meraki_vlan.py @@ -234,7 +234,7 @@ def main(): meraki.params['follow_redirects'] = 'all' query_urls = {'vlan': '/networks/{net_id}/vlans'} - query_url = {'vlan': '/networks/{net_id}/vlans/'} + query_url = {'vlan': '/networks/{net_id}/vlans/{vlan_id}'} create_url = {'vlan': '/networks/{net_id}/vlans'} update_url = {'vlan': '/networks/{net_id}/vlans/'} delete_url = {'vlan': '/networks/{net_id}/vlans/'} @@ -261,7 +261,7 @@ def main(): if not meraki.params['vlan_id']: meraki.result['data'] = get_vlans(meraki, net_id) else: - path = meraki.construct_path('get_one', net_id=net_id) + str(meraki.params['vlan_id']) + path = meraki.construct_path('get_one', net_id=net_id, custom={'vlan_id': meraki.params['vlan_id']}) response = meraki.request(path, method='GET') meraki.result['data'] = response elif meraki.params['state'] == 'present': @@ -276,7 +276,7 @@ def main(): meraki.result['changed'] = True meraki.result['data'] = response else: - path = meraki.construct_path('get_one', net_id=net_id) + str(meraki.params['vlan_id']) + path = meraki.construct_path('get_one', net_id=net_id, custom={'vlan_id': meraki.params['vlan_id']}) original = meraki.request(path, method='GET') if meraki.params['dns_nameservers']: if meraki.params['dns_nameservers'] not in ('opendns', 'google_dns', 'upstream_dns'):