meraki_config_template - Check for HTTP status code (#42145)
* Check for HTTP status code - All requests now check returned status code - Fail if status code isn’t what is expected * Fix blank line error * Change HTTP check logic and improve integration tests - Set HTTP status code check so default path is accept - Added create and delete network for integration test - Remove a few comments to clean up code
This commit is contained in:
parent
40b9862d38
commit
08ddd202fb
2 changed files with 29 additions and 7 deletions
|
@ -83,6 +83,8 @@ from ansible.module_utils.network.meraki.meraki import MerakiModule, meraki_argu
|
||||||
def get_config_templates(meraki, org_id):
|
def get_config_templates(meraki, org_id):
|
||||||
path = meraki.construct_path('get_all', org_id=org_id)
|
path = meraki.construct_path('get_all', org_id=org_id)
|
||||||
response = meraki.request(path, 'GET')
|
response = meraki.request(path, 'GET')
|
||||||
|
if meraki.status != 200:
|
||||||
|
meraki.fail_json(msg='Unable to get configuration templates')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,10 +98,8 @@ def get_template_id(meraki, name, data):
|
||||||
def is_network_bound(meraki, nets, net_name, template_id):
|
def is_network_bound(meraki, nets, net_name, template_id):
|
||||||
for net in nets:
|
for net in nets:
|
||||||
if net['name'] == net_name:
|
if net['name'] == net_name:
|
||||||
# meraki.fail_json(msg=net['name'])
|
|
||||||
try:
|
try:
|
||||||
if net['configTemplateId'] == template_id:
|
if net['configTemplateId'] == template_id:
|
||||||
# meraki.fail_json(msg='Network is already bound.')
|
|
||||||
return True
|
return True
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
@ -111,6 +111,8 @@ def delete_template(meraki, org_id, name, data):
|
||||||
path = meraki.construct_path('delete', org_id=org_id)
|
path = meraki.construct_path('delete', org_id=org_id)
|
||||||
path = path + '/' + template_id
|
path = path + '/' + template_id
|
||||||
response = meraki.request(path, 'DELETE')
|
response = meraki.request(path, 'DELETE')
|
||||||
|
if meraki.status != 200:
|
||||||
|
meraki.fail_json(msg='Unable to remove configuration template')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +128,10 @@ def bind(meraki, org_name, net_name, name, data):
|
||||||
if meraki.params['auto_bind']:
|
if meraki.params['auto_bind']:
|
||||||
payload['autoBind'] = meraki.params['auto_bind']
|
payload['autoBind'] = meraki.params['auto_bind']
|
||||||
meraki.result['changed'] = True
|
meraki.result['changed'] = True
|
||||||
return meraki.request(path, method='POST', payload=json.dumps(payload))
|
r = meraki.request(path, method='POST', payload=json.dumps(payload))
|
||||||
|
if meraki.status != 200:
|
||||||
|
meraki.fail_json(msg='Unable to bind configuration template to network')
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
def unbind(meraki, org_name, net_name, name, data):
|
def unbind(meraki, org_name, net_name, name, data):
|
||||||
|
@ -136,7 +141,10 @@ def unbind(meraki, org_name, net_name, name, data):
|
||||||
if is_network_bound(meraki, nets, net_name, template_id) is True:
|
if is_network_bound(meraki, nets, net_name, template_id) is True:
|
||||||
path = meraki.construct_path('unbind', function='config_template', net_id=net_id)
|
path = meraki.construct_path('unbind', function='config_template', net_id=net_id)
|
||||||
meraki.result['changed'] = True
|
meraki.result['changed'] = True
|
||||||
return meraki.request(path, method='POST')
|
r = meraki.request(path, method='POST')
|
||||||
|
if meraki.status != 200:
|
||||||
|
meraki.fail_json(msg='Unable to unbind configuration template from network')
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -215,8 +223,6 @@ def main():
|
||||||
meraki.params['net_name'],
|
meraki.params['net_name'],
|
||||||
meraki.params['config_template'],
|
meraki.params['config_template'],
|
||||||
get_config_templates(meraki, org_id))
|
get_config_templates(meraki, org_id))
|
||||||
# meraki.fail_json(msg='Output', bind_output=template_bind)
|
|
||||||
# meraki.result['data'] = json.loads(template_bind)
|
|
||||||
elif meraki.params['state'] == 'absent':
|
elif meraki.params['state'] == 'absent':
|
||||||
if not meraki.params['net_name']:
|
if not meraki.params['net_name']:
|
||||||
meraki.result['data'] = delete_template(meraki,
|
meraki.result['data'] = delete_template(meraki,
|
||||||
|
@ -229,7 +235,6 @@ def main():
|
||||||
meraki.params['net_name'],
|
meraki.params['net_name'],
|
||||||
meraki.params['config_template'],
|
meraki.params['config_template'],
|
||||||
get_config_templates(meraki, org_id))
|
get_config_templates(meraki, org_id))
|
||||||
# meraki.result['data'] = json.loads(config_unbind)
|
|
||||||
|
|
||||||
# in the event of a successful module execution, you will want to
|
# in the event of a successful module execution, you will want to
|
||||||
# simple AnsibleModule.exit_json(), passing the key/value results
|
# simple AnsibleModule.exit_json(), passing the key/value results
|
||||||
|
|
|
@ -47,6 +47,15 @@
|
||||||
that:
|
that:
|
||||||
- '"No configuration template named" in deleted.msg'
|
- '"No configuration template named" in deleted.msg'
|
||||||
|
|
||||||
|
- name: Create a network
|
||||||
|
meraki_network:
|
||||||
|
auth_key: '{{auth_key}}'
|
||||||
|
state: present
|
||||||
|
org_name: '{{ test_org_name }}'
|
||||||
|
net_name: '{{ test_net_name }}'
|
||||||
|
type: appliance
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Bind a template to a network
|
- name: Bind a template to a network
|
||||||
meraki_config_template:
|
meraki_config_template:
|
||||||
auth_key: '{{auth_key}}'
|
auth_key: '{{auth_key}}'
|
||||||
|
@ -102,3 +111,11 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
unbind_invalid.changed == False
|
unbind_invalid.changed == False
|
||||||
|
|
||||||
|
- name: Delete network
|
||||||
|
meraki_network:
|
||||||
|
auth_key: '{{auth_key}}'
|
||||||
|
state: absent
|
||||||
|
org_name: '{{ test_org_name }}'
|
||||||
|
net_name: '{{ test_net_name }}'
|
||||||
|
delegate_to: localhost
|
Loading…
Reference in a new issue