# 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 select
import socket
import sys
import termios
import tty
import paramiko
    from StringIO import StringIO
    from io import StringIO
from paramiko.py3compat import u
from opsmgr.inventory import persistent_mgr
from opsmgr.common.utils import entry_exit
        if key:
            ssh_key_string = StringIO(key.value)
            if key.password:
                password = persistent_mgr.decrypt_data(key.password)
        logging.info(
            "%s::Retrieved device details. Opening remote shell to the device (%s).",
            _method_, label)
        try:
            print(_(
                "Establishing remote SSH connection to device (%s).") % label)
            _create_remote_connection(label, address, userid, password, ssh_key_string)
        except Exception as e:
            message = _("Remote access to device (%s) failed due to error :%s") % (
                label, e)
            logging.warning(
                "%s::Failed to connect to device (%s) failed due to error :%s", _method_, label, e)
            return 1, message
    else:
        message = _(
            "Device (%s) not found.") % label
        logging.warning(
            "%s::Device (%s) not found.", _method_, label)
        return 1, message
    logging.info(
        "%s::Remote access to device (%s) successful", _method_, label)
    message = _("Remote access to device (%s) successful") % label
    session.close()
    return 0, message



# 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: opsmgr/inventory/remote_access.py
import logging
import select
import socket
import sys
import termios
import tty
import paramiko
    from StringIO import StringIO
    from io import StringIO
from paramiko.py3compat import u
from opsmgr.inventory import persistent_mgr
from opsmgr.common.utils import entry_exit

        if key:
            ssh_key_string = StringIO(key.value)
            if key.password:
                password = persistent_mgr.decrypt_data(key.password)
        logging.info(
            "%s::Retrieved device details. Opening remote shell to the device (%s).",
            _method_, label)
        try:
            print(_(
                "Establishing remote SSH connection to device (%s).") % label)
            _create_remote_connection(label, address, userid, password, ssh_key_string)
        except Exception as e:
            message = _("Remote access to device (%s) failed due to error :%s") % (
                label, e)
            logging.warning(
                "%s::Failed to connect to device (%s) failed due to error :%s", _method_, label, e)
            return 1, message
    else:
        message = _(
            "Device (%s) not found.") % label
        logging.warning(
            "%s::Device (%s) not found.", _method_, label)
        return 1, message
    logging.info(
        "%s::Remote access to device (%s) successful", _method_, label)
    message = _("Remote access to device (%s) successful") % label
    session.close()
    return 0, message



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