Skip to content

Commit

Permalink
Meraki module utility - get_net() downloads networks if data isn't pr…
Browse files Browse the repository at this point in the history
…ovided (ansible#41423)

* Enable get_net() to download nets if data isn't provided

- Currently, get_net() requires data to be passed to it
- PR enables get_net() to download all networks if data isn't passed
- Slightly simpler code
- Best practice is to download nets early in execution

* Apply fixes related to get_net()

* Removed extra code from the rebase
  • Loading branch information
kbreit authored and dagwieers committed Jul 9, 2018
1 parent eeada86 commit ca5f9aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions lib/ansible/module_utils/network/meraki/meraki.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,17 @@ def get_nets(self, org_name=None, org_id=None):
self.nets.append(t)
return self.nets

def get_net(self, org_name, net_name, data=None):
"""Return network information about a particular network."""
# TODO: Allow method to download data on its own
# if not data:
# org_id = self.get_org_id(org_name)
# path = '/organizations/{org_id}/networks/{net_id}'.format(
# org_id=org_id,
# net_id=self.get_net_id(
# org_name=org_name,
# net_name=net_name,
# data=data)
# )
# return json.loads(self.request('GET', path))
# else:
# def get_net(self, org_name, net_name, data=None):
# path = self.construct_path('get_all', function='network', org_id=org_id)
# r = self.request(path, method='GET')
# return r

def get_net(self, org_name, net_name, org_id=None, data=None):
''' Return network information '''
if not data:
if not org_id:
org_id = self.get_org_id(org_name)
data = self.get_nets(org_id=org_id)
for n in data:
if n['name'] == net_name:
return n
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/meraki/meraki_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def main():
elif meraki.params['net_name'] or meraki.params['net_id'] is not None:
meraki.result['data'] = meraki.get_net(meraki.params['org_name'],
meraki.params['net_name'],
nets
data=nets
)
elif meraki.params['state'] == 'present':
if meraki.params['net_name']: # FIXME: Idempotency check is ugly here, improve
Expand Down

0 comments on commit ca5f9aa

Please sign in to comment.