+ self.DisableConfd()
+ self.inotify_handler.disable()
+ return
+
+ # Reset the timer. If we're polling it will go to the polling rate, if
+ # we're not it will delay it again to its base safe timeout.
+ self._ResetTimer()
+
+ def _DisableTimer(self):
+ if self.timer_handle is not None:
+ self.mainloop.scheduler.cancel(self.timer_handle)
+ self.timer_handle = None
+
+ def _EnableTimer(self):
+ if self.polling:
+ timeout = constants.CONFD_CONFIG_RELOAD_RATELIMIT
+ else:
+ timeout = constants.CONFD_CONFIG_RELOAD_TIMEOUT
+
+ if self.timer_handle is None:
+ self.timer_handle = self.mainloop.scheduler.enter(
+ timeout, 1, self.OnTimer, [])
+
+ def _ResetTimer(self):
+ self._DisableTimer()
+ self._EnableTimer()
+
+ def OnTimer(self):
+ """Function called when the timer fires
+
+ """
+ self.timer_handle = None
+ reloaded = False
+ was_disabled = False
+ try:
+ if self.processor.reader is None:
+ was_disabled = True
+ self.EnableConfd()
+ reloaded = True
+ else:
+ reloaded = self.processor.reader.Reload()
+ except errors.ConfigurationError:
+ self.DisableConfd(silent=was_disabled)
+ return
+
+ if self.polling and reloaded:
+ logging.info("Reloaded ganeti config")
+ elif reloaded:
+ # We have reloaded the config files, but received no inotify event. If
+ # an event is pending though, we just happen to have timed out before
+ # receiving it, so this is not a problem, and we shouldn't alert
+ if not self.notifier.check_events() and not was_disabled:
+ logging.warning("Config file reload at timeout (inotify failure)")
+ elif self.polling:
+ # We're polling, but we haven't reloaded the config:
+ # Going back to inotify mode
+ logging.debug("Moving from polling mode to inotify mode")
+ self.polling = False
+ try:
+ self.inotify_handler.enable()
+ except errors.InotifyError:
+ self.polling = True
+ else:
+ logging.debug("Performed configuration check")