mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 04:34:24 -07:00
Lenovo port to persistence 1 (#43194)
* CNOS Vlag module is refactored to use persistence connection instead of paramiko. * Changing interface and port channel modules to persistent connection and adding UT for them. * Fixing pep8 issues * Removing trailing new line * Removing trailing new line * Removing trailing new line * Correcting indentation mistake * Update cnos_vlag.py * Removing commented examples They are commented because those configurations are not meant for L2 ports
This commit is contained in:
parent
e24041449e
commit
f2c9a6b126
11 changed files with 540 additions and 334 deletions
|
@ -57,7 +57,7 @@ extends_documentation_fragment: cnos
|
|||
options:
|
||||
interfaceRange:
|
||||
description:
|
||||
- This specifies the interface range in which the port aggregation is envisaged
|
||||
- This specifies the interface range in which the port channel is envisaged
|
||||
required: Yes
|
||||
default: Null
|
||||
interfaceOption:
|
||||
|
@ -65,21 +65,21 @@ options:
|
|||
- This specifies the attribute you specify subsequent to interface command
|
||||
required: Yes
|
||||
default: Null
|
||||
choices: [None, ethernet, loopback, mgmt, port-aggregation, vlan]
|
||||
choices: [None, ethernet, loopback, mgmt, port-channel, vlan]
|
||||
interfaceArg1:
|
||||
description:
|
||||
- This is an overloaded interface first argument. Usage of this argument can be found is the User Guide referenced above.
|
||||
required: Yes
|
||||
default: Null
|
||||
choices: [aggregation-group, bfd, bridgeport, description, duplex, flowcontrol, ip, ipv6, lacp, lldp,
|
||||
choices: [channel-group, bfd, switchport, description, duplex, flowcontrol, ip, ipv6, lacp, lldp,
|
||||
load-interval, mac, mac-address, mac-learn, microburst-detection, mtu, service, service-policy,
|
||||
shutdown, snmp, spanning-tree, speed, storm-control, vlan, vrrp, port-aggregation]
|
||||
shutdown, snmp, spanning-tree, speed, storm-control, vlan, vrrp, port-channel]
|
||||
interfaceArg2:
|
||||
description:
|
||||
- This is an overloaded interface second argument. Usage of this argument can be found is the User Guide referenced above.
|
||||
required: No
|
||||
default: Null
|
||||
choices: [aggregation-group number, access or mode or trunk, description, auto or full or half,
|
||||
choices: [channel-group number, access or mode or trunk, description, auto or full or half,
|
||||
receive or send, port-priority, suspend-individual, timeout, receive or transmit or trap-notification,
|
||||
tlv-select, Load interval delay in seconds, counter, Name for the MAC Access List, mac-address in HHHH.HHHH.HHHH format,
|
||||
THRESHOLD Value in unit of buffer cell, <64-9216> MTU in bytes-<64-9216> for L2 packet,<576-9216> for L3 IPv4 packet,
|
||||
|
@ -132,7 +132,7 @@ options:
|
|||
EXAMPLES = '''
|
||||
Tasks : The following are examples of using the module cnos_interface. These are written in the main.yml file of the tasks directory.
|
||||
---
|
||||
- name: Test Interface Ethernet - aggregation-group
|
||||
- name: Test Interface Ethernet - channel-group
|
||||
cnos_interface:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
|
@ -142,11 +142,11 @@ Tasks : The following are examples of using the module cnos_interface. These are
|
|||
outputfile: "./results/test_interface_{{ inventory_hostname }}_output.txt"
|
||||
interfaceOption: 'ethernet'
|
||||
interfaceRange: 1
|
||||
interfaceArg1: "aggregation-group"
|
||||
interfaceArg1: "channel-group"
|
||||
interfaceArg2: 33
|
||||
interfaceArg3: "on"
|
||||
|
||||
- name: Test Interface Ethernet - bridge-port
|
||||
- name: Test Interface Ethernet - switchport
|
||||
cnos_interface:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
|
@ -156,11 +156,11 @@ Tasks : The following are examples of using the module cnos_interface. These are
|
|||
outputfile: "./results/test_interface_{{ inventory_hostname }}_output.txt"
|
||||
interfaceOption: 'ethernet'
|
||||
interfaceRange: 33
|
||||
interfaceArg1: "bridge-port"
|
||||
interfaceArg1: "switchport"
|
||||
interfaceArg2: "access"
|
||||
interfaceArg3: 33
|
||||
|
||||
- name: Test Interface Ethernet - bridgeport mode
|
||||
- name: Test Interface Ethernet - switchport mode
|
||||
cnos_interface:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
|
@ -170,7 +170,7 @@ Tasks : The following are examples of using the module cnos_interface. These are
|
|||
outputfile: "./results/test_interface_{{ inventory_hostname }}_output.txt"
|
||||
interfaceOption: 'ethernet'
|
||||
interfaceRange: 33
|
||||
interfaceArg1: "bridge-port"
|
||||
interfaceArg1: "switchport"
|
||||
interfaceArg2: "mode"
|
||||
interfaceArg3: "access"
|
||||
|
||||
|
@ -505,70 +505,23 @@ def main():
|
|||
interfaceArg7=dict(required=False),),
|
||||
supports_check_mode=False)
|
||||
|
||||
username = module.params['username']
|
||||
password = module.params['password']
|
||||
enablePassword = module.params['enablePassword']
|
||||
interfaceRange = module.params['interfaceRange']
|
||||
interfaceOption = module.params['interfaceOption']
|
||||
interfaceArg1 = module.params['interfaceArg1']
|
||||
interfaceArg2 = module.params['interfaceArg2']
|
||||
interfaceArg3 = module.params['interfaceArg3']
|
||||
interfaceArg4 = module.params['interfaceArg4']
|
||||
interfaceArg5 = module.params['interfaceArg5']
|
||||
interfaceArg6 = module.params['interfaceArg6']
|
||||
interfaceArg7 = module.params['interfaceArg7']
|
||||
outputfile = module.params['outputfile']
|
||||
hostIP = module.params['host']
|
||||
deviceType = module.params['deviceType']
|
||||
|
||||
output = ""
|
||||
if not HAS_PARAMIKO:
|
||||
module.fail_json(msg='paramiko is required for this module')
|
||||
|
||||
# Create instance of SSHClient object
|
||||
remote_conn_pre = paramiko.SSHClient()
|
||||
|
||||
# Automatically add untrusted hosts (make sure okay for security policy in your environment)
|
||||
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
# initiate SSH connection with the switch
|
||||
remote_conn_pre.connect(hostIP, username=username, password=password)
|
||||
time.sleep(2)
|
||||
|
||||
# Use invoke_shell to establish an 'interactive session'
|
||||
remote_conn = remote_conn_pre.invoke_shell()
|
||||
time.sleep(2)
|
||||
|
||||
# Enable and enter configure terminal then send command
|
||||
output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)
|
||||
|
||||
output = output + cnos.enterEnableModeForDevice(enablePassword, 3, remote_conn)
|
||||
|
||||
# Make terminal length = 0
|
||||
output = output + cnos.waitForDeviceResponse("terminal length 0\n", "#", 2, remote_conn)
|
||||
|
||||
# Go to config mode
|
||||
output = output + cnos.waitForDeviceResponse("configure device\n", "(config)#", 2, remote_conn)
|
||||
|
||||
output = ''
|
||||
# Send the CLi command
|
||||
if(interfaceOption is None or interfaceOption == ""):
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, None, interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", None, None)
|
||||
elif(interfaceOption == "ethernet"):
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "ethernet", interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", "ethernet", None)
|
||||
elif(interfaceOption == "loopback"):
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "loopback", interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", "loopback", None)
|
||||
elif(interfaceOption == "mgmt"):
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "mgmt", interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
elif(interfaceOption == "port-aggregation"):
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "port-aggregation", interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", "mgmt", None)
|
||||
elif(interfaceOption == "port-channel"):
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", "port-channel", None)
|
||||
elif(interfaceOption == "vlan"):
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "vlan", interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", "vlan", None)
|
||||
else:
|
||||
output = "Invalid interface option \n"
|
||||
# Save it into the file
|
||||
|
@ -579,7 +532,7 @@ def main():
|
|||
# Logic to check when changes occur or not
|
||||
errorMsg = cnos.checkOutputForError(output)
|
||||
if(errorMsg is None):
|
||||
module.exit_json(changed=True, msg="Interface Configuration is done")
|
||||
module.exit_json(changed=True, msg="Interface Configuration is Accomplished")
|
||||
else:
|
||||
module.fail_json(msg=errorMsg)
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ DOCUMENTATION = '''
|
|||
---
|
||||
module: cnos_portchannel
|
||||
author: "Anil Kumar Muraleedharan (@amuraleedhar)"
|
||||
short_description: Manage portchannel (port aggregation) configuration on devices running Lenovo CNOS
|
||||
short_description: Manage portchannel (port channel) configuration on devices running Lenovo CNOS
|
||||
description:
|
||||
- This module allows you to work with port aggregation related configurations. The operators
|
||||
used are overloaded to ensure control over switch port aggregation configurations. Apart
|
||||
- This module allows you to work with port channel related configurations. The operators
|
||||
used are overloaded to ensure control over switch port channel configurations. Apart
|
||||
from the regular device connection related attributes, there are five LAG arguments which are
|
||||
overloaded variables that will perform further configurations. They are interfaceArg1, interfaceArg2,
|
||||
interfaceArg3, interfaceArg4, and interfaceArg5. For more details on how to use these arguments, see
|
||||
|
@ -50,7 +50,7 @@ extends_documentation_fragment: cnos
|
|||
options:
|
||||
interfaceRange:
|
||||
description:
|
||||
- This specifies the interface range in which the port aggregation is envisaged
|
||||
- This specifies the interface range in which the port channel is envisaged
|
||||
required: Yes
|
||||
default: Null
|
||||
interfaceArg1:
|
||||
|
@ -58,15 +58,15 @@ options:
|
|||
- This is an overloaded Port Channel first argument. Usage of this argument can be found is the User Guide referenced above.
|
||||
required: Yes
|
||||
default: Null
|
||||
choices: [aggregation-group, bfd, bridgeport, description, duplex, flowcontrol, ip, ipv6, lacp, lldp,
|
||||
choices: [channel-group, bfd, bridgeport, description, duplex, flowcontrol, ip, ipv6, lacp, lldp,
|
||||
load-interval, mac, mac-address, mac-learn, microburst-detection, mtu, service, service-policy,
|
||||
shutdown, snmp, spanning-tree, speed, storm-control, vlan, vrrp, port-aggregation]
|
||||
shutdown, snmp, spanning-tree, speed, storm-control, vlan, vrrp, port-channel]
|
||||
interfaceArg2:
|
||||
description:
|
||||
- This is an overloaded Port Channel second argument. Usage of this argument can be found is the User Guide referenced above.
|
||||
required: No
|
||||
default: Null
|
||||
choices: [aggregation-group number, access or mode or trunk, description, auto or full or half,
|
||||
choices: [channel-group number, access or mode or trunk, description, auto or full or half,
|
||||
receive or send, port-priority, suspend-individual, timeout, receive or transmit or trap-notification,
|
||||
tlv-select, Load interval delay in seconds, counter, Name for the MAC Access List, mac-address in HHHH.HHHH.HHHH format,
|
||||
THRESHOLD Value in unit of buffer cell, <64-9216> MTU in bytes-<64-9216> for L2 packet,<576-9216> for
|
||||
|
@ -118,7 +118,7 @@ options:
|
|||
EXAMPLES = '''
|
||||
Tasks : The following are examples of using the module cnos_portchannel. These are written in the main.yml file of the tasks directory.
|
||||
---
|
||||
- name: Test Port Channel - aggregation-group
|
||||
- name: Test Port Channel - channel-group
|
||||
cnos_portchannel:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
|
@ -126,11 +126,11 @@ Tasks : The following are examples of using the module cnos_portchannel. These a
|
|||
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
interfaceRange: 33
|
||||
interfaceArg1: "aggregation-group"
|
||||
interfaceArg1: "channel-group"
|
||||
interfaceArg2: 33
|
||||
interfaceArg3: "on"
|
||||
|
||||
- name: Test Port Channel - aggregation-group - Interface Range
|
||||
- name: Test Port Channel - channel-group - Interface Range
|
||||
cnos_portchannel:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
|
@ -138,7 +138,7 @@ Tasks : The following are examples of using the module cnos_portchannel. These a
|
|||
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
interfaceRange: "1/1-2"
|
||||
interfaceArg1: "aggregation-group"
|
||||
interfaceArg1: "channel-group"
|
||||
interfaceArg2: 33
|
||||
interfaceArg3: "on"
|
||||
|
||||
|
@ -237,17 +237,6 @@ Tasks : The following are examples of using the module cnos_portchannel. These a
|
|||
interfaceArg3: 2
|
||||
interfaceArg4: 33
|
||||
|
||||
#- name: Test Port Channel - mac
|
||||
# cnos_portchannel:
|
||||
# host: "{{ inventory_hostname }}"
|
||||
# username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
# password: "{{ hostvars[inventory_hostname]['ansible_ssh_pass'] }}"
|
||||
# deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
# outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
# interfaceRange: 33,
|
||||
# interfaceArg1: "mac"
|
||||
# interfaceArg2: "copp-system-acl-vlag-hc"
|
||||
|
||||
- name: Test Port Channel - microburst-detection
|
||||
cnos_portchannel:
|
||||
host: "{{ inventory_hostname }}"
|
||||
|
@ -305,16 +294,16 @@ Tasks : The following are examples of using the module cnos_portchannel. These a
|
|||
interfaceArg2: "broadcast"
|
||||
interfaceArg3: 12.5
|
||||
|
||||
#- name: Test Port Channel - vlan
|
||||
# cnos_portchannel:
|
||||
# host: "{{ inventory_hostname }}"
|
||||
# username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
# password: "{{ hostvars[inventory_hostname]['ansible_ssh_pass'] }}"
|
||||
# deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
# outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
# interfaceRange: 33
|
||||
# interfaceArg1: "vlan"
|
||||
# interfaceArg2: "disable"
|
||||
- name: Test Port Channel - vlan
|
||||
cnos_portchannel:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
password: "{{ hostvars[inventory_hostname]['ansible_ssh_pass'] }}"
|
||||
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
interfaceRange: 33
|
||||
interfaceArg1: "vlan"
|
||||
interfaceArg2: "disable"
|
||||
|
||||
- name: Test Port Channel - vrrp
|
||||
cnos_portchannel:
|
||||
|
@ -378,35 +367,6 @@ Tasks : The following are examples of using the module cnos_portchannel. These a
|
|||
interfaceArg2: "port"
|
||||
interfaceArg3: "anil"
|
||||
|
||||
- name: Test Port Channel - bfd
|
||||
cnos_portchannel:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
password: "{{ hostvars[inventory_hostname]['ansible_ssh_pass'] }}"
|
||||
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
interfaceRange: 33
|
||||
interfaceArg1: "bfd"
|
||||
interfaceArg2: "interval"
|
||||
interfaceArg3: 55
|
||||
interfaceArg4: 55
|
||||
interfaceArg5: 33
|
||||
|
||||
- name: Test Port Channel - bfd
|
||||
cnos_portchannel:
|
||||
host: "{{ inventory_hostname }}"
|
||||
username: "{{ hostvars[inventory_hostname]['ansible_ssh_user'] }}"
|
||||
password: "{{ hostvars[inventory_hostname]['ansible_ssh_pass'] }}"
|
||||
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
|
||||
outputfile: "./results/test_portchannel_{{ inventory_hostname }}_output.txt"
|
||||
interfaceRange: 33
|
||||
interfaceArg1: "bfd"
|
||||
interfaceArg2: "ipv4"
|
||||
interfaceArg3: "authentication"
|
||||
interfaceArg4: "meticulous-keyed-md5"
|
||||
interfaceArg5: "key-chain"
|
||||
interfaceArg6: "mychain"
|
||||
|
||||
'''
|
||||
RETURN = '''
|
||||
msg:
|
||||
|
@ -417,11 +377,6 @@ msg:
|
|||
'''
|
||||
|
||||
import sys
|
||||
try:
|
||||
import paramiko
|
||||
HAS_PARAMIKO = True
|
||||
except ImportError:
|
||||
HAS_PARAMIKO = False
|
||||
import time
|
||||
import socket
|
||||
import array
|
||||
|
@ -457,56 +412,13 @@ def main():
|
|||
interfaceArg7=dict(required=False),),
|
||||
supports_check_mode=False)
|
||||
|
||||
username = module.params['username']
|
||||
password = module.params['password']
|
||||
enablePassword = module.params['enablePassword']
|
||||
interfaceRange = module.params['interfaceRange']
|
||||
interfaceArg1 = module.params['interfaceArg1']
|
||||
interfaceArg2 = module.params['interfaceArg2']
|
||||
interfaceArg3 = module.params['interfaceArg3']
|
||||
interfaceArg4 = module.params['interfaceArg4']
|
||||
interfaceArg5 = module.params['interfaceArg5']
|
||||
interfaceArg6 = module.params['interfaceArg6']
|
||||
interfaceArg7 = module.params['interfaceArg7']
|
||||
outputfile = module.params['outputfile']
|
||||
hostIP = module.params['host']
|
||||
deviceType = module.params['deviceType']
|
||||
output = ""
|
||||
if not HAS_PARAMIKO:
|
||||
module.fail_json(msg='paramiko is required for this module')
|
||||
|
||||
# Create instance of SSHClient object
|
||||
remote_conn_pre = paramiko.SSHClient()
|
||||
|
||||
# Automatically add untrusted hosts (make sure okay for security policy in your environment)
|
||||
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
# initiate SSH connection with the switch
|
||||
remote_conn_pre.connect(hostIP, username=username, password=password)
|
||||
time.sleep(2)
|
||||
|
||||
# Use invoke_shell to establish an 'interactive session'
|
||||
remote_conn = remote_conn_pre.invoke_shell()
|
||||
time.sleep(2)
|
||||
|
||||
# Enable and enter configure terminal then send command
|
||||
output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)
|
||||
|
||||
output = output + cnos.enterEnableModeForDevice(enablePassword, 3, remote_conn)
|
||||
|
||||
# Make terminal length = 0
|
||||
output = output + cnos.waitForDeviceResponse("terminal length 0\n", "#", 2, remote_conn)
|
||||
|
||||
# Go to config mode
|
||||
output = output + cnos.waitForDeviceResponse("configure device\n", "(config)#", 2, remote_conn)
|
||||
|
||||
output = ''
|
||||
# Send the CLi command
|
||||
if(interfaceArg1 == "port-aggregation"):
|
||||
output = output + cnos.portChannelConfig(remote_conn, deviceType, "(config)#", 2, interfaceArg1,
|
||||
interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
if(module.params['interfaceArg1'] == "port-channel"):
|
||||
output = output + cnos.portChannelConfig(module, "(config)#", None)
|
||||
else:
|
||||
output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "port-aggregation", interfaceRange,
|
||||
interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
|
||||
output = output + cnos.interfaceConfig(module, "(config)#", "port-channel", None)
|
||||
|
||||
# Save it into the file
|
||||
file = open(outputfile, "a")
|
||||
|
@ -516,7 +428,7 @@ def main():
|
|||
# Logic to check when changes occur or not
|
||||
errorMsg = cnos.checkOutputForError(output)
|
||||
if(errorMsg is None):
|
||||
module.exit_json(changed=True, msg="Port Aggregation configuration is done")
|
||||
module.exit_json(changed=True, msg="Port Channel Configuration is done")
|
||||
else:
|
||||
module.fail_json(msg=errorMsg)
|
||||
|
||||
|
|
|
@ -252,11 +252,6 @@ msg:
|
|||
'''
|
||||
|
||||
import sys
|
||||
try:
|
||||
import paramiko
|
||||
HAS_PARAMIKO = True
|
||||
except ImportError:
|
||||
HAS_PARAMIKO = False
|
||||
import time
|
||||
import socket
|
||||
import array
|
||||
|
@ -291,54 +286,11 @@ def main():
|
|||
vlagArg4=dict(required=False),),
|
||||
supports_check_mode=False)
|
||||
|
||||
username = module.params['username']
|
||||
password = module.params['password']
|
||||
enablePassword = module.params['enablePassword']
|
||||
outputfile = module.params['outputfile']
|
||||
hostIP = module.params['host']
|
||||
deviceType = module.params['deviceType']
|
||||
vlagArg1 = module.params['vlagArg1']
|
||||
vlagArg2 = module.params['vlagArg2']
|
||||
vlagArg3 = module.params['vlagArg3']
|
||||
vlagArg4 = module.params['vlagArg4']
|
||||
output = ""
|
||||
if not HAS_PARAMIKO:
|
||||
module.fail_json(msg='paramiko is required for this module')
|
||||
|
||||
# Create instance of SSHClient object
|
||||
remote_conn_pre = paramiko.SSHClient()
|
||||
|
||||
# Automatically add untrusted hosts (make sure okay for security policy in
|
||||
# your environment)
|
||||
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
# initiate SSH connection with the switch
|
||||
remote_conn_pre.connect(hostIP, username=username, password=password)
|
||||
time.sleep(2)
|
||||
|
||||
# Use invoke_shell to establish an 'interactive session'
|
||||
remote_conn = remote_conn_pre.invoke_shell()
|
||||
time.sleep(2)
|
||||
|
||||
# Enable and enter configure terminal then send command
|
||||
output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)
|
||||
|
||||
output = output + \
|
||||
cnos.enterEnableModeForDevice(enablePassword, 3, remote_conn)
|
||||
|
||||
# Make terminal length = 0
|
||||
output = output + \
|
||||
cnos.waitForDeviceResponse("terminal length 0\n", "#", 2, remote_conn)
|
||||
|
||||
# Go to config mode
|
||||
output = output + \
|
||||
cnos.waitForDeviceResponse(
|
||||
"configure device\n", "(config)#", 2, remote_conn)
|
||||
|
||||
# Send the CLi command
|
||||
output = output + cnos.vlagConfig(
|
||||
remote_conn, deviceType, "(config)#", 2, vlagArg1, vlagArg2, vlagArg3,
|
||||
vlagArg4)
|
||||
output = output + str(cnos.vlagConfig(module, '(config)#', None))
|
||||
|
||||
# Save it into the file
|
||||
file = open(outputfile, "a")
|
||||
|
@ -348,7 +300,7 @@ def main():
|
|||
# need to add logic to check when changes occur or not
|
||||
errorMsg = cnos.checkOutputForError(output)
|
||||
if(errorMsg is None):
|
||||
module.exit_json(changed=True, msg="vlag configurations accomplished")
|
||||
module.exit_json(changed=True, msg="VLAG configurations accomplished")
|
||||
else:
|
||||
module.fail_json(msg=errorMsg)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue