Clean up some of the execution of the module (#48391)

- Module now checks whether a specified network is valid very early
- Simplifies the present code flow
- No functionality enhancement
This commit is contained in:
Kevin Breit 2019-01-10 11:10:31 -06:00 committed by ansibot
parent aea20f95c6
commit 476a7fc27d

View file

@ -237,6 +237,14 @@ def main():
org_id = meraki.get_org_id(meraki.params['org_name']) org_id = meraki.get_org_id(meraki.params['org_name'])
nets = meraki.get_nets(org_id=org_id) nets = meraki.get_nets(org_id=org_id)
# check if network is created
net_id = None
if meraki.params['net_name']:
if is_net_valid(meraki, meraki.params['net_name'], nets) is True:
net_id = meraki.get_net_id(net_name=meraki.params['net_name'], data=nets)
elif meraki.params['net_id']:
net_id = meraki.params['net_id']
if meraki.params['state'] == 'query': if meraki.params['state'] == 'query':
if not meraki.params['net_name'] and not meraki.params['net_id']: if not meraki.params['net_name'] and not meraki.params['net_id']:
meraki.result['data'] = nets meraki.result['data'] = nets
@ -246,8 +254,7 @@ def main():
data=nets data=nets
) )
elif meraki.params['state'] == 'present': elif meraki.params['state'] == 'present':
if meraki.params['net_name']: # FIXME: Idempotency check is ugly here, improve if net_id is None:
if is_net_valid(meraki, meraki.params['net_name'], nets) is False:
path = meraki.construct_path('create', path = meraki.construct_path('create',
org_id=org_id org_id=org_id
) )