def stop_daemon(self, host_id): """ Stops a running daemon. :param host_id: the hash id of the host :type host_id: string """ main_deferred = Deferred() host = self._get_host(host_id) if not host: main_deferred.callback((False, _('Daemon does not exist'))) return main_deferred try: def on_connect(connected, c): if not connected: main_deferred.callback((False, _('Daemon not running'))) return c.daemon.shutdown() main_deferred.callback((True, )) def on_connect_failed(reason): main_deferred.callback((False, reason)) host, port, user, password = host[1:5] c = Client() d = c.connect(host, port, user, password) d.addCallback(on_connect, c) d.addErrback(on_connect_failed) except Exception: main_deferred.callback((False, 'An error occurred')) return main_deferred
def get_hosts(self): """ Return the hosts in the hostlist. """ log.debug("get_hosts called") return [(tuple(host[HOSTS_ID:HOSTS_PORT + 1]) + (_("Offline"), )) for host in self.host_list["hosts"]]
def stop_daemon(self, host_id): """ Stops a running daemon. :param host_id: the hash id of the host :type host_id: string """ main_deferred = Deferred() host = self.get_host(host_id) if not host: main_deferred.callback((False, _("Daemon doesn't exist"))) return main_deferred try: def on_connect(connected, c): if not connected: main_deferred.callback((False, _("Daemon not running"))) return c.daemon.shutdown() main_deferred.callback((True, )) def on_connect_failed(reason): main_deferred.callback((False, reason)) host, port, user, password = host[1:5] c = Client() d = c.connect(host, port, user, password) d.addCallback(on_connect, c) d.addErrback(on_connect_failed) except: main_deferred.callback((False, "An error occurred")) return main_deferred
def on_connect(connected, c, host_id): def on_info(info, c): c.disconnect() return response(_("Online"), info) def on_info_fail(reason, c): c.disconnect() return response(_("Offline")) if not connected: return response(_("Offline")) return c.daemon.info().addCallback(on_info, c).addErrback(on_info_fail, c)
def on_connect(connected, c, host_id): def on_info(info, c): c.disconnect() return response(_("Online"), info) def on_info_fail(reason, c): c.disconnect() return response(_("Offline")) if not connected: return response(_("Offline")) return c.daemon.info( ).addCallback(on_info, c ).addErrback(on_info_fail, c)
def get_host_status(self, host_id): """ Returns the current status for the specified host. :param host_id: the hash id of the host :type host_id: string """ def response(status, info=None): return host_id, host, port, status, info try: host_id, host, port, user, password = self.get_host(host_id) except TypeError, e: return response(_("Offline"))
def on_info(info): return response(_("Connected"), info)
def on_connect_failed(reason, host_id): return response(_("Offline"))
def on_info_fail(reason, c): c.disconnect() return response(_("Offline"))
def on_info(info, c): c.disconnect() return response(_("Online"), info)
def get_hosts(self): """ Return the hosts in the hostlist. """ log.debug("get_hosts called") return [(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]]
def on_connect(connected, c): if not connected: main_deferred.callback((False, _("Daemon not running"))) return c.daemon.shutdown() main_deferred.callback((True, ))
def on_connect(connected, c): if not connected: main_deferred.callback((False, _('Daemon not running'))) return c.daemon.shutdown() main_deferred.callback((True, ))