def _generate_root_wrap(self): if not self.cfg.getboolean("nova", "do_root_wrap"): return False else: lines = list() lines.append("%s ALL=(root) NOPASSWD: %s" % (sh.getuser(), self.root_wrap_bin)) fc = utils.joinlinesep(*lines) root_wrap_fn = sh.joinpths(self.distro.get_command_config("sudoers_dir"), "nova-rootwrap") self.tracewriter.file_touched(root_wrap_fn) with sh.Rooted(True): sh.write_file(root_wrap_fn, fc) sh.chmod(root_wrap_fn, 0440) sh.chown(root_wrap_fn, sh.getuid(sh.ROOT_USER), sh.getgid(sh.ROOT_GROUP)) return True
def store_current_settings(c_settings): try: # Remove certain keys that just shouldn't be saved to_save = dict(c_settings) for k in ['action', 'verbose', 'dryrun']: if k in c_settings: to_save.pop(k, None) 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(to_save))) fh.flush() (uid, gid) = sh.get_suids() sh.chown(SETTINGS_FN, uid, gid) except Exception as e: LOG.debug("Failed writing to %s due to %s", SETTINGS_FN, e)
def store_current_settings(c_settings): try: # Remove certain keys that just shouldn't be saved to_save = dict(c_settings) for k in ['action', 'verbose', 'dryrun']: if k in c_settings: to_save.pop(k, None) 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(to_save))) fh.flush() (uid, gid) = sh.get_suids() sh.chown(SETTINGS_FN, uid, gid) except Exception as e: LOG.debug("Failed writing to %s due to %s", SETTINGS_FN, e)