# 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
# 
# def load_plugin_by_namespace(namespace):
#     plugins = {}
#     extensions = extension.ExtensionManager(namespace=namespace)
# 
#     for ext in extensions:
#         plugins[ext.name] = ext.plugin()
#     return plugins


import logging
from opsmgr.common.utils import entry_exit, load_plugin_by_namespace


@entry_exit(exclude_index=[], exclude_name=[])
def _load_plugins():
    """ Find the discovery provider plugins and return them as
        dictonary[name]=plugin class
    """
    return load_plugin_by_namespace(I_DISCOVERY_PLUGIN)


@entry_exit(exclude_index=[], exclude_name=[])
def list_plugins():
    return sorted(_load_plugins().keys())


@entry_exit(exclude_index=[], exclude_name=[])
def find_resources():
    plugins = _load_plugins()
    plugin_label = 'unknown'  # keeps pylint happy
    message = None
    try:
        for plugin_label, plugin in plugins.items():
            plugin.find_resources()
    except Exception as e:
        logging.exception(e)
        message = _("Error in plugin (%s)::Unable to find resources - reason::%s") % (plugin_label, e)
        return -1, message
    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
# 
# def load_plugin_by_namespace(namespace):
#     plugins = {}
#     extensions = extension.ExtensionManager(namespace=namespace)
# 
#     for ext in extensions:
#         plugins[ext.name] = ext.plugin()
#     return plugins


# Path: opsmgr/discovery/discovery_mgr.py
import logging
from opsmgr.common.utils import entry_exit, load_plugin_by_namespace



@entry_exit(exclude_index=[], exclude_name=[])
def _load_plugins():
    """ Find the discovery provider plugins and return them as
        dictonary[name]=plugin class
    """
    return load_plugin_by_namespace(I_DISCOVERY_PLUGIN)


@entry_exit(exclude_index=[], exclude_name=[])
def list_plugins():
    return sorted(_load_plugins().keys())


@entry_exit(exclude_index=[], exclude_name=[])
def find_resources():
    plugins = _load_plugins()
    plugin_label = 'unknown'  # keeps pylint happy
    message = None
    try:
        for plugin_label, plugin in plugins.items():
            plugin.find_resources()
    except Exception as e:
        logging.exception(e)
        message = _("Error in plugin (%s)::Unable to find resources - reason::%s") % (plugin_label, e)
        return -1, message
    return 0, message



@entry_exit(exclude_index=[], exclude_name=[])