Server IP : 85.214.239.14 / Your IP : 3.135.209.20 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/ansible_collections/mellanox/onyx/plugins/modules/ |
Upload File : |
#!/usr/bin/python # 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_lldp author: "Samer Deeb (@samerd)" short_description: Manage LLDP configuration on Mellanox ONYX network devices description: - This module provides declarative management of LLDP service configuration on Mellanox ONYX network devices. options: state: description: - State of the LLDP protocol configuration. default: present choices: ['present', 'absent'] ''' EXAMPLES = """ - name: Enable LLDP protocol onyx_lldp: state: present - name: Disable LLDP protocol onyx_lldp: state: lldp """ RETURN = """ commands: description: The list of configuration mode commands to send to the device returned: always. type: list sample: - lldp """ 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 OnyxLldpModule(BaseOnyxModule): LLDP_ENTRY = 'LLDP' SHOW_LLDP_CMD = 'show lldp local' @classmethod def _get_element_spec(cls): return dict( state=dict(default='present', choices=['present', 'absent']), ) def init_module(self): """ module initialization """ element_spec = self._get_element_spec() argument_spec = dict() argument_spec.update(element_spec) self._module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True) def get_required_config(self): self._required_config = dict() module_params = self._module.params params = { 'state': module_params['state'], } self.validate_param_values(params) self._required_config.update(params) def _get_lldp_config(self): return show_cmd(self._module, self.SHOW_LLDP_CMD) def load_current_config(self): self._current_config = dict() state = 'absent' config = self._get_lldp_config() or dict() for item in config: lldp_state = item.get(self.LLDP_ENTRY) if lldp_state is not None: if lldp_state == 'enabled': state = 'present' break self._current_config['state'] = state def generate_commands(self): req_state = self._required_config['state'] curr_state = self._current_config['state'] if curr_state != req_state: cmd = 'lldp' if req_state == 'absent': cmd = 'no %s' % cmd self._commands.append(cmd) def main(): """ main entry point for module execution """ OnyxLldpModule.main() if __name__ == '__main__': main()