def start(self): #select how we are going to start it startercls = self._getstartercls(self.run_type) starter = startercls() #start all apps #this fns list will have info about what was started fns = list() apps = self._get_apps_to_start() for app_info in apps: #extract needed keys app_name = app_info.get("name") app_pth = app_info.get("path", app_name) app_dir = app_info.get("app_dir", self.appdir) #adjust the program options now that we have real locations params = self._get_param_map(app_name) program_opts = self._get_app_options(app_name) if params and program_opts: adjusted_opts = list() for opt in program_opts: adjusted_opts.append(utils.param_replace(str(opt), params)) program_opts = adjusted_opts #start it with the given settings LOG.info("Starting [%s] with options [%s]" % (app_name, ", ".join(program_opts))) fn = starter.start(app_name, app_pth, *program_opts, app_dir=app_dir, \ trace_dir=self.tracedir) if fn: fns.append(fn) LOG.info("Started %s, details are in %s" % (app_name, fn)) #this trace is used to locate details about what to stop self.tracewriter.started_info(app_name, fn) else: LOG.info("Started %s" % (app_name)) return fns
def _setup_initer(self): LOG.info("Configuring keystone initializer template %s.", MANAGE_DATA_CONF) (_, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF) params = self._get_param_map(MANAGE_DATA_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bindir, MANAGE_DATA_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _get_app_options(self, app): LOG.debug("Getting options for %s" % (app)) result = list() for opt_str in APP_OPTIONS.get(app): LOG.debug("Checking opt_str for tokens: %s" % (opt_str)) result.append(utils.param_replace(opt_str, self.run_tokens)) LOG.debug("_get_app_options returning with:%s" % (result)) return result
def _setup_network_initer(self): LOG.info("Configuring nova network initializer template %s.", NET_INIT_CONF) (_, contents) = utils.load_template(self.component_name, NET_INIT_CONF) params = self._get_param_map(NET_INIT_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bindir, NET_INIT_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _setup_network_initer(self): LOG.info("Configuring nova network initializer template %s.", NET_INIT_CONF) (_, contents) = utils.load_template(self.component_name, NET_INIT_CONF) params = self._get_param_map(NET_INIT_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bin_dir, NET_INIT_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _setup_initer(self): LOG.info("Configuring keystone initializer template %r", MANAGE_DATA_CONF) (_, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF) mp = self._get_param_map(MANAGE_DATA_CONF) contents = utils.param_replace(contents, mp, True) # FIXME, stop placing in checkout dir... tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _generate_paste_api_conf(self): LOG.info("Setting up %s" % (PASTE_CONF)) mp = dict() mp['SERVICE_TOKEN'] = self.cfg.get("passwords", "service_token") (src_fn, contents) = self._get_source_config(PASTE_CONF) LOG.info("Replacing parameters in file %s" % (src_fn)) LOG.debug("Replacements = %s" % (mp)) contents = utils.param_replace(contents, mp, True) LOG.debug("Writing out to %s" % (self.paste_conf_fn)) sh.write_file(self.paste_conf_fn, contents) self.tracewriter.cfg_write(self.paste_conf_fn)
def _setup_initer(self): LOG.info("Configuring keystone initializer template %s.", MANAGE_DATA_CONF) (_, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF) params = self._get_param_map(MANAGE_DATA_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF) sh.write_file(tgt_fn, contents) sh.chmod(tgt_fn, 0755) self.tracewriter.file_touched(tgt_fn)
def _setup_data(self): LOG.info("Configuring data setup template %s", MANAGE_DATA_CONF) (src_fn, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF) params = self._get_param_map(MANAGE_DATA_CONF) contents = utils.param_replace(contents, params, True) tgt_fn = sh.joinpths(self.bindir, MANAGE_DATA_CONF) sh.write_file(tgt_fn, contents) # This environment additions are important # in that they eventually affect how this script runs env = dict() env['ENABLED_SERVICES'] = ",".join(self.instances.keys()) env['BIN_DIR'] = self.bindir setup_cmd = MANAGER_CMD_ROOT + [tgt_fn] LOG.info("Running (%s) command to setup keystone." % (" ".join(setup_cmd))) sh.execute(*setup_cmd, env_overrides=env)
def _do_upstart_configure(self, app_name, runtime_info): (app_pth, _, program_args) = runtime_info # TODO FIXME symlinks won't work. Need to copy the files there. # https://bugs.launchpad.net/upstart/+bug/665022 cfg_fn = sh.joinpths(CONF_ROOT, app_name + CONF_EXT) if sh.isfile(cfg_fn): LOG.info("Upstart config file already exists: %s" % (cfg_fn)) return LOG.debug("Loading upstart template to be used by: %s" % (cfg_fn)) (_, contents) = utils.load_template('general', UPSTART_CONF_TMPL) params = self._get_upstart_conf_params(app_pth, app_name, *program_args) adjusted_contents = utils.param_replace(contents, params) LOG.debug("Generated up start config for %s: %s" % (app_name, adjusted_contents)) with sh.Rooted(True): sh.write_file(cfg_fn, adjusted_contents) sh.chmod(cfg_fn, 0666)
def generate(self, param_dict=None): gen_lines = list() for line_entry in self.lines: key = line_entry.get('key') opts = line_entry.get('options') if not key: continue if opts is None: key_str = self._form_key(key, False) full_line = key_str else: key_str = self._form_key(key, True) filled_opts = list() for opt in opts: filled_opts.append(utils.param_replace(str(opt), param_dict)) full_line = key_str + ",".join(filled_opts) gen_lines.append(full_line) return gen_lines
def _do_upstart_configure(self, app_name, runtime_info): (app_pth, _, program_args) = runtime_info # TODO FIXME symlinks won't work. Need to copy the files there. # https://bugs.launchpad.net/upstart/+bug/665022 cfg_fn = sh.joinpths(CONF_ROOT, app_name + CONF_EXT) if sh.isfile(cfg_fn): LOG.debug("Upstart config file already exists: %s" % (cfg_fn)) return LOG.debug("Loading upstart template to be used by: %s" % (cfg_fn)) (_, contents) = utils.load_template('general', UPSTART_CONF_TMPL) params = self._get_upstart_conf_params(app_pth, app_name, *program_args) adjusted_contents = utils.param_replace(contents, params) LOG.debug("Generated up start config for %s: %s" % (app_name, adjusted_contents)) with sh.Rooted(True): sh.write_file(cfg_fn, adjusted_contents) sh.chmod(cfg_fn, 0666)
def _configure_files(self): configs = self._get_config_files() if configs: LOG.info("Configuring %s files", len(configs)) for fn in configs: parameters = self._get_param_map(fn) tgt_fn = self._get_target_config_name(fn) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn))) LOG.info("Configuring file %s", fn) (source_fn, contents) = self._get_source_config(fn) LOG.debug("Replacing parameters in file %s", source_fn) LOG.debug("Replacements = %s", parameters) contents = utils.param_replace(contents, parameters) LOG.debug("Applying side-effects of param replacement for template %s", source_fn) contents = self._config_adjust(contents, fn) LOG.info("Writing configuration file %s", tgt_fn) self.tracewriter.cfg_file_written(sh.write_file(tgt_fn, contents)) return len(configs)
def _configure_files(self): configs = self._get_config_files() if configs: LOG.info("Configuring %s files", len(configs)) for fn in configs: parameters = self._get_param_map(fn) tgt_fn = self._get_target_config_name(fn) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn))) LOG.info("Configuring file %s", fn) (source_fn, contents) = self._get_source_config(fn) LOG.debug("Replacing parameters in file %s", source_fn) LOG.debug("Replacements = %s", parameters) contents = utils.param_replace(contents, parameters) LOG.debug( "Applying side-effects of param replacement for template %s", source_fn) contents = self._config_adjust(contents, fn) LOG.info("Writing configuration file %s", tgt_fn) self.tracewriter.cfg_file_written( sh.write_file(tgt_fn, contents)) return len(configs)
def _configure_files(self): configs = self._get_config_files() if configs: LOG.info("Configuring %s files" % (len(configs))) for fn in configs: #get the params and where it should come from and where it should go parameters = self._get_param_map(fn) tgt_fn = self._get_target_config_name(fn) #ensure directory is there (if not created previously) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn))) #now configure it LOG.info("Configuring file %s" % (fn)) (source_fn, contents) = self._get_source_config(fn) LOG.debug("Replacing parameters in file %s" % (source_fn)) LOG.debug("Replacements = %s" % (parameters)) contents = utils.param_replace(contents, parameters) LOG.debug("Applying side-effects of param replacement for template %s" % (source_fn)) contents = self._config_adjust(contents, fn) LOG.info("Writing configuration file %s" % (tgt_fn)) #this trace is used to remove the files configured self.tracewriter.cfg_file_written(sh.write_file(tgt_fn, contents)) return len(configs)
def _config_param_replace(self, config_fn, contents, parameters): return utils.param_replace(contents, parameters)
def _form_entry(self, key, value, params=None): real_value = utils.param_replace(str(value), params) entry = "%s=%s" % (key, real_value) return entry