X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/44fbd23b9830ff2e0c6f814693abd2cdfff2db09..4a78c361a6de3bcbf98f02abfe41ae3b11de2b00:/lib/runtime.py diff --git a/lib/runtime.py b/lib/runtime.py index 4d5e3ef..883b2e5 100644 --- a/lib/runtime.py +++ b/lib/runtime.py @@ -1,4 +1,5 @@ # +# # Copyright (C) 2010 Google Inc. # @@ -25,6 +26,7 @@ import grp import pwd import threading +import platform from ganeti import constants from ganeti import errors @@ -34,6 +36,9 @@ from ganeti import utils _priv = None _priv_lock = threading.Lock() +#: Architecture information +_arch = None + def GetUid(user, _getpwnam): """Retrieve the uid from the database. @@ -73,9 +78,9 @@ class GetentResolver: @ivar rapi_uid: The resolved uid of the rapi user @ivar rapi_gid: The resolved gid of the rapi group @ivar noded_uid: The resolved uid of the noded user - @ivar daemons_gid: The resolved gid of the daemons group @ivar admin_gid: The resolved gid of the admin group + """ def __init__(self, _getpwnam=pwd.getpwnam, _getgrnam=grp.getgrnam): """Initialize the resolver. @@ -170,20 +175,51 @@ def GetEnts(resolver=GetentResolver): """Singleton wrapper around resolver instance. As this method is accessed by multiple threads at the same time - we need to take thread-safty carefully + we need to take thread-safety carefully. """ # We need to use the global keyword here - global _priv # pylint: disable-msg=W0603 + global _priv # pylint: disable=W0603 if not _priv: _priv_lock.acquire() try: if not _priv: # W0621: Redefine '_priv' from outer scope (used for singleton) - _priv = resolver() # pylint: disable-msg=W0621 + _priv = resolver() # pylint: disable=W0621 finally: _priv_lock.release() return _priv + +def InitArchInfo(): + """Initialize architecture information. + + We can assume this information never changes during the lifetime of a + process, therefore the information can easily be cached. + + @note: This function uses C{platform.architecture} to retrieve the Python + binary architecture and does so by forking to run C{file} (see Python + documentation for more information). Therefore it must not be used in a + multi-threaded environment. + + """ + global _arch # pylint: disable=W0603 + + if _arch is not None: + raise errors.ProgrammerError("Architecture information can only be" + " initialized once") + + _arch = (platform.architecture()[0], platform.machine()) + + +def GetArchInfo(): + """Returns previsouly initialized architecture information. + + """ + if _arch is None: + raise errors.ProgrammerError("Architecture information hasn't been" + " initialized") + + return _arch