Revision fbdac0d9 lib/bdev.py
b/lib/bdev.py | ||
---|---|---|
36 | 36 |
from ganeti import objects |
37 | 37 |
from ganeti import compat |
38 | 38 |
from ganeti import netutils |
39 |
from ganeti import pathutils |
|
39 | 40 |
|
40 | 41 |
|
41 | 42 |
# Size of reads in _CanReadDevice |
... | ... | |
88 | 89 |
return False |
89 | 90 |
|
90 | 91 |
|
92 |
def _CheckFileStoragePath(path, allowed): |
|
93 |
"""Checks if a path is in a list of allowed paths for file storage. |
|
94 |
|
|
95 |
@type path: string |
|
96 |
@param path: Path to check |
|
97 |
@type allowed: list |
|
98 |
@param allowed: List of allowed paths |
|
99 |
@raise errors.FileStoragePathError: If the path is not allowed |
|
100 |
|
|
101 |
""" |
|
102 |
if not os.path.isabs(path): |
|
103 |
raise errors.FileStoragePathError("File storage path must be absolute," |
|
104 |
" got '%s'" % path) |
|
105 |
|
|
106 |
for i in allowed: |
|
107 |
if not os.path.isabs(i): |
|
108 |
logging.info("Ignoring relative path '%s' for file storage", i) |
|
109 |
continue |
|
110 |
|
|
111 |
if utils.IsBelowDir(i, path): |
|
112 |
break |
|
113 |
else: |
|
114 |
raise errors.FileStoragePathError("Path '%s' is not acceptable for file" |
|
115 |
" storage" % path) |
|
116 |
|
|
117 |
|
|
118 |
def LoadAllowedFileStoragePaths(filename): |
|
119 |
"""Loads file containing allowed file storage paths. |
|
120 |
|
|
121 |
@rtype: list |
|
122 |
@return: List of allowed paths (can be an empty list) |
|
123 |
|
|
124 |
""" |
|
125 |
try: |
|
126 |
contents = utils.ReadFile(filename) |
|
127 |
except EnvironmentError: |
|
128 |
return [] |
|
129 |
else: |
|
130 |
return utils.FilterEmptyLinesAndComments(contents) |
|
131 |
|
|
132 |
|
|
133 |
def CheckFileStoragePath(path, _filename=pathutils.FILE_STORAGE_PATHS_FILE): |
|
134 |
"""Checks if a path is allowed for file storage. |
|
135 |
|
|
136 |
@type path: string |
|
137 |
@param path: Path to check |
|
138 |
@raise errors.FileStoragePathError: If the path is not allowed |
|
139 |
|
|
140 |
""" |
|
141 |
_CheckFileStoragePath(path, LoadAllowedFileStoragePaths(_filename)) |
|
142 |
|
|
143 |
|
|
144 |
|
|
91 | 145 |
class BlockDev(object): |
92 | 146 |
"""Block device abstract class. |
93 | 147 |
|
Also available in: Unified diff