From 8e081b7e30f765148a9647196d0bf6edccbc7bf9 Mon Sep 17 00:00:00 2001 From: Anil Kumar Muraleedharan Date: Thu, 9 Nov 2017 00:50:50 +0530 Subject: [PATCH] Moving modules from lenovo to cnos (#31401) * Moving modules from lenovo to cnos * Merge conflicts * Update cnos_conditional_template.py Removed 180:5: E265 block comment should start with '# ' 188:34: E226 missing whitespace around arithmetic operator * Update cnos_template.py 155:5: E265 block comment should start with '# ' 162:34: E226 missing whitespace around arithmetic operator * Update cnos_vlan.py 210:1: E302 expected 2 blank lines, found 1 * Update cnos_backup.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_bgp.py Added from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_backup.py Added a line extra * Update cnos_command.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_conditional_command.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_conditional_template.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_factory.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_facts.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_image.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_interface.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_portchannel.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_reload.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_rollback.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_save.py Add from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_showrun.py Add from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_template.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_vlag.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_vlan.py Adding from __future__ import (absolute_import, division, print_function) __metaclass__ = type * Update cnos_backup.py Moving it to top of file * Update cnos_backup.py * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Moving future and metaclass to top * Putting condition to bye pass paramiko * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Condition to byepass paramiko import error * Removing unused import and white spaces * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Dealing with white space and import issues * Update cnos_template.py --- .../network/{lenovo => cnos}/__init__.py | 0 .../network/{lenovo => cnos}/cnos_backup.py | 12 ++++++++++-- .../network/{lenovo => cnos}/cnos_bgp.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_command.py | 12 +++++++++--- .../cnos_conditional_command.py | 11 +++++++++-- .../cnos_conditional_template.py | 15 +++++++++++---- .../network/{lenovo => cnos}/cnos_factory.py | 12 +++++++++--- .../network/{lenovo => cnos}/cnos_facts.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_image.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_interface.py | 11 +++++++++-- .../{lenovo => cnos}/cnos_portchannel.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_reload.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_rollback.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_save.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_showrun.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_template.py | 17 ++++++++++++----- .../network/{lenovo => cnos}/cnos_vlag.py | 11 +++++++++-- .../network/{lenovo => cnos}/cnos_vlan.py | 12 ++++++++++-- test/sanity/pep8/legacy-files.txt | 3 --- 19 files changed, 160 insertions(+), 44 deletions(-) rename lib/ansible/modules/network/{lenovo => cnos}/__init__.py (100%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_backup.py (97%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_bgp.py (98%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_command.py (95%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_conditional_command.py (96%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_conditional_template.py (95%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_factory.py (94%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_facts.py (94%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_image.py (96%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_interface.py (98%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_portchannel.py (98%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_reload.py (94%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_rollback.py (97%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_save.py (94%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_showrun.py (94%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_template.py (94%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_vlag.py (97%) rename lib/ansible/modules/network/{lenovo => cnos}/cnos_vlan.py (97%) diff --git a/lib/ansible/modules/network/lenovo/__init__.py b/lib/ansible/modules/network/cnos/__init__.py similarity index 100% rename from lib/ansible/modules/network/lenovo/__init__.py rename to lib/ansible/modules/network/cnos/__init__.py diff --git a/lib/ansible/modules/network/lenovo/cnos_backup.py b/lib/ansible/modules/network/cnos/cnos_backup.py similarity index 97% rename from lib/ansible/modules/network/lenovo/cnos_backup.py rename to lib/ansible/modules/network/cnos/cnos_backup.py index f235d8f1f26..e73ed5bbbcc 100644 --- a/lib/ansible/modules/network/lenovo/cnos_backup.py +++ b/lib/ansible/modules/network/cnos/cnos_backup.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -168,9 +170,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -219,6 +224,9 @@ def main(): timeout = 90 tftptimeout = 450 + if not HAS_PARAMIKO: + module.fail_json(msg='paramiko is required for this module') + # Create instance of SSHClient object remote_conn_pre = paramiko.SSHClient() diff --git a/lib/ansible/modules/network/lenovo/cnos_bgp.py b/lib/ansible/modules/network/cnos/cnos_bgp.py similarity index 98% rename from lib/ansible/modules/network/lenovo/cnos_bgp.py rename to lib/ansible/modules/network/cnos/cnos_bgp.py index aa1cf0c4f12..d786af9bfd6 100644 --- a/lib/ansible/modules/network/lenovo/cnos_bgp.py +++ b/lib/ansible/modules/network/cnos/cnos_bgp.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -365,9 +367,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -419,6 +424,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_command.py b/lib/ansible/modules/network/cnos/cnos_command.py similarity index 95% rename from lib/ansible/modules/network/lenovo/cnos_command.py rename to lib/ansible/modules/network/cnos/cnos_command.py index 9cb65fa44c5..d028ec02606 100644 --- a/lib/ansible/modules/network/lenovo/cnos_command.py +++ b/lib/ansible/modules/network/cnos/cnos_command.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -76,11 +78,13 @@ msg: sample: "Command Applied" ''' - import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -115,6 +119,8 @@ def main(): outputfile = module.params['outputfile'] hostIP = module.params['host'] 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_conditional_command.py b/lib/ansible/modules/network/cnos/cnos_conditional_command.py similarity index 96% rename from lib/ansible/modules/network/lenovo/cnos_conditional_command.py rename to lib/ansible/modules/network/cnos/cnos_conditional_command.py index 6258062570d..9e6824f3247 100644 --- a/lib/ansible/modules/network/lenovo/cnos_conditional_command.py +++ b/lib/ansible/modules/network/cnos/cnos_conditional_command.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -97,9 +99,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -137,6 +142,8 @@ def main(): deviceType = module.params['deviceType'] hostIP = module.params['host'] output = "" + if not HAS_PARAMIKO: + module.fail_json(msg='paramiko is required for this module') if (condition != flag): module.exit_json(changed=True, msg="Command Skipped for this value") diff --git a/lib/ansible/modules/network/lenovo/cnos_conditional_template.py b/lib/ansible/modules/network/cnos/cnos_conditional_template.py similarity index 95% rename from lib/ansible/modules/network/lenovo/cnos_conditional_template.py rename to lib/ansible/modules/network/cnos/cnos_conditional_template.py index 7de872944c7..a47e14543df 100644 --- a/lib/ansible/modules/network/lenovo/cnos_conditional_template.py +++ b/lib/ansible/modules/network/cnos/cnos_conditional_template.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -104,9 +106,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -146,6 +151,8 @@ def main(): hostIP = module.params['host'] output = "" + if not HAS_PARAMIKO: + module.fail_json(msg='paramiko is required for this module') # Here comes the logic against which a template is # conditionally executed for right Network element. @@ -177,7 +184,7 @@ def main(): # Go to config mode output = output + cnos.waitForDeviceResponse("configure d\n", "(config)#", 2, remote_conn) # Send commands one by one - #with open(commandfile, "r") as f: + # with open(commandfile, "r") as f: f = open(commandfile, "r") for line in f: # Omit the comment lines in template file @@ -185,7 +192,7 @@ def main(): # cnos.debugOutput(line) command = line if not line.endswith("\n"): - command = command+"\n" + command = command + "\n" response = cnos.waitForDeviceResponse(command, "#", 2, remote_conn) errorMsg = cnos.checkOutputForError(response) output = output + response diff --git a/lib/ansible/modules/network/lenovo/cnos_factory.py b/lib/ansible/modules/network/cnos/cnos_factory.py similarity index 94% rename from lib/ansible/modules/network/lenovo/cnos_factory.py rename to lib/ansible/modules/network/cnos/cnos_factory.py index 5e3ba817e3d..4a5f1bac0c0 100644 --- a/lib/ansible/modules/network/lenovo/cnos_factory.py +++ b/lib/ansible/modules/network/cnos/cnos_factory.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -65,11 +67,13 @@ msg: sample: "Switch Startup Config is Reset to factory settings" ''' - import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -103,6 +107,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_facts.py b/lib/ansible/modules/network/cnos/cnos_facts.py similarity index 94% rename from lib/ansible/modules/network/lenovo/cnos_facts.py rename to lib/ansible/modules/network/cnos/cnos_facts.py index 14b8e4ea16b..a1d3655999f 100644 --- a/lib/ansible/modules/network/lenovo/cnos_facts.py +++ b/lib/ansible/modules/network/cnos/cnos_facts.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -64,9 +66,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -98,6 +103,8 @@ def main(): outputfile = module.params['outputfile'] hostIP = module.params['host'] 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_image.py b/lib/ansible/modules/network/cnos/cnos_image.py similarity index 96% rename from lib/ansible/modules/network/lenovo/cnos_image.py rename to lib/ansible/modules/network/cnos/cnos_image.py index 52dc5038d8e..fff09b6bf16 100644 --- a/lib/ansible/modules/network/lenovo/cnos_image.py +++ b/lib/ansible/modules/network/cnos/cnos_image.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -125,9 +127,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -174,6 +179,8 @@ def main(): output = "" timeout = 120 tftptimeout = 600 + if not HAS_PARAMIKO: + module.fail_json(msg='paramiko is required for this module') # Create instance of SSHClient object remote_conn_pre = paramiko.SSHClient() diff --git a/lib/ansible/modules/network/lenovo/cnos_interface.py b/lib/ansible/modules/network/cnos/cnos_interface.py similarity index 98% rename from lib/ansible/modules/network/lenovo/cnos_interface.py rename to lib/ansible/modules/network/cnos/cnos_interface.py index 98e5aaa9493..3f32822cf06 100644 --- a/lib/ansible/modules/network/lenovo/cnos_interface.py +++ b/lib/ansible/modules/network/cnos/cnos_interface.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -463,9 +465,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -517,6 +522,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_portchannel.py b/lib/ansible/modules/network/cnos/cnos_portchannel.py similarity index 98% rename from lib/ansible/modules/network/lenovo/cnos_portchannel.py rename to lib/ansible/modules/network/cnos/cnos_portchannel.py index 42880ba5a05..294d34c905c 100644 --- a/lib/ansible/modules/network/lenovo/cnos_portchannel.py +++ b/lib/ansible/modules/network/cnos/cnos_portchannel.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -415,9 +417,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -467,6 +472,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_reload.py b/lib/ansible/modules/network/cnos/cnos_reload.py similarity index 94% rename from lib/ansible/modules/network/lenovo/cnos_reload.py rename to lib/ansible/modules/network/cnos/cnos_reload.py index 01e6d7778b2..4e911f7749a 100644 --- a/lib/ansible/modules/network/lenovo/cnos_reload.py +++ b/lib/ansible/modules/network/cnos/cnos_reload.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -65,9 +67,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -101,6 +106,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_rollback.py b/lib/ansible/modules/network/cnos/cnos_rollback.py similarity index 97% rename from lib/ansible/modules/network/lenovo/cnos_rollback.py rename to lib/ansible/modules/network/cnos/cnos_rollback.py index 94e82467939..6f25287ed82 100644 --- a/lib/ansible/modules/network/lenovo/cnos_rollback.py +++ b/lib/ansible/modules/network/cnos/cnos_rollback.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -161,9 +163,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -210,6 +215,8 @@ def main(): output = "" timeout = 90 tftptimeout = 450 + if not HAS_PARAMIKO: + module.fail_json(msg='paramiko is required for this module') # Create instance of SSHClient object remote_conn_pre = paramiko.SSHClient() diff --git a/lib/ansible/modules/network/lenovo/cnos_save.py b/lib/ansible/modules/network/cnos/cnos_save.py similarity index 94% rename from lib/ansible/modules/network/lenovo/cnos_save.py rename to lib/ansible/modules/network/cnos/cnos_save.py index 4703ad76a96..8948b1d53e3 100644 --- a/lib/ansible/modules/network/lenovo/cnos_save.py +++ b/lib/ansible/modules/network/cnos/cnos_save.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -66,9 +68,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -102,6 +107,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_showrun.py b/lib/ansible/modules/network/cnos/cnos_showrun.py similarity index 94% rename from lib/ansible/modules/network/lenovo/cnos_showrun.py rename to lib/ansible/modules/network/cnos/cnos_showrun.py index 0e640d33b46..a6581e02828 100644 --- a/lib/ansible/modules/network/lenovo/cnos_showrun.py +++ b/lib/ansible/modules/network/cnos/cnos_showrun.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -67,9 +69,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -101,6 +106,8 @@ def main(): outputfile = module.params['outputfile'] hostIP = module.params['host'] 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_template.py b/lib/ansible/modules/network/cnos/cnos_template.py similarity index 94% rename from lib/ansible/modules/network/lenovo/cnos_template.py rename to lib/ansible/modules/network/cnos/cnos_template.py index bf3261e1ace..3713e25e27b 100644 --- a/lib/ansible/modules/network/lenovo/cnos_template.py +++ b/lib/ansible/modules/network/cnos/cnos_template.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -89,9 +91,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -125,6 +130,8 @@ def main(): deviceType = module.params['deviceType'] hostIP = module.params['host'] 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() @@ -151,15 +158,15 @@ def main(): # Go to config mode output = output + cnos.waitForDeviceResponse("configure d\n", "(config)#", 2, remote_conn) - # Send commands one by one - #with open(commandfile, "r") as f: + # Send commands one by one to the device + # with open(commandfile, "r") as f: f = open(commandfile, "r") for line in f: # Omit the comment lines in template file if not line.startswith("#"): command = line if not line.endswith("\n"): - command = command+"\n" + command = command + "\n" response = cnos.waitForDeviceResponse(command, "#", 2, remote_conn) errorMsg = cnos.checkOutputForError(response) output = output + response diff --git a/lib/ansible/modules/network/lenovo/cnos_vlag.py b/lib/ansible/modules/network/cnos/cnos_vlag.py similarity index 97% rename from lib/ansible/modules/network/lenovo/cnos_vlag.py rename to lib/ansible/modules/network/cnos/cnos_vlag.py index 90d13407ffe..9ee5ea641f6 100644 --- a/lib/ansible/modules/network/lenovo/cnos_vlag.py +++ b/lib/ansible/modules/network/cnos/cnos_vlag.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -250,9 +252,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -297,6 +302,8 @@ def main(): 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() diff --git a/lib/ansible/modules/network/lenovo/cnos_vlan.py b/lib/ansible/modules/network/cnos/cnos_vlan.py similarity index 97% rename from lib/ansible/modules/network/lenovo/cnos_vlan.py rename to lib/ansible/modules/network/cnos/cnos_vlan.py index f791ef1cd32..22bd452b937 100644 --- a/lib/ansible/modules/network/lenovo/cnos_vlan.py +++ b/lib/ansible/modules/network/cnos/cnos_vlan.py @@ -1,5 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # # Copyright (C) 2017 Lenovo, Inc. # @@ -189,9 +191,12 @@ msg: ''' import sys -import paramiko +try: + import paramiko + HAS_PARAMIKO = True +except ImportError: + HAS_PARAMIKO = False import time -import argparse import socket import array import json @@ -207,6 +212,7 @@ except: from ansible.module_utils.basic import AnsibleModule from collections import defaultdict + def main(): # # Define parameters for vlan creation entry @@ -239,6 +245,8 @@ def main(): 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() diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 489adf0b6d2..4fb26669071 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -189,9 +189,6 @@ lib/ansible/modules/network/iosxr/iosxr_command.py lib/ansible/modules/network/iosxr/iosxr_config.py lib/ansible/modules/network/iosxr/iosxr_facts.py lib/ansible/modules/network/iosxr/iosxr_system.py -lib/ansible/modules/network/lenovo/cnos_conditional_template.py -lib/ansible/modules/network/lenovo/cnos_template.py -lib/ansible/modules/network/lenovo/cnos_vlan.py lib/ansible/modules/network/netvisor/pn_cluster.py lib/ansible/modules/network/netvisor/pn_ospfarea.py lib/ansible/modules/network/netvisor/pn_vlag.py