diff options
author | Nathaniel Case <this.is@nathanielca.se> | 2017-06-24 20:09:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-24 20:09:11 +0200 |
commit | 21c7fcf9c07fc203a901864f66e92b087111eb26 (patch) | |
tree | ef82494f41554210a7fb298e108435ec019cea12 /lib | |
parent | Fixes nxos_vpc_interface (#25907) (diff) | |
download | ansible-21c7fcf9c07fc203a901864f66e92b087111eb26.tar.xz ansible-21c7fcf9c07fc203a901864f66e92b087111eb26.zip |
nxos_vxlan_vtep (#25971)
* nxos_vxlan_vtep tests
* Fix issues with nxos_vxlan_vtep
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py | 199 |
1 files changed, 72 insertions, 127 deletions
diff --git a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py index 2820c2a06f..ba848ec463 100644 --- a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py +++ b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py @@ -16,9 +16,11 @@ # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # -ANSIBLE_METADATA = {'metadata_version': '1.0', - 'status': ['preview'], - 'supported_by': 'community'} +ANSIBLE_METADATA = { + 'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'community', +} DOCUMENTATION = ''' @@ -28,55 +30,55 @@ extends_documentation_fragment: nxos version_added: "2.2" short_description: Manages VXLAN Network Virtualization Endpoint (NVE). description: - - Manages VXLAN Network Virtualization Endpoint (NVE) overlay interface - that terminates VXLAN tunnels. + - Manages VXLAN Network Virtualization Endpoint (NVE) overlay interface + that terminates VXLAN tunnels. author: Gabriele Gerbino (@GGabriele) notes: - - The module is used to manage NVE properties, not to create NVE - interfaces. Use M(nxos_interface) if you wish to do so. - - C(state=absent) removes the interface. - - Default, where supported, restores params default value. + - The module is used to manage NVE properties, not to create NVE + interfaces. Use M(nxos_interface) if you wish to do so. + - C(state=absent) removes the interface. + - Default, where supported, restores params default value. options: - interface: - description: - - Interface name for the VXLAN Network Virtualization Endpoint. - required: true + interface: + description: + - Interface name for the VXLAN Network Virtualization Endpoint. + required: true + description: + description: + - Description of the NVE interface. + required: false + default: null + host_reachability: + description: + - Specify mechanism for host reachability advertisement. + required: false + choices: ['true', 'false'] + default: null + shutdown: + description: + - Administratively shutdown the NVE interface. + required: false + choices: ['true','false'] + default: false + source_interface: description: - description: - - Description of the NVE interface. - required: false - default: null - host_reachability: - description: - - Specify mechanism for host reachability advertisement. - required: false - choices: ['true', 'false'] - default: null - shutdown: - description: - - Administratively shutdown the NVE interface. - required: false - choices: ['true','false'] - default: false - source_interface: - description: - - Specify the loopback interface whose IP address should be - used for the NVE interface. - required: false - default: null - source_interface_hold_down_time: - description: - - Suppresses advertisement of the NVE loopback address until - the overlay has converged. - required: false - default: null - state: - description: - - Determines whether the config should be present or not - on the device. - required: false - default: present - choices: ['present','absent'] + - Specify the loopback interface whose IP address should be + used for the NVE interface. + required: false + default: null + source_interface_hold_down_time: + description: + - Suppresses advertisement of the NVE loopback address until + the overlay has converged. + required: false + default: null + state: + description: + - Determines whether the config should be present or not + on the device. + required: false + default: present + choices: ['present','absent'] ''' EXAMPLES = ''' - nxos_vxlan_vtep: @@ -86,47 +88,20 @@ EXAMPLES = ''' source_interface: Loopback0 source_interface_hold_down_time: 30 shutdown: default - username: "{{ un }}" - password: "{{ pwd }}" - host: "{{ inventory_hostname }}" ''' RETURN = ''' -proposed: - description: k/v pairs of parameters passed into module - returned: verbose mode - type: dict - sample: {"description": "simple description", "host_reachability": true, - "interface": "nve1", "shutdown": true, "source_interface": "loopback0", - "source_interface_hold_down_time": "30"} -existing: - description: k/v pairs of existing VXLAN VTEP configuration - returned: verbose mode - type: dict - sample: {} -end_state: - description: k/v pairs of VXLAN VTEP configuration after module execution - returned: verbose mode - type: dict - sample: {"description": "simple description", "host_reachability": true, - "interface": "nve1", "shutdown": true, "source_interface": "loopback0", - "source_interface_hold_down_time": "30"} -updates: +commands: description: commands sent to the device returned: always type: list sample: ["interface nve1", "source-interface loopback0", "source-interface hold-down-time 30", "description simple description", "shutdown", "host-reachability protocol bgp"] -changed: - description: check to see if a change was made on the device - returned: always - type: boolean - sample: true ''' import re -from ansible.module_utils.nxos import get_config, load_config, run_commands +from ansible.module_utils.nxos import get_config, load_config from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.netcfg import CustomNetworkConfig @@ -148,14 +123,6 @@ PARAM_TO_DEFAULT_KEYMAP = { 'shutdown': True, } -WARNINGS = [] - - -def invoke(name, *args, **kwargs): - func = globals().get(name) - if func: - return func(*args, **kwargs) - def get_value(arg, config, module): if arg in BOOL_PARAMS: @@ -305,38 +272,24 @@ def main(): source_interface=dict(required=False, type='str'), source_interface_hold_down_time=dict(required=False, type='str'), m_facts=dict(required=False, default=False, type='bool'), - state=dict(choices=['present', 'absent'], default='present', - required=False), - include_defaults=dict(default=True), - config=dict(), - save=dict(type='bool', default=False) + state=dict(choices=['present', 'absent'], default='present', required=False), ) argument_spec.update(nxos_argument_spec) - module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=True) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() + result = {'changed': False, 'commands': [], 'warnings': warnings} check_args(module, warnings) - state = module.params['state'] - interface = module.params['interface'].lower() - - args = [ - 'interface', - 'description', - 'host_reachability', - 'shutdown', - 'source_interface', - 'source_interface_hold_down_time' - ] - - existing = invoke('get_existing', module, args) - end_state = existing + + args = PARAM_TO_DEFAULT_KEYMAP.keys() + + existing = get_existing(module, args) proposed_args = dict((k, v) for k, v in module.params.items() - if v is not None and k in args) + if v is not None and k in args) proposed = {} for key, value in proposed_args.items(): @@ -352,35 +305,27 @@ def main(): value = False else: value = 'default' - if existing.get(key) or (not existing.get(key) and value): + if existing.get(key) != value: proposed[key] = value - result = {} - if state == 'present' or (state == 'absent' and existing): + candidate = CustomNetworkConfig(indent=3) + if state == 'present': if not existing: - WARNINGS.append("The proposed NVE interface did not exist. " + warnings.append("The proposed NVE interface did not exist. " "It's recommended to use nxos_interface to create " "all logical interfaces.") - candidate = CustomNetworkConfig(indent=3) - invoke('state_%s' % state, module, existing, proposed, candidate) - response = load_config(module, candidate) - result.update(response) + state_present(module, existing, proposed, candidate) + elif state == 'absent' and existing: + state_absent(module, existing, proposed, candidate) - else: - result['updates'] = [] - - if module._verbosity > 0: - end_state = invoke('get_existing', module, args) - result['end_state'] = end_state - result['existing'] = existing - result['proposed'] = proposed_args - - if WARNINGS: - result['warnings'] = WARNINGS + if candidate: + candidate = candidate.items_text() + result['commands'] = candidate + result['changed'] = True + load_config(module, candidate) module.exit_json(**result) if __name__ == '__main__': main() - |