diff options
Diffstat (limited to 'lib/ansible/modules/network/netvisor')
51 files changed, 0 insertions, 12359 deletions
diff --git a/lib/ansible/modules/network/netvisor/_pn_cluster.py b/lib/ansible/modules/network/netvisor/_pn_cluster.py deleted file mode 100644 index 98edab1c62..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_cluster.py +++ /dev/null @@ -1,323 +0,0 @@ -#!/usr/bin/python -""" PN CLI cluster-create/cluster-delete """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_cluster -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to create/delete a cluster. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute cluster-create or cluster-delete command. - - A cluster allows two switches to cooperate in high-availability (HA) - deployments. The nodes that form the cluster must be members of the same - fabric. Clusters are typically used in conjunction with a virtual link - aggregation group (VLAG) that allows links physically connected to two - separate switches appear as a single trunk to a third device. The third - device can be a switch,server, or any Ethernet device. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch to run the cli on. - required: False - default: 'local' - state: - description: - - Specify action to perform. Use 'present' to create cluster and 'absent' - to delete cluster. - required: true - choices: ['present', 'absent'] - pn_name: - description: - - Specify the name of the cluster. - required: true - pn_cluster_node1: - description: - - Specify the name of the first switch in the cluster. - - Required for 'cluster-create'. - pn_cluster_node2: - description: - - Specify the name of the second switch in the cluster. - - Required for 'cluster-create'. - pn_validate: - description: - - Validate the inter-switch links and state of switches in the cluster. - type: bool -""" - -EXAMPLES = """ -- name: create spine cluster - pn_cluster: - state: 'present' - pn_name: 'spine-cluster' - pn_cluster_node1: 'spine01' - pn_cluster_node2: 'spine02' - pn_validate: True - pn_quiet: True - -- name: delete spine cluster - pn_cluster: - state: 'absent' - pn_name: 'spine-cluster' - pn_quiet: True -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the cluster command. - returned: always - type: list -stderr: - description: The set of error responses from the cluster command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - -NAME_EXISTS = None -NODE1_EXISTS = None -NODE2_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks for idempotency using the cluster-show command. - If a cluster with given name exists, return NAME_EXISTS as True else False. - If the given cluster-node-1 is already a part of another cluster, return - NODE1_EXISTS as True else False. - If the given cluster-node-2 is already a part of another cluster, return - NODE2_EXISTS as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: NAME_EXISTS, NODE1_EXISTS, NODE2_EXISTS - """ - name = module.params['pn_name'] - node1 = module.params['pn_cluster_node1'] - node2 = module.params['pn_cluster_node2'] - - show = cli + ' cluster-show format name,cluster-node-1,cluster-node-2 ' - show = shlex.split(show) - out = module.run_command(show)[1] - - out = out.split() - # Global flags - global NAME_EXISTS, NODE1_EXISTS, NODE2_EXISTS - - if name in out: - NAME_EXISTS = True - else: - NAME_EXISTS = False - if node1 in out: - NODE1_EXISTS = True - else: - NODE2_EXISTS = False - if node2 in out: - NODE2_EXISTS = True - else: - NODE2_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'cluster-create' - if state == 'absent': - command = 'cluster-delete' - return command - - -def main(): - """ This section is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent']), - pn_name=dict(required=True, type='str'), - pn_cluster_node1=dict(type='str'), - pn_cluster_node2=dict(type='str'), - pn_validate=dict(type='bool') - ), - required_if=( - ["state", "present", - ["pn_name", "pn_cluster_node1", "pn_cluster_node2"]], - ["state", "absent", ["pn_name"]] - ) - ) - - # Accessing the parameters - state = module.params['state'] - name = module.params['pn_name'] - cluster_node1 = module.params['pn_cluster_node1'] - cluster_node2 = module.params['pn_cluster_node2'] - validate = module.params['pn_validate'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - if command == 'cluster-create': - - check_cli(module, cli) - - if NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='Cluster with name %s already exists' % name - ) - if NODE1_EXISTS is True: - module.exit_json( - skipped=True, - msg='Node %s already part of a cluster' % cluster_node1 - ) - if NODE2_EXISTS is True: - module.exit_json( - skipped=True, - msg='Node %s already part of a cluster' % cluster_node2 - ) - - cli += ' %s name %s ' % (command, name) - cli += 'cluster-node-1 %s cluster-node-2 %s ' % (cluster_node1, - cluster_node2) - if validate is True: - cli += ' validate ' - if validate is False: - cli += ' no-validate ' - - if command == 'cluster-delete': - - check_cli(module, cli) - - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='Cluster with name %s does not exist' % name - ) - cli += ' %s name %s ' % (command, name) - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_ospf.py b/lib/ansible/modules/network/netvisor/_pn_ospf.py deleted file mode 100644 index df54982541..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_ospf.py +++ /dev/null @@ -1,301 +0,0 @@ -#!/usr/bin/python -""" PN-CLI vrouter-ospf-add/remove """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_ospf -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to add/remove ospf protocol to a vRouter. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vrouter-ospf-add, vrouter-ospf-remove command. - - This command adds/removes Open Shortest Path First(OSPF) routing - protocol to a virtual router(vRouter) service. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - default: 'local' - state: - description: - - Assert the state of the ospf. Use 'present' to add ospf - and 'absent' to remove ospf. - required: True - default: present - choices: ['present', 'absent'] - pn_vrouter_name: - description: - - Specify the name of the vRouter. - required: True - pn_network_ip: - description: - - Specify the network IP (IPv4 or IPv6) address. - required: True - pn_ospf_area: - description: - - Stub area number for the configuration. Required for vrouter-ospf-add. -""" - -EXAMPLES = """ -- name: "Add OSPF to vrouter" - pn_ospf: - state: present - pn_vrouter_name: name-string - pn_network_ip: 192.168.11.2/24 - pn_ospf_area: 1.0.0.0 - -- name: "Remove OSPF from vrouter" - pn_ospf: - state: absent - pn_vrouter_name: name-string -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the ospf command. - returned: always - type: list -stderr: - description: The set of error responses from the ospf command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - -VROUTER_EXISTS = None -NETWORK_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-ospf-show command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - If an OSPF network with the given ip exists on the given vRouter, - return NETWORK_EXISTS as True else False. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VROUTER_EXISTS, NETWORK_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - network_ip = module.params['pn_network_ip'] - # Global flags - global VROUTER_EXISTS, NETWORK_EXISTS - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers ' - check_vrouter = shlex.split(check_vrouter) - out = module.run_command(check_vrouter)[1] - out = out.split() - - if vrouter_name in out: - VROUTER_EXISTS = True - else: - VROUTER_EXISTS = False - - # Check for OSPF networks - show = cli + ' vrouter-ospf-show vrouter-name %s ' % vrouter_name - show += 'format network no-show-headers' - show = shlex.split(show) - out = module.run_command(show)[1] - out = out.split() - - if network_ip in out: - NETWORK_EXISTS = True - else: - NETWORK_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - cmd = shlex.split(cli) - - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vrouter-ospf-add' - if state == 'absent': - command = 'vrouter-ospf-remove' - return command - - -def main(): - """ This section is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(type='str', default='present', choices=['present', - 'absent']), - pn_vrouter_name=dict(required=True, type='str'), - pn_network_ip=dict(required=True, type='str'), - pn_ospf_area=dict(type='str') - ), - required_if=( - ['state', 'present', - ['pn_network_ip', 'pn_ospf_area']], - ['state', 'absent', ['pn_network_ip']] - ) - ) - - # Accessing the arguments - state = module.params['state'] - vrouter_name = module.params['pn_vrouter_name'] - network_ip = module.params['pn_network_ip'] - ospf_area = module.params['pn_ospf_area'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - check_cli(module, cli) - - if state == 'present': - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if NETWORK_EXISTS is True: - module.exit_json( - skipped=True, - msg=('OSPF with network ip %s already exists on %s' - % (network_ip, vrouter_name)) - ) - cli += (' %s vrouter-name %s network %s ospf-area %s' - % (command, vrouter_name, network_ip, ospf_area)) - - if state == 'absent': - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if NETWORK_EXISTS is False: - module.exit_json( - skipped=True, - msg=('OSPF with network ip %s already exists on %s' - % (network_ip, vrouter_name)) - ) - cli += (' %s vrouter-name %s network %s' - % (command, vrouter_name, network_ip)) - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_ospfarea.py b/lib/ansible/modules/network/netvisor/_pn_ospfarea.py deleted file mode 100644 index 85e4691cac..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_ospfarea.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/python -""" PN-CLI vrouter-ospf-add/remove """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_ospfarea -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to add/remove ospf area to/from a vrouter. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vrouter-ospf-add, vrouter-ospf-remove command. - - This command adds/removes Open Shortest Path First(OSPF) area to/from - a virtual router(vRouter) service. -options: - pn_cliusername: - description: - - Login username. - required: true - pn_clipassword: - description: - - Login password. - required: true - pn_cliswitch: - description: - - Target switch(es) to run the CLI on. - required: False - state: - description: - - State the action to perform. Use 'present' to add ospf-area, 'absent' - to remove ospf-area and 'update' to modify ospf-area. - required: true - choices: ['present', 'absent', 'update'] - pn_vrouter_name: - description: - - Specify the name of the vRouter. - required: true - pn_ospf_area: - description: - - Specify the OSPF area number. - required: true - pn_stub_type: - description: - - Specify the OSPF stub type. - choices: ['none', 'stub', 'stub-no-summary', 'nssa', 'nssa-no-summary'] - pn_prefix_listin: - description: - - OSPF prefix list for filtering incoming packets. - pn_prefix_listout: - description: - - OSPF prefix list for filtering outgoing packets. - pn_quiet: - description: - - Enable/disable system information. - required: false - type: bool - default: true -""" - -EXAMPLES = """ -- name: "Add OSPF area to vrouter" - pn_ospfarea: - state: present - pn_cliusername: admin - pn_clipassword: admin - pn_ospf_area: 1.0.0.0 - pn_stub_type: stub - -- name: "Remove OSPF from vrouter" - pn_ospf: - state: absent - pn_cliusername: admin - pn_clipassword: admin - pn_vrouter_name: name-string - pn_ospf_area: 1.0.0.0 -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the ospf command. - returned: always - type: list -stderr: - description: The set of error responses from the ospf command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vrouter-ospf-area-add' - if state == 'absent': - command = 'vrouter-ospf-area-remove' - if state == 'update': - command = 'vrouter-ospf-area-modify' - return command - - -def main(): - """ This section is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=True, type='str'), - pn_clipassword=dict(required=True, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=['present', 'absent', 'update']), - pn_vrouter_name=dict(required=True, type='str'), - pn_ospf_area=dict(required=True, type='str'), - pn_stub_type=dict(type='str', choices=['none', 'stub', 'nssa', - 'stub-no-summary', - 'nssa-no-summary']), - pn_prefix_listin=dict(type='str'), - pn_prefix_listout=dict(type='str'), - pn_quiet=dict(type='bool', default='True') - ) - ) - - # Accessing the arguments - cliusername = module.params['pn_cliusername'] - clipassword = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - vrouter_name = module.params['pn_vrouter_name'] - ospf_area = module.params['pn_ospf_area'] - stub_type = module.params['pn_stub_type'] - prefix_listin = module.params['pn_prefix_listin'] - prefix_listout = module.params['pn_prefix_listout'] - quiet = module.params['pn_quiet'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = '/usr/bin/cli' - - if quiet is True: - cli += ' --quiet ' - - cli += ' --user %s:%s ' % (cliusername, clipassword) - - if cliswitch: - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - - cli += ' %s vrouter-name %s area %s ' % (command, vrouter_name, ospf_area) - - if stub_type: - cli += ' stub-type ' + stub_type - - if prefix_listin: - cli += ' prefix-list-in ' + prefix_listin - - if prefix_listout: - cli += ' prefix-list-out ' + prefix_listout - - # Run the CLI command - ospfcommand = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(ospfcommand) - - # Response in JSON format - if result != 0: - module.exit_json( - command=cli, - stderr=err.rstrip("\r\n"), - changed=False - ) - - else: - module.exit_json( - command=cli, - stdout=out.rstrip("\r\n"), - changed=True - ) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_show.py b/lib/ansible/modules/network/netvisor/_pn_show.py deleted file mode 100644 index b30839bb8f..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_show.py +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/python -""" PN CLI show commands """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_show -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: Run show commands on nvOS device. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute show command in the nodes and returns the results - read from the device. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run the cli on. - required: False - pn_command: - description: - - The C(pn_command) takes a CLI show command as value. - required: true - pn_parameters: - description: - - Display output using a specific parameter. Use 'all' to display - possible output. List of comma separated parameters. - default: 'all' - pn_options: - description: - - Specify formatting options. -""" - -EXAMPLES = """ -- name: run the vlan-show command - pn_show: - pn_command: 'vlan-show' - pn_parameters: id,scope,ports - pn_options: 'layout vertical' - -- name: run the vlag-show command - pn_show: - pn_command: 'vlag-show' - pn_parameters: 'id,name,cluster,mode' - pn_options: 'no-show-headers' - -- name: run the cluster-show command - pn_show: - pn_command: 'cluster-show' -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the show command. - returned: always - type: list -stderr: - description: The set of error responses from the show command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused any change on the target. - returned: always(False) - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch: - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - command = module.params['pn_command'] - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - msg='%s: ' % command, - stderr=err.strip(), - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - msg='%s: ' % command, - stdout=out.strip(), - changed=False - ) - - else: - module.exit_json( - command=cli, - msg='%s: Nothing to display!!!' % command, - changed=False - ) - - -def main(): - """ This section is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=True, type='str'), - pn_clipassword=dict(required=True, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str'), - pn_command=dict(required=True, type='str'), - pn_parameters=dict(default='all', type='str'), - pn_options=dict(type='str') - ) - ) - - # Accessing the arguments - command = module.params['pn_command'] - parameters = module.params['pn_parameters'] - options = module.params['pn_options'] - - # Building the CLI command string - cli = pn_cli(module) - - cli += ' %s format %s ' % (command, parameters) - - if options: - cli += options - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_trunk.py b/lib/ansible/modules/network/netvisor/_pn_trunk.py deleted file mode 100644 index 59c97c0867..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_trunk.py +++ /dev/null @@ -1,465 +0,0 @@ -#!/usr/bin/python -""" PN CLI trunk-create/trunk-delete/trunk-modify """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_trunk -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to create/delete/modify a trunk. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute trunk-create or trunk-delete command. - - Trunks can be used to aggregate network links at Layer 2 on the local - switch. Use this command to create a new trunk. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run the cli on. - required: False - default: 'local' - state: - description: - - State the action to perform. Use 'present' to create trunk, - 'absent' to delete trunk and 'update' to modify trunk. - required: True - choices: ['present', 'absent', 'update'] - pn_name: - description: - - Specify the name for the trunk configuration. - required: true - pn_ports: - description: - - Specify the port number(s) for the link(s) to aggregate into the trunk. - - Required for trunk-create. - pn_speed: - description: - - Specify the port speed or disable the port. - choices: ['disable', '10m', '100m', '1g', '2.5g', '10g', '40g'] - pn_egress_rate_limit: - description: - - Specify an egress port data rate limit for the configuration. - pn_jumbo: - description: - - Specify if the port can receive jumbo frames. - type: bool - pn_lacp_mode: - description: - - Specify the LACP mode for the configuration. - choices: ['off', 'passive', 'active'] - pn_lacp_priority: - description: - - Specify the LACP priority. This is a number between 1 and 65535 with a - default value of 32768. - pn_lacp_timeout: - description: - - Specify the LACP time out as slow (30 seconds) or fast (4seconds). - The default value is slow. - choices: ['slow', 'fast'] - pn_lacp_fallback: - description: - - Specify the LACP fallback mode as bundles or individual. - choices: ['bundle', 'individual'] - pn_lacp_fallback_timeout: - description: - - Specify the LACP fallback timeout in seconds. The range is between 30 - and 60 seconds with a default value of 50 seconds. - pn_edge_switch: - description: - - Specify if the switch is an edge switch. - type: bool - pn_pause: - description: - - Specify if pause frames are sent. - type: bool - pn_description: - description: - - Specify a description for the trunk configuration. - pn_loopback: - description: - - Specify loopback if you want to use loopback. - type: bool - pn_mirror_receive: - description: - - Specify if the configuration receives mirrored traffic. - type: bool - pn_unknown_ucast_level: - description: - - Specify an unknown unicast level in percent. The default value is 100%. - pn_unknown_mcast_level: - description: - - Specify an unknown multicast level in percent. The default value is 100%. - pn_broadcast_level: - description: - - Specify a broadcast level in percent. The default value is 100%. - pn_port_macaddr: - description: - - Specify the MAC address of the port. - pn_loopvlans: - description: - - Specify a list of looping vlans. - pn_routing: - description: - - Specify if the port participates in routing on the network. - type: bool - pn_host: - description: - - Host facing port control setting. - type: bool -""" - -EXAMPLES = """ -- name: create trunk - pn_trunk: - state: 'present' - pn_name: 'spine-to-leaf' - pn_ports: '11,12,13,14' - -- name: delete trunk - pn_trunk: - state: 'absent' - pn_name: 'spine-to-leaf' -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the trunk command. - returned: always - type: list -stderr: - description: The set of error responses from the trunk command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# Ansible boiler-plate -from ansible.module_utils.basic import AnsibleModule - -TRUNK_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks for idempotency using the trunk-show command. - If a trunk with given name exists, return TRUNK_EXISTS as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: TRUNK_EXISTS - """ - name = module.params['pn_name'] - - show = cli + ' trunk-show format switch,name no-show-headers' - show = shlex.split(show) - out = module.run_command(show)[1] - - out = out.split() - # Global flags - global TRUNK_EXISTS - if name in out: - TRUNK_EXISTS = True - else: - TRUNK_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'trunk-create' - if state == 'absent': - command = 'trunk-delete' - if state == 'update': - command = 'trunk-modify' - return command - - -def main(): - """ This portion is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent', 'update']), - pn_name=dict(required=True, type='str'), - pn_ports=dict(type='str'), - pn_speed=dict(type='str', - choices=['disable', '10m', '100m', '1g', '2.5g', - '10g', '40g']), - pn_egress_rate_limit=dict(type='str'), - pn_jumbo=dict(type='bool'), - pn_lacp_mode=dict(type='str', choices=[ - 'off', 'passive', 'active']), - pn_lacp_priority=dict(type='int'), - pn_lacp_timeout=dict(type='str', choices=['slow', 'fast']), - pn_lacp_fallback=dict(type='str', choices=[ - 'bundle', 'individual']), - pn_lacp_fallback_timeout=dict(type='str'), - pn_edge_switch=dict(type='bool'), - pn_pause=dict(type='bool'), - pn_description=dict(type='str'), - pn_loopback=dict(type='bool'), - pn_mirror_receive=dict(type='bool'), - pn_unknown_ucast_level=dict(type='str'), - pn_unknown_mcast_level=dict(type='str'), - pn_broadcast_level=dict(type='str'), - pn_port_macaddr=dict(type='str'), - pn_loopvlans=dict(type='str'), - pn_routing=dict(type='bool'), - pn_host=dict(type='bool') - ), - required_if=( - ["state", "present", ["pn_name", "pn_ports"]], - ["state", "absent", ["pn_name"]], - ["state", "update", ["pn_name"]] - ) - ) - - # Accessing the arguments - state = module.params['state'] - name = module.params['pn_name'] - ports = module.params['pn_ports'] - speed = module.params['pn_speed'] - egress_rate_limit = module.params['pn_egress_rate_limit'] - jumbo = module.params['pn_jumbo'] - lacp_mode = module.params['pn_lacp_mode'] - lacp_priority = module.params['pn_lacp_priority'] - lacp_timeout = module.params['pn_lacp_timeout'] - lacp_fallback = module.params['pn_lacp_fallback'] - lacp_fallback_timeout = module.params['pn_lacp_fallback_timeout'] - edge_switch = module.params['pn_edge_switch'] - pause = module.params['pn_pause'] - description = module.params['pn_description'] - loopback = module.params['pn_loopback'] - mirror_receive = module.params['pn_mirror_receive'] - unknown_ucast_level = module.params['pn_unknown_ucast_level'] - unknown_mcast_level = module.params['pn_unknown_mcast_level'] - broadcast_level = module.params['pn_broadcast_level'] - port_macaddr = module.params['pn_port_macaddr'] - loopvlans = module.params['pn_loopvlans'] - routing = module.params['pn_routing'] - host = module.params['pn_host'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - if command == 'trunk-delete': - - check_cli(module, cli) - if TRUNK_EXISTS is False: - module.exit_json( - skipped=True, - msg='Trunk with name %s does not exist' % name - ) - cli += ' %s name %s ' % (command, name) - - else: - if command == 'trunk-create': - check_cli(module, cli) - if TRUNK_EXISTS is True: - module.exit_json( - skipped=True, - msg='Trunk with name %s already exists' % name - ) - cli += ' %s name %s ' % (command, name) - - # Appending options - if ports: - cli += ' ports ' + ports - - if speed: - cli += ' speed ' + speed - - if egress_rate_limit: - cli += ' egress-rate-limit ' + egress_rate_limit - - if jumbo is True: - cli += ' jumbo ' - if jumbo is False: - cli += ' no-jumbo ' - - if lacp_mode: - cli += ' lacp-mode ' + lacp_mode - - if lacp_priority: - cli += ' lacp-priority ' + lacp_priority - - if lacp_timeout: - cli += ' lacp-timeout ' + lacp_timeout - - if lacp_fallback: - cli += ' lacp-fallback ' + lacp_fallback - - if lacp_fallback_timeout: - cli += ' lacp-fallback-timeout ' + lacp_fallback_timeout - - if edge_switch is True: - cli += ' edge-switch ' - if edge_switch is False: - cli += ' no-edge-switch ' - - if pause is True: - cli += ' pause ' - if pause is False: - cli += ' no-pause ' - - if description: - cli += ' description ' + description - - if loopback is True: - cli += ' loopback ' - if loopback is False: - cli += ' no-loopback ' - - if mirror_receive is True: - cli += ' mirror-receive-only ' - if mirror_receive is False: - cli += ' no-mirror-receive-only ' - - if unknown_ucast_level: - cli += ' unknown-ucast-level ' + unknown_ucast_level - - if unknown_mcast_level: - cli += ' unknown-mcast-level ' + unknown_mcast_level - - if broadcast_level: - cli += ' broadcast-level ' + broadcast_level - - if port_macaddr: - cli += ' port-mac-address ' + port_macaddr - - if loopvlans: - cli += ' loopvlans ' + loopvlans - - if routing is True: - cli += ' routing ' - if routing is False: - cli += ' no-routing ' - - if host is True: - cli += ' host-enable ' - if host is False: - cli += ' host-disable ' - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_vlag.py b/lib/ansible/modules/network/netvisor/_pn_vlag.py deleted file mode 100644 index 3d25bc3bbd..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_vlag.py +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/python -""" PN CLI vlag-create/vlag-delete/vlag-modify """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vlag -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to create/delete/modify vlag. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vlag-create/vlag-delete/vlag-modify command. - - A virtual link aggregation group (VLAG) allows links that are physically - connected to two different Pluribus Networks devices to appear as a single - trunk to a third device. The third device can be a switch, server, or any - Ethernet device. A VLAG can provide Layer 2 multipathing, which allows you - to create redundancy by increasing bandwidth, enabling multiple parallel - paths between nodes and loadbalancing traffic where alternative paths exist. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run this command on. - default: 'local' - state: - description: - - State the action to perform. Use 'present' to create vlag, - 'absent' to delete vlag and 'update' to modify vlag. - required: True - choices: ['present', 'absent', 'update'] - pn_name: - description: - - The C(pn_name) takes a valid name for vlag configuration. - required: true - pn_port: - description: - - Specify the local VLAG port. - - Required for vlag-create. - pn_peer_port: - description: - - Specify the peer VLAG port. - - Required for vlag-create. - pn_mode: - description: - - Specify the mode for the VLAG. Active-standby indicates one side is - active and the other side is in standby mode. Active-active indicates - that both sides of the vlag are up by default. - choices: ['active-active', 'active-standby'] - pn_peer_switch: - description: - - Specify the fabric-name of the peer switch. - pn_failover_action: - description: - - Specify the failover action as move or ignore. - choices: ['move', 'ignore'] - pn_lacp_mode: - description: - - Specify the LACP mode. - choices: ['off', 'passive', 'active'] - pn_lacp_timeout: - description: - - Specify the LACP timeout as slow(30 seconds) or fast(4 seconds). - choices: ['slow', 'fast'] - pn_lacp_fallback: - description: - - Specify the LACP fallback mode as bundles or individual. - choices: ['bundle', 'individual'] - pn_lacp_fallback_timeout: - description: - - Specify the LACP fallback timeout in seconds. The range is between 30 - and 60 seconds with a default value of 50 seconds. -""" - -EXAMPLES = """ -- name: create a VLAG - pn_vlag: - state: 'present' - pn_name: spine-to-leaf - pn_port: 'spine01-to-leaf' - pn_peer_port: 'spine02-to-leaf' - pn_peer_switch: spine02 - pn_mode: 'active-active' - -- name: delete VLAGs - pn_vlag: - state: 'absent' - pn_name: spine-to-leaf -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the vlag command. - returned: always - type: list -stderr: - description: The set of error responses from the vlag command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - -VLAG_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks for idempotency using the vlag-show command. - If a vlag with given vlag exists, return VLAG_EXISTS as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VLAG_EXISTS - """ - name = module.params['pn_name'] - - show = cli + ' vlag-show format name no-show-headers' - show = shlex.split(show) - out = module.run_command(show)[1] - - out = out.split() - # Global flags - global VLAG_EXISTS - if name in out: - VLAG_EXISTS = True - else: - VLAG_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vlag-create' - if state == 'absent': - command = 'vlag-delete' - if state == 'update': - command = 'vlag-modify' - return command - - -def main(): - """ This section is for argument parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent', 'update']), - pn_name=dict(required=True, type='str'), - pn_port=dict(type='str'), - pn_peer_port=dict(type='str'), - pn_mode=dict(type='str', choices=[ - 'active-standby', 'active-active']), - pn_peer_switch=dict(type='str'), - pn_failover_action=dict(type='str', choices=['move', 'ignore']), - pn_lacp_mode=dict(type='str', choices=[ - 'off', 'passive', 'active']), - pn_lacp_timeout=dict(type='str', choices=['slow', 'fast']), - pn_lacp_fallback=dict(type='str', choices=[ - 'bundle', 'individual']), - pn_lacp_fallback_timeout=dict(type='str') - ), - required_if=( - ["state", "present", ["pn_name", "pn_port", "pn_peer_port", - "pn_peer_switch"]], - ["state", "absent", ["pn_name"]], - ["state", "update", ["pn_name"]] - ) - ) - - # Argument accessing - state = module.params['state'] - name = module.params['pn_name'] - port = module.params['pn_port'] - peer_port = module.params['pn_peer_port'] - mode = module.params['pn_mode'] - peer_switch = module.params['pn_peer_switch'] - failover_action = module.params['pn_failover_action'] - lacp_mode = module.params['pn_lacp_mode'] - lacp_timeout = module.params['pn_lacp_timeout'] - lacp_fallback = module.params['pn_lacp_fallback'] - lacp_fallback_timeout = module.params['pn_lacp_fallback_timeout'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - if command == 'vlag-delete': - - check_cli(module, cli) - if VLAG_EXISTS is False: - module.exit_json( - skipped=True, - msg='VLAG with name %s does not exist' % name - ) - cli += ' %s name %s ' % (command, name) - - else: - - if command == 'vlag-create': - check_cli(module, cli) - if VLAG_EXISTS is True: - module.exit_json( - skipped=True, - msg='VLAG with name %s already exists' % name - ) - cli += ' %s name %s ' % (command, name) - - if port: - cli += ' port %s peer-port %s ' % (port, peer_port) - - if mode: - cli += ' mode ' + mode - - if peer_switch: - cli += ' peer-switch ' + peer_switch - - if failover_action: - cli += ' failover-' + failover_action + '-L2 ' - - if lacp_mode: - cli += ' lacp-mode ' + lacp_mode - - if lacp_timeout: - cli += ' lacp-timeout ' + lacp_timeout - - if lacp_fallback: - cli += ' lacp-fallback ' + lacp_fallback - - if lacp_fallback_timeout: - cli += ' lacp-fallback-timeout ' + lacp_fallback_timeout - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_vlan.py b/lib/ansible/modules/network/netvisor/_pn_vlan.py deleted file mode 100644 index e3073f07f7..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_vlan.py +++ /dev/null @@ -1,319 +0,0 @@ -#!/usr/bin/python -""" PN CLI vlan-create/vlan-delete """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vlan -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to create/delete a VLAN. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vlan-create or vlan-delete command. - - VLANs are used to isolate network traffic at Layer 2.The VLAN identifiers - 0 and 4095 are reserved and cannot be used per the IEEE 802.1Q standard. - The range of configurable VLAN identifiers is 2 through 4092. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run the cli on. - required: False - default: 'local' - state: - description: - - State the action to perform. Use 'present' to create vlan and - 'absent' to delete vlan. - required: True - choices: ['present', 'absent'] - pn_vlanid: - description: - - Specify a VLAN identifier for the VLAN. This is a value between - 2 and 4092. - required: True - pn_scope: - description: - - Specify a scope for the VLAN. - - Required for vlan-create. - choices: ['fabric', 'local'] - pn_description: - description: - - Specify a description for the VLAN. - pn_stats: - description: - - Specify if you want to collect statistics for a VLAN. Statistic - collection is enabled by default. - type: bool - pn_ports: - description: - - Specifies the switch network data port number, list of ports, or range - of ports. Port numbers must ne in the range of 1 to 64. - pn_untagged_ports: - description: - - Specifies the ports that should have untagged packets mapped to the - VLAN. Untagged packets are packets that do not contain IEEE 802.1Q VLAN - tags. -""" - -EXAMPLES = """ -- name: create a VLAN - pn_vlan: - state: 'present' - pn_vlanid: 1854 - pn_scope: fabric - -- name: delete VLANs - pn_vlan: - state: 'absent' - pn_vlanid: 1854 -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the vlan command. - returned: always - type: list -stderr: - description: The set of error responses from the vlan command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - -VLAN_EXISTS = None -MAX_VLAN_ID = 4092 -MIN_VLAN_ID = 2 - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks for idempotency using the vlan-show command. - If a vlan with given vlan id exists, return VLAN_EXISTS as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VLAN_EXISTS - """ - vlanid = module.params['pn_vlanid'] - - show = cli + \ - ' vlan-show id %s format id,scope no-show-headers' % str(vlanid) - show = shlex.split(show) - out = module.run_command(show)[1] - - out = out.split() - # Global flags - global VLAN_EXISTS - if str(vlanid) in out: - VLAN_EXISTS = True - else: - VLAN_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vlan-create' - if state == 'absent': - command = 'vlan-delete' - return command - - -def main(): - """ This section is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent']), - pn_vlanid=dict(required=True, type='int'), - pn_scope=dict(type='str', choices=['fabric', 'local']), - pn_description=dict(type='str'), - pn_stats=dict(type='bool'), - pn_ports=dict(type='str'), - pn_untagged_ports=dict(type='str') - ), - required_if=( - ["state", "present", ["pn_vlanid", "pn_scope"]], - ["state", "absent", ["pn_vlanid"]] - ) - ) - - # Accessing the arguments - state = module.params['state'] - vlanid = module.params['pn_vlanid'] - scope = module.params['pn_scope'] - description = module.params['pn_description'] - stats = module.params['pn_stats'] - ports = module.params['pn_ports'] - untagged_ports = module.params['pn_untagged_ports'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - if not MIN_VLAN_ID <= vlanid <= MAX_VLAN_ID: - module.exit_json( - msg="VLAN id must be between 2 and 4092", - changed=False - ) - - if command == 'vlan-create': - - check_cli(module, cli) - if VLAN_EXISTS is True: - module.exit_json( - skipped=True, - msg='VLAN with id %s already exists' % str(vlanid) - ) - - cli += ' %s id %s scope %s ' % (command, str(vlanid), scope) - - if description: - cli += ' description ' + description - - if stats is True: - cli += ' stats ' - if stats is False: - cli += ' no-stats ' - - if ports: - cli += ' ports ' + ports - - if untagged_ports: - cli += ' untagged-ports ' + untagged_ports - - if command == 'vlan-delete': - - check_cli(module, cli) - if VLAN_EXISTS is False: - module.exit_json( - skipped=True, - msg='VLAN with id %s does not exist' % str(vlanid) - ) - - cli += ' %s id %s ' % (command, str(vlanid)) - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_vrouter.py b/lib/ansible/modules/network/netvisor/_pn_vrouter.py deleted file mode 100644 index f2a4899e5c..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_vrouter.py +++ /dev/null @@ -1,426 +0,0 @@ -#!/usr/bin/python -""" PN CLI vrouter-create/vrouter-delete/vrouter-modify """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to create/delete/modify a vrouter. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vrouter-create, vrouter-delete, vrouter-modify command. - - Each fabric, cluster, standalone switch, or virtual network (VNET) can - provide its tenants with a virtual router (vRouter) service that forwards - traffic between networks and implements Layer 3 protocols. - - C(vrouter-create) creates a new vRouter service. - - C(vrouter-delete) deletes a vRouter service. - - C(vrouter-modify) modifies a vRouter service. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run the CLI on. - required: False - default: 'local' - state: - description: - - State the action to perform. Use 'present' to create vrouter, - 'absent' to delete vrouter and 'update' to modify vrouter. - required: True - choices: ['present', 'absent', 'update'] - pn_name: - description: - - Specify the name of the vRouter. - required: true - pn_vnet: - description: - - Specify the name of the VNET. - - Required for vrouter-create. - pn_service_type: - description: - - Specify if the vRouter is a dedicated or shared VNET service. - choices: ['dedicated', 'shared'] - pn_service_state: - description: - - Specify to enable or disable vRouter service. - choices: ['enable', 'disable'] - pn_router_type: - description: - - Specify if the vRouter uses software or hardware. - - Note that if you specify hardware as router type, you cannot assign IP - addresses using DHCP. You must specify a static IP address. - choices: ['hardware', 'software'] - pn_hw_vrrp_id: - description: - - Specifies the VRRP ID for a hardware vrouter. - pn_router_id: - description: - - Specify the vRouter IP address. - pn_bgp_as: - description: - - Specify the Autonomous System Number(ASN) if the vRouter runs Border - Gateway Protocol(BGP). - pn_bgp_redistribute: - description: - - Specify how BGP routes are redistributed. - choices: ['static', 'connected', 'rip', 'ospf'] - pn_bgp_max_paths: - description: - - Specify the maximum number of paths for BGP. This is a number between - 1 and 255 or 0 to unset. - pn_bgp_options: - description: - - Specify other BGP options as a whitespaces separated string within - single quotes ''. - pn_rip_redistribute: - description: - - Specify how RIP routes are redistributed. - choices: ['static', 'connected', 'ospf', 'bgp'] - pn_ospf_redistribute: - description: - - Specify how OSPF routes are redistributed. - choices: ['static', 'connected', 'bgp', 'rip'] - pn_ospf_options: - description: - - Specify other OSPF options as a whitespaces separated string within - single quotes ''. - pn_vrrp_track_port: - description: - - Specify list of ports and port ranges. -""" - -EXAMPLES = """ -- name: create vrouter - pn_vrouter: - state: 'present' - pn_name: 'ansible-vrouter' - pn_vnet: 'ansible-fab-global' - pn_router_id: 208.74.182.1 - -- name: delete vrouter - pn_vrouter: - state: 'absent' - pn_name: 'ansible-vrouter' -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the vrouter command. - returned: always - type: list -stderr: - description: The set of error responses from the vrouter command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# AnsibleModule boilerplate -from ansible.module_utils.basic import AnsibleModule - -VROUTER_EXISTS = None -VROUTER_NAME_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks for idempotency using the vlan-show command. - A switch can have only one vRouter configuration. - If a vRouter already exists on the given switch, return VROUTER_EXISTS as - True else False. - If a vRouter with the given name exists(on a different switch), return - VROUTER_NAME_EXISTS as True else False. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VROUTER_EXISTS, VROUTER_NAME_EXISTS - """ - name = module.params['pn_name'] - # Global flags - global VROUTER_EXISTS, VROUTER_NAME_EXISTS - - # Get the name of the local switch - location = cli + ' switch-setup-show format switch-name' - location = shlex.split(location) - out = module.run_command(location)[1] - location = out.split()[1] - - # Check for any vRouters on the switch - check_vrouter = cli + ' vrouter-show location %s ' % location - check_vrouter += 'format name no-show-headers' - check_vrouter = shlex.split(check_vrouter) - out = module.run_command(check_vrouter)[1] - - if out: - VROUTER_EXISTS = True - else: - VROUTER_EXISTS = False - - # Check for any vRouters with the given name - show = cli + ' vrouter-show format name no-show-headers ' - show = shlex.split(show) - out = module.run_command(show)[1] - out = out.split() - - if name in out: - VROUTER_NAME_EXISTS = True - else: - VROUTER_NAME_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vrouter-create' - if state == 'absent': - command = 'vrouter-delete' - if state == 'update': - command = 'vrouter-modify' - return command - - -def main(): - """ This section is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent', 'update']), - pn_name=dict(required=True, type='str'), - pn_vnet=dict(type='str'), - pn_service_type=dict(type='str', choices=['dedicated', 'shared']), - pn_service_state=dict(type='str', choices=['enable', 'disable']), - pn_router_type=dict(type='str', choices=['hardware', 'software']), - pn_hw_vrrp_id=dict(type='int'), - pn_router_id=dict(type='str'), - pn_bgp_as=dict(type='int'), - pn_bgp_redistribute=dict(type='str', choices=['static', 'connected', - 'rip', 'ospf']), - pn_bgp_max_paths=dict(type='int'), - pn_bgp_options=dict(type='str'), - pn_rip_redistribute=dict(type='str', choices=['static', 'connected', - 'bgp', 'ospf']), - pn_ospf_redistribute=dict(type='str', choices=['static', 'connected', - 'bgp', 'rip']), - pn_ospf_options=dict(type='str'), - pn_vrrp_track_port=dict(type='str') - ), - required_if=( - ["state", "present", ["pn_name", "pn_vnet"]], - ["state", "absent", ["pn_name"]], - ["state", "update", ["pn_name"]] - ) - ) - - # Accessing the arguments - state = module.params['state'] - name = module.params['pn_name'] - vnet = module.params['pn_vnet'] - service_type = module.params['pn_service_type'] - service_state = module.params['pn_service_state'] - router_type = module.params['pn_router_type'] - hw_vrrp_id = module.params['pn_hw_vrrp_id'] - router_id = module.params['pn_router_id'] - bgp_as = module.params['pn_bgp_as'] - bgp_redistribute = module.params['pn_bgp_redistribute'] - bgp_max_paths = module.params['pn_bgp_max_paths'] - bgp_options = module.params['pn_bgp_options'] - rip_redistribute = module.params['pn_rip_redistribute'] - ospf_redistribute = module.params['pn_ospf_redistribute'] - ospf_options = module.params['pn_ospf_options'] - vrrp_track_port = module.params['pn_vrrp_track_port'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - if command == 'vrouter-delete': - check_cli(module, cli) - if VROUTER_NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter with name %s does not exist' % name - ) - cli += ' %s name %s ' % (command, name) - - else: - - if command == 'vrouter-create': - check_cli(module, cli) - if VROUTER_EXISTS is True: - module.exit_json( - skipped=True, - msg='Maximum number of vRouters has been reached on this ' - 'switch' - ) - if VROUTER_NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='vRouter with name %s already exists' % name - ) - cli += ' %s name %s ' % (command, name) - - if vnet: - cli += ' vnet ' + vnet - - if service_type: - cli += ' %s-vnet-service ' % service_type - - if service_state: - cli += ' ' + service_state - - if router_type: - cli += ' router-type ' + router_type - - if hw_vrrp_id: - cli += ' hw-vrrp-id ' + str(hw_vrrp_id) - - if router_id: - cli += ' router-id ' + router_id - - if bgp_as: - cli += ' bgp-as ' + str(bgp_as) - - if bgp_redistribute: - cli += ' bgp-redistribute ' + bgp_redistribute - - if bgp_max_paths: - cli += ' bgp-max-paths ' + str(bgp_max_paths) - - if bgp_options: - cli += ' %s ' % bgp_options - - if rip_redistribute: - cli += ' rip-redistribute ' + rip_redistribute - - if ospf_redistribute: - cli += ' ospf-redistribute ' + ospf_redistribute - - if ospf_options: - cli += ' %s ' % ospf_options - - if vrrp_track_port: - cli += ' vrrp-track-port ' + vrrp_track_port - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_vrouterbgp.py b/lib/ansible/modules/network/netvisor/_pn_vrouterbgp.py deleted file mode 100644 index 0716a0e439..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_vrouterbgp.py +++ /dev/null @@ -1,488 +0,0 @@ -#!/usr/bin/python -""" PN-CLI vrouter-bgp-add/vrouter-bgp-remove/vrouter-bgp-modify """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouterbgp -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to add/remove/modify vrouter-bgp. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vrouter-bgp-add, vrouter-bgp-remove, vrouter-bgp-modify command. - - Each fabric, cluster, standalone switch, or virtual network (VNET) can - provide its tenants with a vRouter service that forwards traffic between - networks and implements Layer 4 protocols. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run the cli on. - required: False - default: 'local' - state: - description: - - State the action to perform. Use 'present' to add bgp, - 'absent' to remove bgp and 'update' to modify bgp. - required: True - choices: ['present', 'absent', 'update'] - pn_vrouter_name: - description: - - Specify a name for the vRouter service. - required: True - pn_neighbor: - description: - - Specify a neighbor IP address to use for BGP. - - Required for vrouter-bgp-add. - pn_remote_as: - description: - - Specify the remote Autonomous System(AS) number. This value is between - 1 and 4294967295. - - Required for vrouter-bgp-add. - pn_next_hop_self: - description: - - Specify if the next-hop is the same router or not. - type: bool - pn_password: - description: - - Specify a password, if desired. - pn_ebgp: - description: - - Specify a value for external BGP to accept or attempt BGP connections - to external peers, not directly connected, on the network. This is a - value between 1 and 255. - pn_prefix_listin: - description: - - Specify the prefix list to filter traffic inbound. - pn_prefix_listout: - description: - - Specify the prefix list to filter traffic outbound. - pn_route_reflector: - description: - - Specify if a route reflector client is used. - type: bool - pn_override_capability: - description: - - Specify if you want to override capability. - type: bool - pn_soft_reconfig: - description: - - Specify if you want a soft reconfiguration of inbound traffic. - type: bool - pn_max_prefix: - description: - - Specify the maximum number of prefixes. - pn_max_prefix_warn: - description: - - Specify if you want a warning message when the maximum number of - prefixes is exceeded. - type: bool - pn_bfd: - description: - - Specify if you want BFD protocol support for fault detection. - type: bool - pn_multiprotocol: - description: - - Specify a multi-protocol for BGP. - choices: ['ipv4-unicast', 'ipv6-unicast'] - pn_weight: - description: - - Specify a default weight value between 0 and 65535 for the neighbor - routes. - pn_default_originate: - description: - - Specify if you want announce default routes to the neighbor or not. - type: bool - pn_keepalive: - description: - - Specify BGP neighbor keepalive interval in seconds. - pn_holdtime: - description: - - Specify BGP neighbor holdtime in seconds. - pn_route_mapin: - description: - - Specify inbound route map for neighbor. - pn_route_mapout: - description: - - Specify outbound route map for neighbor. -""" - -EXAMPLES = """ -- name: add vrouter-bgp - pn_vrouterbgp: - state: 'present' - pn_vrouter_name: 'ansible-vrouter' - pn_neighbor: 104.104.104.1 - pn_remote_as: 1800 - -- name: remove vrouter-bgp - pn_vrouterbgp: - state: 'absent' - pn_name: 'ansible-vrouter' -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the vrouterbpg command. - returned: always - type: list -stderr: - description: The set of error responses from the vrouterbgp command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# Ansible boiler-plate -from ansible.module_utils.basic import AnsibleModule - -VROUTER_EXISTS = None -NEIGHBOR_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-bgp-show command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - If a BGP neighbor with the given ip exists on the given vRouter, - return NEIGHBOR_EXISTS as True else False. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VROUTER_EXISTS, NEIGHBOR_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - neighbor = module.params['pn_neighbor'] - # Global flags - global VROUTER_EXISTS, NEIGHBOR_EXISTS - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers ' - check_vrouter = shlex.split(check_vrouter) - out = module.run_command(check_vrouter)[1] - out = out.split() - - if vrouter_name in out: - VROUTER_EXISTS = True - else: - VROUTER_EXISTS = False - - # Check for BGP neighbors - show = cli + ' vrouter-bgp-show vrouter-name %s ' % vrouter_name - show += 'format neighbor no-show-headers' - show = shlex.split(show) - out = module.run_command(show)[1] - out = out.split() - - if neighbor in out: - NEIGHBOR_EXISTS = True - else: - NEIGHBOR_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vrouter-bgp-add' - if state == 'absent': - command = 'vrouter-bgp-remove' - if state == 'update': - command = 'vrouter-bgp-modify' - return command - - -def main(): - """ This portion is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent', 'update']), - pn_vrouter_name=dict(required=True, type='str'), - pn_neighbor=dict(type='str'), - pn_remote_as=dict(type='str'), - pn_next_hop_self=dict(type='bool'), - pn_password=dict(type='str', no_log=True), - pn_ebgp=dict(type='int'), - pn_prefix_listin=dict(type='str'), - pn_prefix_listout=dict(type='str'), - pn_route_reflector=dict(type='bool'), - pn_override_capability=dict(type='bool'), - pn_soft_reconfig=dict(type='bool'), - pn_max_prefix=dict(type='int'), - pn_max_prefix_warn=dict(type='bool'), - pn_bfd=dict(type='bool'), - pn_multiprotocol=dict(type='str', - choices=['ipv4-unicast', 'ipv6-unicast']), - pn_weight=dict(type='int'), - pn_default_originate=dict(type='bool'), - pn_keepalive=dict(type='str'), - pn_holdtime=dict(type='str'), - pn_route_mapin=dict(type='str'), - pn_route_mapout=dict(type='str') - ), - required_if=( - ["state", "present", - ["pn_vrouter_name", "pn_neighbor", "pn_remote_as"]], - ["state", "absent", - ["pn_vrouter_name", "pn_neighbor"]], - ["state", "update", - ["pn_vrouter_name", "pn_neighbor"]] - ) - ) - - # Accessing the arguments - state = module.params['state'] - vrouter_name = module.params['pn_vrouter_name'] - neighbor = module.params['pn_neighbor'] - remote_as = module.params['pn_remote_as'] - next_hop_self = module.params['pn_next_hop_self'] - password = module.params['pn_password'] - ebgp = module.params['pn_ebgp'] - prefix_listin = module.params['pn_prefix_listin'] - prefix_listout = module.params['pn_prefix_listout'] - route_reflector = module.params['pn_route_reflector'] - override_capability = module.params['pn_override_capability'] - soft_reconfig = module.params['pn_soft_reconfig'] - max_prefix = module.params['pn_max_prefix'] - max_prefix_warn = module.params['pn_max_prefix_warn'] - bfd = module.params['pn_bfd'] - multiprotocol = module.params['pn_multiprotocol'] - weight = module.params['pn_weight'] - default_originate = module.params['pn_default_originate'] - keepalive = module.params['pn_keepalive'] - holdtime = module.params['pn_holdtime'] - route_mapin = module.params['pn_route_mapin'] - route_mapout = module.params['pn_route_mapout'] - - # Building the CLI command string - cli = pn_cli(module) - - command = get_command_from_state(state) - if command == 'vrouter-bgp-remove': - check_cli(module, cli) - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if NEIGHBOR_EXISTS is False: - module.exit_json( - skipped=True, - msg=('BGP neighbor with IP %s does not exist on %s' - % (neighbor, vrouter_name)) - ) - cli += (' %s vrouter-name %s neighbor %s ' - % (command, vrouter_name, neighbor)) - - else: - - if command == 'vrouter-bgp-add': - check_cli(module, cli) - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if NEIGHBOR_EXISTS is True: - module.exit_json( - skipped=True, - msg=('BGP neighbor with IP %s already exists on %s' - % (neighbor, vrouter_name)) - ) - - cli += (' %s vrouter-name %s neighbor %s ' - % (command, vrouter_name, neighbor)) - - if remote_as: - cli += ' remote-as ' + str(remote_as) - - if next_hop_self is True: - cli += ' next-hop-self ' - if next_hop_self is False: - cli += ' no-next-hop-self ' - - if password: - cli += ' password ' + password - - if ebgp: - cli += ' ebgp-multihop ' + str(ebgp) - - if prefix_listin: - cli += ' prefix-list-in ' + prefix_listin - - if prefix_listout: - cli += ' prefix-list-out ' + prefix_listout - - if route_reflector is True: - cli += ' route-reflector-client ' - if route_reflector is False: - cli += ' no-route-reflector-client ' - - if override_capability is True: - cli += ' override-capability ' - if override_capability is False: - cli += ' no-override-capability ' - - if soft_reconfig is True: - cli += ' soft-reconfig-inbound ' - if soft_reconfig is False: - cli += ' no-soft-reconfig-inbound ' - - if max_prefix: - cli += ' max-prefix ' + str(max_prefix) - - if max_prefix_warn is True: - cli += ' max-prefix-warn-only ' - if max_prefix_warn is False: - cli += ' no-max-prefix-warn-only ' - - if bfd is True: - cli += ' bfd ' - if bfd is False: - cli += ' no-bfd ' - - if multiprotocol: - cli += ' multi-protocol ' + multiprotocol - - if weight: - cli += ' weight ' + str(weight) - - if default_originate is True: - cli += ' default-originate ' - if default_originate is False: - cli += ' no-default-originate ' - - if keepalive: - cli += ' neighbor-keepalive-interval ' + keepalive - - if holdtime: - cli += ' neighbor-holdtime ' + holdtime - - if route_mapin: - cli += ' route-map-in ' + route_mapin - - if route_mapout: - cli += ' route-map-out ' + route_mapout - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_vrouterif.py b/lib/ansible/modules/network/netvisor/_pn_vrouterif.py deleted file mode 100644 index 6735689f5a..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_vrouterif.py +++ /dev/null @@ -1,493 +0,0 @@ -#!/usr/bin/python -""" PN-CLI vrouter-interface-add/remove/modify """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouterif -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to add/remove/modify vrouter-interface. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vrouter-interface-add, vrouter-interface-remove, - vrouter-interface-modify command. - - You configure interfaces to vRouter services on a fabric, cluster, - standalone switch or virtual network(VNET). -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch to run the cli on. - required: False - default: 'local' - state: - description: - - State the action to perform. Use 'present' to add vrouter interface, - 'absent' to remove vrouter interface and 'update' to modify vrouter - interface. - required: True - choices: ['present', 'absent', 'update'] - pn_vrouter_name: - description: - - Specify the name of the vRouter interface. - required: True - pn_vlan: - description: - - Specify the VLAN identifier. This is a value between 1 and 4092. - pn_interface_ip: - description: - - Specify the IP address of the interface in x.x.x.x/n format. - pn_assignment: - description: - - Specify the DHCP method for IP address assignment. - choices: ['none', 'dhcp', 'dhcpv6', 'autov6'] - pn_vxlan: - description: - - Specify the VXLAN identifier. This is a value between 1 and 16777215. - pn_interface: - description: - - Specify if the interface is management, data or span interface. - choices: ['mgmt', 'data', 'span'] - pn_alias: - description: - - Specify an alias for the interface. - pn_exclusive: - description: - - Specify if the interface is exclusive to the configuration. Exclusive - means that other configurations cannot use the interface. Exclusive is - specified when you configure the interface as span interface and allows - higher throughput through the interface. - type: bool - required: False - pn_nic_enable: - description: - - Specify if the NIC is enabled or not - type: bool - pn_vrrp_id: - description: - - Specify the ID for the VRRP interface. The IDs on both vRouters must be - the same IS number. - pn_vrrp_priority: - description: - - Specify the priority for the VRRP interface. This is a value between - 1 (lowest) and 255 (highest). - pn_vrrp_adv_int: - description: - - Specify a VRRP advertisement interval in milliseconds. The range is - from 30 to 40950 with a default value of 1000. - pn_l3port: - description: - - Specify a Layer 3 port for the interface. - pn_secondary_macs: - description: - - Specify a secondary MAC address for the interface. - pn_nic_str: - description: - - Specify the type of NIC. Used for vrouter-interface remove/modify. -""" - -EXAMPLES = """ -- name: Add vrouter-interface - pn_vrouterif: - pn_cliusername: admin - pn_clipassword: admin - state: 'present' - pn_vrouter_name: 'ansible-vrouter' - pn_interface_ip: 101.101.101.2/24 - pn_vlan: 101 - -- name: Add VRRP.. - pn_vrouterif: - pn_cliusername: admin - pn_clipassword: admin - state: 'present' - pn_vrouter_name: 'ansible-vrouter' - pn_interface_ip: 101.101.101.2/24 - pn_vrrp_ip: 101.101.101.1/24 - pn_vrrp_priority: 100 - pn_vlan: 101 - -- name: Remove vrouter-interface - pn_vrouterif: - pn_cliusername: admin - pn_clipassword: admin - state: 'absent' - pn_vrouter_name: 'ansible-vrouter' - pn_interface_ip: 101.101.101.2/24 -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the vrouterif command. - returned: on success - type: list -stderr: - description: The set of error responses from the vrouterif command. - returned: on error - type: str -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# Ansible boiler-plate -from ansible.module_utils.basic import AnsibleModule - -VROUTER_EXISTS = None -INTERFACE_EXISTS = None -NIC_EXISTS = None -VRRP_EXISTS = None - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-interface-show - command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - - If an interface with the given ip exists on the given vRouter, - return INTERFACE_EXISTS as True else False. This is required for - vrouter-interface-add. - - If nic_str exists on the given vRouter, return NIC_EXISTS as True else - False. This is required for vrouter-interface-remove. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - interface_ip = module.params['pn_interface_ip'] - nic_str = module.params['pn_nic_str'] - - # Global flags - global VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers ' - check_vrouter = shlex.split(check_vrouter) - out = module.run_command(check_vrouter)[1] - out = out.split() - - if vrouter_name in out: - VROUTER_EXISTS = True - else: - VROUTER_EXISTS = False - - if interface_ip: - # Check for interface and VRRP and fetch nic for VRRP - show = cli + ' vrouter-interface-show vrouter-name %s ' % vrouter_name - show += 'ip %s format ip,nic no-show-headers' % interface_ip - show = shlex.split(show) - out = module.run_command(show)[1] - if out: - INTERFACE_EXISTS = True - else: - INTERFACE_EXISTS = False - - if nic_str: - # Check for nic - show = cli + ' vrouter-interface-show vrouter-name %s ' % vrouter_name - show += ' format nic no-show-headers' - show = shlex.split(show) - out = module.run_command(show)[1] - if nic_str in out: - NIC_EXISTS = True - else: - NIC_EXISTS = False - - -def get_nic(module, cli): - """ - This module checks if VRRP interface can be added. If No, return VRRP_EXISTS - as True. - If Yes, fetch the nic string from the primary interface and return nic and - VRRP_EXISTS as False. - :param module: - :param cli: - :return: nic, Global Boolean: VRRP_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - interface_ip = module.params['pn_interface_ip'] - - global VRRP_EXISTS - - # Check for interface and VRRP and fetch nic for VRRP - show = cli + ' vrouter-interface-show vrouter-name %s ' % vrouter_name - show += 'ip %s format ip,nic no-show-headers' % interface_ip - show = shlex.split(show) - out = module.run_command(show)[1] - out = out.split() - - if len(out) > 3: - VRRP_EXISTS = True - return None - else: - nic = out[2] - VRRP_EXISTS = False - return nic - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vrouter-interface-add' - if state == 'absent': - command = 'vrouter-interface-remove' - if state == 'update': - command = 'vrouter-interface-modify' - return command - - -def main(): - """ This portion is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent', 'update']), - pn_vrouter_name=dict(required=True, type='str'), - pn_vlan=dict(type='int'), - pn_interface_ip=dict(required=True, type='str'), - pn_assignment=dict(type='str', - choices=['none', 'dhcp', 'dhcpv6', 'autov6']), - pn_vxlan=dict(type='int'), - pn_interface=dict(type='str', choices=['mgmt', 'data', 'span']), - pn_alias=dict(type='str'), - pn_exclusive=dict(type='bool'), - pn_nic_enable=dict(type='bool'), - pn_vrrp_id=dict(type='int'), - pn_vrrp_priority=dict(type='int'), - pn_vrrp_adv_int=dict(type='str'), - pn_l3port=dict(type='str'), - pn_secondary_macs=dict(type='str'), - pn_nic_str=dict(type='str') - ), - required_if=( - ["state", "present", - ["pn_vrouter_name", "pn_interface_ip"]], - ["state", "absent", - ["pn_vrouter_name", "pn_nic_str"]] - ), - ) - - # Accessing the arguments - state = module.params['state'] - vrouter_name = module.params['pn_vrouter_name'] - vlan = module.params['pn_vlan'] - interface_ip = module.params['pn_interface_ip'] - assignment = module.params['pn_assignment'] - vxlan = module.params['pn_vxlan'] - interface = module.params['pn_interface'] - alias = module.params['pn_alias'] - exclusive = module.params['pn_exclusive'] - nic_enable = module.params['pn_nic_enable'] - vrrp_id = module.params['pn_vrrp_id'] - vrrp_priority = module.params['pn_vrrp_priority'] - vrrp_adv_int = module.params['pn_vrrp_adv_int'] - l3port = module.params['pn_l3port'] - secondary_macs = module.params['pn_secondary_macs'] - nic_str = module.params['pn_nic_str'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - check_cli(module, cli) - if command == 'vrouter-interface-add': - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - - if vrrp_id: - vrrp_primary = get_nic(module, cli) - if VRRP_EXISTS is True: - module.exit_json( - skipped=True, - msg=('VRRP interface on %s already exists. Check ' - 'the IP addresses' % vrouter_name) - ) - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - cli += (' ip %s vrrp-primary %s vrrp-id %s ' - % (interface_ip, vrrp_primary, str(vrrp_id))) - if vrrp_priority: - cli += ' vrrp-priority %s ' % str(vrrp_priority) - if vrrp_adv_int: - cli += ' vrrp-adv-int %s ' % vrrp_adv_int - - else: - if INTERFACE_EXISTS is True: - module.exit_json( - skipped=True, - msg=('vRouter interface on %s already exists. Check the ' - 'IP addresses' % vrouter_name) - ) - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - cli += ' ip %s ' % interface_ip - - if vlan: - cli += ' vlan ' + str(vlan) - - if l3port: - cli += ' l3-port ' + l3port - - if assignment: - cli += ' assignment ' + assignment - - if vxlan: - cli += ' vxlan ' + str(vxlan) - - if interface: - cli += ' if ' + interface - - if alias: - cli += ' alias-on ' + alias - - if exclusive is True: - cli += ' exclusive ' - if exclusive is False: - cli += ' no-exclusive ' - - if nic_enable is True: - cli += ' nic-enable ' - if nic_enable is False: - cli += ' nic-disable ' - - if secondary_macs: - cli += ' secondary-macs ' + secondary_macs - - if command == 'vrouter-interface-remove': - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if NIC_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter interface with nic %s does not exist' % nic_str - ) - cli += ' %s vrouter-name %s nic %s ' % (command, vrouter_name, nic_str) - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/_pn_vrouterlbif.py b/lib/ansible/modules/network/netvisor/_pn_vrouterlbif.py deleted file mode 100644 index 7958a5fa5e..0000000000 --- a/lib/ansible/modules/network/netvisor/_pn_vrouterlbif.py +++ /dev/null @@ -1,334 +0,0 @@ -#!/usr/bin/python -""" PN CLI vrouter-loopback-interface-add/remove """ - -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouterlbif -author: "Pluribus Networks (@amitsi)" -version_added: "2.2" -short_description: CLI command to add/remove vrouter-loopback-interface. -deprecated: - removed_in: '2.12' - why: Doesn't support latest Pluribus Networks netvisor - alternative: Latest modules will be pushed in Ansible future versions. -description: - - Execute vrouter-loopback-interface-add, vrouter-loopback-interface-remove - commands. - - Each fabric, cluster, standalone switch, or virtual network (VNET) can - provide its tenants with a virtual router (vRouter) service that forwards - traffic between networks and implements Layer 3 protocols. -options: - pn_cliusername: - description: - - Provide login username if user is not root. - required: False - pn_clipassword: - description: - - Provide login password if user is not root. - required: False - pn_cliswitch: - description: - - Target switch(es) to run the cli on. - required: False - default: 'local' - state: - description: - - State the action to perform. Use 'present' to add vrouter loopback - interface and 'absent' to remove vrouter loopback interface. - required: True - choices: ['present', 'absent'] - pn_vrouter_name: - description: - - Specify the name of the vRouter. - required: True - pn_index: - description: - - Specify the interface index from 1 to 255. - pn_interface_ip: - description: - - Specify the IP address. - required: True -""" - -EXAMPLES = """ -- name: add vrouter-loopback-interface - pn_vrouterlbif: - state: 'present' - pn_vrouter_name: 'ansible-vrouter' - pn_interface_ip: '104.104.104.1' - -- name: remove vrouter-loopback-interface - pn_vrouterlbif: - state: 'absent' - pn_vrouter_name: 'ansible-vrouter' - pn_interface_ip: '104.104.104.1' -""" - -RETURN = """ -command: - description: The CLI command run on the target node(s). - returned: always - type: str -stdout: - description: The set of responses from the vrouterlb command. - returned: always - type: list -stderr: - description: The set of error responses from the vrouterlb command. - returned: on error - type: list -changed: - description: Indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -import shlex - -# Ansible boiler-plate -from ansible.module_utils.basic import AnsibleModule - -VROUTER_EXISTS = None -LB_INTERFACE_EXISTS = None -# Index range -MIN_INDEX = 1 -MAX_INDEX = 255 - - -def pn_cli(module): - """ - This method is to generate the cli portion to launch the Netvisor cli. - It parses the username, password, switch parameters from module. - :param module: The Ansible module to fetch username, password and switch - :return: returns the cli string for further processing - """ - username = module.params['pn_cliusername'] - password = module.params['pn_clipassword'] - cliswitch = module.params['pn_cliswitch'] - - if username and password: - cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password) - else: - cli = '/usr/bin/cli --quiet ' - - if cliswitch == 'local': - cli += ' switch-local ' - else: - cli += ' switch ' + cliswitch - return cli - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the - vrouter-loopback-interface-show command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - If a loopback interface with the given ip exists on the given vRouter, - return LB_INTERFACE_EXISTS as True else False. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Global Booleans: VROUTER_EXISTS, LB_INTERFACE_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - interface_ip = module.params['pn_interface_ip'] - - # Global flags - global VROUTER_EXISTS, LB_INTERFACE_EXISTS - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers ' - check_vrouter = shlex.split(check_vrouter) - out = module.run_command(check_vrouter)[1] - out = out.split() - - if vrouter_name in out: - VROUTER_EXISTS = True - else: - VROUTER_EXISTS = False - - # Check for loopback interface - show = (cli + ' vrouter-loopback-interface-show vrouter-name %s format ip ' - 'no-show-headers' % vrouter_name) - show = shlex.split(show) - out = module.run_command(show)[1] - out = out.split() - - if interface_ip in out: - LB_INTERFACE_EXISTS = True - else: - LB_INTERFACE_EXISTS = False - - -def run_cli(module, cli): - """ - This method executes the cli command on the target node(s) and returns the - output. The module then exits based on the output. - :param cli: the complete cli string to be executed on the target node(s). - :param module: The Ansible module to fetch command - """ - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - command = get_command_from_state(state) - - cmd = shlex.split(cli) - - # 'out' contains the output - # 'err' contains the error messages - result, out, err = module.run_command(cmd) - - print_cli = cli.split(cliswitch)[1] - - # Response in JSON format - if result != 0: - module.exit_json( - command=print_cli, - stderr=err.strip(), - msg="%s operation failed" % command, - changed=False - ) - - if out: - module.exit_json( - command=print_cli, - stdout=out.strip(), - msg="%s operation completed" % command, - changed=True - ) - - else: - module.exit_json( - command=print_cli, - msg="%s operation completed" % command, - changed=True - ) - - -def get_command_from_state(state): - """ - This method gets appropriate command name for the state specified. It - returns the command name for the specified state. - :param state: The state for which the respective command name is required. - """ - command = None - if state == 'present': - command = 'vrouter-loopback-interface-add' - if state == 'absent': - command = 'vrouter-loopback-interface-remove' - return command - - -def main(): - """ This portion is for arguments parsing """ - module = AnsibleModule( - argument_spec=dict( - pn_cliusername=dict(required=False, type='str'), - pn_clipassword=dict(required=False, type='str', no_log=True), - pn_cliswitch=dict(required=False, type='str', default='local'), - state=dict(required=True, type='str', - choices=['present', 'absent']), - pn_vrouter_name=dict(required=True, type='str'), - pn_interface_ip=dict(type='str'), - pn_index=dict(type='int') - ), - required_if=( - ["state", "present", - ["pn_vrouter_name", "pn_interface_ip"]], - ["state", "absent", - ["pn_vrouter_name", "pn_interface_ip"]] - ) - ) - - # Accessing the arguments - state = module.params['state'] - vrouter_name = module.params['pn_vrouter_name'] - interface_ip = module.params['pn_interface_ip'] - index = module.params['pn_index'] - - command = get_command_from_state(state) - - # Building the CLI command string - cli = pn_cli(module) - - if index: - if not MIN_INDEX <= index <= MAX_INDEX: - module.exit_json( - msg="Index must be between 1 and 255", - changed=False - ) - index = str(index) - - if command == 'vrouter-loopback-interface-remove': - check_cli(module, cli) - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if LB_INTERFACE_EXISTS is False: - module.exit_json( - skipped=True, - msg=('Loopback interface with IP %s does not exist on %s' - % (interface_ip, vrouter_name)) - ) - if not index: - # To remove loopback interface, we need the index. - # If index is not specified, get the Loopback interface index - # using the given interface ip. - get_index = cli - get_index += (' vrouter-loopback-interface-show vrouter-name %s ip ' - '%s ' % (vrouter_name, interface_ip)) - get_index += 'format index no-show-headers' - - get_index = shlex.split(get_index) - out = module.run_command(get_index)[1] - index = out.split()[1] - - cli += ' %s vrouter-name %s index %s' % (command, vrouter_name, index) - - if command == 'vrouter-loopback-interface-add': - check_cli(module, cli) - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg=('vRouter %s does not exist' % vrouter_name) - ) - if LB_INTERFACE_EXISTS is True: - module.exit_json( - skipped=True, - msg=('Loopback interface with IP %s already exists on %s' - % (interface_ip, vrouter_name)) - ) - cli += (' %s vrouter-name %s ip %s' - % (command, vrouter_name, interface_ip)) - if index: - cli += ' index %s ' % index - - run_cli(module, cli) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_access_list.py b/lib/ansible/modules/network/netvisor/pn_access_list.py deleted file mode 100644 index a4c78414a8..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_access_list.py +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_access_list -author: "Pluribus Networks (@amitsi)" -version_added: "2.8" -short_description: CLI command to create/delete access-list -description: - - This module can be used to create and delete an access list. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use 'present' to create access-list and - 'absent' to delete access-list. - required: True - choices: [ "present", "absent"] - pn_name: - description: - - Access List Name. - required: false - type: str - pn_scope: - description: - - 'scope. Available valid values - local or fabric.' - required: false - choices: ['local', 'fabric'] -""" - -EXAMPLES = """ -- name: access list functionality - pn_access_list: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_scope: "local" - state: "present" - -- name: access list functionality - pn_access_list: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_scope: "local" - state: "absent" - -- name: access list functionality - pn_access_list: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_scope: "fabric" - state: "present" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the access-list command. - returned: always - type: list -stderr: - description: set of error responses from the access-list command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the access-list-show command. - If a list with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - list_name = module.params['pn_name'] - - cli += ' access-list-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if list_name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='access-list-create', - absent='access-list-delete', - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_name=dict(required=False, type='str'), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - ), - required_if=( - ["state", "present", ["pn_name", "pn_scope"]], - ["state", "absent", ["pn_name"]], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - list_name = module.params['pn_name'] - scope = module.params['pn_scope'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - ACC_LIST_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, list_name) - - if command == 'access-list-delete': - if ACC_LIST_EXISTS is False: - module.exit_json( - skipped=True, - msg='access-list with name %s does not exist' % list_name - ) - else: - if command == 'access-list-create': - if ACC_LIST_EXISTS is True: - module.exit_json( - skipped=True, - msg='access list with name %s already exists' % list_name - ) - cli += ' scope %s ' % scope - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_access_list_ip.py b/lib/ansible/modules/network/netvisor/pn_access_list_ip.py deleted file mode 100644 index b6ca77fb40..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_access_list_ip.py +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_access_list_ip -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to add/remove access-list-ip -description: - - This modules can be used to add and remove IPs associated with access list. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use 'present' to add access-list-ip and - 'absent' to remove access-list-ip. - required: True - choices: ["present", "absent"] - pn_ip: - description: - - IP associated with the access list. - required: False - default: '::' - type: str - pn_name: - description: - - Access List Name. - required: False - type: str -""" - -EXAMPLES = """ -- name: access list ip functionality - pn_access_list_ip: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_ip: "172.16.3.1" - state: "present" - -- name: access list ip functionality - pn_access_list_ip: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_ip: "172.16.3.1" - state: "absent" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the access-list-ip command. - returned: always - type: list -stderr: - description: set of error responses from the access-list-ip command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the access-list-ip-show command. - If ip exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - ip = module.params['pn_ip'] - clicopy = cli - - cli += ' access-list-show name %s no-show-headers ' % name - out = run_commands(module, cli)[1] - - if name not in out: - module.fail_json( - failed=True, - msg='access-list with name %s does not exist' % name - ) - - cli = clicopy - cli += ' access-list-ip-show name %s format ip no-show-headers' % name - - out = run_commands(module, cli)[1] - out = out.split() - return True if ip in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='access-list-ip-add', - absent='access-list-ip-remove', - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_ip=dict(required=False, type='str', default='::'), - pn_name=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_name"]], - ["state", "absent", ["pn_name", "pn_ip"]], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - ip = module.params['pn_ip'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - IP_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if command == 'access-list-ip-remove': - if IP_EXISTS is False: - module.exit_json( - skipped=True, - msg='access-list with ip %s does not exist' % ip - ) - if ip: - cli += ' ip ' + ip - else: - if command == 'access-list-ip-add': - if IP_EXISTS is True: - module.exit_json( - skipped=True, - msg='access list with ip %s already exists' % ip - ) - if ip: - cli += ' ip ' + ip - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_admin_service.py b/lib/ansible/modules/network/netvisor/pn_admin_service.py deleted file mode 100644 index a7736790eb..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_admin_service.py +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_admin_service -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify admin-service -description: - - This module is used to modify services on the server-switch. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(update) to modify the admin-service. - required: True - type: str - choices: ['update'] - pn_web: - description: - - Web (HTTP) to enable or disable. - required: False - type: bool - pn_web_ssl: - description: - - Web SSL (HTTPS) to enable or disable. - required: False - type: bool - pn_snmp: - description: - - Simple Network Monitoring Protocol (SNMP) to enable or disable. - required: False - type: bool - pn_web_port: - description: - - Web (HTTP) port to enable or disable. - required: False - type: str - pn_web_ssl_port: - description: - - Web SSL (HTTPS) port to enable or disable. - required: False - type: str - pn_nfs: - description: - - Network File System (NFS) to enable or disable. - required: False - type: bool - pn_ssh: - description: - - Secure Shell to enable or disable. - required: False - type: bool - pn_web_log: - description: - - Web logging to enable or disable. - required: False - type: bool - pn__if: - description: - - administrative service interface. - required: False - type: str - choices: ['mgmt', 'data'] - pn_icmp: - description: - - Internet Message Control Protocol (ICMP) to enable or disable. - required: False - type: bool - pn_net_api: - description: - - Netvisor API to enable or disable APIs. - required: False - type: bool -""" - -EXAMPLES = """ -- name: admin service functionality - pn_admin_service: - pn_cliswitch: "sw01" - state: "update" - pn__if: "mgmt" - pn_web: False - pn_icmp: True - -- name: admin service functionality - pn_admin_service: - pn_cliswitch: "sw01" - state: "update" - pn_web: False - pn__if: "mgmt" - pn_snmp: True - pn_net_api: True - pn_ssh: True -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the admin-service command. - returned: always - type: list -stderr: - description: set of error responses from the admin-service command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, booleanArgs, run_cli - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='admin-service-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_web=dict(required=False, type='bool'), - pn_web_ssl=dict(required=False, type='bool'), - pn_snmp=dict(required=False, type='bool'), - pn_web_port=dict(required=False, type='str'), - pn_web_ssl_port=dict(required=False, type='str'), - pn_nfs=dict(required=False, type='bool'), - pn_ssh=dict(required=False, type='bool'), - pn_web_log=dict(required=False, type='bool'), - pn__if=dict(required=False, type='str', choices=['mgmt', 'data']), - pn_icmp=dict(required=False, type='bool'), - pn_net_api=dict(required=False, type='bool'), - ), - required_if=([['state', 'update', ['pn__if']]]), - required_one_of=[['pn_web', 'pn_web_ssl', 'pn_snmp', - 'pn_web_port', 'pn_web_ssl_port', 'pn_nfs', - 'pn_ssh', 'pn_web_log', 'pn_icmp', 'pn_net_api']] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - web = module.params['pn_web'] - web_ssl = module.params['pn_web_ssl'] - snmp = module.params['pn_snmp'] - web_port = module.params['pn_web_port'] - web_ssl_port = module.params['pn_web_ssl_port'] - nfs = module.params['pn_nfs'] - ssh = module.params['pn_ssh'] - web_log = module.params['pn_web_log'] - _if = module.params['pn__if'] - icmp = module.params['pn_icmp'] - net_api = module.params['pn_net_api'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'admin-service-modify': - cli += ' %s ' % command - - if _if: - cli += ' if ' + _if - if web_port: - cli += ' web-port ' + web_port - if web_ssl_port: - cli += ' web-ssl-port ' + web_ssl_port - - cli += booleanArgs(web, 'web', 'no-web') - cli += booleanArgs(web_ssl, 'web-ssl', 'no-web-ssl') - cli += booleanArgs(snmp, 'snmp', 'no-snmp') - cli += booleanArgs(nfs, 'nfs', 'no-nfs') - cli += booleanArgs(ssh, 'ssh', 'no-ssh') - cli += booleanArgs(icmp, 'icmp', 'no-icmp') - cli += booleanArgs(net_api, 'net-api', 'no-net-api') - cli += booleanArgs(web_log, 'web-log', 'no-web-log') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_admin_session_timeout.py b/lib/ansible/modules/network/netvisor/pn_admin_session_timeout.py deleted file mode 100644 index df1eaf71b3..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_admin_session_timeout.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_admin_session_timeout -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify admin-session-timeout -description: - - This module can be used to modify admin session timeout. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. - C(update) to modify the admin-session-timeout. - required: True - type: str - choices: ['update'] - pn_timeout: - description: - - Maximum time to wait for user activity before - terminating login session. Minimum should be 60s. - required: False - type: str -""" - -EXAMPLES = """ -- name: admin session timeout functionality - pn_admin_session_timeout: - pn_cliswitch: "sw01" - state: "update" - pn_timeout: "61s" - -- name: admin session timeout functionality - pn_admin_session_timeout: - pn_cliswitch: "sw01" - state: "update" - pn_timeout: "1d" - -- name: admin session timeout functionality - pn_admin_session_timeout: - pn_cliswitch: "sw01" - state: "update" - pn_timeout: "10d20m3h15s" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the admin-session-timeout command. - returned: always - type: list -stderr: - description: set of error responses from the admin-session-timeout command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='admin-session-timeout-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_timeout=dict(required=False, type='str'), - ), - required_together=[['state', 'pn_timeout']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - timeout = module.params['pn_timeout'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - if command == 'admin-session-timeout-modify': - cli += ' %s ' % command - if timeout: - cli += ' timeout ' + timeout - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_admin_syslog.py b/lib/ansible/modules/network/netvisor/pn_admin_syslog.py deleted file mode 100644 index a9ce53bcad..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_admin_syslog.py +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_admin_syslog -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/modify/delete admin-syslog -description: - - This module can be used to create the scope and other parameters of syslog event collection. - - This module can be used to modify parameters of syslog event collection. - - This module can be used to delete the scope and other parameters of syslog event collection. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(present) to create admin-syslog and - C(absent) to delete admin-syslog C(update) to modify the admin-syslog. - required: True - type: str - choices: ['present', 'absent', 'update'] - pn_scope: - description: - - Scope of the system log. - required: False - type: str - choices: ['local', 'fabric'] - pn_host: - description: - - Hostname to log system events. - required: False - type: str - pn_port: - description: - - Host port. - required: False - type: str - pn_transport: - description: - - Transport for log events - tcp/tls or udp. - required: False - type: str - choices: ['tcp-tls', 'udp'] - default: 'udp' - pn_message_format: - description: - - message-format for log events - structured or legacy. - required: False - choices: ['structured', 'legacy'] - type: str - pn_name: - description: - - name of the system log. - required: False - type: str -""" - -EXAMPLES = """ -- name: admin-syslog functionality - pn_admin_syslog: - pn_cliswitch: "sw01" - state: "absent" - pn_name: "foo" - pn_scope: "local" - -- name: admin-syslog functionality - pn_admin_syslog: - pn_cliswitch: "sw01" - state: "present" - pn_name: "foo" - pn_scope: "local" - pn_host: "166.68.224.46" - pn_message_format: "structured" - -- name: admin-syslog functionality - pn_admin_syslog: - pn_cliswitch: "sw01" - state: "update" - pn_name: "foo" - pn_host: "166.68.224.10" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the admin-syslog command. - returned: always - type: list -stderr: - description: set of error responses from the admin-syslog command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the admin-syslog-show command. - If a user with given name exists, return as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - - name = module.params['pn_name'] - - cli += ' admin-syslog-show format name no-show-headers' - out = run_commands(module, cli)[1] - - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='admin-syslog-create', - absent='admin-syslog-delete', - update='admin-syslog-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - pn_host=dict(required=False, type='str'), - pn_port=dict(required=False, type='str'), - pn_transport=dict(required=False, type='str', - choices=['tcp-tls', 'udp'], default='udp'), - pn_message_format=dict(required=False, type='str', - choices=['structured', 'legacy']), - pn_name=dict(required=False, type='str'), - ), - required_if=( - ['state', 'present', ['pn_name', 'pn_host', 'pn_scope']], - ['state', 'absent', ['pn_name']], - ['state', 'update', ['pn_name']] - ), - required_one_of=[['pn_port', 'pn_message_format', - 'pn_host', 'pn_transport', 'pn_scope']] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - scope = module.params['pn_scope'] - host = module.params['pn_host'] - port = module.params['pn_port'] - transport = module.params['pn_transport'] - message_format = module.params['pn_message_format'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - SYSLOG_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if command == 'admin-syslog-modify': - if SYSLOG_EXISTS is False: - module.fail_json( - failed=True, - msg='admin syslog with name %s does not exist' % name - ) - - if command == 'admin-syslog-delete': - if SYSLOG_EXISTS is False: - module.exit_json( - skipped=True, - msg='admin syslog with name %s does not exist' % name - ) - - if command == 'admin-syslog-create': - if SYSLOG_EXISTS is True: - module.exit_json( - skipped=True, - msg='admin syslog user with name %s already exists' % name - ) - - if command == 'admin-syslog-create': - if scope: - cli += ' scope ' + scope - - if command != 'admin-syslog-delete': - if host: - cli += ' host ' + host - if port: - cli += ' port ' + port - if transport: - cli += ' transport ' + transport - if message_format: - cli += ' message-format ' + message_format - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_connection_stats_settings.py b/lib/ansible/modules/network/netvisor/pn_connection_stats_settings.py deleted file mode 100644 index bd2a4ad19c..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_connection_stats_settings.py +++ /dev/null @@ -1,268 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_connection_stats_settings -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify connection-stats-settings -description: - - This module can be used to modify the settings for collecting statistical - data about connections. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(update) to modify the - connection-stats-settings. - required: True - type: str - choices: ['update'] - pn_enable: - description: - - Enable or disable collecting connections statistics. - required: False - type: bool - pn_connection_backup_enable: - description: - - Enable backup for connection statistics collection. - required: False - type: bool - pn_client_server_stats_max_memory: - description: - - maximum memory for client server statistics. - required: False - type: str - pn_connection_stats_log_disk_space: - description: - - disk-space allocated for statistics (including rotated log files). - required: False - type: str - pn_client_server_stats_log_enable: - description: - - Enable or disable statistics. - required: False - type: bool - pn_service_stat_max_memory: - description: - - maximum memory allowed for service statistics. - required: False - type: str - pn_connection_stats_log_interval: - description: - - interval to collect statistics. - required: False - type: str - pn_fabric_connection_backup_interval: - description: - - backup interval for fabric connection statistics collection. - required: False - type: str - pn_connection_backup_interval: - description: - - backup interval for connection statistics collection. - required: False - type: str - pn_connection_stats_log_enable: - description: - - enable or disable statistics. - required: False - type: bool - pn_fabric_connection_max_memory: - description: - - maximum memory allowed for fabric connection statistics. - required: False - type: str - pn_fabric_connection_backup_enable: - description: - - enable backup for fabric connection statistics collection. - required: False - type: bool - pn_client_server_stats_log_disk_space: - description: - - disk-space allocated for statistics (including rotated log files). - required: False - type: str - pn_connection_max_memory: - description: - - maximum memory allowed for connection statistics. - required: False - type: str - pn_connection_stats_max_memory: - description: - - maximum memory allowed for connection statistics. - required: False - type: str - pn_client_server_stats_log_interval: - description: - - interval to collect statistics. - required: False - type: str -""" - -EXAMPLES = """ -- name: "Modify connection stats settings" - pn_connection_stats_settings: - pn_cliswitch: "sw01" - state: "update" - pn_enable: False - pn_fabric_connection_max_memory: "1000" - -- name: "Modify connection stats settings" - pn_connection_stats_settings: - pn_cliswitch: "sw01" - state: "update" - pn_enable: True -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the connection-stats-settings command. - returned: always - type: list -stderr: - description: set of error responses from the connection-stats-settings command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='connection-stats-settings-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_enable=dict(required=False, type='bool'), - pn_connection_backup_enable=dict(required=False, type='bool'), - pn_client_server_stats_max_memory=dict(required=False, type='str'), - pn_connection_stats_log_disk_space=dict(required=False, - type='str'), - pn_client_server_stats_log_enable=dict(required=False, - type='bool'), - pn_service_stat_max_memory=dict(required=False, type='str'), - pn_connection_stats_log_interval=dict(required=False, type='str'), - pn_fabric_connection_backup_interval=dict(required=False, - type='str'), - pn_connection_backup_interval=dict(required=False, type='str'), - pn_connection_stats_log_enable=dict(required=False, type='bool'), - pn_fabric_connection_max_memory=dict(required=False, type='str'), - pn_fabric_connection_backup_enable=dict(required=False, - type='bool'), - pn_client_server_stats_log_disk_space=dict(required=False, - type='str'), - pn_connection_max_memory=dict(required=False, type='str'), - pn_connection_stats_max_memory=dict(required=False, type='str'), - pn_client_server_stats_log_interval=dict(required=False, - type='str'), - ), - required_one_of=[['pn_enable', 'pn_connection_backup_enable', - 'pn_client_server_stats_max_memory', - 'pn_connection_stats_log_disk_space', - 'pn_client_server_stats_log_enable', - 'pn_service_stat_max_memory', - 'pn_connection_stats_log_interval', - 'pn_connection_backup_interval', - 'pn_connection_stats_log_enable', - 'pn_fabric_connection_max_memory', - 'pn_fabric_connection_backup_enable', - 'pn_client_server_stats_log_disk_space', - 'pn_connection_max_memory', - 'pn_connection_stats_max_memory', - 'pn_client_server_stats_log_interval']] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - enable = module.params['pn_enable'] - connection_backup_enable = module.params['pn_connection_backup_enable'] - client_server_stats_max_memory = module.params['pn_client_server_stats_max_memory'] - connection_stats_log_disk_space = module.params['pn_connection_stats_log_disk_space'] - client_server_stats_log_enable = module.params['pn_client_server_stats_log_enable'] - service_stat_max_memory = module.params['pn_service_stat_max_memory'] - connection_stats_log_interval = module.params['pn_connection_stats_log_interval'] - fabric_connection_backup_interval = module.params['pn_fabric_connection_backup_interval'] - connection_backup_interval = module.params['pn_connection_backup_interval'] - connection_stats_log_enable = module.params['pn_connection_stats_log_enable'] - fabric_connection_max_memory = module.params['pn_fabric_connection_max_memory'] - fabric_connection_backup_enable = module.params['pn_fabric_connection_backup_enable'] - client_server_stats_log_disk_space = module.params['pn_client_server_stats_log_disk_space'] - connection_max_memory = module.params['pn_connection_max_memory'] - connection_stats_max_memory = module.params['pn_connection_stats_max_memory'] - client_server_stats_log_interval = module.params['pn_client_server_stats_log_interval'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'connection-stats-settings-modify': - cli += ' %s ' % command - - cli += booleanArgs(enable, 'enable', 'disable') - cli += booleanArgs(connection_backup_enable, 'connection-backup-enable', 'connection-backup-disable') - cli += booleanArgs(client_server_stats_log_enable, 'client-server-stats-log-enable', 'client-server-stats-log-disable') - cli += booleanArgs(connection_stats_log_enable, 'connection-stats-log-enable', 'connection-stats-log-disable') - cli += booleanArgs(fabric_connection_backup_enable, 'fabric-connection-backup-enable', 'fabric-connection-backup-disable') - - if client_server_stats_max_memory: - cli += ' client-server-stats-max-memory ' + client_server_stats_max_memory - if connection_stats_log_disk_space: - cli += ' connection-stats-log-disk-space ' + connection_stats_log_disk_space - if service_stat_max_memory: - cli += ' service-stat-max-memory ' + service_stat_max_memory - if connection_stats_log_interval: - cli += ' connection-stats-log-interval ' + connection_stats_log_interval - if fabric_connection_backup_interval: - cli += ' fabric-connection-backup-interval ' + fabric_connection_backup_interval - if connection_backup_interval: - cli += ' connection-backup-interval ' + connection_backup_interval - if fabric_connection_max_memory: - cli += ' fabric-connection-max-memory ' + fabric_connection_max_memory - if client_server_stats_log_disk_space: - cli += ' client-server-stats-log-disk-space ' + client_server_stats_log_disk_space - if connection_max_memory: - cli += ' connection-max-memory ' + connection_max_memory - if connection_stats_max_memory: - cli += ' connection-stats-max-memory ' + connection_stats_max_memory - if client_server_stats_log_interval: - cli += ' client-server-stats-log-interval ' + client_server_stats_log_interval - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_cpu_class.py b/lib/ansible/modules/network/netvisor/pn_cpu_class.py deleted file mode 100644 index bc207794df..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_cpu_class.py +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_cpu_class -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/modify/delete cpu-class -description: - - This module can be used to create, modify and delete CPU class information. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(present) to create cpu-class and - C(absent) to delete cpu-class C(update) to modify the cpu-class. - required: True - type: str - choices: ['present', 'absent', 'update'] - pn_scope: - description: - - scope for CPU class. - required: false - choices: ['local', 'fabric'] - pn_hog_protect: - description: - - enable host-based hog protection. - required: False - type: str - choices: ['disable', 'enable', 'enable-and-drop'] - pn_rate_limit: - description: - - rate-limit for CPU class. - required: False - type: str - pn_name: - description: - - name for the CPU class. - required: False - type: str -""" - -EXAMPLES = """ -- name: create cpu class - pn_cpu_class: - pn_cliswitch: 'sw01' - state: 'present' - pn_name: 'icmp' - pn_rate_limit: '1000' - pn_scope: 'local' - -- name: delete cpu class - pn_cpu_class: - pn_cliswitch: 'sw01' - state: 'absent' - pn_name: 'icmp' - - -- name: modify cpu class - pn_cpu_class: - pn_cliswitch: 'sw01' - state: 'update' - pn_name: 'icmp' - pn_rate_limit: '2000' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the cpu-class command. - returned: always - type: list -stderr: - description: set of error responses from the cpu-class command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the cpu-class-show command. - If a user with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - clicopy = cli - - cli += ' system-settings-show format cpu-class-enable no-show-headers' - out = run_commands(module, cli)[1] - out = out.split() - - if 'on' not in out: - module.fail_json( - failed=True, - msg='Enable CPU class before creating or deleting' - ) - - cli = clicopy - cli += ' cpu-class-show format name no-show-headers' - out = run_commands(module, cli)[1] - if out: - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='cpu-class-create', - absent='cpu-class-delete', - update='cpu-class-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - pn_hog_protect=dict(required=False, type='str', - choices=['disable', 'enable', - 'enable-and-drop']), - pn_rate_limit=dict(required=False, type='str'), - pn_name=dict(required=False, type='str'), - ), - required_if=( - ['state', 'present', ['pn_name', 'pn_scope', 'pn_rate_limit']], - ['state', 'absent', ['pn_name']], - ['state', 'update', ['pn_name']], - ) - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - scope = module.params['pn_scope'] - hog_protect = module.params['pn_hog_protect'] - rate_limit = module.params['pn_rate_limit'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if command == 'cpu-class-modify': - if NAME_EXISTS is False: - module.fail_json( - failed=True, - msg='cpu class with name %s does not exist' % name - ) - - if command == 'cpu-class-delete': - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='cpu class with name %s does not exist' % name - ) - - if command == 'cpu-class-create': - if NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='cpu class with name %s already exists' % name - ) - if scope: - cli += ' scope %s ' % scope - - if command != 'cpu-class-delete': - if hog_protect: - cli += ' hog-protect %s ' % hog_protect - if rate_limit: - cli += ' rate-limit %s ' % rate_limit - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_cpu_mgmt_class.py b/lib/ansible/modules/network/netvisor/pn_cpu_mgmt_class.py deleted file mode 100644 index 49c091bfe5..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_cpu_mgmt_class.py +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_cpu_mgmt_class -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: 2.8 -short_description: CLI command to modify cpu-mgmt-class -description: - - This module can we used to update mgmt port ingress policers. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - type: str - required: false - state: - description: - - State the action to perform. Use C(update) to modify cpu-mgmt-class. - type: str - required: true - choices: ['update'] - pn_burst_size: - description: - - ingress traffic burst size (bytes) or default. - required: false - type: str - pn_name: - description: - - mgmt port ingress traffic class. - type: str - required: false - choices: ['arp', 'icmp', 'ssh', 'snmp', 'fabric', 'bcast', 'nfs', - 'web', 'web-ssl', 'net-api'] - pn_rate_limit: - description: - - ingress rate limit on mgmt port(bps) or unlimited. - type: str - required: false -""" - -EXAMPLES = """ -- name: cpu mgmt class modify ingress policers - pn_cpu_mgmt_class: - pn_cliswitch: "sw01" - state: "update" - pn_name: "icmp" - pn_rate_limit: "10000" - pn_burst_size: "14000" - -- name: cpu mgmt class modify ingress policers - pn_cpu_mgmt_class: - pn_cliswitch: "sw01" - state: "update" - pn_name: "snmp" - pn_burst_size: "8000" - pn_rate_limit: "100000" - -- name: cpu mgmt class modify ingress policers - pn_cpu_mgmt_class: - pn_cliswitch: "sw01" - state: "update" - pn_name: "web" - pn_rate_limit: "10000" - pn_burst_size: "1000" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the cpu-mgmt-class command. - returned: always - type: list -stderr: - description: set of error responses from the cpu-mgmt-class command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='cpu-mgmt-class-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', choices=state_map.keys()), - pn_burst_size=dict(required=False, type='str'), - pn_name=dict(required=False, type='str', - choices=['arp', 'icmp', 'ssh', 'snmp', - 'fabric', 'bcast', 'nfs', 'web', - 'web-ssl', 'net-api']), - pn_rate_limit=dict(required=False, type='str'), - ), - required_if=([['state', 'update', ['pn_name', 'pn_burst_size', 'pn_rate_limit']]]), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - burst_size = module.params['pn_burst_size'] - name = module.params['pn_name'] - rate_limit = module.params['pn_rate_limit'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'cpu-mgmt-class-modify': - cli += ' %s name %s ' % (command, name) - cli += ' burst-size %s rate-limit %s' % (burst_size, rate_limit) - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py b/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py deleted file mode 100644 index f154a67a97..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_dhcp_filter -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/modify/delete dhcp-filter -description: - - This module can be used to create, delete and modify a DHCP filter config. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(present) to create dhcp-filter and - C(absent) to delete dhcp-filter C(update) to modify the dhcp-filter. - required: True - type: str - choices: ['present', 'absent', 'update'] - pn_trusted_ports: - description: - - trusted ports of dhcp config. - required: False - type: str - pn_name: - description: - - name of the DHCP filter. - required: false - type: str -""" - -EXAMPLES = """ -- name: dhcp filter create - pn_dhcp_filter: - pn_cliswitch: "sw01" - pn_name: "foo" - state: "present" - pn_trusted_ports: "1" - -- name: dhcp filter delete - pn_dhcp_filter: - pn_cliswitch: "sw01" - pn_name: "foo" - state: "absent" - pn_trusted_ports: "1" - -- name: dhcp filter modify - pn_dhcp_filter: - pn_cliswitch: "sw01" - pn_name: "foo" - state: "update" - pn_trusted_ports: "1,2" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the dhcp-filter command. - returned: always - type: list -stderr: - description: set of error responses from the dhcp-filter command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the dhcp-filter-show command. - If a user with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - user_name = module.params['pn_name'] - - cli += ' dhcp-filter-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if user_name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='dhcp-filter-create', - absent='dhcp-filter-delete', - update='dhcp-filter-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_trusted_ports=dict(required=False, type='str'), - pn_name=dict(required=False, type='str'), - ), - required_if=[ - ["state", "present", ["pn_name", "pn_trusted_ports"]], - ["state", "absent", ["pn_name"]], - ["state", "update", ["pn_name", "pn_trusted_ports"]] - ] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - trusted_ports = module.params['pn_trusted_ports'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - USER_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if command == 'dhcp-filter-modify': - if USER_EXISTS is False: - module.fail_json( - failed=True, - msg='dhcp-filter with name %s does not exist' % name - ) - if command == 'dhcp-filter-delete': - if USER_EXISTS is False: - module.exit_json( - skipped=True, - msg='dhcp-filter with name %s does not exist' % name - ) - if command == 'dhcp-filter-create': - if USER_EXISTS is True: - module.exit_json( - skipped=True, - msg='dhcp-filter with name %s already exists' % name - ) - if command != 'dhcp-filter-delete': - if trusted_ports: - cli += ' trusted-ports ' + trusted_ports - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_dscp_map.py b/lib/ansible/modules/network/netvisor/pn_dscp_map.py deleted file mode 100644 index 63de80a3d0..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_dscp_map.py +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_dscp_map -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/delete dscp-map -description: - - This module can be used to create a DSCP priority mapping table. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(present) to create dscp-map and - C(absent) to delete. - required: True - type: str - choices: ["present", "absent"] - pn_name: - description: - - Name for the DSCP map. - required: False - type: str - pn_scope: - description: - - Scope for dscp map. - required: False - choices: ["local", "fabric"] -""" - -EXAMPLES = """ -- name: dscp map create - pn_dscp_map: - pn_cliswitch: "sw01" - state: "present" - pn_name: "foo" - pn_scope: "local" - -- name: dscp map delete - pn_dscp_map: - pn_cliswitch: "sw01" - state: "absent" - pn_name: "foo" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the dscp-map command. - returned: always - type: list -stderr: - description: set of error responses from the dscp-map command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the dscp-map-show name command. - If a user with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli += ' dscp-map-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='dscp-map-create', - absent='dscp-map-delete' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_name=dict(required=False, type='str'), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - ), - required_if=( - ["state", "present", ["pn_name", "pn_scope"]], - ["state", "absent", ["pn_name"]], - ) - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - name = module.params['pn_name'] - scope = module.params['pn_scope'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if command == 'dscp-map-delete': - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='dscp map with name %s does not exist' % name - ) - else: - if command == 'dscp-map-create': - if NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='dscp map with name %s already exists' % name - ) - - if scope: - cli += ' scope ' + scope - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py b/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py deleted file mode 100644 index 09eec99f5e..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_dscp_map_pri_map -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify dscp-map-pri-map -description: - - This module can be used to update priority mappings in tables. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(update) to modify - the dscp-map-pri-map. - required: True - type: str - choices: ['update'] - pn_pri: - description: - - CoS priority. - required: False - type: str - pn_name: - description: - - Name for the DSCP map. - required: False - type: str - pn_dsmap: - description: - - DSCP value(s). - required: False - type: str -""" - -EXAMPLES = """ -- name: dscp map pri map modify - pn_dscp_map_pri_map: - pn_cliswitch: 'sw01' - state: 'update' - pn_name: 'foo' - pn_pri: '0' - pn_dsmap: '40' - -- name: dscp map pri map modify - pn_dscp_map_pri_map: - pn_cliswitch: 'sw01' - state: 'update' - pn_name: 'foo' - pn_pri: '1' - pn_dsmap: '8,10,12,14' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the dscp-map-pri-map command. - returned: always - type: list -stderr: - description: set of error responses from the dscp-map-pri-map command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the dscp-map-show name command. - If a user with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli += ' dscp-map-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='dscp-map-pri-map-modify' - ) - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_pri=dict(required=False, type='str'), - pn_name=dict(required=False, type='str'), - pn_dsmap=dict(required=False, type='str'), - ), - required_if=( - ['state', 'update', ['pn_name', 'pn_pri']], - ) - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - pri = module.params['pn_pri'] - name = module.params['pn_name'] - dsmap = module.params['pn_dsmap'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module, cli) - - if command == 'dscp-map-pri-map-modify': - if NAME_EXISTS is False: - module.fail_json( - failed=True, - msg='Create dscp map with name %s before updating' % name - ) - cli += ' %s ' % command - if pri: - cli += ' pri ' + pri - if name: - cli += ' name ' + name - if dsmap: - cli += ' dsmap ' + dsmap - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_fabric_local.py b/lib/ansible/modules/network/netvisor/pn_fabric_local.py deleted file mode 100644 index 0db5cbed0b..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_fabric_local.py +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_fabric_local -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to modify fabric-local -description: - - This module can be used to modify fabric local information. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: true - type: str - state: - description: - - State the action to perform. Use C(update) to modify the fabric-local. - required: false - type: str - choices: ['update'] - default: 'update' - pn_fabric_network: - description: - - fabric administration network. - required: false - choices: ['in-band', 'mgmt', 'vmgmt'] - default: 'mgmt' - pn_vlan: - description: - - VLAN assigned to fabric. - required: false - type: str - pn_control_network: - description: - - control plane network. - required: false - choices: ['in-band', 'mgmt', 'vmgmt'] - pn_fabric_advertisement_network: - description: - - network to send fabric advertisements on. - required: false - choices: ['inband-mgmt', 'inband-only', 'inband-vmgmt', 'mgmt-only'] -""" - -EXAMPLES = """ -- name: Fabric local module - pn_fabric_local: - pn_cliswitch: "sw01" - pn_vlan: "500" - -- name: Fabric local module - pn_fabric_local: - pn_cliswitch: "sw01" - pn_fabric_advertisement_network: "mgmt-only" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the fabric-local command. - returned: always - type: list -stderr: - description: set of error responses from the fabric-local command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='fabric-local-modify' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=True, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='update'), - pn_fabric_network=dict(required=False, type='str', - choices=['mgmt', 'in-band', 'vmgmt'], default='mgmt'), - pn_vlan=dict(required=False, type='str'), - pn_control_network=dict(required=False, type='str', - choices=['in-band', 'mgmt', 'vmgmt']), - pn_fabric_advertisement_network=dict(required=False, type='str', - choices=['inband-mgmt', 'inband-only', 'inband-vmgmt', 'mgmt-only']), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_one_of=[['pn_fabric_network', 'pn_vlan', - 'pn_control_network', - 'pn_fabric_advertisement_network']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - fabric_network = module.params['pn_fabric_network'] - vlan = module.params['pn_vlan'] - control_network = module.params['pn_control_network'] - fabric_adv_network = module.params['pn_fabric_advertisement_network'] - - command = state_map[state] - - if vlan: - if int(vlan) < 1 or int(vlan) > 4092: - module.fail_json( - failed=True, - msg='Valid vlan range is 1 to 4092' - ) - cli = pn_cli(module, cliswitch) - cli += ' vlan-show format id no-show-headers' - out = run_commands(module, cli)[1].split() - - if vlan in out and vlan != '1': - module.fail_json( - failed=True, - msg='vlan %s is already in used. Specify unused vlan' % vlan - ) - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'fabric-local-modify': - cli += ' %s ' % command - - if fabric_network: - cli += ' fabric-network ' + fabric_network - - if vlan: - cli += ' vlan ' + vlan - - if control_network: - cli += ' control-network ' + control_network - - if fabric_adv_network: - cli += ' fabric-advertisement-network ' + fabric_adv_network - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_igmp_snooping.py b/lib/ansible/modules/network/netvisor/pn_igmp_snooping.py deleted file mode 100644 index 56912be44c..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_igmp_snooping.py +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_igmp_snooping -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify igmp-snooping -description: - - This module can be used to modify Internet Group Management Protocol (IGMP) snooping. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(update) to modify the igmp-snooping. - required: True - type: str - choices: ['update'] - pn_enable: - description: - - enable or disable IGMP snooping. - required: False - type: bool - pn_query_interval: - description: - - IGMP query interval in seconds. - required: False - type: str - pn_igmpv2_vlans: - description: - - VLANs on which to use IGMPv2 protocol. - required: False - type: str - pn_igmpv3_vlans: - description: - - VLANs on which to use IGMPv3 protocol. - required: False - type: str - pn_enable_vlans: - description: - - enable per VLAN IGMP snooping. - required: False - type: str - pn_vxlan: - description: - - enable or disable IGMP snooping on vxlans. - required: False - type: bool - pn_query_max_response_time: - description: - - maximum response time, in seconds, advertised in IGMP queries. - required: False - type: str - pn_scope: - description: - - IGMP snooping scope - fabric or local. - required: False - choices: ['local', 'fabric'] - pn_no_snoop_linklocal_vlans: - description: - - Remove snooping of link-local groups(224.0.0.0/24) on these vlans. - required: False - type: str - pn_snoop_linklocal_vlans: - description: - - Allow snooping of link-local groups(224.0.0.0/24) on these vlans. - required: False - type: str -""" - -EXAMPLES = """ -- name: 'Modify IGMP Snooping' - pn_igmp_snooping: - pn_cliswitch: 'sw01' - state: 'update' - pn_vxlan: True - pn_enable_vlans: '1-399,401-4092' - pn_no_snoop_linklocal_vlans: 'none' - pn_igmpv3_vlans: '1-399,401-4092' - -- name: 'Modify IGMP Snooping' - pn_igmp_snooping: - pn_cliswitch: 'sw01' - state: 'update' - pn_vxlan: False - pn_enable_vlans: '1-399' - pn_no_snoop_linklocal_vlans: 'none' - pn_igmpv3_vlans: '1-399' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the igmp-snooping command. - returned: always - type: list -stderr: - description: set of error responses from the igmp-snooping command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='igmp-snooping-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_enable=dict(required=False, type='bool'), - pn_query_interval=dict(required=False, type='str'), - pn_igmpv2_vlans=dict(required=False, type='str'), - pn_igmpv3_vlans=dict(required=False, type='str'), - pn_enable_vlans=dict(required=False, type='str'), - pn_vxlan=dict(required=False, type='bool'), - pn_query_max_response_time=dict(required=False, type='str'), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - pn_no_snoop_linklocal_vlans=dict(required=False, type='str'), - pn_snoop_linklocal_vlans=dict(required=False, type='str'), - ), - required_one_of=[['pn_enable', 'pn_query_interval', - 'pn_igmpv2_vlans', - 'pn_igmpv3_vlans', - 'pn_enable_vlans', - 'pn_vxlan', - 'pn_query_max_response_time', - 'pn_scope', - 'pn_no_snoop_linklocal_vlans', - 'pn_snoop_linklocal_vlans']] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - enable = module.params['pn_enable'] - query_interval = module.params['pn_query_interval'] - igmpv2_vlans = module.params['pn_igmpv2_vlans'] - igmpv3_vlans = module.params['pn_igmpv3_vlans'] - enable_vlans = module.params['pn_enable_vlans'] - vxlan = module.params['pn_vxlan'] - query_max_response_time = module.params['pn_query_max_response_time'] - scope = module.params['pn_scope'] - no_snoop_linklocal_vlans = module.params['pn_no_snoop_linklocal_vlans'] - snoop_linklocal_vlans = module.params['pn_snoop_linklocal_vlans'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'igmp-snooping-modify': - cli += ' %s ' % command - - cli += booleanArgs(enable, 'enable', 'disable') - cli += booleanArgs(vxlan, 'vxlan', 'no-vxlan') - - if query_interval: - cli += ' query-interval ' + query_interval - if igmpv2_vlans: - cli += ' igmpv2-vlans ' + igmpv2_vlans - if igmpv3_vlans: - cli += ' igmpv3-vlans ' + igmpv3_vlans - if enable_vlans: - cli += ' enable-vlans ' + enable_vlans - if query_max_response_time: - cli += ' query-max-response-time ' + query_max_response_time - if scope: - cli += ' scope ' + scope - if no_snoop_linklocal_vlans: - cli += ' no-snoop-linklocal-vlans ' + no_snoop_linklocal_vlans - if snoop_linklocal_vlans: - cli += ' snoop-linklocal-vlans ' + snoop_linklocal_vlans - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard.py b/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard.py deleted file mode 100644 index 7755b53ddb..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard.py +++ /dev/null @@ -1,239 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_ipv6security_raguard -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to create/modify/delete ipv6security-raguard -description: - - This module can be used to add ipv6 RA Guard Policy, Update ipv6 RA guard Policy and Remove ipv6 RA Guard Policy. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - ipv6security-raguard configuration command. - required: false - choices: ['present', 'update', 'absent'] - type: str - default: 'present' - pn_device: - description: - - RA Guard Device. host or router. - required: false - choices: ['host', 'router'] - type: str - pn_access_list: - description: - - RA Guard Access List of Source IPs. - required: false - type: str - pn_prefix_list: - description: - - RA Guard Prefix List. - required: false - type: str - pn_router_priority: - description: - - RA Guard Router Priority. - required: false - type: str - choices: ['low', 'medium', 'high'] - pn_name: - description: - - RA Guard Policy Name. - required: true - type: str -""" - -EXAMPLES = """ -- name: ipv6 security ragurad create - pn_ipv6security_raguard: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_device: "host" - -- name: ipv6 security ragurad create - pn_ipv6security_raguard: - pn_cliswitch: "sw01" - pn_name: "foo1" - pn_device: "host" - pn_access_list: "sample" - pn_prefix_list: "sample" - pn_router_priority: "low" - -- name: ipv6 security ragurad modify - pn_ipv6security_raguard: - pn_cliswitch: "sw01" - pn_name: "foo1" - pn_device: "router" - pn_router_priority: "medium" - state: "update" - -- name: ipv6 security ragurad delete - pn_ipv6security_raguard: - pn_cliswitch: "sw01" - pn_name: "foo" - state: "absent" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the ipv6security-raguard command. - returned: always - type: list -stderr: - description: set of error responses from the ipv6security-raguard command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module): - """ - This method checks for idempotency using the ipv6security-raguard-show command. - If a name exists, return True if name exists else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli = 'ipv6security-raguard-show format name parsable-delim ,' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if name in out else False - - -def check_list(module, list_name, command): - """ - This method checks for idempotency using provided command. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - - cli = '%s format name no-show-headers' % command - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - if list_name not in out: - module.fail_json( - failed=True, - msg='%s name %s does not exists' % (command, list_name) - ) - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='ipv6security-raguard-create', - absent='ipv6security-raguard-delete', - update='ipv6security-raguard-modify' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_device=dict(required=False, type='str', choices=['host', 'router']), - pn_access_list=dict(required=False, type='str'), - pn_prefix_list=dict(required=False, type='str'), - pn_router_priority=dict(required=False, type='str', choices=['low', 'medium', 'high']), - pn_name=dict(required=True, type='str'), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ['pn_device']], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - device = module.params['pn_device'] - access_list = module.params['pn_access_list'] - prefix_list = module.params['pn_prefix_list'] - router_priority = module.params['pn_router_priority'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module) - - if command == 'ipv6security-raguard-modify': - if not device and not access_list and not prefix_list and not router_priority: - module.fail_json( - failed=True, - msg='required one of device, access_list, prefix_list or router_priority' - ) - - if command == 'ipv6security-raguard-create': - if NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='ipv6 security raguard with name %s already exists' % name - ) - - if command != 'ipv6security-raguard-create': - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='ipv6 security raguard with name %s does not exist' % name - ) - - cli += ' %s name %s ' % (command, name) - if command != 'ipv6security-raguard-delete': - if device == 'router': - cli += ' device ' + device - if access_list: - check_list(module, access_list, 'access-list-show') - cli += ' access-list ' + access_list - if prefix_list: - check_list(module, prefix_list, 'prefix-list-show') - cli += ' prefix-list ' + prefix_list - if router_priority: - cli += ' router-priority ' + router_priority - if device == 'host': - cli += ' device ' + device - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard_port.py b/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard_port.py deleted file mode 100644 index d866f37a45..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard_port.py +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_ipv6security_raguard_port -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to add/remove ipv6security-raguard-port -description: - - This module can be used to add ports to RA Guard Policy and remove ports to RA Guard Policy. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - ipv6security-raguard-port configuration command. - required: false - type: str - choices: ['present', 'absent'] - default: 'present' - pn_name: - description: - - RA Guard Policy Name. - required: true - type: str - pn_ports: - description: - - Ports attached to RA Guard Policy. - required: true - type: str -""" - -EXAMPLES = """ -- name: ipv6 security raguard port add - pn_ipv6security_raguard_port: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_ports: "1" - -- name: ipv6 security raguard port remove - pn_ipv6security_raguard_port: - pn_cliswitch: "sw01" - pn_name: "foo" - state: "absent" - pn_ports: "1" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the ipv6security-raguard-port command. - returned: always - type: list -stderr: - description: set of error responses from the ipv6security-raguard-port command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module): - """ - This method checks for idempotency using the ipv6security-raguard-show command. - If a name exists, return True if name exists else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli = 'ipv6security-raguard-show format name parsable-delim ,' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='ipv6security-raguard-port-add', - absent='ipv6security-raguard-port-remove' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_name=dict(required=True, type='str'), - pn_ports=dict(required=True, type='str') - ) - - module = AnsibleModule( - argument_spec=argument_spec - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - name = module.params['pn_name'] - ports = module.params['pn_ports'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module) - - if command: - if NAME_EXISTS is False: - module.fail_json( - failed=True, - msg='ipv6 security raguard with name %s does not exist to add ports' % name - ) - - cli += ' %s name %s ports %s' % (command, name, ports) - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard_vlan.py b/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard_vlan.py deleted file mode 100644 index 9d9e35b2d3..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_ipv6security_raguard_vlan.py +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_ipv6security_raguard_vlan -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to add/remove ipv6security-raguard-vlan -description: - - This module can be used to Add vlans to RA Guard Policy and Remove vlans to RA Guard Policy. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - ipv6security-raguard-vlan configuration command. - required: false - type: str - choices: ['present', 'absent'] - default: 'present' - pn_vlans: - description: - - Vlans attached to RA Guard Policy. - required: true - type: str - pn_name: - description: - - RA Guard Policy Name. - required: true - type: str -""" - -EXAMPLES = """ -- name: ipv6 security raguard vlan add - pn_ipv6security_raguard_vlan: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_vlans: "100-105" - -- name: ipv6 security raguard vlan add - pn_ipv6security_raguard_vlan: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_vlans: "100" - -- name: ipv6 security raguard vlan remove - pn_ipv6security_raguard_vlan: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_vlans: "100-105" - state: 'absent' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the ipv6security-raguard-vlan command. - returned: always - type: list -stderr: - description: set of error responses from the ipv6security-raguard-vlan command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the ipv6-security-reguard command. - If a name exists, return True if name exists else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - vlans = module.params['pn_vlans'] - show = cli - - cli += ' ipv6security-raguard-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - NAME_EXISTS = True if name in out else False - - show += ' vlan-show format id no-show-headers' - out = run_commands(module, show)[1] - if out: - out = out.split() - - if vlans and '-' in vlans: - vlan_list = list() - vlans = vlans.strip().split('-') - for vlan in range(int(vlans[0]), int(vlans[1]) + 1): - vlan_list.append(str(vlan)) - - for vlan in vlan_list: - if vlan not in out: - module.fail_json( - failed=True, - msg='vlan id %s does not exist. Make sure you create vlan before adding it' % vlan - ) - else: - if vlans not in out: - module.fail_json( - failed=True, - msg='vlan id %s does not exist. Make sure you create vlan before adding it' % vlans - ) - - return NAME_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='ipv6security-raguard-vlan-add', - absent='ipv6security-raguard-vlan-remove' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_vlans=dict(required=True, type='str'), - pn_name=dict(required=True, type='str'), - ) - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - vlans = module.params['pn_vlans'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module, cli) - - cli += ' %s name %s ' % (command, name) - - if command: - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='ipv6security raguard with name %s does not exist' % name - ) - if vlans: - cli += ' vlans ' + vlans - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_log_audit_exception.py b/lib/ansible/modules/network/netvisor/pn_log_audit_exception.py deleted file mode 100644 index fe42dfa412..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_log_audit_exception.py +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/license/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_log_audit_exception -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to create/delete an audit exception -description: - - This module can be used to create an audit exception and delete an audit exception. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - pn_audit_type: - description: - - Specify the type of audit exception. - required: false - type: str - choices: ['cli', 'shell', 'vtysh'] - state: - description: - - State the action to perform. Use 'present' to create audit-exception and - 'absent' to delete audit-exception. - required: false - type: str - choices: ['present', 'absent'] - default: 'present' - pn_pattern: - description: - - Specify a regular expression to match exceptions. - required: false - type: str - pn_scope: - description: - - scope - local or fabric. - required: false - type: str - choices: ['local', 'fabric'] - pn_access: - description: - - Specify the access type to match exceptions. - required: true - type: str - choices: ['any', 'read-only', 'read-write'] -""" - -EXAMPLES = """ -- name: create a log-audit-exception - pn_log_audit_exception: - pn_audit_type: "cli" - pn_pattern: "test" - state: "present" - pn_access: "any" - pn_scope: "local" - -- name: delete a log-audit-exception - pn_log_audit_exception: - pn_audit_type: "shell" - pn_pattern: "test" - state: "absent" - pn_access: "any" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the pn_log_audit_exceptions command. - returned: always - type: list -stderr: - description: set of error responses from the log_audit_exceptions command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the log-audit-exception command. - If a list with given name exists, return exists as True else False. - :param module: The Ansible module to fetch input parameters. - :return Booleans: True or False. - """ - state = module.params['state'] - audit_type = module.params['pn_audit_type'] - pattern = module.params['pn_pattern'] - access = module.params['pn_access'] - scope = module.params['pn_scope'] - cli += ' log-audit-exception-show' - cli += ' no-show-headers format ' - cli += ' type,pattern,access,scope parsable-delim DELIM' - - stdout = run_commands(module, cli)[1] - - if stdout: - linelist = stdout.strip().split('\n') - for line in linelist: - wordlist = line.split('DELIM') - count = 0 - - if wordlist[0] == audit_type: - count += 1 - if wordlist[1] == pattern: - count += 1 - if wordlist[2] == access: - count += 1 - if state == 'present' and wordlist[3] == scope: - count += 1 - elif state == 'absent' and count == 3: - return True - if state == 'present' and count == 4: - return True - - return False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='log-audit-exception-create', - absent='log-audit-exception-delete', - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - pn_pattern=dict(required=True, type='str'), - state=dict(required=False, type='str', - choices=state_map.keys(), default='present'), - pn_access=dict(required=True, type='str', choices=['any', 'read-only', 'read-write']), - pn_audit_type=dict(required=True, type='str', choices=['cli', 'shell', 'vtysh']), - pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ["pn_scope"]], - ), - ) - - # Accessing the arguments - - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - access = module.params['pn_access'] - audit_type = module.params['pn_audit_type'] - pattern = module.params['pn_pattern'] - scope = module.params['pn_scope'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - audit_log_exists = check_cli(module, cli) - - cli += ' %s %s pattern %s %s' % (command, audit_type, pattern, access) - - if state == 'absent': - if audit_log_exists is False: - module.exit_json( - skipped=True, - msg='This audit log exception entry does not exist' - ) - run_cli(module, cli, state_map) - - elif state == 'present': - if audit_log_exists is True: - module.exit_json( - skipped=True, - msg='This audit log exception entry already exists' - ) - cli += ' scope %s ' % scope - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_port_config.py b/lib/ansible/modules/network/netvisor/pn_port_config.py deleted file mode 100644 index 87e1baebb0..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_port_config.py +++ /dev/null @@ -1,383 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_port_config -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: 2.8 -short_description: CLI command to modify port-config -description: - - This module can be used to modify a port configuration. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(update) to modify the port-config. - required: True - type: str - choices: ['update'] - pn_intf: - description: - - physical interface. - required: False - type: str - pn_crc_check_enable: - description: - - CRC check on ingress and rewrite on egress. - required: False - type: bool - pn_dscp_map: - description: - - DSCP map name to enable on port. - required: False - type: str - pn_autoneg: - description: - - physical port autonegotiation. - required: False - type: bool - pn_speed: - description: - - physical port speed. - required: False - choices: ['disable', '10m', '100m', '1g', - '2.5g', '10g', '25g', '40g', '50g', '100g'] - pn_port: - description: - - physical port. - required: False - type: str - pn_vxlan_termination: - description: - - physical port vxlan termination setting. - required: False - type: bool - pn_pause: - description: - - physical port pause. - required: False - type: bool - pn_loopback: - description: - - physical port loopback. - required: False - type: bool - pn_loop_vlans: - description: - - looping vlans. - required: False - type: str - pn_routing: - description: - - routing. - required: False - type: bool - pn_edge_switch: - description: - - physical port edge switch. - required: False - type: bool - pn_enable: - description: - - physical port enable. - required: False - type: bool - pn_description: - description: - - physical port description. - required: False - type: str - pn_host_enable: - description: - - Host facing port control setting. - required: False - type: bool - pn_allowed_tpid: - description: - - Allowed TPID in addition to 0x8100 on Vlan header. - required: False - type: str - choices: ['vlan', 'q-in-q', 'q-in-q-old'] - pn_mirror_only: - description: - - physical port mirror only. - required: False - type: bool - pn_reflect: - description: - - physical port reflection. - required: False - type: bool - pn_jumbo: - description: - - jumbo frames on physical port. - required: False - type: bool - pn_egress_rate_limit: - description: - - max egress port data rate limit. - required: False - type: str - pn_eth_mode: - description: - - physical Ethernet mode. - required: False - choices: ['1000base-x', 'sgmii', 'disabled', 'GMII'] - pn_fabric_guard: - description: - - Fabric guard configuration. - required: False - type: bool - pn_local_switching: - description: - - no-local-switching port cannot bridge traffic to - another no-local-switching port. - required: False - type: bool - pn_lacp_priority: - description: - - LACP priority from 1 to 65535. - required: False - type: str - pn_send_port: - description: - - send port. - required: False - type: str - pn_port_mac_address: - description: - - physical port MAC Address. - required: False - type: str - pn_defer_bringup: - description: - - defer port bringup. - required: False - type: bool -""" - -EXAMPLES = """ -- name: port config modify - pn_port_config: - pn_cliswitch: "sw01" - state: "update" - pn_port: "all" - pn_dscp_map: "foo" - -- name: port config modify - pn_port_config: - pn_cliswitch: "sw01" - state: "update" - pn_port: "all" - pn_host_enable: true -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the port-config command. - returned: always - type: list -stderr: - description: set of error responses from the port-config command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the dscp-map-show name command. - If a user with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_dscp_map'] - - cli += ' dscp-map-show name %s format name no-show-headers' % name - out = run_commands(module, cli)[1] - - out = out.split() - - return True if name in out[-1] else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='port-config-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=['update']), - pn_intf=dict(required=False, type='str'), - pn_crc_check_enable=dict(required=False, type='bool'), - pn_dscp_map=dict(required=False, type='str'), - pn_autoneg=dict(required=False, type='bool'), - pn_speed=dict(required=False, type='str', - choices=['disable', '10m', '100m', - '1g', '2.5g', '10g', '25g', - '40g', '50g', '100g']), - pn_port=dict(required=False, type='str'), - pn_vxlan_termination=dict(required=False, type='bool'), - pn_pause=dict(required=False, type='bool'), - pn_loopback=dict(required=False, type='bool'), - pn_loop_vlans=dict(required=False, type='str'), - pn_routing=dict(required=False, type='bool'), - pn_edge_switch=dict(required=False, type='bool'), - pn_enable=dict(required=False, type='bool'), - pn_description=dict(required=False, type='str'), - pn_host_enable=dict(required=False, type='bool'), - pn_allowed_tpid=dict(required=False, type='str', - choices=['vlan', 'q-in-q', 'q-in-q-old']), - pn_mirror_only=dict(required=False, type='bool'), - pn_reflect=dict(required=False, type='bool'), - pn_jumbo=dict(required=False, type='bool'), - pn_egress_rate_limit=dict(required=False, type='str'), - pn_eth_mode=dict(required=False, type='str', - choices=['1000base-x', 'sgmii', - 'disabled', 'GMII']), - pn_fabric_guard=dict(required=False, type='bool'), - pn_local_switching=dict(required=False, type='bool'), - pn_lacp_priority=dict(required=False, type='str'), - pn_send_port=dict(required=False, type='str'), - pn_port_mac_address=dict(required=False, type='str'), - pn_defer_bringup=dict(required=False, type='bool'), - ), - required_if=( - ['state', 'update', ['pn_port']], - ), - required_one_of=[['pn_intf', 'pn_crc_check_enable', 'pn_dscp_map', - 'pn_speed', 'pn_autoneg', - 'pn_vxlan_termination', 'pn_pause', - 'pn_fec', 'pn_loopback', 'pn_loop_vlans', - 'pn_routing', 'pn_edge_switch', - 'pn_enable', 'pn_description', - 'pn_host_enable', 'pn_allowed_tpid', - 'pn_mirror_only', 'pn_reflect', - 'pn_jumbo', 'pn_egress_rate_limit', - 'pn_eth_mode', 'pn_fabric_guard', - 'pn_local_switching', 'pn_lacp_priority', - 'pn_send_port', 'pn_port_mac_address', - 'pn_defer_bringup']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - intf = module.params['pn_intf'] - crc_check_enable = module.params['pn_crc_check_enable'] - dscp_map = module.params['pn_dscp_map'] - autoneg = module.params['pn_autoneg'] - speed = module.params['pn_speed'] - port = module.params['pn_port'] - vxlan_termination = module.params['pn_vxlan_termination'] - pause = module.params['pn_pause'] - loopback = module.params['pn_loopback'] - loop_vlans = module.params['pn_loop_vlans'] - routing = module.params['pn_routing'] - edge_switch = module.params['pn_edge_switch'] - enable = module.params['pn_enable'] - description = module.params['pn_description'] - host_enable = module.params['pn_host_enable'] - allowed_tpid = module.params['pn_allowed_tpid'] - mirror_only = module.params['pn_mirror_only'] - reflect = module.params['pn_reflect'] - jumbo = module.params['pn_jumbo'] - egress_rate_limit = module.params['pn_egress_rate_limit'] - eth_mode = module.params['pn_eth_mode'] - fabric_guard = module.params['pn_fabric_guard'] - local_switching = module.params['pn_local_switching'] - lacp_priority = module.params['pn_lacp_priority'] - send_port = module.params['pn_send_port'] - port_mac_address = module.params['pn_port_mac_address'] - defer_bringup = module.params['pn_defer_bringup'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if dscp_map: - NAME_EXISTS = check_cli(module, cli) - - if command == 'port-config-modify': - cli += ' %s ' % command - if dscp_map: - if NAME_EXISTS is False: - module.fail_json( - failed=True, - msg='Create dscp map with name %s before updating' % dscp_map - ) - - cli += ' dscp-map ' + dscp_map - if intf: - cli += ' intf ' + intf - if speed: - cli += ' speed ' + speed - if port: - cli += ' port ' + port - if allowed_tpid: - cli += ' allowed-tpid ' + allowed_tpid - if egress_rate_limit: - cli += ' egress-rate-limit ' + egress_rate_limit - if eth_mode: - cli += ' eth-mode ' + eth_mode - if lacp_priority: - cli += ' lacp-priority ' + lacp_priority - if send_port: - cli += ' send-port ' + send_port - if port_mac_address: - cli += ' port-mac-address ' + port_mac_address - - cli += booleanArgs(crc_check_enable, 'crc-check-enable', 'crc-check-disable') - cli += booleanArgs(autoneg, 'autoneg', 'no-autoneg') - cli += booleanArgs(vxlan_termination, 'vxlan-termination', 'no-vxlan-termination') - cli += booleanArgs(pause, 'pause', 'no-pause') - cli += booleanArgs(loopback, 'loopback', 'no-loopback') - cli += booleanArgs(routing, 'routing', 'no-routing') - cli += booleanArgs(edge_switch, 'edge-switch', 'no-edge-switch') - cli += booleanArgs(enable, 'enable', 'disable') - cli += booleanArgs(host_enable, 'host-enable', 'host-disable') - cli += booleanArgs(mirror_only, 'mirror-only', 'no-mirror-receive-only') - cli += booleanArgs(reflect, 'reflect', 'no-reflect') - cli += booleanArgs(jumbo, 'jumbo', 'no-jumbo') - cli += booleanArgs(fabric_guard, 'fabric-guard', 'no-fabric-guard') - cli += booleanArgs(local_switching, 'local-switching', 'no-local-switching') - cli += booleanArgs(defer_bringup, 'defer-bringup', 'no-defer-bringup') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_port_cos_bw.py b/lib/ansible/modules/network/netvisor/pn_port_cos_bw.py deleted file mode 100644 index 6b88e5e7d2..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_port_cos_bw.py +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_port_cos_bw -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify port-cos-bw -description: - - This module can be used to update bw settings for CoS queues. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: False - type: str - state: - description: - - State the action to perform. Use C(update) to modify the port-cos-bw. - required: True - type: str - choices: ['update'] - pn_max_bw_limit: - description: - - Maximum b/w in percentage. - required: False - type: str - pn_cos: - description: - - CoS priority. - required: False - type: str - pn_port: - description: - - physical port number. - required: False - type: str - pn_weight: - description: - - Scheduling weight (1 to 127) after b/w guarantee met. - required: False - type: str - choices: ['priority', 'no-priority'] - pn_min_bw_guarantee: - description: - - Minimum b/w in percentage. - required: False - type: str -""" - -EXAMPLES = """ -- name: port cos bw modify - pn_port_cos_bw: - pn_cliswitch: "sw01" - state: "update" - pn_port: "1" - pn_cos: "0" - pn_min_bw_guarantee: "60" - -- name: port cos bw modify - pn_port_cos_bw: - pn_cliswitch: "sw01" - state: "update" - pn_port: "all" - pn_cos: "0" - pn_weight: "priority" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the port-cos-bw command. - returned: always - type: list -stderr: - description: set of error responses from the port-cos-bw command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='port-cos-bw-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_max_bw_limit=dict(required=False, type='str'), - pn_cos=dict(required=False, type='str'), - pn_port=dict(required=False, type='str'), - pn_weight=dict(required=False, type='str', - choices=['priority', 'no-priority']), - pn_min_bw_guarantee=dict(required=False, type='str'), - ), - required_if=( - ['state', 'update', ['pn_cos', 'pn_port']], - ), - required_one_of=[['pn_max_bw_limit', 'pn_min_bw_guarantee', 'pn_weight']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - max_bw_limit = module.params['pn_max_bw_limit'] - cos = module.params['pn_cos'] - port = module.params['pn_port'] - weight = module.params['pn_weight'] - min_bw_guarantee = module.params['pn_min_bw_guarantee'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'port-cos-bw-modify': - cli += ' %s ' % command - if max_bw_limit: - cli += ' max-bw-limit ' + max_bw_limit - if cos: - cli += ' cos ' + cos - if port: - cli += ' port ' + port - if weight: - cli += ' weight ' + weight - if min_bw_guarantee: - cli += ' min-bw-guarantee ' + min_bw_guarantee - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_port_cos_rate_setting.py b/lib/ansible/modules/network/netvisor/pn_port_cos_rate_setting.py deleted file mode 100644 index f8b3ebd59a..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_port_cos_rate_setting.py +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_port_cos_rate_setting -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify port-cos-rate-setting -description: - - This modules can be used to update the port cos rate limit. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(update) to modify - the port-cos-rate-setting. - required: true - type: str - choices: ['update'] - pn_cos0_rate: - description: - - cos0 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos1_rate: - description: - - cos1 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos2_rate: - description: - - cos2 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos3_rate: - description: - - cos3 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos4_rate: - description: - - cos4 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos5_rate: - description: - - cos5 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos6_rate: - description: - - cos6 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_cos7_rate: - description: - - cos7 rate limit (pps) unlimited or 0 to 10000000. - required: false - type: str - pn_port: - description: - - port. - required: false - type: str - choices: ['control-port', 'data-port', 'span-ports'] -""" - -EXAMPLES = """ -- name: port cos rate modify - pn_port_cos_rate_setting: - pn_cliswitch: "sw01" - state: "update" - pn_port: "control-port" - pn_cos1_rate: "1000" - pn_cos5_rate: "1000" - pn_cos2_rate: "1000" - pn_cos0_rate: "1000" - -- name: port cos rate modify - pn_port_cos_rate_setting: - pn_cliswitch: "sw01" - state: "update" - pn_port: "data-port" - pn_cos1_rate: "2000" - pn_cos5_rate: "2000" - pn_cos2_rate: "2000" - pn_cos0_rate: "2000" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the port-cos-rate-setting command. - returned: always - type: list -stderr: - description: set of error responses from the port-cos-rate-setting command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='port-cos-rate-setting-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_cos1_rate=dict(required=False, type='str'), - pn_cos5_rate=dict(required=False, type='str'), - pn_cos2_rate=dict(required=False, type='str'), - pn_cos0_rate=dict(required=False, type='str'), - pn_cos6_rate=dict(required=False, type='str'), - pn_cos3_rate=dict(required=False, type='str'), - pn_cos4_rate=dict(required=False, type='str'), - pn_cos7_rate=dict(required=False, type='str'), - pn_port=dict(required=False, type='str', - choices=['control-port', 'data-port', 'span-ports']), - ), - required_if=( - ['state', 'update', ['pn_port']], - ), - required_one_of=[['pn_cos0_rate', - 'pn_cos1_rate', - 'pn_cos2_rate', - 'pn_cos3_rate', - 'pn_cos4_rate', - 'pn_cos5_rate', - 'pn_cos6_rate', - 'pn_cos7_rate']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - cos1_rate = module.params['pn_cos1_rate'] - cos5_rate = module.params['pn_cos5_rate'] - cos2_rate = module.params['pn_cos2_rate'] - cos0_rate = module.params['pn_cos0_rate'] - cos6_rate = module.params['pn_cos6_rate'] - cos3_rate = module.params['pn_cos3_rate'] - cos4_rate = module.params['pn_cos4_rate'] - cos7_rate = module.params['pn_cos7_rate'] - port = module.params['pn_port'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'port-cos-rate-setting-modify': - cli += ' %s ' % command - if cos1_rate: - cli += ' cos1-rate ' + cos1_rate - if cos5_rate: - cli += ' cos5-rate ' + cos5_rate - if cos2_rate: - cli += ' cos2-rate ' + cos2_rate - if cos0_rate: - cli += ' cos0-rate ' + cos0_rate - if cos6_rate: - cli += ' cos6-rate ' + cos6_rate - if cos3_rate: - cli += ' cos3-rate ' + cos3_rate - if cos4_rate: - cli += ' cos4-rate ' + cos4_rate - if cos7_rate: - cli += ' cos7-rate ' + cos7_rate - if port: - cli += ' port ' + port - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_prefix_list.py b/lib/ansible/modules/network/netvisor/pn_prefix_list.py deleted file mode 100644 index c3ab7dfbb7..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_prefix_list.py +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_prefix_list -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to create/delete prefix-list -description: - - This module can be used to create or delete prefix list. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to create prefix-list and - C(absent) to delete prefix-list. - required: false - type: str - choices: ['present', 'absent'] - default: 'present' - pn_name: - description: - - Prefix List Name. - required: true - type: str - pn_scope: - description: - - scope of prefix-list. - required: false - type: str - choices: ['local', 'fabric'] -""" - -EXAMPLES = """ -- name: Create prefix list - pn_prefix_list: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_scope: "local" - state: "present" - -- name: Delete prefix list - pn_prefix_list: - pn_cliswitch: "sw01" - pn_name: "foo" - state: "absent" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the prefix-list command. - returned: always - type: list -stderr: - description: set of error responses from the prefix-list command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the prefix-list-show command. - If a name exists, return True if name exists else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli += ' prefix-list-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='prefix-list-create', - absent='prefix-list-delete' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', - choices=state_map.keys(), default='present'), - pn_name=dict(required=True, type='str'), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ["pn_name", "pn_scope"]], - ["state", "absent", ["pn_name"]], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - name = module.params['pn_name'] - scope = module.params['pn_scope'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module, cli) - - cli += ' %s name %s ' % (command, name) - - if command == 'prefix-list-delete': - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='prefix-list with name %s does not exist' % name - ) - else: - if command == 'prefix-list-create': - if NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='prefix list with name %s already exists' % name - ) - cli += ' scope %s ' % scope - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py b/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py deleted file mode 100644 index bc2f10786d..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_prefix_list_network -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to add/remove prefix-list-network -description: - - This module is used to add network associated with prefix list - and remove networks associated with prefix list. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to create - prefix-list-network and C(absent) to delete prefix-list-network. - required: true - type: str - choices: ['present', 'absent'] - pn_netmask: - description: - - netmask of the network associated the prefix list. - required: false - type: str - pn_name: - description: - - Prefix List Name. - required: false - type: str - pn_network: - description: - - network associated with the prefix list. - required: false - type: str -""" - -EXAMPLES = """ -- name: prefix list network add - pn_prefix_list_network: - pn_cliswitch: "sw01" - pn_name: "foo" - pn_network: "172.16.3.1" - pn_netmask: "24" - state: "present" - -- name: prefix list network remove - pn_prefix_list_network: - pn_cliswitch: "sw01" - state: "absent" - pn_name: "foo" - pn_network: "172.16.3.1" - pn_netmask: "24" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the prefix-list-network command. - returned: always - type: list -stderr: - description: set of error responses from the prefix-list-network command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using prefix-list-network-show command. - If network exists, return as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - network = module.params['pn_network'] - show = cli - - cli += ' prefix-list-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if name not in out.split()[-1]: - module.fail_json( - failed=True, - msg='Prefix list with name %s does not exists' % name - ) - - cli = show - cli += ' prefix-list-network-show name %s format network no-show-headers' % name - rc, out, err = run_commands(module, cli) - - if out: - out = out.split()[-1] - return True if network in out.split('/')[0] else False - - return False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='prefix-list-network-add', - absent='prefix-list-network-remove' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_netmask=dict(required=False, type='str'), - pn_name=dict(required=False, type='str'), - pn_network=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_name", "pn_network", "pn_netmask"]], - ["state", "absent", ["pn_name", "pn_network", "pn_netmask"]], - ), - required_together=( - ["pn_network", "pn_netmask"], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - netmask = module.params['pn_netmask'] - name = module.params['pn_name'] - network = module.params['pn_network'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NETWORK_EXISTS = check_cli(module, cli) - cli += ' %s ' % command - - if command == 'prefix-list-network-remove': - if NETWORK_EXISTS is False: - module.exit_json( - skipped=True, - msg='Prefix list with network %s does not exist' % network - ) - - if command == 'prefix-list-network-add': - if NETWORK_EXISTS is True: - module.exit_json( - skipped=True, - msg='Prefix list with network %s already exists' % network - ) - - if name: - cli += ' name ' + name - if network: - cli += ' network ' + network - if netmask: - cli += ' netmask ' + netmask - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_role.py b/lib/ansible/modules/network/netvisor/pn_role.py deleted file mode 100644 index ba2306de7f..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_role.py +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_role -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/delete/modify role -description: - - This module can be used to create, delete and modify user roles. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to create role and - C(absent) to delete role and C(update) to modify role. - required: true - type: str - choices: ['present', 'absent', 'update'] - pn_scope: - description: - - local or fabric. - required: false - type: str - choices: ['local', 'fabric'] - pn_access: - description: - - type of access. - required: false - type: str - choices: ['read-only', 'read-write'] - pn_shell: - description: - - allow shell command. - required: false - type: bool - pn_sudo: - description: - - allow sudo from shell. - required: false - type: bool - pn_running_config: - description: - - display running configuration of switch. - required: false - type: bool - pn_name: - description: - - role name. - required: true - type: str - pn_delete_from_users: - description: - - delete from users. - required: false - type: bool -""" - -EXAMPLES = """ -- name: Role create - pn_role: - pn_cliswitch: 'sw01' - state: 'present' - pn_name: 'foo' - pn_scope: 'local' - pn_access: 'read-only' - -- name: Role delete - pn_role: - pn_cliswitch: 'sw01' - state: 'absent' - pn_name: 'foo' - -- name: Role modify - pn_role: - pn_cliswitch: 'sw01' - state: 'update' - pn_name: 'foo' - pn_access: 'read-write' - pn_sudo: true - pn_shell: true -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the role command. - returned: always - type: list -stderr: - description: set of error responses from the role command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the role-show command. - If a role with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - role_name = module.params['pn_name'] - - cli += ' role-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if role_name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='role-create', - absent='role-delete', - update='role-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - pn_access=dict(required=False, type='str', - choices=['read-only', 'read-write']), - pn_shell=dict(required=False, type='bool'), - pn_sudo=dict(required=False, type='bool'), - pn_running_config=dict(required=False, type='bool'), - pn_name=dict(required=False, type='str'), - pn_delete_from_users=dict(required=False, type='bool'), - ), - required_if=( - ["state", "present", ["pn_name", "pn_scope"]], - ["state", "absent", ["pn_name"]], - ["state", "update", ["pn_name"]], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - scope = module.params['pn_scope'] - access = module.params['pn_access'] - shell = module.params['pn_shell'] - sudo = module.params['pn_sudo'] - running_config = module.params['pn_running_config'] - name = module.params['pn_name'] - delete_from_users = module.params['pn_delete_from_users'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - ROLE_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if shell is (False or '') and sudo is True: - module.fail_json( - failed=True, - msg='sudo access requires shell access' - ) - - if command == 'role-modify': - if ROLE_EXISTS is False: - module.fail_json( - failed=True, - msg='Role with name %s does not exist' % name - ) - - if command == 'role-delete': - if ROLE_EXISTS is False: - module.exit_json( - skipped=True, - msg='Role with name %s does not exist' % name - ) - - if command == 'role-create': - if ROLE_EXISTS is True: - module.exit_json( - skipped=True, - msg='Role with name %s already exists' % name - ) - - if scope: - cli += ' scope ' + scope - - if command != 'role-delete': - if access: - cli += ' access ' + access - - cli += booleanArgs(shell, 'shell', 'no-shell') - cli += booleanArgs(sudo, 'sudo', 'no-sudo') - cli += booleanArgs(running_config, 'running-config', 'no-running-config') - - if command == 'role-modify': - if delete_from_users: - cli += ' delete-from-users ' + delete_from_users - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_snmp_community.py b/lib/ansible/modules/network/netvisor/pn_snmp_community.py deleted file mode 100644 index 1679ca4fcb..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_snmp_community.py +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_snmp_community -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/modify/delete snmp-community -description: - - This module can be used to create SNMP communities for SNMPv1 or - delete SNMP communities for SNMPv1 or modify SNMP communities for SNMPv1. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - state: - description: - - State the action to perform. Use C(present) to create snmp-community and - C(absent) to delete snmp-community C(update) to update snmp-community. - required: true - type: str - choices: ['present', 'absent', 'update'] - pn_community_type: - description: - - community type. - type: str - choices: ['read-only', 'read-write'] - pn_community_string: - description: - - community name. - type: str -""" - -EXAMPLES = """ -- name: Create snmp community - pn_snmp_community: - pn_cliswitch: "sw01" - state: "present" - pn_community_string: "foo" - pn_community_type: "read-write" - -- name: Delete snmp community - pn_snmp_community: - pn_cliswitch: "sw01" - state: "absent" - pn_community_string: "foo" - -- name: Modify snmp community - pn_snmp_community: - pn_cliswitch: "sw01" - state: "update" - pn_community_string: "foo" - pn_community_type: "read-only" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the snmp-community command. - returned: always - type: list -stderr: - description: set of error responses from the snmp-community command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the snmp-community-show command. - If a user with given name exists, return as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - comm_str = module.params['pn_community_string'] - - cli += ' snmp-community-show format community-string no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if comm_str in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='snmp-community-create', - absent='snmp-community-delete', - update='snmp-community-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_community_type=dict(required=False, type='str', - choices=['read-only', 'read-write']), - pn_community_string=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_community_type", "pn_community_string"]], - ["state", "absent", ["pn_community_string"]], - ["state", "update", ["pn_community_type", "pn_community_string"]], - ) - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - community_type = module.params['pn_community_type'] - comm_str = module.params['pn_community_string'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - COMMUNITY_EXISTS = check_cli(module, cli) - - if command == 'snmp-community-modify': - if COMMUNITY_EXISTS is False: - module.fail_json( - failed=True, - msg='snmp community name %s does not exist' % comm_str - ) - - if command == 'snmp-community-delete': - if COMMUNITY_EXISTS is False: - module.exit_json( - skipped=True, - msg='snmp community name %s does not exist' % comm_str - ) - - if command == 'snmp-community-create': - if COMMUNITY_EXISTS is True: - module.exit_json( - skipped=True, - msg='snmp community with name %s already exists' % comm_str - ) - - cli += ' %s community-string %s ' % (command, comm_str) - - if command != 'snmp-community-delete' and community_type: - cli += ' community-type ' + community_type - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py b/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py deleted file mode 100644 index f8e90a1a6e..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py +++ /dev/null @@ -1,215 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_snmp_trap_sink -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/delete snmp-trap-sink -description: - - This module can be used to create a SNMP trap sink and delete a SNMP trap sink. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to create snmp-trap-sink and - C(absent) to delete snmp-trap-sink. - required: true - type: str - choices: ['present', 'absent'] - pn_dest_host: - description: - - destination host. - type: str - pn_community: - description: - - community type. - type: str - pn_dest_port: - description: - - destination port. - type: str - default: '162' - pn_type: - description: - - trap type. - type: str - choices: ['TRAP_TYPE_V1_TRAP', 'TRAP_TYPE_V2C_TRAP', 'TRAP_TYPE_V2_INFORM'] - default: 'TRAP_TYPE_V2C_TRAP' -""" - -EXAMPLES = """ -- name: snmp trap sink functionality - pn_snmp_trap_sink: - pn_cliswitch: "sw01" - state: "present" - pn_community: "foo" - pn_type: "TRAP_TYPE_V2_INFORM" - pn_dest_host: "192.168.67.8" - -- name: snmp trap sink functionality - pn_snmp_trap_sink: - pn_cliswitch: "sw01" - state: "absent" - pn_community: "foo" - pn_type: "TRAP_TYPE_V2_INFORM" - pn_dest_host: "192.168.67.8" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the snmp-trap-sink command. - returned: always - type: list -stderr: - description: set of error responses from the snmp-trap-sink command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the snmp-trap-sink-show command. - If a trap with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - community = module.params['pn_community'] - dest_host = module.params['pn_dest_host'] - - show = cli - cli += ' snmp-community-show format community-string no-show-headers' - rc, out, err = run_commands(module, cli) - - if out: - out = out.split() - - if community in out: - cli = show - cli += ' snmp-trap-sink-show community %s format type,dest-host no-show-headers' % community - rc, out, err = run_commands(module, cli) - - if out: - out = out.split() - - return True if dest_host in out else False - else: - return None - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='snmp-trap-sink-create', - absent='snmp-trap-sink-delete' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_dest_host=dict(required=False, type='str'), - pn_community=dict(required=False, type='str'), - pn_dest_port=dict(required=False, type='str', default='162'), - pn_type=dict(required=False, type='str', - choices=['TRAP_TYPE_V1_TRAP', - 'TRAP_TYPE_V2C_TRAP', - 'TRAP_TYPE_V2_INFORM'], - default='TRAP_TYPE_V2C_TRAP'), - ), - required_if=( - ["state", "present", ["pn_community", "pn_dest_host"]], - ["state", "absent", ["pn_community", "pn_dest_host"]], - ) - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - dest_host = module.params['pn_dest_host'] - community = module.params['pn_community'] - dest_port = module.params['pn_dest_port'] - pn_type = module.params['pn_type'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - VALUE_EXISTS = check_cli(module, cli) - cli += ' %s ' % command - - if command == 'snmp-trap-sink-create': - if VALUE_EXISTS is True: - module.exit_json( - skipped=True, - msg='snmp trap sink already exists' - ) - if VALUE_EXISTS is None: - module.fail_json( - failed=True, - msg='snmp community does not exists to create trap sink' - ) - if pn_type: - cli += ' type ' + pn_type - if dest_host: - cli += ' dest-host ' + dest_host - if community: - cli += ' community ' + community - if dest_port: - cli += ' dest-port ' + dest_port - - if command == 'snmp-trap-sink-delete': - if VALUE_EXISTS is None: - module.fail_json( - failed=True, - msg='snmp community does not exists to delete trap sink' - ) - if VALUE_EXISTS is False: - module.exit_json( - skipped=True, - msg='snmp-trap-sink with community %s does not exist with dest-host %s ' % (community, dest_host) - ) - if community: - cli += ' community ' + community - if dest_host: - cli += ' dest-host ' + dest_host - if dest_port: - cli += ' dest-port ' + dest_port - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py b/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py deleted file mode 100644 index 77b67ef071..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_snmp_vacm -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/modify/delete snmp-vacm -description: - - This module can be used to create View Access Control Models (VACM), - modify VACM and delete VACM. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - type: str - required: false - state: - description: - - State the action to perform. Use C(present) to create snmp-vacm and - C(absent) to delete snmp-vacm and C(update) to modify snmp-vacm. - type: str - required: true - choices: ['present', 'absent', 'update'] - pn_oid_restrict: - description: - - restrict OID. - type: str - pn_priv: - description: - - privileges. - type: bool - pn_auth: - description: - - authentication required. - type: bool - pn_user_type: - description: - - SNMP user type. - type: str - choices: ['rouser', 'rwuser'] - pn_user_name: - description: - - SNMP administrator name. - type: str -""" - -EXAMPLES = """ -- name: create snmp vacm - pn_snmp_vacm: - pn_cliswitch: "sw01" - state: "present" - pn_user_name: "foo" - pn_user_type: "rouser" - -- name: update snmp vacm - pn_snmp_vacm: - pn_cliswitch: "sw01" - state: "update" - pn_user_name: "foo" - pn_user_type: "rwuser" - -- name: delete snmp vacm - pn_snmp_vacm: - pn_cliswitch: "sw01" - state: "absent" - pn_user_name: "foo" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the snmp-vacm command. - returned: always - type: list -stderr: - description: set of error responses from the snmp-vacm command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the snmp-vacm-show command. - If a user with given name exists, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - user_name = module.params['pn_user_name'] - show = cli - - cli += ' snmp-user-show format user-name no-show-headers' - rc, out, err = run_commands(module, cli) - - if out and user_name in out.split(): - pass - else: - return None - - cli = show - cli += ' snmp-vacm-show format user-name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if user_name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='snmp-vacm-create', - absent='snmp-vacm-delete', - update='snmp-vacm-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_oid_restrict=dict(required=False, type='str'), - pn_priv=dict(required=False, type='bool'), - pn_auth=dict(required=False, type='bool'), - pn_user_type=dict(required=False, type='str', - choices=['rouser', 'rwuser']), - pn_user_name=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_user_name"]], - ["state", "absent", ["pn_user_name"]], - ["state", "update", ["pn_user_name"]] - ) - - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - oid_restrict = module.params['pn_oid_restrict'] - priv = module.params['pn_priv'] - auth = module.params['pn_auth'] - user_type = module.params['pn_user_type'] - user_name = module.params['pn_user_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - USER_EXISTS = check_cli(module, cli) - cli += ' %s user-name %s ' % (command, user_name) - - if command == 'snmp-vacm-modify': - if USER_EXISTS is None: - module.fail_json( - failed=True, - msg='snmp user with name %s does not exists' % user_name - ) - if USER_EXISTS is False: - module.fail_json( - failed=True, - msg='snmp vacm with name %s does not exists' % user_name - ) - - if command == 'snmp-vacm-delete': - if USER_EXISTS is None: - module.fail_json( - failed=True, - msg='snmp user with name %s does not exists' % user_name - ) - - if USER_EXISTS is False: - module.exit_json( - skipped=True, - msg='snmp vacm with name %s does not exist' % user_name - ) - - if command == 'snmp-vacm-create': - if USER_EXISTS is None: - module.fail_json( - failed=True, - msg='snmp user with name %s does not exists' % user_name - ) - if USER_EXISTS is True: - module.exit_json( - skipped=True, - msg='snmp vacm with name %s already exists' % user_name - ) - - if command != 'snmp-vacm-delete': - if oid_restrict: - cli += ' oid-restrict ' + oid_restrict - if user_type: - cli += ' user-type ' + user_type - - cli += booleanArgs(auth, 'auth', 'no-auth') - cli += booleanArgs(priv, 'priv', 'no-priv') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_stp.py b/lib/ansible/modules/network/netvisor/pn_stp.py deleted file mode 100644 index 6039ed40ec..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_stp.py +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_stp -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify stp -description: - - This module can be used to modify Spanning Tree Protocol parameters. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - type: str - required: false - state: - description: - - State the action to perform. Use C(update) to stp. - type: str - required: true - choices: ['update'] - pn_hello_time: - description: - - STP hello time between 1 and 10 secs. - type: str - default: '2' - pn_enable: - description: - - enable or disable STP - type: bool - pn_root_guard_wait_time: - description: - - root guard wait time between 0 and 300 secs. 0 to disable wait. - type: str - default: '20' - pn_bpdus_bridge_ports: - description: - - BPDU packets to bridge specific port. - type: bool - pn_mst_max_hops: - description: - - maximum hop count for mstp bpdu. - type: str - default: '20' - pn_bridge_id: - description: - - STP bridge id. - type: str - pn_max_age: - description: - - maximum age time between 6 and 40 secs. - type: str - default: '20' - pn_stp_mode: - description: - - STP mode. - type: str - choices: ['rstp', 'mstp'] - pn_mst_config_name: - description: - - Name for MST Configuration Instance. - type: str - pn_forwarding_delay: - description: - - STP forwarding delay between 4 and 30 secs. - type: str - default: '15' - pn_bridge_priority: - description: - - STP bridge priority. - type: str - default: '32768' -""" - -EXAMPLES = """ -- name: Modify stp - pn_stp: - pn_cliswitch: "sw01" - state: "update" - pn_hello_time: "3" - pn_stp_mode: "rstp" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the stp command. - returned: always - type: list -stderr: - description: set of error responses from the stp command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='stp-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_hello_time=dict(required=False, type='str', default='2'), - pn_enable=dict(required=False, type='bool'), - pn_root_guard_wait_time=dict(required=False, type='str', default='20'), - pn_bpdus_bridge_ports=dict(required=False, type='bool'), - pn_mst_max_hops=dict(required=False, type='str', default='20'), - pn_bridge_id=dict(required=False, type='str'), - pn_max_age=dict(required=False, type='str', default='20'), - pn_stp_mode=dict(required=False, type='str', - choices=['rstp', 'mstp']), - pn_mst_config_name=dict(required=False, type='str'), - pn_forwarding_delay=dict(required=False, type='str', default='15'), - pn_bridge_priority=dict(required=False, type='str', default='32768'), - ), - required_one_of=[['pn_enable', 'pn_hello_time', - 'pn_root_guard_wait_time', - 'pn_bpdus_bridge_ports', - 'pn_mst_max_hops', - 'pn_bridge_id', - 'pn_max_age', - 'pn_stp_mode', - 'pn_mst_config_name', - 'pn_forwarding_delay', - 'pn_bridge_priority']] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - hello_time = module.params['pn_hello_time'] - enable = module.params['pn_enable'] - root_guard_wait_time = module.params['pn_root_guard_wait_time'] - bpdus_bridge_ports = module.params['pn_bpdus_bridge_ports'] - mst_max_hops = module.params['pn_mst_max_hops'] - bridge_id = module.params['pn_bridge_id'] - max_age = module.params['pn_max_age'] - stp_mode = module.params['pn_stp_mode'] - mst_config_name = module.params['pn_mst_config_name'] - forwarding_delay = module.params['pn_forwarding_delay'] - bridge_priority = module.params['pn_bridge_priority'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'stp-modify': - cli += ' %s ' % command - if hello_time: - cli += ' hello-time ' + hello_time - if root_guard_wait_time: - cli += ' root-guard-wait-time ' + root_guard_wait_time - if mst_max_hops: - cli += ' mst-max-hops ' + mst_max_hops - if bridge_id: - cli += ' bridge-id ' + bridge_id - if max_age: - cli += ' max-age ' + max_age - if stp_mode: - cli += ' stp-mode ' + stp_mode - if mst_config_name: - cli += ' mst-config-name ' + mst_config_name - if forwarding_delay: - cli += ' forwarding-delay ' + forwarding_delay - if bridge_priority: - cli += ' bridge-priority ' + bridge_priority - - cli += booleanArgs(enable, 'enable', 'disable') - cli += booleanArgs(bpdus_bridge_ports, 'bpdus-bridge-ports', 'bpdus-all-ports') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_stp_port.py b/lib/ansible/modules/network/netvisor/pn_stp_port.py deleted file mode 100644 index a117bd5c8e..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_stp_port.py +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_stp_port -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify stp-port. -description: - - This module can be used modify Spanning Tree Protocol (STP) parameters on ports. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - type: str - required: false - state: - description: - - State the action to perform. Use C(update) to update stp-port. - type: str - required: true - choices: ['update'] - pn_priority: - description: - - STP port priority from 0 to 240. - type: str - default: '128' - pn_cost: - description: - - STP port cost from 1 to 200000000. - type: str - default: '2000' - pn_root_guard: - description: - - STP port Root guard. - type: bool - pn_filter: - description: - - STP port filters BPDUs. - type: bool - pn_edge: - description: - - STP port is an edge port. - type: bool - pn_bpdu_guard: - description: - - STP port BPDU guard. - type: bool - pn_port: - description: - - STP port. - type: str - pn_block: - description: - - Specify if a STP port blocks BPDUs. - type: bool -""" - -EXAMPLES = """ -- name: Modify stp port - pn_stp_port: - pn_cliswitch: "sw01" - state: "update" - pn_port: "1" - pn_filter: True - pn_priority: '144' - -- name: Modify stp port - pn_stp_port: - pn_cliswitch: "sw01" - state: "update" - pn_port: "1" - pn_cost: "200" - -- name: Modify stp port - pn_stp_port: - pn_cliswitch: "sw01" - state: "update" - pn_port: "1" - pn_edge: True - pn_cost: "200" - -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the stp-port command. - returned: always - type: list -stderr: - description: set of error responses from the stp-port command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='stp-port-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_priority=dict(required=False, type='str', default='128'), - pn_cost=dict(required=False, type='str', default='2000'), - pn_root_guard=dict(required=False, type='bool'), - pn_filter=dict(required=False, type='bool'), - pn_edge=dict(required=False, type='bool'), - pn_bpdu_guard=dict(required=False, type='bool'), - pn_port=dict(required=False, type='str'), - pn_block=dict(required=False, type='bool'), - ), - required_if=( - ["state", "update", ["pn_port"]], - ), - required_one_of=( - ['pn_cost', 'pn_root_guard', 'pn_filter', - 'pn_edge', 'pn_bpdu_guard', 'pn_block'], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - priority = module.params['pn_priority'] - cost = module.params['pn_cost'] - root_guard = module.params['pn_root_guard'] - pn_filter = module.params['pn_filter'] - edge = module.params['pn_edge'] - bpdu_guard = module.params['pn_bpdu_guard'] - port = module.params['pn_port'] - block = module.params['pn_block'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'stp-port-modify': - cli += ' %s ' % command - if priority and (int(priority) % 16 == 0 and int(priority) < 240): - cli += ' priority ' + priority - else: - module.fail_json( - failed=True, - msg='Priority must be increment of 16 and should be less that 240' - ) - if cost and (int(cost) < 200000000): - cli += ' cost ' + cost - else: - module.fail_json( - failed=True, - msg='cost must be between 1 and 200000000' - ) - if port: - cli += ' port ' + port - - cli += booleanArgs(root_guard, 'root-guard', 'no-root-guard') - cli += booleanArgs(pn_filter, 'filter', 'no-filter') - cli += booleanArgs(edge, 'edge', 'no-edge') - cli += booleanArgs(bpdu_guard, 'bpdu-guard', 'no-bpdu-guard') - cli += booleanArgs(block, 'block', 'no-block') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_switch_setup.py b/lib/ansible/modules/network/netvisor/pn_switch_setup.py deleted file mode 100644 index 4d9f4aec5d..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_switch_setup.py +++ /dev/null @@ -1,413 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_switch_setup -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify switch-setup -description: - - This module can be used to modify switch setup. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(update) to modify the switch-setup. - required: true - type: str - choices: ['update'] - pn_force: - description: - - Force analytics-store change even if it involves removing data. - required: false - type: bool - pn_dns_ip: - description: - - DNS IP address. - required: false - type: str - pn_mgmt_netmask: - description: - - Netmask. - required: false - type: str - pn_gateway_ip6: - description: - - Gateway IPv6 address. - required: false - type: str - pn_in_band_ip6_assign: - description: - - Data IPv6 address assignment. - required: false - type: str - choices: ['none', 'autoconf'] - pn_domain_name: - description: - - Domain name. - required: false - type: str - pn_timezone: - description: - - Timezone to be configured. - required: false - type: str - pn_in_band_netmask: - description: - - Data in-band netmask. - required: false - type: str - pn_in_band_ip6: - description: - - Data in-band IPv6 address. - required: false - type: str - pn_in_band_netmask_ip6: - description: - - Data in-band IPv6 netmask. - required: false - type: str - pn_motd: - description: - - Message of the Day. - required: false - type: str - pn_loopback_ip6: - description: - - loopback IPv6 address. - required: false - type: str - pn_mgmt_ip6_assignment: - description: - - IPv6 address assignment. - required: false - choices: ['none', 'autoconf'] - pn_ntp_secondary_server: - description: - - Secondary NTP server. - required: false - type: str - pn_in_band_ip: - description: - - data in-band IP address. - required: false - type: str - pn_eula_accepted: - description: - - Accept EULA. - required: false - type: str - choices: ['true', 'false'] - pn_mgmt_ip: - description: - - Management IP address. - required: false - type: str - pn_ntp_server: - description: - - NTP server. - required: false - type: str - pn_mgmt_ip_assignment: - description: - - IP address assignment. - required: false - type: str - choices: ['none', 'dhcp'] - pn_date: - description: - - Date. - required: false - type: str - pn_password: - description: - - plain text password. - required: false - type: str - pn_banner: - description: - - Banner to display on server-switch. - required: false - type: str - pn_loopback_ip: - description: - - loopback IPv4 address. - required: false - type: str - pn_dns_secondary_ip: - description: - - secondary DNS IP address. - required: false - type: str - pn_switch_name: - description: - - switch name. - required: false - type: str - pn_eula_timestamp: - description: - - EULA timestamp. - required: false - type: str - pn_mgmt_netmask_ip6: - description: - - IPv6 netmask. - required: false - type: str - pn_enable_host_ports: - description: - - Enable host ports by default. - required: false - type: bool - pn_mgmt_ip6: - description: - - IPv6 address. - required: false - type: str - pn_analytics_store: - description: - - type of disk storage for analytics. - required: false - type: str - choices: ['default', 'optimized'] - pn_gateway_ip: - description: - - gateway IPv4 address. - required: false - type: str -""" - -EXAMPLES = """ -- name: Modify switch - pn_switch_setup: - pn_cliswitch: "sw01" - state: "update" - pn_timezone: "America/New_York" - pn_in_band_ip: "20.20.1.1" - pn_in_band_netmask: "24" - -- name: Modify switch - pn_switch_setup: - pn_cliswitch: "sw01" - state: "update" - pn_in_band_ip6: "2001:0db8:85a3::8a2e:0370:7334" - pn_in_band_netmask_ip6: "127" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the switch-setup command. - returned: always - type: list -stderr: - description: set of error responses from the switch-setup command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, booleanArgs, run_cli - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='switch-setup-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=['update']), - pn_force=dict(required=False, type='bool'), - pn_dns_ip=dict(required=False, type='str'), - pn_mgmt_netmask=dict(required=False, type='str'), - pn_gateway_ip6=dict(required=False, type='str'), - pn_in_band_ip6_assign=dict(required=False, type='str', - choices=['none', 'autoconf']), - pn_domain_name=dict(required=False, type='str'), - pn_timezone=dict(required=False, type='str'), - pn_in_band_netmask=dict(required=False, type='str'), - pn_in_band_ip6=dict(required=False, type='str'), - pn_in_band_netmask_ip6=dict(required=False, type='str'), - pn_motd=dict(required=False, type='str'), - pn_loopback_ip6=dict(required=False, type='str'), - pn_mgmt_ip6_assignment=dict(required=False, type='str', - choices=['none', 'autoconf']), - pn_ntp_secondary_server=dict(required=False, type='str'), - pn_in_band_ip=dict(required=False, type='str'), - pn_eula_accepted=dict(required=False, type='str', - choices=['true', 'false']), - pn_mgmt_ip=dict(required=False, type='str'), - pn_ntp_server=dict(required=False, type='str'), - pn_mgmt_ip_assignment=dict(required=False, type='str', - choices=['none', 'dhcp']), - pn_date=dict(required=False, type='str'), - pn_password=dict(required=False, type='str', no_log=True), - pn_banner=dict(required=False, type='str'), - pn_loopback_ip=dict(required=False, type='str'), - pn_dns_secondary_ip=dict(required=False, type='str'), - pn_switch_name=dict(required=False, type='str'), - pn_eula_timestamp=dict(required=False, type='str'), - pn_mgmt_netmask_ip6=dict(required=False, type='str'), - pn_enable_host_ports=dict(required=False, type='bool'), - pn_mgmt_ip6=dict(required=False, type='str'), - pn_analytics_store=dict(required=False, type='str', - choices=['default', 'optimized']), - pn_gateway_ip=dict(required=False, type='str'), - ), - required_one_of=[['pn_force', 'pn_dns_ip', 'pn_mgmt_netmask', - 'pn_gateway_ip6', 'pn_in_band_ip6_assign', - 'pn_domain_name', 'pn_timezone', - 'pn_in_band_netmask', 'pn_in_band_ip6', - 'pn_in_band_netmask_ip6', 'pn_motd', - 'pn_loopback_ip6', 'pn_mgmt_ip6_assignment', - 'pn_ntp_secondary_server', 'pn_in_band_ip', - 'pn_eula_accepted', 'pn_mgmt_ip', - 'pn_ntp_server', 'pn_mgmt_ip_assignment', - 'pn_date', 'pn_password', - 'pn_banner', 'pn_loopback_ip', - 'pn_dns_secondary_ip', 'pn_switch_name', - 'pn_eula_timestamp', 'pn_mgmt_netmask_ip6', - 'pn_enable_host_ports', 'pn_mgmt_ip6', - 'pn_analytics_store', 'pn_gateway_ip']], - required_together=[['pn_in_band_ip6', 'pn_in_band_netmask_ip6'], - ['pn_in_band_ip', 'pn_in_band_netmask'], - ['pn_mgmt_ip', 'pn_mgmt_netmask'], - ['pn_mgmt_ip6', 'pn_mgmt_netmask_ip6']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - force = module.params['pn_force'] - dns_ip = module.params['pn_dns_ip'] - mgmt_netmask = module.params['pn_mgmt_netmask'] - gateway_ip6 = module.params['pn_gateway_ip6'] - in_band_ip6_assign = module.params['pn_in_band_ip6_assign'] - domain_name = module.params['pn_domain_name'] - timezone = module.params['pn_timezone'] - in_band_netmask = module.params['pn_in_band_netmask'] - in_band_ip6 = module.params['pn_in_band_ip6'] - in_band_netmask_ip6 = module.params['pn_in_band_netmask_ip6'] - motd = module.params['pn_motd'] - loopback_ip6 = module.params['pn_loopback_ip6'] - mgmt_ip6_assignment = module.params['pn_mgmt_ip6_assignment'] - ntp_secondary_server = module.params['pn_ntp_secondary_server'] - in_band_ip = module.params['pn_in_band_ip'] - eula_accepted = module.params['pn_eula_accepted'] - mgmt_ip = module.params['pn_mgmt_ip'] - ntp_server = module.params['pn_ntp_server'] - mgmt_ip_assignment = module.params['pn_mgmt_ip_assignment'] - date = module.params['pn_date'] - password = module.params['pn_password'] - banner = module.params['pn_banner'] - loopback_ip = module.params['pn_loopback_ip'] - dns_secondary_ip = module.params['pn_dns_secondary_ip'] - switch_name = module.params['pn_switch_name'] - eula_timestamp = module.params['pn_eula_timestamp'] - mgmt_netmask_ip6 = module.params['pn_mgmt_netmask_ip6'] - enable_host_ports = module.params['pn_enable_host_ports'] - mgmt_ip6 = module.params['pn_mgmt_ip6'] - analytics_store = module.params['pn_analytics_store'] - gateway_ip = module.params['pn_gateway_ip'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'switch-setup-modify': - cli += ' %s ' % command - if dns_ip: - cli += ' dns-ip ' + dns_ip - if mgmt_netmask: - cli += ' mgmt-netmask ' + mgmt_netmask - if gateway_ip6: - cli += ' gateway-ip6 ' + gateway_ip6 - if in_band_ip6_assign: - cli += ' in-band-ip6-assign ' + in_band_ip6_assign - if domain_name: - cli += ' domain-name ' + domain_name - if timezone: - cli += ' timezone ' + timezone - if in_band_netmask: - cli += ' in-band-netmask ' + in_band_netmask - if in_band_ip6: - cli += ' in-band-ip6 ' + in_band_ip6 - if in_band_netmask_ip6: - cli += ' in-band-netmask-ip6 ' + in_band_netmask_ip6 - if motd: - cli += ' motd ' + motd - if loopback_ip6: - cli += ' loopback-ip6 ' + loopback_ip6 - if mgmt_ip6_assignment: - cli += ' mgmt-ip6-assignment ' + mgmt_ip6_assignment - if ntp_secondary_server: - cli += ' ntp-secondary-server ' + ntp_secondary_server - if in_band_ip: - cli += ' in-band-ip ' + in_band_ip - if eula_accepted: - cli += ' eula-accepted ' + eula_accepted - if mgmt_ip: - cli += ' mgmt-ip ' + mgmt_ip - if ntp_server: - cli += ' ntp-server ' + ntp_server - if mgmt_ip_assignment: - cli += ' mgmt-ip-assignment ' + mgmt_ip_assignment - if date: - cli += ' date ' + date - if password: - cli += ' password ' + password - if banner: - cli += ' banner ' + banner - if loopback_ip: - cli += ' loopback-ip ' + loopback_ip - if dns_secondary_ip: - cli += ' dns-secondary-ip ' + dns_secondary_ip - if switch_name: - cli += ' switch-name ' + switch_name - if eula_timestamp: - cli += ' eula_timestamp ' + eula_timestamp - if mgmt_netmask_ip6: - cli += ' mgmt-netmask-ip6 ' + mgmt_netmask_ip6 - if mgmt_ip6: - cli += ' mgmt-ip6 ' + mgmt_ip6 - if analytics_store: - cli += ' analytics-store ' + analytics_store - if gateway_ip: - cli += ' gateway-ip ' + gateway_ip - - cli += booleanArgs(force, 'force', 'no-force') - cli += booleanArgs(enable_host_ports, 'enable-host-ports', 'disable-host-ports') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_user.py b/lib/ansible/modules/network/netvisor/pn_user.py deleted file mode 100644 index 53d7ac971d..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_user.py +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_user -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to create/modify/delete user -description: - - This module can be used to create a user and apply a role, - update a user and delete a user. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - type: str - required: false - state: - description: - - State the action to perform. Use C(present) to create user and - C(absent) to delete user C(update) to update user. - type: str - required: true - choices: ['present', 'absent', 'update'] - pn_scope: - description: - - local or fabric. - type: str - choices: ['local', 'fabric'] - pn_initial_role: - description: - - initial role for user. - type: str - pn_password: - description: - - plain text password. - type: str - pn_name: - description: - - username. - type: str -""" - -EXAMPLES = """ -- name: Create user - pn_user: - pn_cliswitch: "sw01" - state: "present" - pn_scope: "fabric" - pn_password: "foo123" - pn_name: "foo" - -- name: Delete user - pn_user: - pn_cliswitch: "sw01" - state: "absent" - pn_name: "foo" - -- name: Modify user - pn_user: - pn_cliswitch: "sw01" - state: "update" - pn_password: "test1234" - pn_name: "foo" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the user command. - returned: always - type: list -stderr: - description: set of error responses from the user command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the user-show command. - If a user already exists on the given switch, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli += ' user-show format name no-show-headers' - out = run_commands(module, cli)[1] - - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='user-create', - absent='user-delete', - update='user-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_scope=dict(required=False, type='str', - choices=['local', 'fabric']), - pn_initial_role=dict(required=False, type='str'), - pn_password=dict(required=False, type='str', no_log=True), - pn_name=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_name", "pn_scope"]], - ["state", "absent", ["pn_name"]], - ["state", "update", ["pn_name", "pn_password"]] - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - scope = module.params['pn_scope'] - initial_role = module.params['pn_initial_role'] - password = module.params['pn_password'] - name = module.params['pn_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - USER_EXISTS = check_cli(module, cli) - cli += ' %s name %s ' % (command, name) - - if command == 'user-modify': - if USER_EXISTS is False: - module.fail_json( - failed=True, - msg='User with name %s does not exist' % name - ) - if initial_role or scope: - module.fail_json( - failed=True, - msg='Only password can be modified' - ) - - if command == 'user-delete': - if USER_EXISTS is False: - module.exit_json( - skipped=True, - msg='user with name %s does not exist' % name - ) - - if command == 'user-create': - if USER_EXISTS is True: - module.exit_json( - skipped=True, - msg='User with name %s already exists' % name - ) - if scope: - cli += ' scope ' + scope - - if initial_role: - cli += ' initial-role ' + initial_role - - if command != 'user-delete': - if password: - cli += ' password ' + password - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vflow_table_profile.py b/lib/ansible/modules/network/netvisor/pn_vflow_table_profile.py deleted file mode 100644 index eec65d5702..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vflow_table_profile.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vflow_table_profile -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify vflow-table-profile -description: - - This module can be used to modify a vFlow table profile. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(update) to modify - the vflow-table-profile. - required: true - type: str - choices: ['update'] - pn_profile: - description: - - type of vFlow profile. - required: false - type: str - choices: ['application', 'ipv6', 'qos'] - pn_hw_tbl: - description: - - hardware table used by vFlow. - required: false - type: str - choices: ['switch-main', 'switch-hash', 'npu-main', 'npu-hash'] - pn_enable: - description: - - enable or disable vflow profile table. - required: false - type: bool -""" - -EXAMPLES = """ -- name: Modify vflow table profile - pn_vflow_table_profile: - pn_cliswitch: 'sw01' - state: 'update' - pn_profile: 'ipv6' - pn_hw_tbl: 'switch-main' - pn_enable: true - -- name: Modify vflow table profile - pn_vflow_table_profile: - state: 'update' - pn_profile: 'qos' - pn_hw_tbl: 'switch-main' - pn_enable: false -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vflow-table-profile command. - returned: always - type: list -stderr: - description: set of error responses from the vflow-table-profile command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='vflow-table-profile-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_profile=dict(required=False, type='str', - choices=['application', 'ipv6', 'qos']), - pn_hw_tbl=dict(required=False, type='str', - choices=['switch-main', 'switch-hash', - 'npu-main', 'npu-hash']), - pn_enable=dict(required=False, type='bool'), - ), - required_if=( - ['state', 'update', ['pn_profile', 'pn_hw_tbl']], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - profile = module.params['pn_profile'] - hw_tbl = module.params['pn_hw_tbl'] - enable = module.params['pn_enable'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'vflow-table-profile-modify': - cli += ' %s ' % command - if profile: - cli += ' profile ' + profile - if hw_tbl: - cli += ' hw-tbl ' + hw_tbl - - cli += booleanArgs(enable, 'enable', 'disable') - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_bgp.py b/lib/ansible/modules/network/netvisor/pn_vrouter_bgp.py deleted file mode 100644 index 21f6d68f17..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_bgp.py +++ /dev/null @@ -1,473 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_bgp -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to add/modify/remove vrouter-bgp -description: - - This module can be used to add Border Gateway Protocol neighbor to a vRouter - modify Border Gateway Protocol neighbor to a vRouter and remove Border Gateway Protocol - neighbor from a vRouter. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - vrouter-bgp configuration command. - required: false - type: str - choices: ['present', 'absent', 'update'] - default: 'present' - pn_neighbor: - description: - - IP address for BGP neighbor. - required: true - type: str - pn_vrouter_name: - description: - - name of service config. - required: true - type: str - pn_send_community: - description: - - send any community attribute to neighbor. - required: false - type: bool - pn_weight: - description: - - default weight value between 0 and 65535 for the neighbor's routes. - required: false - pn_multi_protocol: - description: - - Multi-protocol features. - required: false - choices: ['ipv4-unicast', 'ipv6-unicast'] - pn_prefix_list_in: - description: - - prefixes used for filtering. - required: false - type: str - pn_route_reflector_client: - description: - - set as route reflector client. - required: false - type: bool - pn_default_originate: - description: - - announce default routes to the neighbor or not. - required: false - type: bool - pn_neighbor_holdtime: - description: - - BGP Holdtime (seconds). - required: false - type: str - pn_connect_retry_interval: - description: - - BGP Connect retry interval (seconds). - required: false - type: str - pn_advertisement_interval: - description: - - Minimum interval between sending BGP routing updates. - required: false - type: str - pn_route_map_out: - description: - - route map out for nbr. - required: false - type: str - pn_update_source: - description: - - IP address of BGP packets required for peering over loopback interface. - required: false - type: str - pn_bfd: - description: - - BFD protocol support for fault detection. - required: false - type: bool - default: False - pn_next_hop_self: - description: - - BGP next hop is self or not. - required: false - type: bool - pn_allowas_in: - description: - - Allow/reject routes with local AS in AS_PATH. - required: false - type: bool - pn_neighbor_keepalive_interval: - description: - - BGP Keepalive interval (seconds). - required: false - type: str - pn_max_prefix: - description: - - maximum number of prefixes. - required: false - type: str - pn_bfd_multihop: - description: - - always use BFD multi-hop port for fault detection. - required: false - type: bool - pn_interface: - description: - - Interface to reach the neighbor. - required: false - type: str - pn_password: - description: - - password for MD5 BGP. - required: false - type: str - pn_route_map_in: - description: - - route map in for nbr. - required: false - type: str - pn_soft_reconfig_inbound: - description: - - soft reset to reconfigure inbound traffic. - required: false - type: bool - pn_override_capability: - description: - - override capability. - required: false - type: bool - pn_max_prefix_warn_only: - description: - - warn if the maximum number of prefixes is exceeded. - required: false - type: bool - pn_ebgp_multihop: - description: - - value for external BGP from 1 to 255. - required: false - type: str - pn_remote_as: - description: - - BGP remote AS from 1 to 4294967295. - required: false - type: str - pn_prefix_list_out: - description: - - prefixes used for filtering outgoing packets. - required: false - type: str - pn_no_route_map_out: - description: - - Remove egress route-map from BGP neighbor. - required: false - type: str - pn_no_route_map_in: - description: - - Remove ingress route-map from BGP neighbor. - required: false - type: str -""" - -EXAMPLES = """ -- name: "Add BGP to vRouter" - pn_vrouter_bgp: - state: 'present' - pn_vrouter_name: 'sw01-vrouter' - pn_neighbor: '105.104.104.1' - pn_remote_as: 65000 - pn_bfd: true - -- name: "Remove BGP to vRouter" - pn_vrouter_bgp: - state: 'absent' - pn_vrouter_name: 'sw01-vrouter' - pn_neighbor: '105.104.104.1' - -- name: "Modify BGP to vRouter" - pn_vrouter_bgp: - state: 'update' - pn_vrouter_name: 'sw01-vrouter' - pn_neighbor: '105.104.104.1' - pn_remote_as: 65000 - pn_bfd: false - pn_allowas_in: true -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-bgp command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-bgp command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli, booleanArgs -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def is_valid(module, param_name, param_val, min_val, max_val): - if int(param_val) < min_val or int(param_val) > max_val: - module.fail_json( - failed=True, - msg='Valid %s range is %s to %s' % (param_name, min_val, max_val) - ) - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-bgp-show command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - If the given neighbor exists on the given vRouter, return NEIGHBOR_EXISTS as True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Booleans: VROUTER_EXISTS, NEIGHBOR_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - neighbor = module.params['pn_neighbor'] - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers' - out = run_commands(module, check_vrouter)[1] - if out: - out = out.split() - - VROUTER_EXISTS = True if vrouter_name in out else False - - if neighbor: - # Check for BGP neighbor - show = cli + ' vrouter-bgp-show vrouter-name %s ' % vrouter_name - show += 'format neighbor no-show-headers' - out = run_commands(module, show)[1] - - if out and neighbor in out.split(): - NEIGHBOR_EXISTS = True - else: - NEIGHBOR_EXISTS = False - - return VROUTER_EXISTS, NEIGHBOR_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-bgp-add', - absent='vrouter-bgp-remove', - update='vrouter-bgp-modify' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_neighbor=dict(required=True, type='str'), - pn_vrouter_name=dict(required=True, type='str'), - pn_send_community=dict(required=False, type='bool'), - pn_weight=dict(required=False, type='str'), - pn_multi_protocol=dict(required=False, type='str', choices=['ipv4-unicast', 'ipv6-unicast']), - pn_prefix_list_in=dict(required=False, type='str'), - pn_route_reflector_client=dict(required=False, type='bool'), - pn_default_originate=dict(required=False, type='bool'), - pn_neighbor_holdtime=dict(required=False, type='str'), - pn_connect_retry_interval=dict(required=False, type='str'), - pn_advertisement_interval=dict(required=False, type='str'), - pn_route_map_out=dict(required=False, type='str'), - pn_update_source=dict(required=False, type='str'), - pn_bfd=dict(required=False, type='bool', default=False), - pn_next_hop_self=dict(required=False, type='bool'), - pn_allowas_in=dict(required=False, type='bool'), - pn_neighbor_keepalive_interval=dict(required=False, type='str'), - pn_max_prefix=dict(required=False, type='str'), - pn_bfd_multihop=dict(required=False, type='bool'), - pn_interface=dict(required=False, type='str'), - pn_password=dict(required=False, type='str', no_log=True), - pn_route_map_in=dict(required=False, type='str'), - pn_soft_reconfig_inbound=dict(required=False, type='bool'), - pn_override_capability=dict(required=False, type='bool'), - pn_max_prefix_warn_only=dict(required=False, type='bool'), - pn_ebgp_multihop=dict(required=False, type='str'), - pn_remote_as=dict(required=False, type='str'), - pn_prefix_list_out=dict(required=False, type='str'), - pn_no_route_map_out=dict(required=False, type='str'), - pn_no_route_map_in=dict(required=False, type='str'), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ["pn_vrouter_name", "pn_neighbor", "pn_remote_as"]], - ["state", "absent", ["pn_vrouter_name", "pn_neighbor"]], - ["state", "update", ["pn_vrouter_name", "pn_neighbor"]] - ), - required_one_of=[['pn_send_community', 'pn_weight', 'pn_multi_protocol', - 'pn_prefix_list_in', 'pn_route_reflector_client', 'pn_default_originate', - 'pn_neighbor_holdtime', 'pn_connect_retry_interval', 'pn_advertisement_interval', - 'pn_route_map_out', 'pn_update_source', 'pn_bfd', - 'pn_next_hop_self', 'pn_allowas_in', 'pn_neighbor_keepalive_interval', - 'pn_max_prefix', 'pn_bfd_multihop', 'pn_interface', - 'pn_password', 'pn_route_map_in', 'pn_soft_reconfig_inbound', - 'pn_override_capability', 'pn_max_prefix_warn_only', 'pn_ebgp_multihop', - 'pn_remote_as', 'pn_prefix_list_out', 'pn_no_route_map_out', - 'pn_no_route_map_in']], - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - neighbor = module.params['pn_neighbor'] - vrouter_name = module.params['pn_vrouter_name'] - send_community = module.params['pn_send_community'] - weight = module.params['pn_weight'] - multi_protocol = module.params['pn_multi_protocol'] - prefix_list_in = module.params['pn_prefix_list_in'] - route_reflector_client = module.params['pn_route_reflector_client'] - default_originate = module.params['pn_default_originate'] - neighbor_holdtime = module.params['pn_neighbor_holdtime'] - connect_retry_interval = module.params['pn_connect_retry_interval'] - advertisement_interval = module.params['pn_advertisement_interval'] - route_map_out = module.params['pn_route_map_out'] - update_source = module.params['pn_update_source'] - bfd = module.params['pn_bfd'] - next_hop_self = module.params['pn_next_hop_self'] - allowas_in = module.params['pn_allowas_in'] - neighbor_keepalive_interval = module.params['pn_neighbor_keepalive_interval'] - max_prefix = module.params['pn_max_prefix'] - bfd_multihop = module.params['pn_bfd_multihop'] - interface = module.params['pn_interface'] - password = module.params['pn_password'] - route_map_in = module.params['pn_route_map_in'] - soft_reconfig_inbound = module.params['pn_soft_reconfig_inbound'] - override_capability = module.params['pn_override_capability'] - max_prefix_warn_only = module.params['pn_max_prefix_warn_only'] - ebgp_multihop = module.params['pn_ebgp_multihop'] - remote_as = module.params['pn_remote_as'] - prefix_list_out = module.params['pn_prefix_list_out'] - no_route_map_out = module.params['pn_no_route_map_out'] - no_route_map_in = module.params['pn_no_route_map_in'] - - command = state_map[state] - - if weight and weight != 'none': - if int(weight) < 1 or int(weight) > 65535: - module.fail_json( - failed=True, - msg='Valid weight range is 1 to 65535' - ) - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - VROUTER_EXISTS, NEIGHBOR_EXISTS = check_cli(module, cli) - - if state: - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - - if command == 'vrouter-bgp-remove' or command == 'vrouter-bgp-modify': - if NEIGHBOR_EXISTS is False: - module.exit_json( - skipped=True, - msg='BGP neighbor with IP %s does not exist on %s' % (neighbor, vrouter_name) - ) - - if command == 'vrouter-bgp-add': - if NEIGHBOR_EXISTS is True: - module.exit_json( - skipped=True, - msg='BGP neighbor with IP %s already exists on %s' % (neighbor, vrouter_name) - ) - - cli += ' %s vrouter-name %s neighbor %s ' % (command, vrouter_name, neighbor) - - if command == 'vrouter-bgp-add' or command == 'vrouter-bgp-modify': - if weight: - cli += ' weight ' + weight - if multi_protocol: - cli += ' multi-protocol ' + multi_protocol - if prefix_list_in: - cli += ' prefix-list-in ' + prefix_list_in - if neighbor_holdtime: - is_valid(module, 'neighbor holdtime', neighbor_holdtime, '0', '65535') - cli += ' neighbor-holdtime ' + neighbor_holdtime - if connect_retry_interval: - is_valid(module, 'connect retry interval', connect_retry_interval, '0', '65535') - cli += ' connect-retry-interval ' + connect_retry_interval - if advertisement_interval: - is_valid(module, 'advertisement interval', advertisement_interval, '0', '65535') - cli += ' advertisement-interval ' + advertisement_interval - if route_map_out: - cli += ' route-map-out ' + route_map_out - if update_source: - cli += ' update-source ' + update_source - if neighbor_keepalive_interval: - is_valid(module, 'neighbor keepalive interval', neighbor_keepalive_interval, '0', '65535') - cli += ' neighbor-keepalive-interval ' + neighbor_keepalive_interval - if max_prefix: - cli += ' max-prefix ' + max_prefix - if interface: - cli += ' interface ' + interface - if password: - cli += ' password ' + password - if route_map_in: - cli += ' route-map-in ' + route_map_in - if ebgp_multihop: - is_valid(module, 'ebgp_multihop', ebgp_multihop, '1', '255') - cli += ' ebgp-multihop ' + ebgp_multihop - if remote_as: - cli += ' remote-as ' + remote_as - if prefix_list_out: - cli += ' prefix-list-out ' + prefix_list_out - cli += booleanArgs(send_community, 'send-community', 'no-send-community') - cli += booleanArgs(route_reflector_client, 'route-reflector-client', 'no-route-reflector-client') - cli += booleanArgs(default_originate, 'default-originate', 'no-default-originate') - cli += booleanArgs(bfd, 'bfd', 'no-bfd') - cli += booleanArgs(next_hop_self, 'next-hop-self', 'no-next-hop-self') - cli += booleanArgs(allowas_in, 'allowas-in', 'no-allowas-in') - cli += booleanArgs(bfd_multihop, 'bfd-multihop', 'no-bfd-multihop') - cli += booleanArgs(soft_reconfig_inbound, 'soft-reconfig-inbound', 'no-soft-reconfig-inbound') - cli += booleanArgs(override_capability, 'override-capability', 'no-override-capability') - cli += booleanArgs(max_prefix_warn_only, 'max-prefix-warn-only', 'no-max-prefix-warn-only') - - if command == 'vrouter-bgp-modify': - if no_route_map_out: - cli += ' no-route-map-out ' + no_route_map_out - if no_route_map_in: - cli += ' no-route-map-in ' + no_route_map_in - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_bgp_network.py b/lib/ansible/modules/network/netvisor/pn_vrouter_bgp_network.py deleted file mode 100644 index c2bb804e34..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_bgp_network.py +++ /dev/null @@ -1,187 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_bgp_network -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to add/remove vrouter-bgp-network -description: - - This module can be used to add Border Gateway Protocol network to a vRouter - and remove Border Gateway Protocol network from a vRouter. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to add bgp network and - C(absent) to remove bgp network. - required: true - type: str - choices: ['present', 'absent'] - pn_netmask: - description: - - BGP network mask. - required: false - type: str - pn_network: - description: - - IP address for BGP network. - required: false - type: str - pn_vrouter_name: - description: - - name of service config. - required: false - type: str -""" - -EXAMPLES = """ -- name: Add network to bgp - pn_vrouter_bgp_network: - pn_cliswitch: "sw01" - state: "present" - pn_vrouter_name: "foo-vrouter" - pn_network: '10.10.10.10' - pn_netmask: '31' - -- name: Remove network from bgp - pn_vrouter_bgp_network: - pn_cliswitch: "sw01" - state: "absent" - pn_vrouter_name: "foo-vrouter" - pn_network: '10.10.10.10' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-bgp-network command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-bgp-network command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for pim ssm config using the vrouter-show command. - If a user already exists on the given switch, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_vrouter_name'] - network = module.params['pn_network'] - - show = cli - cli += ' vrouter-show name %s format name no-show-headers' % name - rc, out, err = run_commands(module, cli) - VROUTER_EXISTS = '' if out else None - - cli = show - cli += ' vrouter-bgp-network-show vrouter-name %s network %s format network no-show-headers' % (name, network) - out = run_commands(module, cli)[1] - out = out.split() - NETWORK_EXISTS = True if network in out[-1] else False - - return NETWORK_EXISTS, VROUTER_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-bgp-network-add', - absent='vrouter-bgp-network-remove' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_netmask=dict(required=False, type='str'), - pn_network=dict(required=False, type='str'), - pn_vrouter_name=dict(required=False, type='str'), - ), - required_if=( - ['state', 'present', ['pn_vrouter_name', 'pn_netmask', 'pn_network']], - ['state', 'absent', ['pn_vrouter_name', 'pn_network']], - ), - ) - - # Accessing the arguments - state = module.params['state'] - cliswitch = module.params['pn_cliswitch'] - netmask = module.params['pn_netmask'] - network = module.params['pn_network'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NETWORK_EXISTS, VROUTER_EXISTS = check_cli(module, cli) - - if VROUTER_EXISTS is None: - module.fail_json( - failed=True, - msg='vRouter %s does not exists' % vrouter_name - ) - - if command == 'vrouter-bgp-network-add': - if NETWORK_EXISTS is True: - module.exit_json( - skipped=True, - msg='Network %s already added to bgp' % network - ) - - if command == 'vrouter-bgp-network-remove': - if NETWORK_EXISTS is False: - module.exit_json( - skipped=True, - msg='Network %s does not exists' % network - ) - - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - - if netmask: - cli += ' netmask ' + netmask - if network: - cli += ' network ' + network - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py b/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py deleted file mode 100644 index 0cfe81479c..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py +++ /dev/null @@ -1,253 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_interface_ip -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to add/remove vrouter-interface-ip -description: - - This module can be used to add an IP address on interface from a vRouter - or remove an IP address on interface from a vRouter. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to addvrouter-interface-ip - and C(absent) to remove vrouter-interface-ip. - required: true - type: str - choices: ['present', 'absent'] - pn_bd: - description: - - interface Bridge Domain. - required: false - type: str - pn_netmask: - description: - - netmask. - required: false - type: str - pn_vnet: - description: - - interface VLAN VNET. - required: false - type: str - pn_ip: - description: - - IP address. - required: false - type: str - pn_nic: - description: - - virtual NIC assigned to interface. - required: false - type: str - pn_vrouter_name: - description: - - name of service config. - required: false - type: str -""" - -EXAMPLES = """ -- name: Add vrouter interface to nic - pn_vrouter_interface_ip: - state: "present" - pn_cliswitch: "sw01" - pn_vrouter_name: "foo-vrouter" - pn_ip: "2620:0:1651:1::30" - pn_netmask: "127" - pn_nic: "eth0.4092" - -- name: Remove vrouter interface to nic - pn_vrouter_interface_ip: - state: "absent" - pn_cliswitch: "sw01" - pn_vrouter_name: "foo-vrouter" - pn_ip: "2620:0:1651:1::30" - pn_nic: "eth0.4092" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-interface-ip command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-interface-ip command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-interface-show - command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - - If an interface with the given ip exists on the given vRouter, - return INTERFACE_EXISTS as True else False. This is required for - vrouter-interface-add. - - If nic_str exists on the given vRouter, return NIC_EXISTS as True else - False. This is required for vrouter-interface-remove. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Booleans: VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - interface_ip = module.params['pn_ip'] - nic_str = module.params['pn_nic'] - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers' - out = run_commands(module, check_vrouter)[1] - if out: - out = out.split() - - VROUTER_EXISTS = True if vrouter_name in out else False - - if interface_ip: - # Check for interface and VRRP and fetch nic for VRRP - show = cli + ' vrouter-interface-show vrouter-name %s ' % vrouter_name - show += 'ip2 %s format ip2,nic no-show-headers' % interface_ip - out = run_commands(module, show)[1] - - if out and interface_ip in out.split(' ')[-2]: - INTERFACE_EXISTS = True - else: - INTERFACE_EXISTS = False - - if nic_str: - # Check for nic - show = cli + ' vrouter-interface-show vrouter-name %s ' % vrouter_name - show += 'format nic no-show-headers' - out = run_commands(module, show)[1] - - if out: - out = out.split() - - NIC_EXISTS = True if nic_str in out else False - - return VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-interface-ip-add', - absent='vrouter-interface-ip-remove' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_bd=dict(required=False, type='str'), - pn_netmask=dict(required=False, type='str'), - pn_vnet=dict(required=False, type='str'), - pn_ip=dict(required=False, type='str'), - pn_nic=dict(required=False, type='str'), - pn_vrouter_name=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_vrouter_name", "pn_nic", "pn_ip", "pn_netmask"]], - ["state", "absent", ["pn_vrouter_name", "pn_nic", "pn_ip"]] - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - bd = module.params['pn_bd'] - netmask = module.params['pn_netmask'] - vnet = module.params['pn_vnet'] - ip = module.params['pn_ip'] - nic = module.params['pn_nic'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS = check_cli(module, cli) - - if VROUTER_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter %s does not exist' % vrouter_name - ) - - if NIC_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter with nic %s does not exist' % nic - ) - - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - - if command == 'vrouter-interface-ip-add': - if INTERFACE_EXISTS is True: - module.exit_json( - skipped=True, - msg='vRouter with interface ip %s exist' % ip - ) - cli += ' nic %s ip %s ' % (nic, ip) - - if bd: - cli += ' bd ' + bd - if netmask: - cli += ' netmask ' + netmask - if vnet: - cli += ' vnet ' + vnet - - if command == 'vrouter-interface-ip-remove': - if INTERFACE_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter with interface ip %s does not exist' % ip - ) - if nic: - cli += ' nic %s ' % nic - if ip: - cli += ' ip %s ' % ip.split('/')[0] - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_loopback_interface.py b/lib/ansible/modules/network/netvisor/pn_vrouter_loopback_interface.py deleted file mode 100644 index bd2066ef54..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_loopback_interface.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_loopback_interface -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to add/remove vrouter-loopback-interface -description: - - This module can be used to add loopback interface to a vRouter or - remove loopback interface from a vRouter. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to add vrouter-loopback-interface - and C(absent) to remove vrouter-loopback-interface. - required: false - type: str - choices: ['present', 'absent'] - default: 'present' - pn_ip: - description: - - loopback IP address. - required: true - type: str - pn_index: - description: - - loopback index from 1 to 255. - required: false - type: str - pn_vrouter_name: - description: - - name of service config. - required: true - type: str -""" - -EXAMPLES = """ -- name: Add vrouter loopback interface - pn_vrouter_loopback_interface: - state: "present" - pn_cliswitch: "sw01" - pn_vrouter_name: "sw01-vrouter" - pn_ip: "192.168.10.1" - -- name: Remove vrouter loopback interface - pn_vrouter_loopback_interface: - state: "absent" - pn_cliswitch: "sw01" - pn_vrouter_name: "sw01-vrouter" - pn_ip: "192.168.10.1" - pn_index: "2" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-loopback-interface command. - returned: always - type: list -stderr: - description: set of error response from the vrouter-loopback-interface - command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-interface-show - command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Booleans: VROUTER_EXISTS, INTERFACE_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - interface_ip = module.params['pn_ip'] - - # Check for vRouter - check_vrouter = 'vrouter-show format name no-show-headers' - out = run_commands(module, check_vrouter)[1] - if out: - out = out.split() - - VROUTER_EXISTS = True if vrouter_name in out else False - - if interface_ip: - # Check for interface and VRRP and fetch nic for VRRP - show = cli + ' vrouter-loopback-interface-show ' - show += 'vrouter-name %s ' % vrouter_name - show += 'format ip no-show-headers' - out = run_commands(module, show)[1] - - if out and interface_ip in out.split(): - INTERFACE_EXISTS = True - else: - INTERFACE_EXISTS = False - - return VROUTER_EXISTS, INTERFACE_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-loopback-interface-add', - absent='vrouter-loopback-interface-remove' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', - choices=state_map.keys(), default='present'), - pn_ip=dict(required=True, type='str'), - pn_index=dict(required=False, type='str'), - pn_vrouter_name=dict(required=True, type='str'), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ["pn_vrouter_name", "pn_ip"]], - ["state", "absent", ["pn_vrouter_name", "pn_ip", "pn_index"]] - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - ip = module.params['pn_ip'] - index = module.params['pn_index'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - VROUTER_EXISTS, INTERFACE_EXISTS = check_cli(module, cli) - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - - if index and (int(index) < 1 or int(index) > 255): - module.fail_json( - failed=True, - msg='index should be in range 1 to 255' - ) - - if index and state == 'present': - show = 'vrouter-loopback-interface-show format index parsable-delim ,' - out = run_commands(module, show)[1] - if out: - out = out.split() - for res in out: - res = res.strip().split(',') - if index in res: - module.fail_json( - failed=True, - msg='index with value %s exist' % index - ) - - if command == 'vrouter-loopback-interface-add': - if VROUTER_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if INTERFACE_EXISTS is True: - module.exit_json( - skipped=True, - msg='vRouter with loopback ip %s exist' % ip - ) - if ip: - cli += ' ip ' + ip - if index: - cli += ' index ' + index - - if command == 'vrouter-loopback-interface-remove': - if VROUTER_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter %s does not exist' % vrouter_name - ) - if INTERFACE_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter with loopback ip %s doesnt exist' % ip - ) - - if index: - cli += ' index ' + index - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_ospf.py b/lib/ansible/modules/network/netvisor/pn_vrouter_ospf.py deleted file mode 100644 index 55a77b07f2..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_ospf.py +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_ospf -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to add/remove vrouter-ospf -description: - - This module can be used to add OSPF protocol to vRouter - and remove OSPF protocol from a vRouter -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - vrouter-ospf configuration command. - required: false - type: str - choices: ['present', 'absent'] - default: 'present' - pn_netmask: - description: - - OSPF network IP address netmask. - required: false - type: str - pn_ospf_area: - description: - - stub area number for the configuration. - required: false - type: str - pn_network: - description: - - OSPF network IP address. - required: true - type: str - pn_vrouter_name: - description: - - name of service config. - required: true - type: str -""" - -EXAMPLES = """ -- name: Add OSPF to vRouter - pn_vrouter_ospf: - state: 'present' - pn_vrouter_name: 'sw01-vrouter' - pn_network: '105.104.104.1' - pn_netmask: '24' - pn_ospf_area: '0' -- name: "Remove OSPF to vRouter" - pn_vrouter_ospf: - state: 'absent' - pn_vrouter_name: 'sw01-vrouter' - pn_network: '105.104.104.1' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-ospf command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-ospf command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the show command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - If an OSPF network with the given ip exists on the given vRouter, - return NETWORK_EXISTS as True else False. - - :param module: The Ansible module to fetch input parameters - :return Booleans: VROUTER_EXISTS, NETWORK_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - network = module.params['pn_network'] - show_cli = pn_cli(module) - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers ' - out = run_commands(module, check_vrouter)[1] - if out: - out = out.split() - - VROUTER_EXISTS = True if vrouter_name in out else False - - # Check for OSPF networks - check_network = cli + ' vrouter-ospf-show vrouter-name %s ' % vrouter_name - check_network += 'format network no-show-headers' - out = run_commands(module, check_network)[1] - - if out and network in out: - NETWORK_EXISTS = True - else: - NETWORK_EXISTS = False - - return VROUTER_EXISTS, NETWORK_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-ospf-add', - absent='vrouter-ospf-remove' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_netmask=dict(required=False, type='str'), - pn_ospf_area=dict(required=False, type='str'), - pn_network=dict(required=True, type='str'), - pn_vrouter_name=dict(required=True, type='str'), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ['pn_vrouter_name', 'pn_network', 'pn_netmask', 'pn_ospf_area']], - ["state", "absent", ['pn_vrouter_name', 'pn_network']], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - netmask = module.params['pn_netmask'] - ospf_area = module.params['pn_ospf_area'] - network = module.params['pn_network'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - VROUTER_EXISTS, NETWORK_EXISTS = check_cli(module, cli) - - if state: - if VROUTER_EXISTS is False: - module.exit_json( - skipped=True, - msg='vRouter %s does not exist' % vrouter_name - ) - - if command == 'vrouter-ospf-remove': - if NETWORK_EXISTS is False: - module.exit_json( - skipped=True, - msg='OSPF with network %s dose not exists' % network - ) - cli += ' %s vrouter-name %s network %s' % (command, vrouter_name, network) - - if command == 'vrouter-ospf-add': - if NETWORK_EXISTS is True: - module.exit_json( - skipped=True, - msg='OSPF with network %s already exists' % network - ) - if netmask: - cli += ' netmask ' + netmask - if ospf_area: - cli += ' ospf-area ' + ospf_area - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py b/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py deleted file mode 100644 index 7fbebb7cf0..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_ospf6 -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to add/remove vrouter-ospf6 -description: - - This module can be used to add interface ip to OSPF6 protocol - or remove interface ip from OSPF6 protocol on vRouter. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(present) to add vrouter-ospf6 and - C(absent) to remove interface from vrouter-ospf6. - required: true - type: str - choices: ['present', 'absent'] - pn_ospf6_area: - description: - - area id for this interface in IPv4 address format. - required: false - type: str - pn_nic: - description: - - OSPF6 control for this interface. - required: false - type: str - pn_vrouter_name: - description: - - name of service config. - required: false - type: str -""" - -EXAMPLES = """ -- name: Add vrouter interface nic to ospf6 - pn_vrouter_ospf6: - pn_cliswitch: "sw01" - state: "present" - pn_vrouter_name: "foo-vrouter" - pn_nic: "eth0.4092" - pn_ospf6_area: "0.0.0.0" - -- name: Remove vrouter interface nic to ospf6 - pn_vrouter_ospf6: - pn_cliswitch: "sw01" - state: "absent" - pn_vrouter_name: "foo-vrouter" - pn_nic: "eth0.4092" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-ospf6 command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-ospf6 command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-interface-show - command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - - If nic_str exists on the given vRouter, return NIC_EXISTS as True else - False. This is required for vrouter-ospf6-remove. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Booleans: VROUTER_EXISTS, NIC_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - nic_str = module.params['pn_nic'] - - # Check for vRouter - check_vrouter = cli + ' vrouter-show format name no-show-headers ' - out = run_commands(module, check_vrouter)[1] - if out: - out = out.split() - - VROUTER_EXISTS = True if vrouter_name in out else False - - if nic_str: - # Check for nic - show = cli + ' vrouter-ospf6-show vrouter-name %s format nic no-show-headers' % vrouter_name - out = run_commands(module, show)[1] - - if out: - out.split() - - NIC_EXISTS = True if nic_str in out else False - - return VROUTER_EXISTS, NIC_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-ospf6-add', - absent='vrouter-ospf6-remove' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_ospf6_area=dict(required=False, type='str'), - pn_nic=dict(required=False, type='str'), - pn_vrouter_name=dict(required=False, type='str'), - ), - required_if=( - ["state", "present", ["pn_vrouter_name", "pn_nic", - "pn_ospf6_area"]], - ["state", "absent", ["pn_vrouter_name", "pn_nic"]] - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - ospf6_area = module.params['pn_ospf6_area'] - nic = module.params['pn_nic'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - VROUTER_EXISTS, NIC_EXISTS = check_cli(module, cli) - - if VROUTER_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter %s does not exist' % vrouter_name - ) - - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - - if command == 'vrouter-ospf6-add': - if NIC_EXISTS is True: - module.exit_json( - skipped=True, - msg='OSPF6 with nic %s already exist' % nic - ) - if nic: - cli += ' nic %s' % nic - if ospf6_area: - cli += ' ospf6-area %s ' % ospf6_area - - if command == 'vrouter-ospf6-remove': - if NIC_EXISTS is False: - module.exit_json( - skipped=True, - msg='OSPF6 with nic %s does not exist' % nic - ) - if nic: - cli += ' nic %s' % nic - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_packet_relay.py b/lib/ansible/modules/network/netvisor/pn_vrouter_packet_relay.py deleted file mode 100644 index a4e6e960d1..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_packet_relay.py +++ /dev/null @@ -1,200 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_packet_relay -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to add/remove vrouter-packet-relay -description: - - This module can be used to add packet relay configuration for DHCP on vrouter - and remove packet relay configuration for DHCP on vrouter. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - vrouter-packet-relay configuration command. - required: false - choices: ['present', 'absent'] - type: str - default: 'present' - pn_forward_ip: - description: - - forwarding IP address. - required: true - type: str - pn_nic: - description: - - NIC. - required: true - type: str - pn_forward_proto: - description: - - protocol type to forward packets. - required: false - type: str - choices: ['dhcp'] - default: 'dhcp' - pn_vrouter_name: - description: - - name of service config. - required: true - type: str -""" - -EXAMPLES = """ -- name: vRouter packet relay add - pn_vrouter_packet_relay: - pn_cliswitch: "sw01" - pn_forward_ip: "192.168.10.1" - pn_nic: "eth0.4092" - pn_vrouter_name: "sw01-vrouter" - -- name: vRouter packet relay remove - pn_vrouter_packet_relay: - pn_cliswitch: "sw01" - state: "absent" - pn_forward_ip: "192.168.10.1" - pn_nic: "eth0.4092" - pn_vrouter_name: "sw01-vrouter" -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-packet-relay command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-packet-relay command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks if vRouter exists on the target node. - This method also checks for idempotency using the vrouter-interface-show - command. - If the given vRouter exists, return VROUTER_EXISTS as True else False. - - If nic_str exists on the given vRouter, return NIC_EXISTS as True else - False. - - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - :return Booleans: VROUTER_EXISTS, NIC_EXISTS - """ - vrouter_name = module.params['pn_vrouter_name'] - nic_str = module.params['pn_nic'] - - # Check for vRouter - check_vrouter = 'vrouter-show format name no-show-headers' - out = run_commands(module, check_vrouter)[1] - - if out: - out = out.split() - - VROUTER_EXISTS = True if vrouter_name in out else False - - if nic_str: - # Check for nic - show = 'vrouter-interface-show vrouter-name %s format nic no-show-headers' % vrouter_name - out = run_commands(module, show)[1] - if out: - out = out.split() - - NIC_EXISTS = True if nic_str in out else False - - return VROUTER_EXISTS, NIC_EXISTS - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vrouter-packet-relay-add', - absent='vrouter-packet-relay-remove' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_forward_ip=dict(required=True, type='str'), - pn_nic=dict(required=True, type='str'), - pn_forward_proto=dict(required=False, type='str', choices=['dhcp'], default='dhcp'), - pn_vrouter_name=dict(required=True, type='str'), - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ["pn_vrouter_name", "pn_forward_ip", "pn_nic", "pn_forward_proto"]], - ["state", "absent", ["pn_vrouter_name", "pn_forward_ip", "pn_nic", "pn_forward_proto"]], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - forward_ip = module.params['pn_forward_ip'] - nic = module.params['pn_nic'] - forward_proto = module.params['pn_forward_proto'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - VROUTER_EXISTS, NIC_EXISTS = check_cli(module, cli) - - if VROUTER_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter %s does not exist' % vrouter_name - ) - - if NIC_EXISTS is False: - module.fail_json( - failed=True, - msg='vRouter with nic %s does not exist' % nic - ) - - if command == 'vrouter-packet-relay-add' or command == 'vrouter-packet-relay-remove': - cli += ' %s' % command - cli += ' vrouter-name %s nic %s' % (vrouter_name, nic) - cli += ' forward-proto %s forward-ip %s' % (forward_proto, forward_ip) - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py b/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py deleted file mode 100644 index 0c93761e3f..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py +++ /dev/null @@ -1,175 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vrouter_pim_config -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.8" -short_description: CLI command to modify vrouter-pim-config -description: - - This module can be used to modify pim parameters. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - State the action to perform. Use C(update) to modify the vrouter-pim-config. - required: true - type: str - choices: ['update'] - pn_query_interval: - description: - - igmp query interval in seconds. - required: false - type: str - pn_querier_timeout: - description: - - igmp querier timeout in seconds. - required: false - type: str - pn_hello_interval: - description: - - hello interval in seconds. - required: false - type: str - pn_vrouter_name: - description: - - name of service config. - required: false - type: str -""" - -EXAMPLES = """ -- name: pim config modify - pn_vrouter_pim_config: - pn_cliswitch: '192.168.1.1' - pn_query_interval: '10' - pn_querier_timeout: '30' - state: 'update' - pn_vrouter_name: 'ansible-spine1-vrouter' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vrouter-pim-config command. - returned: always - type: list -stderr: - description: set of error responses from the vrouter-pim-config command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for pim ssm config using the vrouter-show command. - If a user already exists on the given switch, return True else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_vrouter_name'] - - show = cli - cli += ' vrouter-show format name no-show-headers ' - out = run_commands(module, cli)[1] - if out: - out = out.split() - if name in out: - pass - else: - return False - - cli = show - cli += ' vrouter-show name %s format proto-multi no-show-headers' % name - out = run_commands(module, cli)[1] - if out: - out = out.split() - - return True if 'none' not in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - update='vrouter-pim-config-modify' - ) - - module = AnsibleModule( - argument_spec=dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=True, type='str', - choices=state_map.keys()), - pn_query_interval=dict(required=False, type='str'), - pn_querier_timeout=dict(required=False, type='str'), - pn_hello_interval=dict(required=False, type='str'), - pn_vrouter_name=dict(required=True, type='str'), - ), - required_if=( - ['state', 'update', ['pn_vrouter_name']], - ), - required_one_of=[['pn_query_interval', - 'pn_querier_timeout', - 'pn_hello_interval']] - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - query_interval = module.params['pn_query_interval'] - querier_timeout = module.params['pn_querier_timeout'] - hello_interval = module.params['pn_hello_interval'] - vrouter_name = module.params['pn_vrouter_name'] - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - if command == 'vrouter-pim-config-modify': - PIM_SSM_CONFIG = check_cli(module, cli) - if PIM_SSM_CONFIG is False: - module.exit_json( - skipped=True, - msg='vrouter proto-multi is not configured/vrouter is not created' - ) - cli += ' %s vrouter-name %s ' % (command, vrouter_name) - if querier_timeout: - cli += ' querier-timeout ' + querier_timeout - if hello_interval: - cli += ' hello-interval ' + hello_interval - if query_interval: - cli += ' query-interval ' + query_interval - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/netvisor/pn_vtep.py b/lib/ansible/modules/network/netvisor/pn_vtep.py deleted file mode 100644 index d52ee55566..0000000000 --- a/lib/ansible/modules/network/netvisor/pn_vtep.py +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/python -# Copyright: (c) 2018, Pluribus Networks -# 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 - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = """ ---- -module: pn_vtep -author: "Pluribus Networks (@rajaspachipulusu17)" -version_added: "2.9" -short_description: CLI command to create/delete vtep -description: - - This module can be used to create a vtep and delete a vtep. -options: - pn_cliswitch: - description: - - Target switch to run the CLI on. - required: false - type: str - state: - description: - - vtep configuration command. - required: false - choices: ['present', 'absent'] - type: str - default: 'present' - pn_name: - description: - - vtep name. - required: false - type: str - pn_ip: - description: - - Primary IP address. - required: false - type: str - pn_vrouter_name: - description: - - name of the vrouter service. - required: false - type: str - pn_virtual_ip: - description: - - Virtual/Secondary IP address. - required: false - type: str - pn_location: - description: - - switch name. - required: false - type: str - pn_switch_in_cluster: - description: - - Tells whether switch in cluster or not. - required: false - type: bool - default: True -""" - -EXAMPLES = """ -- name: create vtep - pn_vtep: - pn_cliswitch: 'sw01' - pn_name: 'foo' - pn_vrouter_name: 'foo-vrouter' - pn_ip: '22.22.22.2' - pn_location: 'sw01' - pn_virtual_ip: "22.22.22.1" - -- name: delete vtep - pn_vtep: - pn_cliswitch: 'sw01' - state: 'absent' - pn_name: 'foo' -""" - -RETURN = """ -command: - description: the CLI command run on the target node. - returned: always - type: str -stdout: - description: set of responses from the vtep command. - returned: always - type: list -stderr: - description: set of error responses from the vtep command. - returned: on error - type: list -changed: - description: indicates whether the CLI caused changes on the target. - returned: always - type: bool -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.netvisor.pn_nvos import pn_cli, run_cli -from ansible.module_utils.network.netvisor.netvisor import run_commands - - -def check_cli(module, cli): - """ - This method checks for idempotency using the vtep-show command. - If a name exists, return True if name exists else False. - :param module: The Ansible module to fetch input parameters - :param cli: The CLI string - """ - name = module.params['pn_name'] - - cli += ' vtep-show format name no-show-headers' - out = run_commands(module, cli)[1] - - if out: - out = out.split() - - return True if name in out else False - - -def main(): - """ This section is for arguments parsing """ - - state_map = dict( - present='vtep-create', - absent='vtep-delete' - ) - - argument_spec = dict( - pn_cliswitch=dict(required=False, type='str'), - state=dict(required=False, type='str', choices=state_map.keys(), default='present'), - pn_name=dict(required=False, type='str'), - pn_ip=dict(required=False, type='str'), - pn_vrouter_name=dict(required=False, type='str'), - pn_virtual_ip=dict(required=False, type='str'), - pn_location=dict(required=False, type='str'), - pn_switch_in_cluster=dict(required=False, type='bool', default='True') - ) - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=( - ["state", "present", ["pn_name", "pn_ip", "pn_vrouter_name", "pn_location"]], - ["state", "absent", ["pn_name"]], - ), - ) - - # Accessing the arguments - cliswitch = module.params['pn_cliswitch'] - state = module.params['state'] - name = module.params['pn_name'] - ip = module.params['pn_ip'] - vrouter_name = module.params['pn_vrouter_name'] - virtual_ip = module.params['pn_virtual_ip'] - location = module.params['pn_location'] - switch_in_cluster = module.params['pn_switch_in_cluster'] - - if switch_in_cluster and not virtual_ip and state == 'present': - module.exit_json( - failed=True, - msg='virtual ip is required when switch is in cluster' - ) - - command = state_map[state] - - # Building the CLI command string - cli = pn_cli(module, cliswitch) - - NAME_EXISTS = check_cli(module, cli) - - cli += ' %s name %s ' % (command, name) - - if command == 'vtep-delete': - if NAME_EXISTS is False: - module.exit_json( - skipped=True, - msg='vtep with name %s does not exist' % name - ) - - if command == 'vtep-create': - if NAME_EXISTS is True: - module.exit_json( - skipped=True, - msg='vtpe with name %s already exists' % name - ) - - cli += 'vrouter-name %s ' % vrouter_name - cli += 'ip %s ' % ip - cli += 'location %s ' % location - - if virtual_ip: - cli += 'virtual-ip %s ' % virtual_ip - - run_cli(module, cli, state_map) - - -if __name__ == '__main__': - main() |