def _setup_pki(self): LOG.info("Setting up keystone's pki support.") for value in kconf.PKI_FILES.values(): sh.mkdirslist(sh.dirname(sh.joinpths(self.configurator.link_dir, value)), tracewriter=self.tracewriter) pki_cmd = MANAGE_CMD + ['pki_setup'] cmds = [{'cmd': pki_cmd}] utils.execute_template(*cmds, cwd=self.bin_dir, params=self.config_params(None))
def _start(self): if self.started: return else: trace_dirs = sh.mkdirslist(sh.dirname(self.trace_fn)) sh.touch_file(self.trace_fn, die_if_there=self.break_if_there) self.started = True self.dirs_made(*trace_dirs)
def _setup_logs(self, clear): log_fns = [self.access_log, self.error_log] utils.log_iterable(log_fns, logger=LOG, header="Adjusting %s log files" % (len(log_fns))) for fn in log_fns: with sh.Rooted(True): if clear: sh.unlink(fn, True) sh.mkdirslist(sh.dirname(fn)) sh.touch_file(fn, die_if_there=False) sh.chmod(fn, 0666) self.tracewriter.file_touched(fn) return len(log_fns)
def _configure_files(self): config_fns = self.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.target_config(fn) sh.mkdirslist(sh.dirname(tgt_fn), tracewriter=self.tracewriter) (source_fn, contents) = self.source_config(fn) LOG.debug("Configuring file %s ---> %s.", (source_fn), (tgt_fn)) contents = self._config_param_replace(fn, contents, self.config_params(fn)) contents = self._config_adjust(contents, fn) sh.write_file(tgt_fn, contents, tracewriter=self.tracewriter) return len(config_fns)
def configure(self): configs_made = nova.NovaInstaller.configure(self) driver_canon = utils.canon_virt_driver(self.get_option('virt_driver')) if driver_canon == 'libvirt': # Create a libvirtd user group if not sh.group_exists('libvirtd'): cmd = ['groupadd', 'libvirtd'] sh.execute(cmd) if not sh.isfile(LIBVIRT_POLICY_FN): contents = self._get_policy(self._get_policy_users()) sh.mkdirslist(sh.dirname(LIBVIRT_POLICY_FN)) sh.write_file(LIBVIRT_POLICY_FN, contents) configs_made += 1 return configs_made
def configure(self): configs_made = nova.NovaInstaller.configure(self) driver_canon = nhelper.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_files(self): config_fns = self.configurator.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.configurator.target_config(fn) sh.mkdirslist(sh.dirname(tgt_fn), tracewriter=self.tracewriter) (source_fn, contents) = self.configurator.source_config(fn) LOG.debug("Configuring file %s ---> %s.", (source_fn), (tgt_fn)) contents = self.configurator.config_param_replace(fn, contents, self.config_params(fn)) contents = self.configurator.config_adjust(contents, fn) sh.write_file(tgt_fn, contents, tracewriter=self.tracewriter) return len(config_fns)
def store_current_settings(settings): base_dir = sh.dirname(SETTINGS_FN) if not sh.isdir(base_dir): # Don't use sh here so that we always # read this (even if dry-run) os.makedirs(base_dir) try: with sh.Rooted(True): with open(SETTINGS_FN, 'w') as fh: fh.write("# Anvil last used settings\n") fh.write(utils.add_header(SETTINGS_FN, utils.prettify_yaml(settings))) fh.flush() (uid, gid) = sh.get_suids() sh.chown_r(base_dir, uid, gid) except Exception as e: pass
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): 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 %s.", colorizer.quote(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 %s to %s.", colorizer.quote(source_fn), colorizer.quote(tgt_fn)) self.tracewriter.cfg_file_written(sh.write_file(tgt_fn, contents)) return len(config_fns)
def _get_component_name(pkg_dir): return sh.basename(sh.dirname(pkg_dir))
def _generate_nova_conf(self, root_wrapped): conf_fn = self._get_target_config_name(API_CONF) LOG.info("Generating dynamic content for nova: %s.", colorizer.quote(conf_fn)) nova_conf_contents = self.conf_maker.configure(fn=conf_fn, root_wrapped=root_wrapped) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(conf_fn))) self.tracewriter.cfg_file_written(sh.write_file(conf_fn, nova_conf_contents))