Beispiel #1
0
    def do_action(self, req, action_id, body={}):
        """Execute a action by name(uuid) (doesn't require task sources)

        **Example request**:

        ..code-block:: bash

          root@samsung:~# http POST 10.10.10.23:8004/action/do/1
          HTTP/1.1 200 OK
          Content-Length: 288
          Content-Type: application/json; charset=UTF-8
          Date: Mon, 12 Jan 2015 19:21:21 GMT

          {
              "action": {
                  "command": "reactor.commit_action", 
                  "description": "Long description for this action", 
                  "id": 1, 
                  "name": "Turn light 4 on in the kitchen", 
                  "options": {
                      "queue": "reactor"
                  }, 
                  "short_name": "Light in kitchen"
              }, 
              "state": "PENDING", 
              "task-id": "e2b8925a-fb68-4390-ae9f-da725ea4c53e"
          }

        """

        action = actions.get(action_id)

        LOG.error(action)

        app = self.app(default=True)

        args, kwargs, options = self._get_task_args(action.get("options"))
        command = action.get("command", None)
        LOG.error(args)
        LOG.debug("Invoking task '%s' with '%s' and '%s'",
                  command, args, kwargs)

        result = app.send_task(
            command, args=args, kwargs=kwargs, **options)
        response = {'task-id': result.task_id}

        response["action"] = action

        if self.backend_configured(result):
            response.update(state=result.state)

        return response
Beispiel #2
0
    def action_get(self, req, id):
        """get single action

        response:

        ..code-block:: json
            {
                id: 1
                name: foo,
                command: reactor.commit_action,
                options:
                  device: foo
                  value: 1
            }

        """

        action = None

        try:
            action = actions.get(id)
        except Exception, e:
            pass