예제 #1
0
    def proc_cmd(self, cmd):
        """
        Process received Command.

        @cmd is a command. Should be an instance of Command class.
        """
        print "%s.proc_cmd(%r)" % (self, cmd)
        handler = getattr(self, "proc_cmd_"+cmd.command(), None)
        if not handler:
            echo_evt = self.proc_def_handler(cmd, event.echo(cmd,
                ECHO.NOT_IMPLEMENTED, origin=self.origin()))
        else:
            try:
                echo_evt = handler(cmd, event.echo(cmd, ECHO.OK,
                    origin=self.origin()))
            except:
                echo_evt = self.proc_exception(cmd, event.echo(cmd, ECHO.EXCEPTION,
                    origin=self.origin(), exception=format_exc()))
        if echo_evt:
            self.send_cmd(echo_evt)
예제 #2
0
 def proc_cmd_forward(self, cmd, echo_evt):
     evt = event.event(cmd.arg('event'))
     evev = evt.event()
     if evev not in ['variable_get', 'variable_set']:
         return echo_evt
     new_cmd = self.proc_evt(evt)
     if new_cmd:
         self.send_cmd(event.forward_response(new_cmd, cmd.id()))
     else:
         echo_evt = event.echo(cmd, ECHO.EXCEPTION, origin=self.origin(),
                 exception='No forward_response.')
     return echo_evt
예제 #3
0
    def proc_cmd(self, backend, cmd):
        """Process Command received from backend.

        @backend is the backend, which issued the command.
        @cmd is a command. Should be an instance of Command class.

        This is the only method mandatory for Backend side
        Controller-Adaptor."""
        log.debug("Controller: proc_cmd(..., %r)", cmd)
        handler = getattr(self, "proc_cmd_"+cmd.command(), None)
        if not handler:
            evt = event.echo(cmd, ECHO.NOT_IMPLEMENTED, origin=self.__origin)
        else:
            evt = event.echo(cmd, ECHO.OK, origin=self.__origin)
            try:
                handler(backend, cmd, evt)
            except:
                self.handle_exception("Handling %s raised an exception." %
                        cmd.command())
                dict_update(evt.args(),
                        rc=ECHO.EXCEPTION,
                        exception=format_exc())
        log.debug("Controller: echo(%r)", evt)
        backend.proc_evt(evt, explicit=True)