# Path: opsmgr/inventory/interfaces/IOperationsPlugin.py
# class IOperationsPlugin(object):
#     __metaclass__ = ABCMeta
# 
#     @staticmethod
#     @abstractmethod
#     def get_application_url():
#         pass
# 
#     @staticmethod
#     @abstractmethod
#     def get_plugins_status():
#         pass
# 
# Path: opsmgr/inventory/plugins.py
# I_OPERATIONS_PLUGINS = "opsmgr.inventory.interfaces.IOperationsPlugin"
# class PluginApplication():
#     def __init__(self, name, function, protocol, host, port, path):
#     def get_name(self):
#     def get_function(self):
#     def get_protocol(self):
#     def get_host(self):
#     def get_port(self):
#     def get_path(self):
#     def get_operations_plugins():
#     def get_plugins_status():
#     def _load_operations_plugins():
# 
# 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 os
import paramiko
from backports import configparser
from opsmgr.inventory.interfaces.IManagerDeviceHook import IManagerDeviceHook
from opsmgr.inventory.interfaces.IOperationsPlugin import IOperationsPlugin
from opsmgr.inventory import plugins
from opsmgr.common import exceptions
from opsmgr.common.utils import entry_exit
            (_stdin, stdout, _stderr) = client.exec_command(GangliaPlugin.VERIFY_COMMAND)
            rc = stdout.channel.recv_exit_status()
            output = stdout.read().decode()
            if rc != 0:
                raise exceptions.OpsException("Validation of the gmetad configuration failed:\n"
                                              "Command: " + GangliaPlugin.VERIFY_COMMAND + "\n"
                                              "Output: " + output + "\n")
            # Reload gmetad service
            (_stdin, stdout, _stderr) = client.exec_command(GangliaPlugin.RELOAD_COMMAND)
            rc = stdout.channel.recv_exit_status()
            output = stdout.read().decode()
            if rc != 0:
                raise exceptions.OpsException("service reload of gmetad failed:\n"
                                              "Command: " + GangliaPlugin.RELOAD_COMMAND + "\n"
                                              "Output: " + output + "\n")
        finally:
            client.close()

    @staticmethod
    @entry_exit(exclude_index=[], exclude_name=[])
    def _write_gmetad_config_file(address):
        try:
            client = GangliaPlugin._connect()
            cmd = ("cat /etc/ganglia/gmetad.conf |grep " + address + "; if [ $? == 1 ]; then " +
                   "sudo sed -i 's/localhost[[:space:]]*$/" + address +
                   " &/' /etc/ganglia/gmetad.conf; service gmetad restart; fi")
            (_stdin, stdout, _stderr) = client.exec_command(cmd)
            rc = stdout.channel.recv_exit_status()
            output = stdout.read().decode()
            if rc != 0:

# Path: opsmgr/inventory/interfaces/IOperationsPlugin.py
# class IOperationsPlugin(object):
#     __metaclass__ = ABCMeta
# 
#     @staticmethod
#     @abstractmethod
#     def get_application_url():
#         pass
# 
#     @staticmethod
#     @abstractmethod
#     def get_plugins_status():
#         pass
# 
# Path: opsmgr/inventory/plugins.py
# I_OPERATIONS_PLUGINS = "opsmgr.inventory.interfaces.IOperationsPlugin"
# class PluginApplication():
#     def __init__(self, name, function, protocol, host, port, path):
#     def get_name(self):
#     def get_function(self):
#     def get_protocol(self):
#     def get_host(self):
#     def get_port(self):
#     def get_path(self):
#     def get_operations_plugins():
#     def get_plugins_status():
#     def _load_operations_plugins():
# 
# 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/operations/ganglia/opsmgr/plugins/operations/ganglia/GangliaOperationsPlugin.py
import os
import paramiko
from backports import configparser
from opsmgr.inventory.interfaces.IManagerDeviceHook import IManagerDeviceHook
from opsmgr.inventory.interfaces.IOperationsPlugin import IOperationsPlugin
from opsmgr.inventory import plugins
from opsmgr.common import exceptions
from opsmgr.common.utils import entry_exit

            (_stdin, stdout, _stderr) = client.exec_command(GangliaPlugin.VERIFY_COMMAND)
            rc = stdout.channel.recv_exit_status()
            output = stdout.read().decode()
            if rc != 0:
                raise exceptions.OpsException("Validation of the gmetad configuration failed:\n"
                                              "Command: " + GangliaPlugin.VERIFY_COMMAND + "\n"
                                              "Output: " + output + "\n")
            # Reload gmetad service
            (_stdin, stdout, _stderr) = client.exec_command(GangliaPlugin.RELOAD_COMMAND)
            rc = stdout.channel.recv_exit_status()
            output = stdout.read().decode()
            if rc != 0:
                raise exceptions.OpsException("service reload of gmetad failed:\n"
                                              "Command: " + GangliaPlugin.RELOAD_COMMAND + "\n"
                                              "Output: " + output + "\n")
        finally:
            client.close()

    @staticmethod
    @entry_exit(exclude_index=[], exclude_name=[])
    def _write_gmetad_config_file(address):
        try:
            client = GangliaPlugin._connect()
            cmd = ("cat /etc/ganglia/gmetad.conf |grep " + address + "; if [ $? == 1 ]; then " +
                   "sudo sed -i 's/localhost[[:space:]]*$/" + address +
                   " &/' /etc/ganglia/gmetad.conf; service gmetad restart; fi")
            (_stdin, stdout, _stderr) = client.exec_command(cmd)
            rc = stdout.channel.recv_exit_status()
            output = stdout.read().decode()
            if rc != 0:

                raise exceptions.OpsException("Error when change gmetad config file:\n"