def _generate_nova_conf(self): conf_fn = self._get_target_config_name(API_CONF) LOG.info("Generating dynamic content for nova: %r" % (conf_fn)) nova_conf_contents = self.conf_maker.configure() self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(conf_fn))) self.tracewriter.cfg_file_written( sh.write_file(conf_fn, nova_conf_contents))
def _generate_nova_conf(self): LOG.info("Generating dynamic content for nova configuration (%s)." % (API_CONF)) conf_gen = NovaConfConfigurator(self) nova_conf_contents = conf_gen.configure() conf_fn = self._get_target_config_name(API_CONF) LOG.info("Writing nova configuration to %s" % (conf_fn)) LOG.debug(nova_conf_contents) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(conf_fn))) self.tracewriter.cfg_file_written(sh.write_file(conf_fn, nova_conf_contents))
def _start(self): if self.started: return else: trace_dirs = sh.mkdirslist(sh.dirname(self.trace_fn)) sh.touch_file(self.trace_fn) self.trace(TRACE_VERSION, str(TRACE_VER)) self.started = True self.dirs_made(*trace_dirs)
def _generate_nova_conf(self): LOG.info("Generating dynamic content for nova configuration (%s)." % (API_CONF)) conf_gen = NovaConfConfigurator(self) nova_conf = conf_gen.configure() tgtfn = self._get_target_config_name(API_CONF) LOG.info("Writing nova configuration to %s" % (tgtfn)) LOG.debug(nova_conf) self.tracewriter.make_dir(sh.dirname(tgtfn)) sh.write_file(tgtfn, nova_conf) self.tracewriter.cfg_write(tgtfn)
def _generate_nova_conf(self): LOG.info("Generating dynamic content for nova configuration (%s)." % (API_CONF)) conf_gen = NovaConfConfigurator(self) nova_conf_contents = conf_gen.configure() conf_fn = self._get_target_config_name(API_CONF) LOG.info("Writing nova configuration to %s" % (conf_fn)) LOG.debug(nova_conf_contents) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(conf_fn))) self.tracewriter.cfg_file_written( sh.write_file(conf_fn, nova_conf_contents))
def _config_adjust(self, contents, name): # Even bother opening?? if name not in READ_CONFIGS: return contents # Use config parser and # then extract known configs that # will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) if config.getboolean('default', 'image_cache_enabled'): cache_dir = config.get('default', "image_cache_datadir") if cache_dir: LOG.info("Ensuring image cache data directory %s exists "\ "(and is empty)" % (cache_dir)) # Destroy then recreate the image cache directory sh.deldir(cache_dir) self.tracewriter.dirs_made(*sh.mkdirslist(cache_dir)) if config.get('default', 'default_store') == 'file': file_dir = config.get('default', 'filesystem_store_datadir') if file_dir: LOG.info( "Ensuring file system store directory %s exists and is empty." % (file_dir)) # Delete existing images # and recreate the image directory sh.deldir(file_dir) self.tracewriter.dirs_made(*sh.mkdirslist(file_dir)) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.dirs_made(*sh.mkdirslist(log_dir)) # Destroy then recreate it (the log file) sh.unlink(log_filename) self.tracewriter.file_touched(sh.touch_file(log_filename)) if config.getboolean('default', 'delayed_delete'): data_dir = config.get('default', 'scrubber_datadir') if data_dir: LOG.info( "Ensuring scrubber data dir %s exists and is empty." % (data_dir)) # Destroy then recreate the scrubber data directory sh.deldir(data_dir) self.tracewriter.dirs_made(*sh.mkdirslist(data_dir)) # Nothing modified so just return the original return contents
def configure(self): configs_made = nova.NovaInstaller.configure(self) driver_canon = nova.canon_virt_driver(self.cfg.get("nova", "virt_driver")) if driver_canon == "libvirt": (fn, contents) = self._get_policy(self._get_policy_users()) dirs_made = list() with sh.Rooted(True): # TODO check if this dir is restricted before assuming it isn't? dirs_made.extend(sh.mkdirslist(sh.dirname(fn))) sh.write_file(fn, contents) self.tracewriter.cfg_file_written(fn) self.tracewriter.dirs_made(*dirs_made) configs_made += 1 return configs_made
def _generate_nova_conf(self): LOG.info("Generating dynamic content for nova configuration (%s)." % (API_CONF)) component_dirs = dict() component_dirs['app'] = self.appdir component_dirs['cfg'] = self.cfgdir component_dirs['bin'] = self.bindir conf_gen = NovaConfigurator(self) nova_conf = conf_gen.configure(component_dirs) tgtfn = self._get_target_config_name(API_CONF) LOG.info("Writing nova configuration to %s" % (tgtfn)) LOG.debug(nova_conf) self.tracewriter.make_dir(sh.dirname(tgtfn)) sh.write_file(tgtfn, nova_conf) self.tracewriter.cfg_write(tgtfn)
def configure(self): configs_made = nova.NovaInstaller.configure(self) driver_canon = nova.canon_virt_driver(self.cfg.get('nova', 'virt_driver')) if driver_canon == 'libvirt': (fn, contents) = self._get_policy(self._get_policy_users()) dirs_made = list() with sh.Rooted(True): # TODO check if this dir is restricted before assuming it isn't? dirs_made.extend(sh.mkdirslist(sh.dirname(fn))) sh.write_file(fn, contents) self.tracewriter.cfg_file_written(fn) self.tracewriter.dirs_made(*dirs_made) configs_made += 1 return configs_made
def configure(self): configs_made = comp.PythonInstallComponent.configure(self) self._generate_nova_conf() configs_made += 1 # TODO: maybe this should be a subclass that handles these differences driver_canon = _canon_virt_driver(self.cfg.get('nova', 'virt_driver')) if (self.distro in POLICY_DISTROS) and driver_canon == virsh.VIRT_TYPE: with sh.Rooted(True): dirsmade = sh.mkdirslist(sh.dirname(LIBVIRT_POLICY_FN)) sh.write_file(LIBVIRT_POLICY_FN, LIBVIRT_POLICY_CONTENTS) self.tracewriter.dir_made(*dirsmade) self.tracewriter.cfg_write(LIBVIRT_POLICY_FN) configs_made += 1 return configs_made
def configure(self): configs_made = comp.PythonInstallComponent.configure(self) self._generate_nova_conf() configs_made += 1 driver_canon = _canon_virt_driver(self.cfg.get('nova', 'virt_driver')) # TODO maybe move this?? if driver_canon == 'libvirt' and self.distro.get_command('virt-policy', quiet=True): (fn, contents) = self.distro.get_command('virt-policy') dirs_made = list() with sh.Rooted(True): dirs_made = sh.mkdirslist(sh.dirname(fn)) sh.write_file(fn, contents) self.tracewriter.dirs_made(*dirs_made) self.tracewriter.cfg_file_written(fn) configs_made += 1 return configs_made
def _config_adjust(self, contents, name): #even bother opening?? if name not in READ_CONFIGS: return contents #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) if config.getboolean('default', 'image_cache_enabled'): cache_dir = config.get('default', "image_cache_datadir") if cache_dir: LOG.info("Ensuring image cache data directory %s exists "\ "(and is empty)" % (cache_dir)) #destroy then recreate the image cache directory sh.deldir(cache_dir) self.tracewriter.make_dir(cache_dir) if config.get('default', 'default_store') == 'file': file_dir = config.get('default', 'filesystem_store_datadir') if file_dir: LOG.info("Ensuring file system store directory %s exists and is empty." % (file_dir)) #delete existing images #and recreate the image directory sh.deldir(file_dir) self.tracewriter.make_dir(file_dir) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) if config.getboolean('default', 'delayed_delete'): data_dir = config.get('default', 'scrubber_datadir') if data_dir: LOG.info("Ensuring scrubber data dir %s exists and is empty." % (data_dir)) #destroy then recreate the scrubber data directory sh.deldir(data_dir) self.tracewriter.make_dir(data_dir) #we might need to handle more in the future... #nothing modified so just return the original return contents
def _configure_files(self): config_fns = self._get_config_files() if config_fns: utils.log_iterable(config_fns, logger=LOG, header="Configuring %s files" % (len(config_fns))) for fn in config_fns: tgt_fn = self._get_target_config_name(fn) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn))) LOG.info("Configuring file %r", fn) (source_fn, contents) = self._get_source_config(fn) LOG.debug("Replacing parameters in file %r", source_fn) contents = self._config_param_replace(fn, contents, self._get_param_map(fn)) LOG.debug("Applying final adjustments in file %r", source_fn) contents = self._config_adjust(contents, fn) LOG.info("Writing configuration file %r => %r", source_fn, tgt_fn) self.tracewriter.cfg_file_written(sh.write_file(tgt_fn, contents)) return len(config_fns)
def _configure_instances_path(self, instances_path, nova_conf): nova_conf.add('instances_path', instances_path) LOG.debug("Attempting to create instance directory: %r", instances_path) self.tracewriter.dirs_made(*sh.mkdirslist(instances_path)) LOG.debug("Adjusting permissions of instance directory: %r", instances_path) sh.chmod(instances_path, 0777) instance_parent = sh.dirname(instances_path) LOG.debug("Adjusting permissions of instance directory parent: %r", instance_parent) # In cases where you are using kvm + qemu # On certain distros (ie RHEL) this user needs to be able # To enter the parents of the instance path, if this is in /home/BLAH/ then # Without enabling the whole path, this user can't write there. This helps fix that... with sh.Rooted(True): for p in sh.explode_path(instance_parent): if not os.access(p, os.X_OK) and sh.isdir(p): # Need to be able to go into that directory sh.chmod(p, os.stat(p).st_mode | 0755)
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_adjust(self, contents, name): if name == ROOT_CONF: #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) elif name == CATALOG_CONF: nlines = list() if utils.service_enabled(settings.SWIFT, self.instances): mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Swift additions") nlines.extend(utils.param_replace_list(SWIFT_TEMPL_ADDS, mp)) nlines.append("") if utils.service_enabled(settings.QUANTUM, self.instances) or \ utils.service_enabled(settings.QUANTUM_CLIENT, self.instances): mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Quantum additions") nlines.extend(utils.param_replace_list(QUANTUM_TEMPL_ADDS, mp)) nlines.append("") if nlines: nlines.insert(0, contents) contents = cfg.add_header(name, utils.joinlinesep(*nlines)) return contents
def _config_adjust(self, contents, name): if name == ROOT_CONF: # Use config parser and # then extract known configs that # ill need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.dirs_made(*sh.mkdirslist(log_dir)) # Destroy then recreate it (the log file) sh.unlink(log_filename) self.tracewriter.file_touched(sh.touch_file(log_filename)) elif name == CATALOG_CONF: nlines = list() if 'swift' in self.options: mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Swift additions") nlines.extend(utils.param_replace_list(SWIFT_TEMPL_ADDS, mp)) nlines.append("") if 'quantum' in self.options: mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Quantum additions") nlines.extend(utils.param_replace_list(QUANTUM_TEMPL_ADDS, mp)) nlines.append("") if nlines: nlines.insert(0, contents) contents = cfg.add_header(name, utils.joinlinesep(*nlines)) return contents
def _config_adjust(self, contents, name): if name not in CONFIGS: return contents #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) log_filename = config.get('log_file', CFG_SECTION) if log_filename: LOG.info("Ensuring log file %s exists and is empty" % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists" % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) #we might need to handle more in the future... #nothing modified so just return the original return contents
def _generate_nova_conf(self): conf_fn = self._get_target_config_name(API_CONF) LOG.info("Generating dynamic content for nova: %r" % (conf_fn)) nova_conf_contents = self.conf_maker.configure() self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(conf_fn))) self.tracewriter.cfg_file_written(sh.write_file(conf_fn, nova_conf_contents))