����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_ntp
version_added: '0.2.0'
author: "Sara-Touqan (@sarato)"
short_description: Manage NTP general configurations and ntp keys configurations on Mellanox ONYX network devices
description:
- This module provides declarative management of NTP & NTP Keys
on Mellanox ONYX network devices.
options:
state:
description:
- State of the NTP configuration.
choices: ['enabled', 'disabled']
type: str
authenticate_state:
description:
- State of the NTP authentication configuration.
choices: ['enabled', 'disabled']
type: str
ntp_authentication_keys:
type: list
description:
- List of ntp authentication keys
suboptions:
auth_key_id:
description:
- Configures ntp key-id, range 1-65534
required: true
type: int
auth_key_encrypt_type:
description:
- encryption type used to configure ntp authentication key.
required: true
choices: ['md5', 'sha1']
type: str
auth_key_password:
description:
- password used for ntp authentication key.
required: true
type: str
auth_key_state:
description:
- Used to decide if you want to delete given ntp key or not
choices: ['present', 'absent']
type: str
trusted_keys:
type: list
description:
- List of ntp trusted keys
'''
EXAMPLES = """
- name: Configure NTP
onyx_ntp:
state: enabled
authenticate_state: enabled
ntp_authentication_keys:
- auth_key_id: 1
auth_key_encrypt_type: md5
auth_key_password: 12345
auth_key_state: absent
trusted_keys: 1,2,3
"""
RETURN = """
commands:
description: The list of configuration mode commands to send to the device
returned: always.
type: list
sample:
- ntp enable
- ntp disable
- ntp authenticate
- no ntp authenticate
- ntp authentication-key 1 md5 12345
- no ntp authentication-key 1
- ntp trusted-key 1,2,3
"""
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.mellanox.onyx.plugins.module_utils.network.onyx.onyx import BaseOnyxModule
from ansible_collections.mellanox.onyx.plugins.module_utils.network.onyx.onyx import show_cmd
class OnyxNTPModule(BaseOnyxModule):
def init_module(self):
""" module initialization
"""
ntp_authentication_key_spec = dict(auth_key_id=dict(type='int', required=True),
auth_key_encrypt_type=dict(required=True, choices=['md5', 'sha1']),
auth_key_password=dict(required=True),
auth_key_state=dict(choices=['present', 'absent']))
element_spec = dict(
state=dict(choices=['enabled', 'disabled']),
authenticate_state=dict(choices=['enabled', 'disabled']),
ntp_authentication_keys=dict(type='list', elements='dict', options=ntp_authentication_key_spec),
trusted_keys=dict(type='list', elements='int')
)
argument_spec = dict()
argument_spec.update(element_spec)
self._module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True)
def _validate_key_id(self):
keys_id_list = self._required_config.get("ntp_authentication_keys")
if keys_id_list:
for key_item in keys_id_list:
key_id = key_item.get("auth_key_id")
if (key_id < 1) or (key_id > 65534):
self._module.fail_json(
msg='Invalid Key value, value should be in the range 1-65534')
def get_required_config(self):
module_params = self._module.params
self._required_config = dict(module_params)
self.validate_param_values(self._required_config)
self._validate_key_id()
def _show_ntp_config(self):
show_cmds = []
cmd = "show ntp"
show_cmds.append(show_cmd(self._module, cmd, json_fmt=True, fail_on_error=False))
cmd = "show ntp keys"
show_cmds.append(show_cmd(self._module, cmd, json_fmt=True, fail_on_error=False))
return show_cmds
def _set_ntp_keys_config(self, ntp_config):
if not ntp_config:
return
for req_ntp_auth_key in ntp_config:
ecryption_type = req_ntp_auth_key.get("Encryption Type")
self._current_config[req_ntp_auth_key.get("header")] = ecryption_type
def _set_ntp_config(self, ntp_config):
ntp_config = ntp_config[0]
if not ntp_config:
return
self._current_config['state'] = ntp_config.get("NTP is administratively")
self._current_config['authenticate_state'] = ntp_config.get("NTP Authentication administratively")
def load_current_config(self):
self._current_config = dict()
ntp_config = self._show_ntp_config()
if ntp_config:
if ntp_config[0]:
self._set_ntp_config(ntp_config[0])
if ntp_config[1]:
self._set_ntp_keys_config(ntp_config[1])
def generate_commands(self):
current_state = self._current_config.get("state")
state = self._required_config.get("state")
if state is None:
state = current_state
if state is not None:
if current_state != state:
if state == 'enabled':
self._commands.append('ntp enable')
else:
self._commands.append('no ntp enable')
authenticate_state = self._required_config.get("authenticate_state")
if authenticate_state:
current_authenticate_state = self._current_config.get("authenticate_state")
if authenticate_state is not None:
if current_authenticate_state != authenticate_state:
if authenticate_state == 'enabled':
self._commands.append('ntp authenticate')
else:
self._commands.append('no ntp authenticate')
req_ntp_auth_keys = self._required_config.get('ntp_authentication_keys')
if req_ntp_auth_keys:
if req_ntp_auth_keys is not None:
for req_ntp_auth_key in req_ntp_auth_keys:
req_key_id = req_ntp_auth_key.get('auth_key_id')
req_key = 'NTP Key ' + str(req_key_id)
current_req_key = self._current_config.get(req_key)
auth_key_state = req_ntp_auth_key.get('auth_key_state')
req_encrypt_type = req_ntp_auth_key.get('auth_key_encrypt_type')
req_password = req_ntp_auth_key.get('auth_key_password')
if current_req_key:
if req_encrypt_type == current_req_key:
if auth_key_state:
if auth_key_state == 'absent':
self._commands.append('no ntp authentication-key {0}' .format(req_key_id))
else:
continue
else:
if auth_key_state:
if auth_key_state == 'present':
self._commands.append('ntp authentication-key {0} {1} {2}'
.format(req_key_id,
req_encrypt_type,
req_password))
else:
self._commands.append('ntp authentication-key {0} {1} {2}'
.format(req_key_id,
req_encrypt_type,
req_password))
else:
if auth_key_state:
if auth_key_state == 'present':
self._commands.append('ntp authentication-key {0} {1} {2}'
.format(req_key_id,
req_encrypt_type,
req_password))
else:
self._commands.append('ntp authentication-key {0} {1} {2}'
.format(req_key_id,
req_encrypt_type,
req_password))
req_trusted_keys = self._required_config.get('trusted_keys')
if req_trusted_keys:
for key in req_trusted_keys:
self._commands.append('ntp trusted-key {0}' .format(key))
def main():
""" main entry point for module execution
"""
OnyxNTPModule.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 |
|