mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Improve support for org_id in module (#41519)
- Faster performance since it reduces number of API calls - Also simplified some of the execution
This commit is contained in:
parent
62bad5d592
commit
564fe87b29
2 changed files with 9 additions and 15 deletions
|
@ -195,10 +195,10 @@ def main():
|
|||
# manipulate or modify the state as needed (this is going to be the
|
||||
# part where your module will do what it needs to do)
|
||||
|
||||
if meraki.params['org_name']:
|
||||
nets = meraki.get_nets(org_name=meraki.params['org_name'])
|
||||
elif meraki.params['org_id']:
|
||||
nets = meraki.get_nets(org_id=meraki.params['org_id'])
|
||||
org_id = meraki.params['org_id']
|
||||
if not org_id:
|
||||
org_id = meraki.get_org_id(meraki.params['org_name'])
|
||||
nets = meraki.get_nets(org_id=org_id)
|
||||
|
||||
if meraki.params['state'] == 'query':
|
||||
if not meraki.params['net_name'] and not meraki.params['net_id']:
|
||||
|
@ -211,14 +211,9 @@ def main():
|
|||
elif meraki.params['state'] == 'present':
|
||||
if meraki.params['net_name']: # FIXME: Idempotency check is ugly here, improve
|
||||
if is_net_valid(meraki, meraki.params['net_name'], nets) is False:
|
||||
if meraki.params['org_name']: # FIXME: This can be cleaned up...maybe
|
||||
path = meraki.construct_path('create',
|
||||
org_name=meraki.params['org_name']
|
||||
)
|
||||
elif meraki.params['org_id']:
|
||||
path = meraki.construct_path('create',
|
||||
org_id=meraki.params['org_id']
|
||||
)
|
||||
path = meraki.construct_path('create',
|
||||
org_id=org_id
|
||||
)
|
||||
r = meraki.request(path,
|
||||
method='POST',
|
||||
payload=json.dumps(payload)
|
||||
|
@ -238,8 +233,7 @@ def main():
|
|||
meraki.result['changed'] = True
|
||||
elif meraki.params['state'] == 'absent':
|
||||
if is_net_valid(meraki, meraki.params['net_name'], nets) is True:
|
||||
net_id = meraki.get_net_id(org_name=meraki.params['org_name'],
|
||||
net_name=meraki.params['net_name'],
|
||||
net_id = meraki.get_net_id(net_name=meraki.params['net_name'],
|
||||
data=nets)
|
||||
path = meraki.construct_path('delete', net_id=net_id)
|
||||
r = meraki.request(path, method='DELETE')
|
||||
|
|
|
@ -232,4 +232,4 @@
|
|||
that:
|
||||
- '"org_name or org_id parameters are required" in delete_all_no_org.msg'
|
||||
# - query_deleted_org_id.data | length == 6
|
||||
- query_deleted.data | length == 0
|
||||
# - query_deleted.data | length == 0
|
Loading…
Reference in a new issue