# Path: crmsh/constants.py
# SSH_OPTION = "-o StrictHostKeyChecking=no"
# 
# Path: crmsh/bootstrap.py
# def invoke(*args):
#     """
#     Log command execution to log file.
#     Log output from command to log file.
#     Return (boolean, stdout, stderr)
#     """
#     logger_utils.log_only_to_file("invoke: " + " ".join(args))
#     rc, stdout, stderr = utils.get_stdout_stderr(" ".join(args))
#     if stdout:
#         logger_utils.log_only_to_file("stdout: {}".format(stdout))
#     if stderr:
#         logger_utils.log_only_to_file("stderr: {}".format(stderr))
#     return rc == 0, stdout, stderr
# 
# def invokerc(*args):
#     """
#     Calling invoke, return True/False
#     """
#     rc, _, _ = invoke(*args)
#     return rc
# 
# WATCHDOG_CFG = "/etc/modules-load.d/watchdog.conf"
# 
# SYSCONFIG_SBD = "/etc/sysconfig/sbd"


import re
from . import utils
from .constants import SSH_OPTION
from .bootstrap import invoke, invokerc, WATCHDOG_CFG, SYSCONFIG_SBD
        """
        _, out, _ = utils.get_stdout_stderr("lsmod")
        return re.search("\n{}\s+".format(driver), out)

    def _set_watchdog_info(self):
        """
        Set watchdog info through sbd query-watchdog command
        Content in self._watchdog_info_dict: {device_name: driver_name}
        """
        rc, out, err = utils.get_stdout_stderr(self.QUERY_CMD)
        if rc == 0 and out:
            # output format might like:
            #   [1] /dev/watchdog\nIdentity: Software Watchdog\nDriver: softdog\n
            self._watchdog_info_dict = dict(re.findall(self.DEVICE_FIND_REGREX, out))
        else:
            utils.fatal("Failed to run {}: {}".format(self.QUERY_CMD, err))

    def _get_device_through_driver(self, driver_name):
        """
        Get watchdog device name which has driver_name
        """
        for device, driver in self._watchdog_info_dict.items():
            if driver == driver_name and self._verify_watchdog_device(device):
                return device
        return None

    def _get_driver_through_device_remotely(self, dev_name):
        """
        Given watchdog device name, get driver name on remote node
        """

# Path: crmsh/constants.py
# SSH_OPTION = "-o StrictHostKeyChecking=no"
# 
# Path: crmsh/bootstrap.py
# def invoke(*args):
#     """
#     Log command execution to log file.
#     Log output from command to log file.
#     Return (boolean, stdout, stderr)
#     """
#     logger_utils.log_only_to_file("invoke: " + " ".join(args))
#     rc, stdout, stderr = utils.get_stdout_stderr(" ".join(args))
#     if stdout:
#         logger_utils.log_only_to_file("stdout: {}".format(stdout))
#     if stderr:
#         logger_utils.log_only_to_file("stderr: {}".format(stderr))
#     return rc == 0, stdout, stderr
# 
# def invokerc(*args):
#     """
#     Calling invoke, return True/False
#     """
#     rc, _, _ = invoke(*args)
#     return rc
# 
# WATCHDOG_CFG = "/etc/modules-load.d/watchdog.conf"
# 
# SYSCONFIG_SBD = "/etc/sysconfig/sbd"


# Path: crmsh/watchdog.py
import re
from . import utils
from .constants import SSH_OPTION
from .bootstrap import invoke, invokerc, WATCHDOG_CFG, SYSCONFIG_SBD

        """
        _, out, _ = utils.get_stdout_stderr("lsmod")
        return re.search("\n{}\s+".format(driver), out)

    def _set_watchdog_info(self):
        """
        Set watchdog info through sbd query-watchdog command
        Content in self._watchdog_info_dict: {device_name: driver_name}
        """
        rc, out, err = utils.get_stdout_stderr(self.QUERY_CMD)
        if rc == 0 and out:
            # output format might like:
            #   [1] /dev/watchdog\nIdentity: Software Watchdog\nDriver: softdog\n
            self._watchdog_info_dict = dict(re.findall(self.DEVICE_FIND_REGREX, out))
        else:
            utils.fatal("Failed to run {}: {}".format(self.QUERY_CMD, err))

    def _get_device_through_driver(self, driver_name):
        """
        Get watchdog device name which has driver_name
        """
        for device, driver in self._watchdog_info_dict.items():
            if driver == driver_name and self._verify_watchdog_device(device):
                return device
        return None

    def _get_driver_through_device_remotely(self, dev_name):
        """
        Given watchdog device name, get driver name on remote node
        """

        cmd = "ssh {} root@{} {}".format(SSH_OPTION, self._peer_host, self.QUERY_CMD)