def read_file_as_root(file_path): """Secure helper to read file as root.""" try: out, _err = execute('cat', file_path, run_as_root=True) return out except processutils.ProcessExecutionError: raise exception.FileNotFound(file_path=file_path)
def removefile(path): if not os.path.exists(path): raise exception.FileNotFound(file_path=path) os.unlink(path)
def symlink(src, dest): if not os.path.exists(src): raise exception.FileNotFound(file_path=src) os.symlink(src, dest)
def readfile(path): if not os.path.exists(path): raise exception.FileNotFound(file_path=path) with open(path, 'r') as f: return f.read()