# Path: mongoctl/utils.py
# def resolve_path(path):
#     # handle file uris
#     path = path.replace("file://", "")
# 
#     # expand vars
#     path =  os.path.expandvars(custom_expanduser(path))
#     # Turn relative paths to absolute
#     try:
#         path = os.path.abspath(path)
#     except OSError, e:
#         # handle the case where cwd does not exist
#         if "No such file or directory" in str(e):
#             pass
#         else:
#             raise
# 
#     return path
# 
# def system_memory_size_gbs():
#     """
#     credit https://stackoverflow.com/questions/22102999/get-total-physical-memory-in-python
#     :return: total system memory size in gbs
#     """
# 
#     mem_bytes = psutil.virtual_memory().total
#     return mem_bytes/(1024.**3)
# 
# Path: mongoctl/mongoctl_logging.py
# def log_verbose(msg):
#     get_logger().log(VERBOSE, msg)
# 
# def log_debug(msg):
#     get_logger().debug(msg)
# 
# def log_exception(exception):
#     log_debug("EXCEPTION: %s" % exception)
#     log_debug(traceback.format_exc())
# 
# def log_warning(msg):
#     get_logger().warning(msg)
# 
# def log_info(msg):
#     get_logger().info(msg)
# 
# Path: mongoctl/errors.py
# class MongoctlException(Exception):
#     def __init__(self, message, cause=None):
#         super(MongoctlException, self).__init__(message)
#         self._cause = cause
# 
# Path: mongoctl/mongodb_version.py
# def make_version_info(version_number, edition=None):
#     if version_number is None:
#         return None
# 
#     version_number = version_number.strip()
#     version_number = version_number.replace("-pre-" , "-pre")
#     version_info = MongoDBVersionInfo(version_number, edition=edition)
# 
#     # validate version string
#     if not is_valid_version_info(version_info):
#         raise MongoctlException("Invalid version '%s." % version_info)
#     else:
#         return version_info


import server
from mongoctl.utils import resolve_path, system_memory_size_gbs
from mongoctl.mongoctl_logging import log_verbose, log_debug, log_exception, \
    log_warning, log_info
from bson.son import SON
from mongoctl.errors import MongoctlException
from replicaset_cluster import ReplicaSetCluster, get_member_repl_lag
from sharded_cluster import ShardedCluster
from mongoctl.mongodb_version import make_version_info
    def is_wired_tiger(self):
        version = self.get_mongo_version_info()
        storage_engine = self.get_cmd_option("storageEngine")

        if version >= make_version_info("3.2.0"):
            return not storage_engine or storage_engine == "wiredTiger"
        elif version >= make_version_info("3.0.0"):
            return storage_engine == "wiredTiger"

    ###########################################################################
    def set_runtime_parameters(self):
        params = self.generate_runtime_parameters()

        if params:
            for name, val in params.items():
                self.set_runtime_parameter_cmd(name, val)

            # verify that params were applied properly
            self.verify_runtime_parameters()

    ###########################################################################
    def verify_runtime_parameters(self):
        log_info("Verifying runtime params...")
        wtcs_gb = self.get_cmd_option("wiredTigerCacheSizeGB")
        if wtcs_gb is not None and isinstance(wtcs_gb, float):
            wtcs_bytes = int(wtcs_gb * 1024 * 1024 * 1024)
            server_status = self.server_status()
            if not(server_status and "wiredTiger" in server_status and "cache" in server_status["wiredTiger"] and
                           "maximum bytes configured" in server_status["wiredTiger"]["cache"] and
                           server_status["wiredTiger"]["cache"]["maximum bytes configured"] == wtcs_bytes):

# Path: mongoctl/utils.py
# def resolve_path(path):
#     # handle file uris
#     path = path.replace("file://", "")
# 
#     # expand vars
#     path =  os.path.expandvars(custom_expanduser(path))
#     # Turn relative paths to absolute
#     try:
#         path = os.path.abspath(path)
#     except OSError, e:
#         # handle the case where cwd does not exist
#         if "No such file or directory" in str(e):
#             pass
#         else:
#             raise
# 
#     return path
# 
# def system_memory_size_gbs():
#     """
#     credit https://stackoverflow.com/questions/22102999/get-total-physical-memory-in-python
#     :return: total system memory size in gbs
#     """
# 
#     mem_bytes = psutil.virtual_memory().total
#     return mem_bytes/(1024.**3)
# 
# Path: mongoctl/mongoctl_logging.py
# def log_verbose(msg):
#     get_logger().log(VERBOSE, msg)
# 
# def log_debug(msg):
#     get_logger().debug(msg)
# 
# def log_exception(exception):
#     log_debug("EXCEPTION: %s" % exception)
#     log_debug(traceback.format_exc())
# 
# def log_warning(msg):
#     get_logger().warning(msg)
# 
# def log_info(msg):
#     get_logger().info(msg)
# 
# Path: mongoctl/errors.py
# class MongoctlException(Exception):
#     def __init__(self, message, cause=None):
#         super(MongoctlException, self).__init__(message)
#         self._cause = cause
# 
# Path: mongoctl/mongodb_version.py
# def make_version_info(version_number, edition=None):
#     if version_number is None:
#         return None
# 
#     version_number = version_number.strip()
#     version_number = version_number.replace("-pre-" , "-pre")
#     version_info = MongoDBVersionInfo(version_number, edition=edition)
# 
#     # validate version string
#     if not is_valid_version_info(version_info):
#         raise MongoctlException("Invalid version '%s." % version_info)
#     else:
#         return version_info


# Path: mongoctl/objects/mongod.py
import server
from mongoctl.utils import resolve_path, system_memory_size_gbs
from mongoctl.mongoctl_logging import log_verbose, log_debug, log_exception, \
    log_warning, log_info
from bson.son import SON
from mongoctl.errors import MongoctlException
from replicaset_cluster import ReplicaSetCluster, get_member_repl_lag
from sharded_cluster import ShardedCluster
from mongoctl.mongodb_version import make_version_info

    def is_wired_tiger(self):
        version = self.get_mongo_version_info()
        storage_engine = self.get_cmd_option("storageEngine")

        if version >= make_version_info("3.2.0"):
            return not storage_engine or storage_engine == "wiredTiger"
        elif version >= make_version_info("3.0.0"):
            return storage_engine == "wiredTiger"

    ###########################################################################
    def set_runtime_parameters(self):
        params = self.generate_runtime_parameters()

        if params:
            for name, val in params.items():
                self.set_runtime_parameter_cmd(name, val)

            # verify that params were applied properly
            self.verify_runtime_parameters()

    ###########################################################################
    def verify_runtime_parameters(self):
        log_info("Verifying runtime params...")
        wtcs_gb = self.get_cmd_option("wiredTigerCacheSizeGB")
        if wtcs_gb is not None and isinstance(wtcs_gb, float):
            wtcs_bytes = int(wtcs_gb * 1024 * 1024 * 1024)
            server_status = self.server_status()
            if not(server_status and "wiredTiger" in server_status and "cache" in server_status["wiredTiger"] and
                           "maximum bytes configured" in server_status["wiredTiger"]["cache"] and
                           server_status["wiredTiger"]["cache"]["maximum bytes configured"] == wtcs_bytes):

                raise MongoctlException("CONFIG ERROR: wiredTigerCacheSizeGB was not applied")