add check mode to interface_bridge_port

This commit is contained in:
Valentin Gurmeza 2017-06-05 15:51:08 -07:00
parent 297f3228bc
commit 35020e9c4e

View file

@ -96,44 +96,44 @@ from ansible.module_utils.basic import AnsibleModule
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
hostname =dict(required=True), hostname =dict(required=True),
username =dict(required=True), username =dict(required=True),
password =dict(required=True), password =dict(required=True),
interface =dict(required=True, type='str'), interface =dict(required=True, type='str'),
bridge =dict(required=False, type='str'), bridge =dict(required=False, type='str'),
comment =dict(required=False, type='str'), comment =dict(required=False, type='str'),
path_cost =dict(required=False, type='str'), path_cost =dict(required=False, type='str'),
priority =dict(required=False, type='str'), priority =dict(required=False, type='str'),
horizon =dict(required=False, type='str'), horizon =dict(required=False, type='str'),
external_fdb=dict( external_fdb=dict(
required=False, required=False,
choices=['yes', 'no', 'auto'], choices=['yes', 'no', 'auto'],
type='str' type='str'
), ),
auto_isolate=dict( auto_isolate=dict(
required=False, required=False,
choices=['yes', 'no'], choices=['yes', 'no'],
type='str' type='str'
), ),
edge=dict( edge=dict(
required=False, required=False,
choices=['auto', 'yes', 'no', 'no-discover', 'yes-discover'], choices=['auto', 'yes', 'no', 'no-discover', 'yes-discover'],
type='str' type='str'
), ),
point_to_point=dict( point_to_point=dict(
required=False, required=False,
choices=['yes', 'no', 'auto'], choices=['yes', 'no', 'auto'],
type='str' type='str'
), ),
state=dict( state=dict(
required=True, required=True,
choices=['present', 'absent'], choices=['present', 'absent'],
type='str' type='str'
), ),
) ),
supports_check_mode=True
) )
hostname = module.params['hostname'] hostname = module.params['hostname']
@ -143,6 +143,7 @@ def main():
ansible_bridge_port_interface = module.params['interface'] ansible_bridge_port_interface = module.params['interface']
changed = False changed = False
changed_message = [] changed_message = []
check_mode = module.check_mode
msg = "" msg = ""
mk = mt_api.Mikrotik(hostname, username, password) mk = mt_api.Mikrotik(hostname, username, password)
@ -184,10 +185,11 @@ def main():
if state == "present": if state == "present":
if mikrotik_bridge_port == {}: if mikrotik_bridge_port == {}:
mk.api_add( if not check_mode:
base_path=bridge_port_path, mk.api_add(
params=bridge_port_params base_path=bridge_port_path,
) params=bridge_port_params
)
changed_message.append(ansible_bridge_port_interface + " added to bridge") changed_message.append(ansible_bridge_port_interface + " added to bridge")
changed = True, changed = True,
else: else:
@ -201,7 +203,8 @@ def main():
bridge_port_diff_keys[key] = bridge_port_params[key] bridge_port_diff_keys[key] = bridge_port_params[key]
if bridge_port_diff_keys != {}: if bridge_port_diff_keys != {}:
bridge_port_diff_keys['numbers'] = client_id bridge_port_diff_keys['numbers'] = client_id
mk.api_edit(base_path=bridge_port_path, params=bridge_port_diff_keys) if not check_mode:
mk.api_edit(base_path=bridge_port_path, params=bridge_port_diff_keys)
changed = True changed = True
changed_message.append("Changed bridge port: " + bridge_port_params['bridge']) changed_message.append("Changed bridge port: " + bridge_port_params['bridge'])
else: else:
@ -213,7 +216,8 @@ def main():
elif state == "absent": elif state == "absent":
if client_id: if client_id:
mk.api_remove(base_path=bridge_port_path, remove_id=client_id) if not check_mode:
mk.api_remove(base_path=bridge_port_path, remove_id=client_id)
changed_message.append(bridge_port_params['interface'] + " removed") changed_message.append(bridge_port_params['interface'] + " removed")
changed = True changed = True
##################################################### #####################################################