Revision a2e60f14
b/daemons/ganeti-rapi | ||
---|---|---|
32 | 32 |
import os |
33 | 33 |
import os.path |
34 | 34 |
|
35 |
try: |
|
36 |
from pyinotify import pyinotify # pylint: disable-msg=E0611 |
|
37 |
except ImportError: |
|
38 |
import pyinotify |
|
39 |
|
|
40 |
from ganeti import asyncnotifier |
|
35 | 41 |
from ganeti import constants |
36 | 42 |
from ganeti import http |
37 | 43 |
from ganeti import daemon |
... | ... | |
89 | 95 |
|
90 | 96 |
# Load password file |
91 | 97 |
if os.path.isfile(constants.RAPI_USERS_FILE): |
92 |
self._users = http.auth.ReadPasswordFile(constants.RAPI_USERS_FILE) |
|
98 |
wm = pyinotify.WatchManager() |
|
99 |
hdl = asyncnotifier.SingleFileEventHandler(wm, self._OnUsersFileUpdate, |
|
100 |
constants.RAPI_USERS_FILE) |
|
101 |
self._users_inotify_handler = hdl |
|
102 |
asyncnotifier.AsyncNotifier(wm, default_proc_fun=hdl) |
|
103 |
self._users = None |
|
104 |
self._OnUsersFileUpdate(False) |
|
93 | 105 |
else: |
94 | 106 |
self._users = None |
95 | 107 |
|
108 |
def _OnUsersFileUpdate(self, notifier_enabled): |
|
109 |
"""Called upon update of the RAPI users file by pyinotify. |
|
110 |
|
|
111 |
@type notifier_enabled: boolean |
|
112 |
@param notifier_enabled: whether the notifier is still enabled |
|
113 |
|
|
114 |
""" |
|
115 |
logging.info("Reloading modified %s", constants.RAPI_USERS_FILE) |
|
116 |
|
|
117 |
try: |
|
118 |
users = http.auth.ReadPasswordFile(constants.RAPI_USERS_FILE) |
|
119 |
self._users = users |
|
120 |
except Exception, err: # pylint: disable-msg=W0703 |
|
121 |
# We don't care about the type of exception |
|
122 |
logging.error("Error while reading %s: %s", constants.RAPI_USERS_FILE, |
|
123 |
err) |
|
124 |
|
|
125 |
# Renable the watch again if we'd an atomic update of the file (e.g. mv) |
|
126 |
if not notifier_enabled: |
|
127 |
self._users_inotify_handler.enable() |
|
128 |
|
|
96 | 129 |
def _GetRequestContext(self, req): |
97 | 130 |
"""Returns the context for a request. |
98 | 131 |
|
Also available in: Unified diff