# Path: opsmgr/common/exceptions.py
# class OpsException(Exception):
# class ConnectionException(OpsException):
# class AuthenticationException(OpsException):
# class DeviceException(OpsException):
# class InvalidDeviceException(DeviceException):
# class ProviderException(OpsException):
# 
# Path: opsmgr/common/utils.py
# def entry_exit(exclude_index=None, exclude_name=None, log_name=None, level=logging.INFO):
#     """
#     it's a decorator that to add entry and exit log for a function
# 
#     input:
#     excludeIndex -- the index of params that you don't want to be record
#     excludeName -- the name of dictionary params that you don't wnat to be record
#     log_name -- name of the log to write the logging to.
#     level -- the logging level to log the entry/exit with.  default is INFO level
#     """
# 
#     def f(func):
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
# 
#             args_for_print = []
#             tmp_index = 0
#             arg_len = len(args)
#             while tmp_index < arg_len:
#                 if tmp_index not in exclude_index:
#                     args_for_print.append(args[tmp_index])
#                 tmp_index += 1
# 
#             kwargs_for_print = {}
#             for a in kwargs:
#                 if a in exclude_name:
#                     continue
#                 else:
#                     kwargs_for_print[a] = kwargs[a]
# 
#             logging.getLogger(log_name).log(level,
#                                             "%s::Entry params %s %s", func.__name__, "{}".format(
#                                                 args_for_print), "{}".format(kwargs_for_print))
#             result = func(*args, **kwargs)
#             logging.getLogger(log_name).log(level,
#                                             "%s::Exit %s ", func.__name__, "{}".format(result))
#             return result
#         return wrapper
#     return f


import logging
import socket
import time
import paramiko
    from StringIO import StringIO
    from io import StringIO
from opsmgr.common import constants
from opsmgr.common import exceptions
from opsmgr.common.utils import entry_exit
from opsmgr.inventory.interfaces import IManagerDevicePlugin
    SERIAL_NUM_TAG = "Switch Serial"
    MTM_TAG = "MTM Value"

    ENABLE_COMMAND = "enable\n"
    PASSWORD_CHANGE_COMMAND = "password\n"

    PASSWORD_CHANGED_MESSAGE = "Password changed and applied"

    def __init__(self):
        self.client = None
        self.host = None
        self.userid = None
        self.password = None
        self.ssh_key_string = None
        self.machine_type_model = ""
        self.serial_number = ""
        self.version = ""

    @staticmethod
    def get_type():
        return "LenovoRackSwitch"

    @staticmethod
    def get_web_url(host):
        return "https://" + host

    @staticmethod
    def get_capabilities():
        return [constants.MONITORING_CAPABLE]


# Path: opsmgr/common/exceptions.py
# class OpsException(Exception):
# class ConnectionException(OpsException):
# class AuthenticationException(OpsException):
# class DeviceException(OpsException):
# class InvalidDeviceException(DeviceException):
# class ProviderException(OpsException):
# 
# Path: opsmgr/common/utils.py
# def entry_exit(exclude_index=None, exclude_name=None, log_name=None, level=logging.INFO):
#     """
#     it's a decorator that to add entry and exit log for a function
# 
#     input:
#     excludeIndex -- the index of params that you don't want to be record
#     excludeName -- the name of dictionary params that you don't wnat to be record
#     log_name -- name of the log to write the logging to.
#     level -- the logging level to log the entry/exit with.  default is INFO level
#     """
# 
#     def f(func):
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
# 
#             args_for_print = []
#             tmp_index = 0
#             arg_len = len(args)
#             while tmp_index < arg_len:
#                 if tmp_index not in exclude_index:
#                     args_for_print.append(args[tmp_index])
#                 tmp_index += 1
# 
#             kwargs_for_print = {}
#             for a in kwargs:
#                 if a in exclude_name:
#                     continue
#                 else:
#                     kwargs_for_print[a] = kwargs[a]
# 
#             logging.getLogger(log_name).log(level,
#                                             "%s::Entry params %s %s", func.__name__, "{}".format(
#                                                 args_for_print), "{}".format(kwargs_for_print))
#             result = func(*args, **kwargs)
#             logging.getLogger(log_name).log(level,
#                                             "%s::Exit %s ", func.__name__, "{}".format(result))
#             return result
#         return wrapper
#     return f


# Path: plugins/devices/lenovo/opsmgr/plugins/devices/lenovo/LenovoRackSwitchPlugin.py
import logging
import socket
import time
import paramiko
    from StringIO import StringIO
    from io import StringIO
from opsmgr.common import constants
from opsmgr.common import exceptions
from opsmgr.common.utils import entry_exit
from opsmgr.inventory.interfaces import IManagerDevicePlugin

    SERIAL_NUM_TAG = "Switch Serial"
    MTM_TAG = "MTM Value"

    ENABLE_COMMAND = "enable\n"
    PASSWORD_CHANGE_COMMAND = "password\n"

    PASSWORD_CHANGED_MESSAGE = "Password changed and applied"

    def __init__(self):
        self.client = None
        self.host = None
        self.userid = None
        self.password = None
        self.ssh_key_string = None
        self.machine_type_model = ""
        self.serial_number = ""
        self.version = ""

    @staticmethod
    def get_type():
        return "LenovoRackSwitch"

    @staticmethod
    def get_web_url(host):
        return "https://" + host

    @staticmethod
    def get_capabilities():
        return [constants.MONITORING_CAPABLE]


    @entry_exit(exclude_index=[0, 3, 4], exclude_name=["self", "password", "ssh_key_string"])