mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -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
|
@ -164,7 +164,8 @@ def run_commands(module, commands, check_rc=True):
|
|||
|
||||
def run_cnos_commands(module, commands, check_rc=True):
|
||||
retVal = ''
|
||||
enter_config = {'command': 'configure terminal', 'prompt': None, 'answer': None}
|
||||
enter_config = {'command': 'configure terminal', 'prompt': None,
|
||||
'answer': None}
|
||||
exit_config = {'command': 'end', 'prompt': None, 'answer': None}
|
||||
commands.insert(0, enter_config)
|
||||
commands.append(exit_config)
|
||||
|
@ -212,128 +213,97 @@ def get_defaults_flag(module):
|
|||
return 'full'
|
||||
|
||||
|
||||
def interfaceConfig(
|
||||
obj, deviceType, prompt, timeout, interfaceArg1,
|
||||
interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5,
|
||||
interfaceArg6, interfaceArg7, interfaceArg8, interfaceArg9):
|
||||
def interfaceConfig(module, prompt, functionality, answer):
|
||||
retVal = ""
|
||||
command = "interface "
|
||||
newPrompt = prompt
|
||||
if(interfaceArg1 == "port-aggregation"):
|
||||
command = command + " " + interfaceArg1 + " " + interfaceArg2 + "\n"
|
||||
interfaceArg1 = functionality
|
||||
interfaceArg2 = module.params['interfaceRange']
|
||||
interfaceArg3 = module.params['interfaceArg1']
|
||||
interfaceArg4 = module.params['interfaceArg2']
|
||||
interfaceArg5 = module.params['interfaceArg3']
|
||||
interfaceArg6 = module.params['interfaceArg4']
|
||||
interfaceArg7 = module.params['interfaceArg5']
|
||||
interfaceArg8 = module.params['interfaceArg6']
|
||||
interfaceArg9 = module.params['interfaceArg7']
|
||||
deviceType = module.params['deviceType']
|
||||
|
||||
if(interfaceArg1 == "port-channel"):
|
||||
command = command + " " + interfaceArg1 + " " + interfaceArg2
|
||||
# debugOutput(command)
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "portchannel_interface_value", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if)#"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "portchannel_interface_range", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if-range)#"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "portchannel_interface_string", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if-range)#"
|
||||
if '/' in interfaceArg2:
|
||||
newPrompt = "(config-if)#"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
cmd = [{'command': command, 'prompt': None,
|
||||
'answer': None}]
|
||||
else:
|
||||
retVal = "Error-102"
|
||||
return retVal
|
||||
|
||||
retVal = retVal + interfaceLevel2Config(
|
||||
obj, deviceType, newPrompt, timeout, interfaceArg3, interfaceArg4,
|
||||
interfaceArg5, interfaceArg6, interfaceArg7, interfaceArg8,
|
||||
interfaceArg9)
|
||||
retVal = retVal + interfaceLevel2Config(module, cmd, prompt, answer)
|
||||
elif(interfaceArg1 == "ethernet"):
|
||||
# command = command + interfaceArg1 + " 1/"
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "ethernet_interface_value", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if)#"
|
||||
command = command + interfaceArg1 + " 1/" + interfaceArg2 + " \n"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
command = command + interfaceArg1 + " 1/" + interfaceArg2
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "ethernet_interface_range", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
command = command + \
|
||||
interfaceArg1 + " 1/" + interfaceArg2 + " \n"
|
||||
newPrompt = "(config-if-range)#"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
command = command + interfaceArg1 + " 1/" + interfaceArg2
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "ethernet_interface_string", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
command = command + \
|
||||
interfaceArg1 + " " + interfaceArg2 + "\n"
|
||||
newPrompt = "(config-if-range)#"
|
||||
if '/' in interfaceArg2:
|
||||
newPrompt = "(config-if)#"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
command = command + interfaceArg1 + " " + interfaceArg2
|
||||
cmd = [{'command': command, 'prompt': None,
|
||||
'answer': None}]
|
||||
else:
|
||||
retVal = "Error-102"
|
||||
return retVal
|
||||
|
||||
retVal = retVal + interfaceLevel2Config(
|
||||
obj, deviceType, newPrompt, timeout, interfaceArg3, interfaceArg4,
|
||||
interfaceArg5, interfaceArg6, interfaceArg7, interfaceArg8,
|
||||
interfaceArg9)
|
||||
retVal = retVal + interfaceLevel2Config(module, cmd, prompt, answer)
|
||||
elif(interfaceArg1 == "loopback"):
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "loopback_interface_value", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if)#"
|
||||
command = command + interfaceArg1 + " " + interfaceArg2 + "\n"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
command = command + interfaceArg1 + " " + interfaceArg2
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
retVal = "Error-102"
|
||||
return retVal
|
||||
retVal = retVal + interfaceLevel2Config(
|
||||
obj, deviceType, newPrompt, timeout, interfaceArg3, interfaceArg4,
|
||||
interfaceArg5, interfaceArg6, interfaceArg7, interfaceArg8,
|
||||
interfaceArg9)
|
||||
retVal = retVal + interfaceLevel2Config(module, cmd, prompt, answer)
|
||||
elif(interfaceArg1 == "mgmt"):
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "mgmt_interface_value", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if)#"
|
||||
command = command + interfaceArg1 + " " + interfaceArg2 + "\n"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
command = command + interfaceArg1 + " " + interfaceArg2
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
retVal = "Error-102"
|
||||
return retVal
|
||||
retVal = retVal + interfaceLevel2Config(
|
||||
obj, deviceType, newPrompt, timeout, interfaceArg3, interfaceArg4,
|
||||
interfaceArg5, interfaceArg6, interfaceArg7, interfaceArg8,
|
||||
interfaceArg9)
|
||||
retVal = retVal + interfaceLevel2Config(module, cmd, prompt, answer)
|
||||
elif(interfaceArg1 == "vlan"):
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "vlan_interface_value", interfaceArg2)
|
||||
if(value == "ok"):
|
||||
newPrompt = "(config-if)#"
|
||||
command = command + interfaceArg1 + " " + interfaceArg2 + "\n"
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, newPrompt, timeout, obj)
|
||||
command = command + interfaceArg1 + " " + interfaceArg2
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
else:
|
||||
retVal = "Error-102"
|
||||
return retVal
|
||||
retVal = retVal + interfaceLevel2Config(
|
||||
obj, deviceType, newPrompt, timeout, interfaceArg3, interfaceArg4,
|
||||
interfaceArg5, interfaceArg6, interfaceArg7, interfaceArg8,
|
||||
interfaceArg9)
|
||||
retVal = retVal + interfaceLevel2Config(module, cmd, prompt, answer)
|
||||
else:
|
||||
retVal = "Error-102"
|
||||
|
||||
|
@ -341,14 +311,20 @@ def interfaceConfig(
|
|||
# EOM
|
||||
|
||||
|
||||
def interfaceLevel2Config(
|
||||
obj, deviceType, prompt, timeout, interfaceL2Arg1, interfaceL2Arg2,
|
||||
interfaceL2Arg3, interfaceL2Arg4, interfaceL2Arg5, interfaceL2Arg6,
|
||||
interfaceL2Arg7):
|
||||
def interfaceLevel2Config(module, cmd, prompt, answer):
|
||||
retVal = ""
|
||||
command = ""
|
||||
if(interfaceL2Arg1 == "aggregation-group"):
|
||||
# debugOutput("aggregation-group")
|
||||
interfaceL2Arg1 = module.params['interfaceArg1']
|
||||
interfaceL2Arg2 = module.params['interfaceArg2']
|
||||
interfaceL2Arg3 = module.params['interfaceArg3']
|
||||
interfaceL2Arg4 = module.params['interfaceArg4']
|
||||
interfaceL2Arg5 = module.params['interfaceArg5']
|
||||
interfaceL2Arg6 = module.params['interfaceArg6']
|
||||
interfaceL2Arg7 = module.params['interfaceArg7']
|
||||
deviceType = module.params['deviceType']
|
||||
|
||||
if(interfaceL2Arg1 == "channel-group"):
|
||||
# debugOutput("channel-group")
|
||||
command = interfaceL2Arg1 + " "
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "aggregation_group_no", interfaceL2Arg2)
|
||||
|
@ -583,8 +559,8 @@ def interfaceLevel2Config(
|
|||
retVal = "Error-205"
|
||||
return retVal
|
||||
|
||||
elif (interfaceL2Arg1 == "bridge-port"):
|
||||
# debugOutput("bridge-port")
|
||||
elif (interfaceL2Arg1 == "switchport"):
|
||||
# debugOutput("switchport")
|
||||
command = interfaceL2Arg1 + " "
|
||||
if(interfaceL2Arg2 is None):
|
||||
command = command.strip()
|
||||
|
@ -1335,26 +1311,27 @@ def interfaceLevel2Config(
|
|||
retVal = "Error-233"
|
||||
return retVal
|
||||
|
||||
command = command + "\n"
|
||||
# debugOutput(command)
|
||||
retVal = retVal + waitForDeviceResponse(command, prompt, timeout, obj)
|
||||
inner_cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
cmd.extend(inner_cmd)
|
||||
retVal = retVal + str(run_cnos_commands(module, cmd))
|
||||
# Come back to config mode
|
||||
if((prompt == "(config-if)#") or (prompt == "(config-if-range)#")):
|
||||
command = "exit \n"
|
||||
command = "exit"
|
||||
# debugOutput(command)
|
||||
retVal = retVal + \
|
||||
waitForDeviceResponse(command, "(config)#", timeout, obj)
|
||||
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
# retVal = retVal + str(run_cnos_commands(module, cmd))
|
||||
return retVal
|
||||
# EOM
|
||||
|
||||
|
||||
def portChannelConfig(
|
||||
obj, deviceType, prompt, timeout, portChArg1, portChArg2, portChArg3,
|
||||
portChArg4, portChArg5, portChArg6, portChArg7):
|
||||
retVal = ""
|
||||
command = ""
|
||||
if(portChArg1 == "port-aggregation" and prompt == "(config)#"):
|
||||
def portChannelConfig(module, prompt, answer):
|
||||
retVal = ''
|
||||
command = ''
|
||||
portChArg1 = module.params['interfaceArg1']
|
||||
portChArg2 = module.params['interfaceArg2']
|
||||
portChArg3 = module.params['interfaceArg3']
|
||||
if(portChArg1 == "port-channel" and prompt == "(config)#"):
|
||||
command = command + portChArg1 + " load-balance ethernet "
|
||||
if(portChArg2 == "destination-ip" or
|
||||
portChArg2 == "destination-mac" or
|
||||
|
@ -1373,13 +1350,14 @@ def portChannelConfig(
|
|||
command = command + ""
|
||||
elif(portChArg3 == "source-interface"):
|
||||
command = command + portChArg3
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
retVal = retVal + str(run_cnos_commands(module, cmd))
|
||||
else:
|
||||
retVal = "Error-231"
|
||||
return retVal
|
||||
else:
|
||||
retVal = "Error-232"
|
||||
return retVal
|
||||
|
||||
# EOM
|
||||
|
||||
|
||||
|
@ -2554,15 +2532,17 @@ def createVlan(module, prompt, answer):
|
|||
# EOM
|
||||
|
||||
|
||||
def vlagConfig(
|
||||
obj, deviceType, prompt, timeout, vlagArg1, vlagArg2, vlagArg3,
|
||||
vlagArg4):
|
||||
def vlagConfig(module, prompt, answer):
|
||||
|
||||
retVal = ""
|
||||
# Wait time to get response from server
|
||||
timeout = timeout
|
||||
retVal = ''
|
||||
# vlag config command happens here.
|
||||
command = "vlag "
|
||||
command = 'vlag '
|
||||
|
||||
vlagArg1 = module.params['vlagArg1']
|
||||
vlagArg2 = module.params['vlagArg2']
|
||||
vlagArg3 = module.params['vlagArg3']
|
||||
vlagArg4 = module.params['vlagArg4']
|
||||
deviceType = module.params['deviceType']
|
||||
|
||||
if(vlagArg1 == "enable"):
|
||||
# debugOutput("enable")
|
||||
|
@ -2592,7 +2572,7 @@ def vlagConfig(
|
|||
|
||||
elif(vlagArg1 == "isl"):
|
||||
# debugOutput("isl")
|
||||
command = command + vlagArg1 + " port-aggregation "
|
||||
command = command + vlagArg1 + " port-channel "
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "vlag_port_aggregation", vlagArg2)
|
||||
if(value == "ok"):
|
||||
|
@ -2651,7 +2631,7 @@ def vlagConfig(
|
|||
if(value == "ok"):
|
||||
command = command + vlagArg2
|
||||
if(vlagArg3 is not None):
|
||||
command = command + " port-aggregation "
|
||||
command = command + " port-channel "
|
||||
value = checkSanityofVariable(
|
||||
deviceType, "vlag_port_aggregation", vlagArg3)
|
||||
if(value == "ok"):
|
||||
|
@ -2718,10 +2698,8 @@ def vlagConfig(
|
|||
return retVal
|
||||
|
||||
# debugOutput(command)
|
||||
command = command + "\n"
|
||||
# debugOutput(command)
|
||||
retVal = retVal + waitForDeviceResponse(command, "(config)#", timeout, obj)
|
||||
|
||||
cmd = [{'command': command, 'prompt': None, 'answer': None}]
|
||||
retVal = retVal + str(run_cnos_commands(module, cmd))
|
||||
return retVal
|
||||
# EOM
|
||||
|
||||
|
|
|
@ -1356,7 +1356,7 @@ g8272_cnos = {'vlan_id': 'INTEGER_VALUE:1-3999',
|
|||
'portchannel_ipv6_address': 'IPV6Address:',
|
||||
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
|
||||
link-local,nd,neighbor',
|
||||
'interface_speed': 'TEXT_OPTIONS:1000,10000,40000,auto',
|
||||
'interface_speed': 'TEXT_OPTIONS:1000,10000,40000',
|
||||
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
|
||||
unicast',
|
||||
'stormcontrol_level': 'FLOAT:',
|
||||
|
|
|
@ -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