meraki_config_template - Remove mandatory network lookup (#56525)

* Module only makes network lookups when needed instead of every execution

* Formatting fixes
pull/57125/head
Kevin Breit 6 years ago committed by Nilashish Chakraborty
parent b143918f30
commit 57e1063fc7

@ -0,0 +1,2 @@
bugfixes:
- meraki_config_template - Don't query all networks unless needed.

@ -229,9 +229,13 @@ def main():
if meraki.params['org_name']: if meraki.params['org_name']:
org_id = meraki.get_org_id(meraki.params['org_name']) org_id = meraki.get_org_id(meraki.params['org_name'])
net_id = meraki.params['net_id'] net_id = meraki.params['net_id']
nets = meraki.get_nets(org_id=org_id) nets = None
if meraki.params['net_name']: if net_id is None:
net_id = meraki.get_net_id(net_name=meraki.params['net_name'], data=nets) if meraki.params['net_name'] is not None:
nets = meraki.get_nets(org_id=org_id)
net_id = meraki.get_net_id(net_name=meraki.params['net_name'], data=nets)
else:
nets = meraki.get_nets(org_id=org_id)
if meraki.params['state'] == 'query': if meraki.params['state'] == 'query':
meraki.result['data'] = get_config_templates(meraki, org_id) meraki.result['data'] = get_config_templates(meraki, org_id)
@ -239,6 +243,8 @@ def main():
template_id = get_template_id(meraki, template_id = get_template_id(meraki,
meraki.params['config_template'], meraki.params['config_template'],
get_config_templates(meraki, org_id)) get_config_templates(meraki, org_id))
if nets is None:
nets = meraki.get_nets(org_id=org_id)
if is_network_bound(meraki, nets, net_id, template_id) is False: if is_network_bound(meraki, nets, net_id, template_id) is False:
template_bind = bind(meraki, template_bind = bind(meraki,
net_id, net_id,
@ -261,6 +267,8 @@ def main():
template_id = get_template_id(meraki, template_id = get_template_id(meraki,
meraki.params['config_template'], meraki.params['config_template'],
get_config_templates(meraki, org_id)) get_config_templates(meraki, org_id))
if nets is None:
nets = meraki.get_nets(org_id=org_id)
if is_network_bound(meraki, nets, net_id, template_id) is True: if is_network_bound(meraki, nets, net_id, template_id) is True:
config_unbind = unbind(meraki, config_unbind = unbind(meraki,
net_id) net_id)

Loading…
Cancel
Save