# 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

    @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"])
    def connect(self, host, userid, password=None, ssh_key_string=None):
        _method_ = "MLNXOSPlugin.connect"
        self.host = host
        self.userid = userid
        try:
            self.client = paramiko.SSHClient()
            self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            if ssh_key_string:
                private_key = paramiko.RSAKey.from_private_key(StringIO(ssh_key_string), password)
                self.client.connect(host, username=userid, pkey=private_key, timeout=30,
                                    allow_agent=False)
            else:
                self.client.connect(host, username=userid, password=password, timeout=30,
                                    allow_agent=False)
            if not self._is_mellanox_switch():
                raise exceptions.InvalidDeviceException(
                    "Device is not a Mellanox Switch")
        except paramiko.AuthenticationException:
            logging.error("%s::userid/password combination not valid. host=%s userid=%s",
                          _method_, host, userid)

# 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/mellanox/opsmgr/plugins/devices/mellanox/MLNXOSManagerPlugin.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


    @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"])
    def connect(self, host, userid, password=None, ssh_key_string=None):
        _method_ = "MLNXOSPlugin.connect"
        self.host = host
        self.userid = userid
        try:
            self.client = paramiko.SSHClient()
            self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            if ssh_key_string:
                private_key = paramiko.RSAKey.from_private_key(StringIO(ssh_key_string), password)
                self.client.connect(host, username=userid, pkey=private_key, timeout=30,
                                    allow_agent=False)
            else:
                self.client.connect(host, username=userid, password=password, timeout=30,
                                    allow_agent=False)
            if not self._is_mellanox_switch():
                raise exceptions.InvalidDeviceException(
                    "Device is not a Mellanox Switch")
        except paramiko.AuthenticationException:
            logging.error("%s::userid/password combination not valid. host=%s userid=%s",
                          _method_, host, userid)

            raise exceptions.AuthenticationException(