mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Handle nxos platform diffs with cli conf implementation (#34020)
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
2db3d861e0
commit
27be2a0f5a
4 changed files with 85 additions and 39 deletions
|
@ -29,6 +29,8 @@ short_description: Handles the EVPN control plane for VXLAN.
|
||||||
description:
|
description:
|
||||||
- Handles the EVPN control plane for VXLAN.
|
- Handles the EVPN control plane for VXLAN.
|
||||||
author: Gabriele Gerbino (@GGabriele)
|
author: Gabriele Gerbino (@GGabriele)
|
||||||
|
notes:
|
||||||
|
- This module is not supported on Nexus 3000 series of switches.
|
||||||
options:
|
options:
|
||||||
nv_overlay_evpn:
|
nv_overlay_evpn:
|
||||||
description:
|
description:
|
||||||
|
@ -52,13 +54,10 @@ commands:
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.nxos.nxos import get_config, load_config
|
from ansible.module_utils.network.nxos.nxos import get_config, load_config
|
||||||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec
|
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
|
||||||
from ansible.module_utils.network.nxos.nxos import check_args as nxos_check_args
|
|
||||||
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
def check_args(module, warnings):
|
||||||
nxos_check_args(module, warnings)
|
|
||||||
|
|
||||||
for key in ('include_defaults', 'config', 'save'):
|
for key in ('include_defaults', 'config', 'save'):
|
||||||
if module.params[key] is not None:
|
if module.params[key] is not None:
|
||||||
warnings.append('argument %s is no longer supported, ignoring value' % key)
|
warnings.append('argument %s is no longer supported, ignoring value' % key)
|
||||||
|
@ -88,6 +87,12 @@ def main():
|
||||||
config = get_config(module)
|
config = get_config(module)
|
||||||
commands = list()
|
commands = list()
|
||||||
|
|
||||||
|
info = get_capabilities(module).get('device_info', {})
|
||||||
|
os_platform = info.get('network_os_platform', '')
|
||||||
|
|
||||||
|
if '3K' in os_platform:
|
||||||
|
module.fail_json(msg='This module is not supported on Nexus 3000 series')
|
||||||
|
|
||||||
if module.params['nv_overlay_evpn'] is True:
|
if module.params['nv_overlay_evpn'] is True:
|
||||||
if 'nv overlay evpn' not in config:
|
if 'nv overlay evpn' not in config:
|
||||||
commands.append('nv overlay evpn')
|
commands.append('nv overlay evpn')
|
||||||
|
|
|
@ -73,13 +73,10 @@ import re
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
||||||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec
|
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
|
||||||
from ansible.module_utils.network.nxos.nxos import check_args as nxos_check_args
|
|
||||||
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
def check_args(module, warnings):
|
||||||
nxos_check_args(module, warnings)
|
|
||||||
|
|
||||||
for key in ('include_defaults', 'config', 'save'):
|
for key in ('include_defaults', 'config', 'save'):
|
||||||
if module.params[key] is not None:
|
if module.params[key] is not None:
|
||||||
warnings.append('argument %s is no longer supported, ignoring value' % key)
|
warnings.append('argument %s is no longer supported, ignoring value' % key)
|
||||||
|
@ -139,39 +136,73 @@ def validate_feature(module, mode='show'):
|
||||||
how they are configured'''
|
how they are configured'''
|
||||||
|
|
||||||
feature = module.params['feature']
|
feature = module.params['feature']
|
||||||
|
info = get_capabilities(module).get('device_info', {})
|
||||||
|
os_version = info.get('network_os_version', '')
|
||||||
|
|
||||||
feature_to_be_mapped = {
|
if '8.1' in os_version:
|
||||||
'show': {
|
feature_to_be_mapped = {
|
||||||
'nv overlay': 'nve',
|
'show': {
|
||||||
'vn-segment-vlan-based': 'vnseg_vlan',
|
'nv overlay': 'nve',
|
||||||
'hsrp': 'hsrp_engine',
|
'vn-segment-vlan-based': 'vnseg_vlan',
|
||||||
'fabric multicast': 'fabric_mcast',
|
'hsrp': 'hsrp_engine',
|
||||||
'scp-server': 'scpServer',
|
'fabric multicast': 'fabric_mcast',
|
||||||
'sftp-server': 'sftpServer',
|
'scp-server': 'scpServer',
|
||||||
'sla responder': 'sla_responder',
|
'sftp-server': 'sftpServer',
|
||||||
'sla sender': 'sla_sender',
|
'sla responder': 'sla_responder',
|
||||||
'ssh': 'sshServer',
|
'sla sender': 'sla_sender',
|
||||||
'tacacs+': 'tacacs',
|
'ssh': 'sshServer',
|
||||||
'telnet': 'telnetServer',
|
'tacacs+': 'tacacs',
|
||||||
'ethernet-link-oam': 'elo',
|
'telnet': 'telnetServer',
|
||||||
'port-security': 'eth_port_sec'
|
'ethernet-link-oam': 'elo'
|
||||||
},
|
},
|
||||||
'config': {
|
'config': {
|
||||||
'nve': 'nv overlay',
|
'nve': 'nv overlay',
|
||||||
'vnseg_vlan': 'vn-segment-vlan-based',
|
'vnseg_vlan': 'vn-segment-vlan-based',
|
||||||
'hsrp_engine': 'hsrp',
|
'hsrp_engine': 'hsrp',
|
||||||
'fabric_mcast': 'fabric multicast',
|
'fabric_mcast': 'fabric multicast',
|
||||||
'scpServer': 'scp-server',
|
'scpServer': 'scp-server',
|
||||||
'sftpServer': 'sftp-server',
|
'sftpServer': 'sftp-server',
|
||||||
'sla_sender': 'sla sender',
|
'sla_sender': 'sla sender',
|
||||||
'sla_responder': 'sla responder',
|
'sla_responder': 'sla responder',
|
||||||
'sshServer': 'ssh',
|
'sshServer': 'ssh',
|
||||||
'tacacs': 'tacacs+',
|
'tacacs': 'tacacs+',
|
||||||
'telnetServer': 'telnet',
|
'telnetServer': 'telnet',
|
||||||
'elo': 'ethernet-link-oam',
|
'elo': 'ethernet-link-oam'
|
||||||
'eth_port_sec': 'port-security'
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
feature_to_be_mapped = {
|
||||||
|
'show': {
|
||||||
|
'nv overlay': 'nve',
|
||||||
|
'vn-segment-vlan-based': 'vnseg_vlan',
|
||||||
|
'hsrp': 'hsrp_engine',
|
||||||
|
'fabric multicast': 'fabric_mcast',
|
||||||
|
'scp-server': 'scpServer',
|
||||||
|
'sftp-server': 'sftpServer',
|
||||||
|
'sla responder': 'sla_responder',
|
||||||
|
'sla sender': 'sla_sender',
|
||||||
|
'ssh': 'sshServer',
|
||||||
|
'tacacs+': 'tacacs',
|
||||||
|
'telnet': 'telnetServer',
|
||||||
|
'ethernet-link-oam': 'elo',
|
||||||
|
'port-security': 'eth_port_sec'
|
||||||
|
},
|
||||||
|
'config': {
|
||||||
|
'nve': 'nv overlay',
|
||||||
|
'vnseg_vlan': 'vn-segment-vlan-based',
|
||||||
|
'hsrp_engine': 'hsrp',
|
||||||
|
'fabric_mcast': 'fabric multicast',
|
||||||
|
'scpServer': 'scp-server',
|
||||||
|
'sftpServer': 'sftp-server',
|
||||||
|
'sla_sender': 'sla sender',
|
||||||
|
'sla_responder': 'sla responder',
|
||||||
|
'sshServer': 'ssh',
|
||||||
|
'tacacs': 'tacacs+',
|
||||||
|
'telnetServer': 'telnet',
|
||||||
|
'elo': 'ethernet-link-oam',
|
||||||
|
'eth_port_sec': 'port-security'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if feature in feature_to_be_mapped[mode]:
|
if feature in feature_to_be_mapped[mode]:
|
||||||
feature = feature_to_be_mapped[mode][feature]
|
feature = feature_to_be_mapped[mode][feature]
|
||||||
|
|
|
@ -37,10 +37,15 @@ class TestNxosEvpnGlobalModule(TestNxosModule):
|
||||||
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_evpn_global.load_config')
|
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_evpn_global.load_config')
|
||||||
self.load_config = self.mock_load_config.start()
|
self.load_config = self.mock_load_config.start()
|
||||||
|
|
||||||
|
self.mock_get_capabilities = patch('ansible.modules.network.nxos.nxos_evpn_global.get_capabilities')
|
||||||
|
self.get_capabilities = self.mock_get_capabilities.start()
|
||||||
|
self.get_capabilities.return_value = {'network_api': 'cliconf'}
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestNxosEvpnGlobalModule, self).tearDown()
|
super(TestNxosEvpnGlobalModule, self).tearDown()
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
self.mock_load_config.stop()
|
self.mock_load_config.stop()
|
||||||
|
self.mock_get_capabilities.stop()
|
||||||
|
|
||||||
def load_fixtures(self, commands=None, device=''):
|
def load_fixtures(self, commands=None, device=''):
|
||||||
self.load_config.return_value = None
|
self.load_config.return_value = None
|
||||||
|
|
|
@ -38,10 +38,15 @@ class TestNxosFeatureModule(TestNxosModule):
|
||||||
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_feature.load_config')
|
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_feature.load_config')
|
||||||
self.load_config = self.mock_load_config.start()
|
self.load_config = self.mock_load_config.start()
|
||||||
|
|
||||||
|
self.mock_get_capabilities = patch('ansible.modules.network.nxos.nxos_feature.get_capabilities')
|
||||||
|
self.get_capabilities = self.mock_get_capabilities.start()
|
||||||
|
self.get_capabilities.return_value = {'network_api': 'cliconf'}
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestNxosFeatureModule, self).tearDown()
|
super(TestNxosFeatureModule, self).tearDown()
|
||||||
self.mock_run_commands.stop()
|
self.mock_run_commands.stop()
|
||||||
self.mock_load_config.stop()
|
self.mock_load_config.stop()
|
||||||
|
self.mock_get_capabilities.stop()
|
||||||
|
|
||||||
def load_fixtures(self, commands=None, device=''):
|
def load_fixtures(self, commands=None, device=''):
|
||||||
def load_from_file(*args, **kwargs):
|
def load_from_file(*args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue