Revision a20e4768 lib/runtime.py
b/lib/runtime.py | ||
---|---|---|
26 | 26 |
import grp |
27 | 27 |
import pwd |
28 | 28 |
import threading |
29 |
import platform |
|
29 | 30 |
|
30 | 31 |
from ganeti import constants |
31 | 32 |
from ganeti import errors |
... | ... | |
35 | 36 |
_priv = None |
36 | 37 |
_priv_lock = threading.Lock() |
37 | 38 |
|
39 |
#: Architecture information |
|
40 |
_arch = None |
|
41 |
|
|
38 | 42 |
|
39 | 43 |
def GetUid(user, _getpwnam): |
40 | 44 |
"""Retrieve the uid from the database. |
... | ... | |
187 | 191 |
_priv_lock.release() |
188 | 192 |
|
189 | 193 |
return _priv |
194 |
|
|
195 |
|
|
196 |
def InitArchInfo(): |
|
197 |
"""Initialize architecture information. |
|
198 |
|
|
199 |
We can assume this information never changes during the lifetime of a |
|
200 |
process, therefore the information can easily be cached. |
|
201 |
|
|
202 |
@note: This function uses C{platform.architecture} to retrieve the Python |
|
203 |
binary architecture and does so by forking to run C{file} (see Python |
|
204 |
documentation for more information). Therefore it must not be used in a |
|
205 |
multi-threaded environment. |
|
206 |
|
|
207 |
""" |
|
208 |
global _arch # pylint: disable=W0603 |
|
209 |
|
|
210 |
if _arch is not None: |
|
211 |
raise errors.ProgrammerError("Architecture information can only be" |
|
212 |
" initialized once") |
|
213 |
|
|
214 |
_arch = (platform.architecture()[0], platform.machine()) |
|
215 |
|
|
216 |
|
|
217 |
def GetArchInfo(): |
|
218 |
"""Returns previsouly initialized architecture information. |
|
219 |
|
|
220 |
""" |
|
221 |
if _arch is None: |
|
222 |
raise errors.ProgrammerError("Architecture information hasn't been" |
|
223 |
" initialized") |
|
224 |
|
|
225 |
return _arch |
Also available in: Unified diff