def start(self): # Anything to start? am_started = 0 apps_to_start = self._get_apps_to_start() if not apps_to_start: return am_started # Select how we are going to start it run_type = self._fetch_run_type() starter = importer.import_entry_point(run_type)(self) for app_info in apps_to_start: app_name = app_info["name"] app_pth = app_info.get("path", app_name) app_dir = app_info.get("app_dir", self.get_option('app_dir')) # Adjust the program options now that we have real locations program_opts = utils.param_replace_list(self._get_app_options(app_name), self._get_param_map(app_name)) # Start it with the given settings LOG.debug("Starting %r using %r", app_name, run_type) details_fn = starter.start(app_name, app_pth=app_pth, app_dir=app_dir, opts=program_opts) LOG.info("Started %s details are in %s", colorizer.quote(app_name), colorizer.quote(details_fn)) # This trace is used to locate details about what to stop self.tracewriter.app_started(app_name, details_fn, run_type) if app_info.get('sleep_time'): LOG.info("%s requested a %s second sleep time, please wait...", colorizer.quote(app_name), app_info.get('sleep_time')) sh.sleep(app_info.get('sleep_time')) am_started += 1 return am_started
def __init__(self, installer): super(QuantumConfigurator, self).__init__(installer, CONFIGS) self.core_plugin = installer.get_option("core_plugin") self.plugin_configurator = importer.import_entry_point( "anvil.components.configurators.quantum_plugins.%s:%sConfigurator" % (self.core_plugin, self.core_plugin.title()))(installer) self.config_adjusters = { PASTE_CONF: self._config_adjust_paste, API_CONF: self._config_adjust_api, } self.config_adjusters.update(self.plugin_configurator.config_adjusters)
def make_packager(package, default_class, **kwargs): packager_name = package.get("packager_name") or "" packager_name = packager_name.strip() if packager_name: packager_cls = importer.import_entry_point(packager_name) else: packager_cls = default_class if packager_cls in _PACKAGERS: return _PACKAGERS[packager_cls] p = packager_cls(**kwargs) _PACKAGERS[packager_cls] = p return p
def make_packager(package, default_class, **kwargs): packager_name = package.get('packager_name') or '' packager_name = packager_name.strip() if packager_name: packager_cls = importer.import_entry_point(packager_name) else: packager_cls = default_class if packager_cls in _PACKAGERS: return _PACKAGERS[packager_cls] p = packager_cls(**kwargs) _PACKAGERS[packager_cls] = p return p
def extract_component(self, name, action): """Return the class + component info to use for doing the action w/the component.""" try: # Use a copy instead of the original component_info = copy.deepcopy(self._components[name]) action_classes = dict(component_info['action_classes']) entry_point = action_classes[action] del action_classes[action] cls = importer.import_entry_point(entry_point) return ((cls, component_info), action_classes) except KeyError: raise RuntimeError('No class configured to %r %r on %r' % (action, name, self.name))
def extract_component(self, name, action): """Return the class + component info to use for doing the action w/the component.""" try: # Use a copy instead of the original component_info = copy.deepcopy(self._components[name]) action_classes = component_info['action_classes'] entry_point = action_classes[action] del action_classes[action] cls = importer.import_entry_point(entry_point) return ((cls, component_info), action_classes) except KeyError: raise RuntimeError('No class configured to %r %r on %r' % (action, name, self.name))
def get_packager_for(self, pkg_info): packager_name = pkg_info.get(self.PACKAGER_KEY_NAME) if not packager_name or not packager_name.strip(): packager = self._get_default_pkgr() else: if packager_name in self.fetched_packagers: packager = self.fetched_packagers[packager_name] else: packager_cls = importer.import_entry_point(packager_name) LOG.debug('Loading custom package manager %s for package %r', packager_cls, pkg_info['name']) packager = self._construct_pkger(packager_cls) self.fetched_packagers[packager_name] = packager return packager
def _construct_siblings(self, name, siblings, params, sibling_instances): there_siblings = {} for (action, cls_name) in siblings.items(): if action not in sibling_instances: sibling_instances[action] = {} cls = importer.import_entry_point(cls_name) sibling_params = utils.merge_dicts(params, self.cli_opts, preserve=True) sibling_params["instances"] = sibling_instances[action] LOG.debug("Construction of sibling component %r (%r) params are:", name, action) utils.log_object(sibling_params, logger=LOG, level=logging.DEBUG) a_sibling = cls(**sibling_params) # Update the sibling we are returning and the corresponding # siblings for that action (so that the sibling can have the # correct 'sibling' instances associated with it, if it needs those...) there_siblings[action] = a_sibling sibling_instances[action][name] = a_sibling return there_siblings
def __init__(self, installer): super(NeutronConfigurator, self).__init__(installer, CONFIGS) self.core_plugin = installer.get_option("core_plugin") self.plugin_configurators = { 'core_plugin': importer.import_entry_point( "anvil.components.configurators.neutron_plugins.%s:%sConfigurator" % (self.core_plugin, self.core_plugin.title()))(installer), 'l3': l3.L3Configurator(installer), 'dhcp': dhcp.DhcpConfigurator(installer), } self.config_adjusters = { PASTE_CONF: self._config_adjust_paste, API_CONF: self._config_adjust_api, } for plugin_configurator in self.plugin_configurators.values(): self.config_adjusters.update(plugin_configurator.config_adjusters)
def _locate_investigators(self, apps_started): investigators = dict() to_investigate = list() for (app_name, trace_fn, how) in apps_started: inv_cls = None try: inv_cls = importer.import_entry_point(how) except RuntimeError as e: LOG.warn("Could not load class %s which should be used to investigate %s: %s", colorizer.quote(how), colorizer.quote(app_name), e) continue investigator = None if inv_cls in investigators: investigator = investigators[inv_cls] else: investigator = inv_cls(self) investigators[inv_cls] = investigator to_investigate.append((app_name, investigator)) return to_investigate
def _construct_siblings(self, name, siblings, params, sibling_instances): there_siblings = {} for (action, cls_name) in siblings.items(): if action not in sibling_instances: sibling_instances[action] = {} cls = importer.import_entry_point(cls_name) sibling_params = utils.merge_dicts(params, self.cli_opts, preserve=True) sibling_params['instances'] = sibling_instances[action] LOG.debug("Construction of sibling component %r (%r) params are:", name, action) utils.log_object(sibling_params, logger=LOG, level=logging.DEBUG) a_sibling = cls(**sibling_params) # Update the sibling we are returning and the corresponding # siblings for that action (so that the sibling can have the # correct 'sibling' instances associated with it, if it needs those...) there_siblings[action] = a_sibling sibling_instances[action][name] = a_sibling return there_siblings
def configure(self): # Anything to configure for starting? apps_to_start = self._get_apps_to_start() am_configured = 0 if not apps_to_start: return am_configured # First make a pass and make sure all runtime # (e.g. upstart starting) # config files are in place.... run_type = self._fetch_run_type() configurer = importer.import_entry_point(run_type)(self) for app_info in apps_to_start: app_name = app_info["name"] app_pth = app_info.get("path", app_name) app_dir = app_info.get("app_dir", self.get_option('app_dir')) # Configure it with the given settings LOG.debug("Configuring runner %r for program %r", run_type, app_name) cfg_am = configurer.configure(app_name, app_pth=app_pth, app_dir=app_dir, opts=utils.param_replace_list(self._get_app_options(app_name), self._get_param_map(app_name))) LOG.debug("Configured %s files for runner for program %r", cfg_am, app_name) am_configured += cfg_am return am_configured
def get_packager_class(package_info, default_packager_class=None): packager_name = package_info.get('packager_name') or '' packager_name = packager_name.strip() if not packager_name: return default_packager_class return importer.import_entry_point(packager_name)
def install_helper_class(self): """Return an install helper that will work for this distro.""" return importer.import_entry_point(self._install_helper)
def get_default_package_manager_cls(self): """Return a package manager that will work for this distro.""" return importer.import_entry_point(self._packager_name)
def package_manager_class(self): """Return a package manager that will work for this distro.""" return importer.import_entry_point(self._packager_name)
def __init__(self, cfg): # Late load since its using a client lib that is only avail after install... self.cfg = cfg client_cls = importer.import_entry_point("keystoneclient.v2_0.client:Client") self.client = client_cls(token=self.cfg['service_token'], endpoint=self.cfg['endpoints']['admin']['uri'])
def dependency_handler_class(self): """Return a dependency handler that will work for this distro.""" return importer.import_entry_point(self._dependency_handler["name"])