Example #1
0
    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
Example #2
0
 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"]]
Example #3
0
    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
Example #4
0
        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)
Example #5
0
        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)
Example #6
0
    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"))
Example #7
0
 def on_info(info):
     return response(_("Connected"), info)
Example #8
0
 def on_connect_failed(reason, host_id):
     return response(_("Offline"))
Example #9
0
 def on_info_fail(reason, c):
     c.disconnect()
     return response(_("Offline"))
Example #10
0
 def on_info(info, c):
     c.disconnect()
     return response(_("Online"), info)
Example #11
0
 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"]]
Example #12
0
 def on_info(info):
     return response(_("Connected"), info)
Example #13
0
 def on_connect_failed(reason, host_id):
     return response(_("Offline"))
Example #14
0
 def on_info_fail(reason, c):
     c.disconnect()
     return response(_("Offline"))
Example #15
0
 def on_info(info, c):
     c.disconnect()
     return response(_("Online"), info)
Example #16
0
 def on_connect(connected, c):
     if not connected:
         main_deferred.callback((False, _("Daemon not running")))
         return
     c.daemon.shutdown()
     main_deferred.callback((True, ))
Example #17
0
 def on_connect(connected, c):
     if not connected:
         main_deferred.callback((False, _('Daemon not running')))
         return
     c.daemon.shutdown()
     main_deferred.callback((True, ))