Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.148.104.103
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/lib/python3/dist-packages/ansible_collections/mellanox/onyx/plugins/modules//onyx_protocol.py
#!/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_protocol
author: "Samer Deeb (@samerd)"
short_description: Enables/Disables protocols on Mellanox ONYX network devices
description:
  - This module provides a mechanism for enabling and disabling protocols
    Mellanox on ONYX network devices.
notes:
  - Tested on ONYX 3.6.4000
options:
  mlag:
    description: MLAG protocol
    choices: ['enabled', 'disabled']
  magp:
    description: MAGP protocol
    choices: ['enabled', 'disabled']
  spanning_tree:
    description: Spanning Tree support
    choices: ['enabled', 'disabled']
  dcb_pfc:
    description: DCB priority flow control
    choices: ['enabled', 'disabled']
  igmp_snooping:
    description: IP IGMP snooping
    choices: ['enabled', 'disabled']
  lacp:
    description: LACP protocol
    choices: ['enabled', 'disabled']
  ip_l3:
    description: IP L3 support
    choices: ['enabled', 'disabled']
  ip_routing:
    description: IP routing support
    choices: ['enabled', 'disabled']
  lldp:
    description: LLDP protocol
    choices: ['enabled', 'disabled']
  bgp:
    description: BGP protocol
    choices: ['enabled', 'disabled']
  ospf:
    description: OSPF protocol
    choices: ['enabled', 'disabled']
  nve:
    description: nve protocol
    choices: ['enabled', 'disabled']
  bfd:
    description: bfd protocol
    choices: ['enabled', 'disabled']
    version_added: '0.2.0'
'''

EXAMPLES = """
- name: Enable protocols for MLAG
  onyx_protocol:
    lacp: enabled
    spanning_tree: disabled
    ip_routing: enabled
    mlag: enabled
    dcb_pfc: enabled
"""

RETURN = """
commands:
  description: The list of configuration mode commands to send to the device.
  returned: always
  type: list
  sample:
    - no spanning-tree
    - protocol mlag
"""

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems

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 OnyxProtocolModule(BaseOnyxModule):

    PROTOCOL_MAPPING = dict(
        mlag=dict(name="mlag", enable="protocol mlag",
                  disable="no protocol mlag"),
        magp=dict(name="magp", enable="protocol magp",
                  disable="no protocol magp"),
        spanning_tree=dict(name="spanning-tree", enable="spanning-tree",
                           disable="no spanning-tree"),
        dcb_pfc=dict(name="priority-flow-control",
                     enable="dcb priority-flow-control enable force",
                     disable="no dcb priority-flow-control enable force"),
        igmp_snooping=dict(name="igmp-snooping", enable="ip igmp snooping",
                           disable="no ip igmp snooping"),
        lacp=dict(name="lacp", enable="lacp", disable="no lacp"),
        ip_l3=dict(name="IP L3", enable="ip l3",
                        disable="no ip l3"),
        ip_routing=dict(name="IP routing", enable="ip routing",
                        disable="no ip routing"),
        lldp=dict(name="lldp", enable="lldp", disable="no lldp"),
        bgp=dict(name="bgp", enable="protocol bgp", disable="no protocol bgp"),
        ospf=dict(name="ospf", enable="protocol ospf",
                  disable="no protocol ospf"),
        nve=dict(name="nve", enable="protocol nve",
                 disable="no protocol nve"),
        bfd=dict(name="bfd", enable="protocol bfd",
                 disable="no protocol bfd"),
    )

    @classmethod
    def _get_element_spec(cls):
        element_spec = dict()
        for protocol in cls.PROTOCOL_MAPPING:
            element_spec[protocol] = dict(choices=['enabled', 'disabled'])
        return element_spec

    def init_module(self):
        """ Ansible 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
        for key, val in iteritems(module_params):
            if key in self.PROTOCOL_MAPPING and val is not None:
                self._required_config[key] = val

    def _get_protocols(self):
        return show_cmd(self._module, "show protocols")

    def _get_ip_routing(self):
        return show_cmd(self._module, 'show ip routing | include "IP routing"',
                        json_fmt=False)

    def load_current_config(self):
        self._current_config = dict()
        protocols_config = self._get_protocols()
        if not protocols_config:
            protocols_config = dict()
        ip_config = self._get_ip_routing()
        if ip_config:
            lines = ip_config.split('\n')
            for line in lines:
                line = line.strip()
                line_attr = line.split(':')
                if len(line_attr) == 2:
                    attr = line_attr[0].strip()
                    val = line_attr[1].strip()
                    protocols_config[attr] = val
        for protocol, protocol_metadata in iteritems(self.PROTOCOL_MAPPING):
            protocol_json_attr = protocol_metadata['name']
            val = protocols_config.get(protocol_json_attr, 'disabled')
            if val not in ('enabled', 'disabled'):
                val = 'enabled'
            self._current_config[protocol] = val

    def generate_commands(self):
        for protocol, req_val in iteritems(self._required_config):
            protocol_metadata = self.PROTOCOL_MAPPING[protocol]
            curr_val = self._current_config.get(protocol, 'disabled')
            if curr_val != req_val:
                if req_val == 'disabled':
                    command = protocol_metadata['disable']
                else:
                    command = protocol_metadata['enable']
                self._commands.append(command)


def main():
    """ main entry point for module execution
    """
    OnyxProtocolModule.main()


if __name__ == '__main__':
    main()

Anon7 - 2022
AnonSec Team