# Path: crmsh/constants.py
# SSH_OPTION = "-o StrictHostKeyChecking=no"


import os
import sys
import subprocess
import re
import glob
import time
import datetime
import shutil
import shlex
import bz2
import fnmatch
import gc
import ipaddress
import argparse
import random
import string
            import traceback
        import pwd
        import grp
    import tempfile
    import traceback
    import inspect
        import curses
    import dateutil
    import dateutil.tz
    import configparser
    import configparser
    import socket
        import parallax
        import parallax
        import parallax
        import parallax
    import hashlib
        import parallax
        import urllib2 as urllib
        import urllib.request as urllib
    import socket
from tempfile import mkstemp
from pathlib import Path
from contextlib import contextmanager, closing
from stat import S_ISBLK
from lxml import etree
from . import config
from . import userdir
from . import constants
from . import options
from . import term
from . import parallax
from distutils.version import LooseVersion
from .constants import SSH_OPTION
from . import log
        from pwd import getpwnam
    from os.path import join, basename
    from math import ceil
        from dateutil import parser, tz
        from dateutil import parser, tz
    from . import xmlutil
    from . import tmpfiles
    from . import corosync
    from . import corosync
    from . import bootstrap
    from . import sbd
    from .cibconfig import cib_factory
    from . import xmlutil
    from . import xmlutil
    from .cibconfig import cib_factory
        # check on remote
        prompt_msg = "Check whether {} is installed on {}".format(pkg, remote_addr)
        rc, _, _ = run_cmd_on_remote(cmd, remote_addr, prompt_msg)
    else:
        # check on local
        rc, _ = get_stdout(cmd)
    return rc == 0


def ping_node(node):
    """
    Check if the remote node is reachable
    """
    rc, _, err = get_stdout_stderr("ping -c 1 {}".format(node))
    if rc != 0:
        raise ValueError("host \"{}\" is unreachable: {}".format(node, err))


def calculate_quorate_status(expected_votes, actual_votes):
    """
    Given expected votes and actual votes, calculate if is quorated
    """
    return int(actual_votes)/int(expected_votes) > 0.5


def get_stdout_or_raise_error(cmd, remote=None, success_val_list=[0], no_raise=False):
    """
    Common function to get stdout from cmd or raise exception
    """
    if remote:

# Path: crmsh/constants.py
# SSH_OPTION = "-o StrictHostKeyChecking=no"


# Path: crmsh/utils.py
import os
import sys
import subprocess
import re
import glob
import time
import datetime
import shutil
import shlex
import bz2
import fnmatch
import gc
import ipaddress
import argparse
import random
import string
            import traceback
        import pwd
        import grp
    import tempfile
    import traceback
    import inspect
        import curses
    import dateutil
    import dateutil.tz
    import configparser
    import configparser
    import socket
        import parallax
        import parallax
        import parallax
        import parallax
    import hashlib
        import parallax
        import urllib2 as urllib
        import urllib.request as urllib
    import socket
from tempfile import mkstemp
from pathlib import Path
from contextlib import contextmanager, closing
from stat import S_ISBLK
from lxml import etree
from . import config
from . import userdir
from . import constants
from . import options
from . import term
from . import parallax
from distutils.version import LooseVersion
from .constants import SSH_OPTION
from . import log
        from pwd import getpwnam
    from os.path import join, basename
    from math import ceil
        from dateutil import parser, tz
        from dateutil import parser, tz
    from . import xmlutil
    from . import tmpfiles
    from . import corosync
    from . import corosync
    from . import bootstrap
    from . import sbd
    from .cibconfig import cib_factory
    from . import xmlutil
    from . import xmlutil
    from .cibconfig import cib_factory

        # check on remote
        prompt_msg = "Check whether {} is installed on {}".format(pkg, remote_addr)
        rc, _, _ = run_cmd_on_remote(cmd, remote_addr, prompt_msg)
    else:
        # check on local
        rc, _ = get_stdout(cmd)
    return rc == 0


def ping_node(node):
    """
    Check if the remote node is reachable
    """
    rc, _, err = get_stdout_stderr("ping -c 1 {}".format(node))
    if rc != 0:
        raise ValueError("host \"{}\" is unreachable: {}".format(node, err))


def calculate_quorate_status(expected_votes, actual_votes):
    """
    Given expected votes and actual votes, calculate if is quorated
    """
    return int(actual_votes)/int(expected_votes) > 0.5


def get_stdout_or_raise_error(cmd, remote=None, success_val_list=[0], no_raise=False):
    """
    Common function to get stdout from cmd or raise exception
    """
    if remote:

        cmd = "ssh {} root@{} \"{}\"".format(SSH_OPTION, remote, cmd)