nrmd 4.86 KB
Newer Older
1 2
#!/usr/bin/env python2

3 4 5 6 7 8 9 10 11 12
###############################################################################
# Copyright 2019 UChicago Argonne, LLC.
# (c.f. AUTHORS, LICENSE)
#
# This file is part of the NRM project.
# For more info, see https://xgitlab.cels.anl.gov/argo/nrm
#
# SPDX-License-Identifier: BSD-3-Clause
###############################################################################

13 14 15
import argparse
import json
import sys
16 17
import nrm
import nrm.daemon
18 19
import os

20

21
def main(argv=None):
22 23
    if argv is None:
        argv = sys.argv
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    conf_parser = argparse.ArgumentParser(
      description=__doc__,
      formatter_class=argparse.RawDescriptionHelpFormatter,
      add_help=False
      )
    conf_parser.add_argument(
            "-c",
            "--configuration",
            help="Specify a config json-formatted config file to override "
                 "any of the available CLI options. If an option is "
                 "actually provided on the command-line, it overrides "
                 "its corresponding value from the configuration file.",
            metavar="FILE")
    conf_parser.add_argument("-d", "--print_defaults", action='store_true',
                             help="Print the default configuration file.")
    args, remaining_argv = conf_parser.parse_known_args()
41

42 43 44
    defaults = {"nrm_log": "/tmp/nrm.log",
                "hwloc": "hwloc",
                "perf": "perf",
45
                "argo_perf_wrapper": "nrm-perfwrapper",
46 47
                "argo_nodeos_config": "argo_nodeos_config",
                "pmpi_lib": "/usr/lib/libnrm-pmpi.so",
48 49
                "singularity": "singularity",
                "container_runtime": "nodeos",
50
                }
51

52 53 54
    if args.print_defaults:
        print defaults
        return(0)
55

56 57 58 59 60
    if args.configuration:
        defaults.update(json.load(open(args.configuration)))

    parser = argparse.ArgumentParser(parents=[conf_parser])
    parser.set_defaults(**defaults)
61 62
    parser.add_argument("-v", "--verbose", help="increase output verbosity",
                        action="store_true")
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    parser.add_argument(
           "--nrm_log",
           help="Main log file. Override default with the NRM_LOG."
                "environment variable",
           default=os.environ.get('NRM_LOG',
                                  '/tmp/nrm.log'))
    parser.add_argument(
            '--hwloc',
            help="Path to the hwloc to use. This path can be "
                 "relative and makes uses of the $PATH if necessary."
                 "Override default with the HWLOC environment"
                 "variable.",
            default=os.environ.get('HWLOC',
                                   'hwloc'))
    parser.add_argument(
            '--argo_nodeos_config',
            help="Path to the argo_nodeos_config to use. This path "
                 "can be relative and makes uses of the $PATH if "
                 "necessary. Override default with the "
                 "ARGO_NODEOS_CONFIG environment variable.",
            default=os.environ.get('ARGO_NODEOS_CONFIG',
                                   'argo_nodeos_config'))
    parser.add_argument(
            '--perf',
            help="Path to the linux perf tool to use. This path can be"
                 "relative and makes uses of the $PATH if necessary."
                 "Override default with the PERF environment"
                 "variable.",
            default=os.environ.get('PERF',
                                   'perf'))
93 94 95 96 97
    parser.add_argument(
            '--pmpi_lib',
            help="Path to the libnrm PMPI library used for the power policy"
                 "Override default with the PMPI environment variable.",
            default=os.environ.get('PMPI', defaults['pmpi_lib']))
98 99 100 101 102 103 104
    parser.add_argument(
            '--argo_perf_wrapper',
            help="Path to the linux perf tool to use. This path can"
                 "be relative and makes uses of the $PATH if "
                 "necessary. Override default with the PERFWRAPPER "
                 "environment variable.",
            default=os.environ.get('ARGO_PERF_WRAPPER',
105
                                   'nrm-perfwrapper'))
106 107 108 109 110 111 112 113 114 115 116 117 118 119
    parser.add_argument(
            '--singularity',
            help="Path to the singularity command. "
                 "Override default with the SINGULARITY environment variable.",
            default=os.environ.get('SINGULARITY', defaults['singularity']))
    parser.add_argument(
            '--container-runtime',
            help="Choice of container runtime. "
                 "Override default with the ARGO_CONTAINER_RUNTIME "
                 "environment variable.",
            choices=['nodeos', 'singularity'],
            default=os.environ.get('ARGO_CONTAINER_RUNTIME',
                                   defaults['container_runtime']))

120 121 122
    args = parser.parse_args(remaining_argv)
    nrm.daemon.runner(config=args)
    return(0)
123

124 125

if __name__ == "__main__":
126
    sys.exit(main())