����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: onyx_wjh
author: "Anas Shami (@anass)"
short_description: Configure what-just-happend module
description:
- This module provides declarative management of wjh
on Mellanox ONYX network devices.
notes:
options:
group:
description:
- Name of wjh group.
choices: ['all', 'forwarding', 'acl']
type: str
enabled:
description:
- wjh group status
type: bool
auto_export:
description:
- wjh group auto export pcap file status
type: bool
export_group:
description:
- wjh group auto export group
choices: ['all', 'forwarding', 'acl']
type: str
clear_group:
description:
- clear pcap file by group
choices: ['all', 'user', 'auto-export']
type: str
'''
EXAMPLES = """
- name: Enable wjh
onyx_wjh:
group: forwarding
enabled: True
- name: Disable wjh
onyx_wjh:
group: forwarding
enabled: False
- name: Enable auto-export
onyx_wjh:
auto_export: True
export_group: forwarding
- name: Disable auto-export
onyx_wjh:
auto_export: False
export_group: forwarding
- name: Clear pcap file
onyx_wjh:
clear_group: auto-export
"""
RETURN = """
commands:
description: The list of configuration mode commands to send to the device.
returned: always
type: list
sample:
- what-just-happend forwarding enable
- what-just-happend auto-export forwarding enable
- clear what-just-happend pcap-file user
"""
import re
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.mellanox.onyx.plugins.module_utils.network.onyx.onyx import BaseOnyxModule, show_cmd
class OnyxWJHModule(BaseOnyxModule):
WJH_DISABLED_REGX = re.compile(r'^no what-just-happened ([a-z]+) enable.*')
WJH_DISABLED_AUTO_EXPORT_REGX = re.compile(r'^no what-just-happened auto-export ([a-z]+) enable.*')
WJH_CMD_FMT = '{0}what-just-happened {1} enable'
WJH_EXPORT_CMD_FMT = '{0}what-just-happened auto-export {1} enable'
WJH_CLEAR_CMD_FMT = 'clear what-just-happened pcap-files {0}'
WJH_GROUPS = ['all', 'forwarding', 'acl']
CLEAR_GROUPS = ['all', 'user', 'auto-export']
def init_module(self):
"""
module initialization
"""
element_spec = dict(group=dict(choices=self.WJH_GROUPS),
enabled=dict(type='bool'),
auto_export=dict(type='bool'),
export_group=dict(choices=self.WJH_GROUPS),
clear_group=dict(choices=self.CLEAR_GROUPS))
argument_spec = dict()
argument_spec.update(element_spec)
self._module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_together=[
['group', 'enabled'],
['auto_export', 'export_group']
])
def get_required_config(self):
self._required_config = dict()
module_params = self._module.params
group = module_params.get('group')
export_group = module_params.get('export_group')
clear_group = module_params.get('clear_group')
params = dict()
if group:
enabled = module_params.get('enabled')
params.update({
'group': group,
'enabled': enabled
})
if export_group:
auto_export = module_params.get('auto_export')
params.update({
'export_group': export_group,
'auto_export': auto_export
})
if clear_group:
params.update({
'clear_group': clear_group
})
self.validate_param_values(params)
self._required_config = params
def _get_wjh_config(self):
return show_cmd(self._module, "show running-config | include .*what-just-happened.*", json_fmt=False, fail_on_error=False)
def _set_current_config(self, config):
if not config:
return
current_config = self._current_config
lines = config.split('\n')
for line in lines:
if line.startswith('#'):
continue
match = self.WJH_DISABLED_REGX.match(line)
if match:
# wjh is disabled
group = match.group(1)
current_config[group] = False
match = self.WJH_DISABLED_AUTO_EXPORT_REGX.match(line)
if match:
# wjh auto export is disabled
export_group = match.group(1) + '_export'
current_config[export_group] = False
'''
show running config will contains [no wjh * group enable] if disabled - default config is enabled
'''
def load_current_config(self):
self._current_config = dict()
config_lines = self._get_wjh_config()
if config_lines:
self._set_current_config(config_lines)
def wjh_group_status(self, current_config, group_value, suffix=''):
current_enabled = False
if group_value == 'all':
# no disabled group so all would be false
current_enabled = not all([
(group + suffix) in current_config for group in self.WJH_GROUPS])
else:
# if no current-value its enabled
current_enabled = current_config[group_value + suffix] if((group_value + suffix) in current_config) else True
return current_enabled
'''
wjh is enabled "by default"
when wjh disable we will find no wjh commands in running config
'''
def generate_commands(self):
current_config, required_config = self._current_config, self._required_config
group = required_config.get('group')
export_group = required_config.get('export_group')
clear_group = required_config.get('clear_group')
if group:
current_enabled = self.wjh_group_status(current_config, group)
if(required_config['enabled'] != current_enabled):
self._commands.append(self.WJH_CMD_FMT
.format(('' if required_config['enabled'] else 'no '), group))
if export_group:
current_enabled = self.wjh_group_status(current_config, required_config['export_group'], '_export')
if(required_config['auto_export'] != current_enabled):
self._commands.append(self.WJH_EXPORT_CMD_FMT
.format(('' if required_config['auto_export'] else 'no '), export_group))
if clear_group:
# clear pcap files
self._commands.append(self.WJH_CLEAR_CMD_FMT.format(clear_group))
def main():
""" main entry point for module execution
"""
OnyxWJHModule.main()
if __name__ == '__main__':
main()
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 0 B | 0644 |
|
| onyx_aaa.py | File | 5.63 KB | 0644 |
|
| onyx_bfd.py | File | 10.93 KB | 0644 |
|
| onyx_bgp.py | File | 18.75 KB | 0644 |
|
| onyx_buffer_pool.py | File | 4.68 KB | 0644 |
|
| onyx_command.py | File | 6.46 KB | 0644 |
|
| onyx_config.py | File | 9.21 KB | 0644 |
|
| onyx_facts.py | File | 6.88 KB | 0644 |
|
| onyx_igmp.py | File | 7.56 KB | 0644 |
|
| onyx_igmp_interface.py | File | 3.93 KB | 0644 |
|
| onyx_igmp_vlan.py | File | 18.34 KB | 0644 |
|
| onyx_interface.py | File | 16.85 KB | 0644 |
|
| onyx_l2_interface.py | File | 10.62 KB | 0644 |
|
| onyx_l3_interface.py | File | 9.8 KB | 0644 |
|
| onyx_linkagg.py | File | 12.1 KB | 0644 |
|
| onyx_lldp.py | File | 2.92 KB | 0644 |
|
| onyx_lldp_interface.py | File | 7.16 KB | 0644 |
|
| onyx_magp.py | File | 8.01 KB | 0644 |
|
| onyx_mlag_ipl.py | File | 6.51 KB | 0644 |
|
| onyx_mlag_vip.py | File | 5.61 KB | 0644 |
|
| onyx_ntp.py | File | 9.2 KB | 0644 |
|
| onyx_ntp_servers_peers.py | File | 10.83 KB | 0644 |
|
| onyx_ospf.py | File | 7.89 KB | 0644 |
|
| onyx_pfc_interface.py | File | 6.86 KB | 0644 |
|
| onyx_protocol.py | File | 6.24 KB | 0644 |
|
| onyx_ptp_global.py | File | 6.65 KB | 0644 |
|
| onyx_ptp_interface.py | File | 7.83 KB | 0644 |
|
| onyx_qos.py | File | 9.01 KB | 0644 |
|
| onyx_snmp.py | File | 19.22 KB | 0644 |
|
| onyx_snmp_hosts.py | File | 20.09 KB | 0644 |
|
| onyx_snmp_users.py | File | 11.59 KB | 0644 |
|
| onyx_syslog_files.py | File | 9.45 KB | 0644 |
|
| onyx_syslog_remote.py | File | 13.2 KB | 0644 |
|
| onyx_traffic_class.py | File | 14.01 KB | 0644 |
|
| onyx_username.py | File | 10.18 KB | 0644 |
|
| onyx_vlan.py | File | 6.24 KB | 0644 |
|
| onyx_vxlan.py | File | 9.21 KB | 0644 |
|
| onyx_wjh.py | File | 7.02 KB | 0644 |
|