mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Persistence connection for cnos_vlan (#42500)
* Changing Lenovo Inc to Lenovo and update License file to be consistent. * Changing cnos_vlan from paramiko to persistence connection of Ansible. Also talking care of CLI changes in CNOS commands with backward compatibility. * Fixing Validation issues * Trailing lines removal * Review comments of Gundalow are getting addressed. He mentioned only at one place for cnos.py. But I have covered the entire file. * Changes to incorporate Review comments from Qalthos * Removing configure terminal command from module code * Aligning with change in run_cnos_commands method changes * Editing cliconf for latest CNOS CLIs
This commit is contained in:
parent
1a0330488f
commit
0897e79bd1
6 changed files with 204 additions and 151 deletions
|
@ -43,13 +43,12 @@ description:
|
|||
filter. After passing this level, there are five VLAN arguments that will
|
||||
perform further configurations. They are vlanArg1, vlanArg2, vlanArg3,
|
||||
vlanArg4, and vlanArg5. The value of vlanArg1 will determine the way
|
||||
following arguments will be evaluated. For more details on how to use these
|
||||
arguments, see [Overloaded Variables].
|
||||
This module uses SSH to manage network device configuration.
|
||||
The results of the operation will be placed in a directory named 'results'
|
||||
that must be created by the user in their local directory to where the playbook is run.
|
||||
For more information about this module from Lenovo and customizing it usage for your
|
||||
use cases, please visit U(http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_vlan.html)
|
||||
following arguments will be evaluated. This module uses SSH to manage network
|
||||
device configuration. The results of the operation will be placed in a directory
|
||||
named 'results' that must be created by the user in their local directory to
|
||||
where the playbook is run. For more information about this module from Lenovo and
|
||||
customizing it usage for your use cases,
|
||||
please visit U(http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_vlan.html)
|
||||
version_added: "2.3"
|
||||
extends_documentation_fragment: cnos
|
||||
options:
|
||||
|
@ -182,24 +181,17 @@ msg:
|
|||
'''
|
||||
|
||||
import sys
|
||||
try:
|
||||
import paramiko
|
||||
HAS_PARAMIKO = True
|
||||
except ImportError:
|
||||
HAS_PARAMIKO = False
|
||||
import time
|
||||
import socket
|
||||
import array
|
||||
import json
|
||||
import time
|
||||
import re
|
||||
|
||||
try:
|
||||
from ansible.module_utils.network.cnos import cnos
|
||||
HAS_LIB = True
|
||||
except:
|
||||
HAS_LIB = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from collections import defaultdict
|
||||
|
||||
|
@ -223,58 +215,14 @@ def main():
|
|||
vlanArg5=dict(required=False),),
|
||||
supports_check_mode=False)
|
||||
|
||||
username = module.params['username']
|
||||
password = module.params['password']
|
||||
enablePassword = module.params['enablePassword']
|
||||
vlanArg1 = module.params['vlanArg1']
|
||||
vlanArg2 = module.params['vlanArg2']
|
||||
vlanArg3 = module.params['vlanArg3']
|
||||
vlanArg4 = module.params['vlanArg4']
|
||||
vlanArg5 = module.params['vlanArg5']
|
||||
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)
|
||||
|
||||
# Send the CLi command
|
||||
output = output + \
|
||||
cnos.vlanConfig(
|
||||
remote_conn, deviceType, "(config)#", 2, vlanArg1, vlanArg2,
|
||||
vlanArg3, vlanArg4, vlanArg5)
|
||||
output = output + str(cnos.vlanConfig(module, "(config)#", None))
|
||||
|
||||
# Save it into the file
|
||||
# Save it operation details into the file
|
||||
file = open(outputfile, "a")
|
||||
file.write(output)
|
||||
file.close()
|
||||
|
@ -282,7 +230,8 @@ 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="VLAN configuration is accomplished")
|
||||
module.exit_json(changed=True,
|
||||
msg="VLAN configuration is accomplished")
|
||||
else:
|
||||
module.fail_json(msg=errorMsg)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# GNU General Public License for more details.
|
||||
#
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# Module to Collect facts from Lenovo Switches running Lenovo ENOS commands
|
||||
# Lenovo Networking
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue