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
pull/42776/head
Kevin Breit 6 years ago committed by Dag Wieers
parent 5d76b627ef
commit 106e4b374a

@ -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):

@ -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'):

Loading…
Cancel
Save