Example #1
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        cfg_files = cfg.find_config_files(
            project='glance', prog='glance-registry')
        cfg_files.extend(
            cfg.find_config_files(project='glance', prog='glance-api'))
        config.parse_args(
            default_config_files=cfg_files, usage="%(prog)s [options] <cmd>")
        log.setup('glance')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        if CONF.command.action.startswith('db'):
            return CONF.command.action_fn()
        else:
            func_kwargs = {}
            for k in CONF.command.action_kwargs:
                v = getattr(CONF.command, 'action_kwarg_' + k)
                if v is None:
                    continue
                func_kwargs[k] = strutils.safe_decode(v)

            func_args = [
                strutils.safe_decode(arg) for arg in CONF.command.action_args
            ]
            return CONF.command.action_fn(*func_args, **func_kwargs)
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % utils.exception_to_str(e))
Example #2
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        cfg_files = cfg.find_config_files(project='sps', prog='sps-registry')
        cfg_files.extend(cfg.find_config_files(project='sps', prog='sps-api'))
        config.parse_args(default_config_files=cfg_files,
                          usage="%(prog)s [options] <cmd>")
        log.setup('sps')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        if CONF.command.action.startswith('db'):
            return CONF.command.action_fn()
        else:
            func_kwargs = {}
            for k in CONF.command.action_kwargs:
                v = getattr(CONF.command, 'action_kwarg_' + k)
                if v is None:
                    continue
                func_kwargs[k] = strutils.safe_decode(v)

            func_args = [
                strutils.safe_decode(arg) for arg in CONF.command.action_args
            ]
            return CONF.command.action_fn(*func_args, **func_kwargs)
    except exception.spsException as e:
        sys.exit("ERROR: %s" % e)
Example #3
0
def parse_power_config(argv, base_project, base_prog=None):
    """Loads configuration information from powervc.conf as well as a project
    specific file.  Expectation is that all powervc config options will be in
    the common powervc.conf file and the base_project will represent open stack
    component configuration like nova.conf or cinder.conf. A base_prog file
    name can be optionally specified as well. That is a specific file name to
    use from the specified open stack component. This function should only be
    called once, in the startup path of a component (probably as soon as
    possible since many modules will have a dependency on the config options).
    """
    # Ensure that we only try to load the config once. Loading it a second
    # time will result in errors.
    if hasattr(parse_power_config, 'power_config_loaded'):
        return

    if base_project and base_project.startswith('powervc-'):
        default_files = cfg.find_config_files(project='powervc',
                                              prog=base_project)
    else:
        default_files = cfg.find_config_files(
            project=base_project,
            prog=(base_project if base_prog is None else base_prog))
        default_files.extend(
            cfg.find_config_files(project='powervc', prog='powervc'))
    # reduce duplicates
    default_files = list(set(default_files))
    CONF(argv[1:], default_config_files=default_files)
    parse_power_config.power_config_loaded = True
Example #4
0
def parse_power_config(argv, base_project, base_prog=None):
    """
    Loads configuration information from powervc.conf as well as a project
    specific file.  Expectation is that all powervc config options will be in
    the common powervc.conf file and the base_project will represent open stack
    component configuration like nova.conf or cinder.conf. A base_prog file
    name can be optionally specified as well. That is a specific file name to
    use from the specified open stack component. This function should only be
    called once, in the startup path of a component (probably as soon as
    possible since many modules will have a dependency on the config options).
    """
    # Ensure that we only try to load the config once. Loading it a second
    # time will result in errors.
    if hasattr(parse_power_config, 'power_config_loaded'):
        return

    if base_project and base_project.startswith('powervc-'):
        default_files = cfg.find_config_files(project='powervc',
                                              prog=base_project)
    else:
        default_files = cfg.find_config_files(project=base_project,
                                              prog=(base_project
                                                    if base_prog is None
                                                    else base_prog))
        default_files.extend(cfg.find_config_files(project='powervc',
                                                   prog='powervc'))
    # reduce duplicates
    default_files = list(set(default_files))
    CONF(argv[1:], default_config_files=default_files)
    parse_power_config.power_config_loaded = True
Example #5
0
def make_api(config_path=None):
    # Find configuration files
    config_files = cfg.find_config_files(PROJECT)

    # Check for environmental variable config file
    env_config_loc = os.environ.get('JUMPGATE_CONFIG')
    if env_config_loc and os.path.exists(env_config_loc):
        config_files.insert(0, env_config_loc)

    # Check for explit config file
    if config_path and os.path.exists(config_path):
        config_files.insert(0, config_path)

    if not config_files:
        raise Exception('No config files for %s found.' % PROJECT)

    jumpgate_config.CONF(project=PROJECT,
                         args=[],  # We don't want CLI arguments
                         default_config_files=config_files)

    logger = logging.getLogger(PROJECT)
    logger.setLevel(getattr(logging,
                            jumpgate_config.CONF['log_level'].upper()))
    logger.addHandler(logging.StreamHandler())
    app = api.Jumpgate()
    app.load_endpoints()
    app.load_drivers()

    return app.make_api()
Example #6
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        cfg_files = cfg.find_config_files(project='glance',
                                          prog='glance-registry')
        cfg_files.extend(cfg.find_config_files(project='glance',
                                               prog='glance-api'))
        config.parse_args(default_config_files=cfg_files,
                          usage="%(prog)s [options] <cmd>")
        log.setup('glance')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:

        CONF.command.action_fn()
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % e)
Example #7
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        # We load the glance-registry config section because
        # sql_connection is only part of the glance registry.
        glance.db.sqlalchemy.api.add_cli_options()

        cfg_files = cfg.find_config_files(project='glance',
                                          prog='glance-registry')
        cfg_files.extend(
            cfg.find_config_files(project='glance', prog='glance-api'))
        config.parse_args(default_config_files=cfg_files,
                          usage="%(prog)s [options] <cmd>")
        log.setup('glance')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % e)
Example #8
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        # We load the glance-registry config section because
        # sql_connection is only part of the glance registry.
        glance.db.sqlalchemy.api.add_cli_options()

        cfg_files = cfg.find_config_files(project='glance',
                                          prog='glance-registry')
        cfg_files.extend(cfg.find_config_files(project='glance',
                                               prog='glance-api'))
        config.parse_args(default_config_files=cfg_files,
                          usage="%(prog)s [options] <cmd>")
        log.setup('glance')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % e)
Example #9
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        default_config_files = cfg.find_config_files('heat', 'heat-engine')
        CONF(sys.argv[1:], project='heat', prog='heat-manage',
             version=version.version_info.version_string(),
             default_config_files=default_config_files)
        log.setup("heat")
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        sys.exit("ERROR: %s" % e)
Example #10
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        default_config_files = cfg.find_config_files('heat', 'heat-engine')
        CONF(sys.argv[1:], project='heat', prog='heat-manage',
             version=version.version_info.version_string(),
             default_config_files=default_config_files)
        log.setup("heat")
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        sys.exit("ERROR: %s" % e)
Example #11
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        #Check how to make this correctly
        version='2013072501'
        default_config_files = cfg.find_config_files('rushstack', 'rushstack-engine')
        CONF(sys.argv[1:], project='rushstack', prog='rushstack-manage',
             version=version,
             default_config_files=default_config_files)
        log.setup("rushstack")
        db_api.configure()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        print traceback.format_exc()
        sys.exit("ERROR: %s" % e)
Example #12
0
def parse_configs(argv=None, conf_files=None):
    if argv is not None:
        global ARGV
        ARGV = argv

    # TODO(slukjanov): remove this code (temp to migrate to the new name)
    if conf_files is None:
        conf_files = []
    conf_files += cfg.find_config_files(project="sahara")

    try:
        version_string = version.version_info.version_string()
        CONF(ARGV, project='sahara', version=version_string,
             default_config_files=conf_files)
    except cfg.RequiredOptError as roe:
        # TODO(slukjanov): replace RuntimeError with concrete exception
        raise RuntimeError("Option '%s' is required for config group "
                           "'%s'" % (roe.opt_name, roe.group.name))
    validate_configs()
Example #13
0
def _load_power_config(argv):
    """
    Loads the powervc config.
    """
    # Cinder is typically started with the --config-file option.
    # This prevents the default config files from loading since
    # the olso config code will only load those
    # config files as specified on the command line.
    # If the cinder is started with the
    # --config-file option then append our powervc.conf file to
    # the command line so it gets loaded as well.
    for arg in argv:
        if arg == '--config-file' or arg.startswith('--config-file='):
            argv[len(argv):] = ["--config-file"] + \
                [cfg.find_config_files(project='powervc',
                                       prog='powervc')[0]]
            break

    config.parse_power_config(argv, 'cinder')
def main():
    CONF.register_cli_opt(command_opt)
    try:
        default_config_files = cfg.find_config_files("dragon", "dragon-engine")
        CONF(
            sys.argv[1:],
            project="dragon",
            prog="dragon-manage",
            version=version.version_info.version_string(),
            default_config_files=default_config_files,
        )
        log.setup("dragon")
        db_api.configure()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        sys.exit("ERROR: %s" % e)
Example #15
0
def main():
    CONF.register_cli_opt(command_opt)

    try:
        default_config_files = cfg.find_config_files('murano', 'murano')
        CONF(sys.argv[1:], project='murano', prog='murano-manage',
             version=version.version_string,
             default_config_files=default_config_files)
        logging.setup("murano")
    except RuntimeError as e:
        LOG.error(_LE("failed to initialize murano-manage: %s") % e)
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        tb = traceback.format_exc()
        err_msg = _LE("murano-manage command failed: {0}\n{1}").format(e, tb)
        LOG.error(err_msg)
        sys.exit(err_msg)
Example #16
0
def parse_configs(argv=None, conf_files=None):
    if argv is not None:
        global ARGV
        ARGV = argv

    # TODO(slukjanov): remove this code (temp to migrate to the new name)
    if conf_files is None:
        conf_files = []
    conf_files += cfg.find_config_files(project="sahara")

    try:
        version_string = version.version_info.version_string()
        CONF(ARGV,
             project='sahara',
             version=version_string,
             default_config_files=conf_files)
    except cfg.RequiredOptError as roe:
        # TODO(slukjanov): replace RuntimeError with concrete exception
        raise RuntimeError("Option '%s' is required for config group "
                           "'%s'" % (roe.opt_name, roe.group.name))
    validate_configs()
Example #17
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        default_config_files = cfg.find_config_files('murano-api', 'murano')
        CONF(sys.argv[1:],
             project='murano-api',
             prog='murano-manage',
             version=muranoapi.__version__,
             default_config_files=default_config_files)
        logging.setup("murano-api")
    except RuntimeError as e:
        LOG.error("failed to initialize murano-manage: %s" % e)
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        tb = traceback.format_exc()
        err_msg = "murano-manage command failed: {0}\n{1}".format(e, tb)
        LOG.error(err_msg)
        sys.exit(err_msg)
Example #18
0
def main():
    CONF.register_cli_opt(command_opt)
    try:
        default_config_files = cfg.find_config_files("murano-api", "murano")
        CONF(
            sys.argv[1:],
            project="murano-api",
            prog="murano-manage",
            version=muranoapi.__version__,
            default_config_files=default_config_files,
        )
        logging.setup("murano-api")
    except RuntimeError as e:
        LOG.error("failed to initialize murano-manage: %s" % e)
        sys.exit("ERROR: %s" % e)

    try:
        CONF.command.func()
    except Exception as e:
        tb = traceback.format_exc()
        err_msg = "murano-manage command failed: {0}\n{1}".format(e, tb)
        LOG.error(err_msg)
        sys.exit(err_msg)
Example #19
0
    def _set_notif_params(self):
        """Read notification parameters from the config file."""
        self._notif_params.update(notif_params[self._service])
        temp_db = {}
        cfgfile = cfg.find_config_files(self._service)
        multi_parser = cfg.MultiConfigParser()
        cfgr = multi_parser.read(cfgfile)
        if len(cfgr) == 0:
            LOG.error(_("Failed to read %s."), cfgfile)
            return
        for parsed_file in multi_parser.parsed:
            for parsed_item in parsed_file.keys():
                for key, value in parsed_file[parsed_item].items():
                    if key in self._notif_params:
                        val = notif_params[self._service].get(key)
                        if val != value[0]:
                            temp_db[key] = value[0]

        self._notif_params.update(temp_db)
        self._token = self.get_notif_params().get('admin_token')
        _endpoint = self.get_notif_params().get('admin_endpoint')
        self._endpoint_url = _endpoint % self.get_notif_params() + 'v3/'
        self._keystone = client.Client(token=self._token,
                                       endpoint=self._endpoint_url)
Example #20
0
def parse_cache_args(args=None):
    config_files = cfg.find_config_files(project='glance', prog='glance-cache')
    parse_args(args=args, default_config_files=config_files)
Example #21
0
def parse_cache_args(args=None):
    config_files = cfg.find_config_files(project='glance', prog='glance-cache')
    parse_args(args=args, default_config_files=config_files)