def setup_backends(load_extra_backends_fn=lambda: {}, startup_application_fn=lambda: None): drivers = backends.load_backends() drivers.update(load_extra_backends_fn()) res = startup_application_fn() drivers.update(dependency.resolve_future_dependencies()) return drivers, res
def main(): def validate_options(): # NOTE(henry-nash); It would be nice to use the argparse automated # checking for this validation, but the only way I can see doing # that is to make the default (i.e. if no optional parameters # are specified) to purge all mappings - and that sounds too # dangerous as a default. So we use it in a slightly # unconventional way, where all parameters are optional, but you # must specify at least one. if (CONF.command.all is False and CONF.command.domain_name is None and CONF.command.public_id is None and CONF.command.local_id is None and CONF.command.type is None): raise ValueError(_('At least one option must be provided')) if (CONF.command.all is True and (CONF.command.domain_name is not None or CONF.command.public_id is not None or CONF.command.local_id is not None or CONF.command.type is not None)): raise ValueError( _('--all option cannot be mixed with ' 'other options')) def get_domain_id(name): try: return resource_manager.get_domain_by_name(name)['id'] except KeyError: raise ValueError( _("Unknown domain '%(name)s' specified by " "--domain-name") % {'name': name}) validate_options() drivers = backends.load_backends() resource_manager = drivers['resource_api'] mapping_manager = drivers['id_mapping_api'] # Now that we have validated the options, we know that at least one # option has been specified, and if it was the --all option then this # was the only option specified. # # The mapping dict is used to filter which mappings are purged, so # leaving it empty means purge them all mapping = {} if CONF.command.domain_name is not None: mapping['domain_id'] = get_domain_id(CONF.command.domain_name) if CONF.command.public_id is not None: mapping['public_id'] = CONF.command.public_id if CONF.command.local_id is not None: mapping['local_id'] = CONF.command.local_id if CONF.command.type is not None: mapping['type'] = CONF.command.type mapping_manager.purge_mappings(mapping)
def main(): def validate_options(): # NOTE(henry-nash); It would be nice to use the argparse automated # checking for this validation, but the only way I can see doing # that is to make the default (i.e. if no optional parameters # are specified) to purge all mappings - and that sounds too # dangerous as a default. So we use it in a slightly # unconventional way, where all parameters are optional, but you # must specify at least one. if (CONF.command.all is False and CONF.command.domain_name is None and CONF.command.public_id is None and CONF.command.local_id is None and CONF.command.type is None): raise ValueError(_('At least one option must be provided')) if (CONF.command.all is True and (CONF.command.domain_name is not None or CONF.command.public_id is not None or CONF.command.local_id is not None or CONF.command.type is not None)): raise ValueError(_('--all option cannot be mixed with ' 'other options')) def get_domain_id(name): try: return resource_manager.get_domain_by_name(name)['id'] except KeyError: raise ValueError(_("Unknown domain '%(name)s' specified by " "--domain-name") % {'name': name}) validate_options() drivers = backends.load_backends() resource_manager = drivers['resource_api'] mapping_manager = drivers['id_mapping_api'] # Now that we have validated the options, we know that at least one # option has been specified, and if it was the --all option then this # was the only option specified. # # The mapping dict is used to filter which mappings are purged, so # leaving it empty means purge them all mapping = {} if CONF.command.domain_name is not None: mapping['domain_id'] = get_domain_id(CONF.command.domain_name) if CONF.command.public_id is not None: mapping['public_id'] = CONF.command.public_id if CONF.command.local_id is not None: mapping['local_id'] = CONF.command.local_id if CONF.command.type is not None: mapping['type'] = CONF.command.type mapping_manager.purge_mappings(mapping)
def load_backends(self): """Initializes each manager and assigns them to an attribute.""" # TODO(blk-u): Shouldn't need to clear the registry here, but some # tests call load_backends multiple times. These should be fixed to # only call load_backends once. dependency.reset() # TODO(morganfainberg): Shouldn't need to clear the registry here, but # some tests call load_backends multiple times. Since it is not # possible to re-configure a backend, we need to clear the list. This # should eventually be removed once testing has been cleaned up. kvs_core.KEY_VALUE_STORE_REGISTRY.clear() self.clear_auth_plugin_registry() drivers = backends.load_backends() drivers.update(dependency.resolve_future_dependencies()) for manager_name, manager in six.iteritems(drivers): setattr(self, manager_name, manager) self.addCleanup(self.cleanup_instance(*drivers.keys()))
from keystone.common import environment from keystone.common import sql from keystone import config from keystone.openstack.common import log from keystone import service CONF = config.CONF config.configure() sql.initialize() config.set_default_for_default_log_levels() CONF(project='keystone') config.setup_logging() environment.use_stdlib() name = os.path.basename(__file__) if CONF.debug: CONF.log_opt_values(log.getLogger(CONF.prog), logging.DEBUG) drivers = backends.load_backends() # NOTE(ldbragst): 'application' is required in this context by WSGI spec. # The following is a reference to Python Paste Deploy documentation # http://pythonpaste.org/deploy/ application = service.loadapp('config:%s' % config.find_paste_config(), name) dependency.resolve_future_dependencies()
def load_backends(self): drivers = backends.load_backends() self.resource_manager = drivers['resource_api'] self.domain_config_manager = drivers['domain_config_api']
def get_application(configure=True): import os import sys import java.util from java.io import File from org.python.util import jython jar_location = (jython() .getClass() .getProtectionDomain() .getCodeSource() .getLocation() .getPath()) sys.executable = jar_location import pbr.version pbr.version.VersionInfo.version_string = lambda x: '' from keystone import backends from keystone import config from keystone.common import sql from oslo.db import options as db_options from keystone.common import dependency import logging from paste import deploy from java.lang import System logging.basicConfig() if configure: config.configure() CONF = config.CONF sql.initialize() prop_dir = System.getProperty("config_dir", "etc") if len(sys.argv) > 0: saved_argv = sys.argv sys.argv = [sys.argv[0]] config_file = ['{prop_dir}/keystone.conf'.format(prop_dir=prop_dir)] CONF(project='keystone', prog='keystone', default_config_files=config_file) name = 'main' name = 'admin' config.setup_logging() if CONF.debug: CONF.log_opt_values(logging.getLogger(CONF.prog), logging.DEBUG) elif CONF.verbose: CONF.log_opt_values(logging.getLogger(CONF.prog), logging.INFO) else: CONF.log_opt_values(logging.getLogger(CONF.prog), logging.WARNING) backends.load_backends() application = deploy.loadapp('config:{prop_dir}/keystone-paste.ini'.format( prop_dir=prop_dir), name=name, relative_to='.') dependency.resolve_future_dependencies() if len(sys.argv) > 0: sys.argv = saved_argv return application