• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17from host_controller.tfc import api_message
18
19
20class Request(api_message.ApiMessage):
21    """The requests defined by TFC API.
22
23    Attributes:
24        _BODY: The requests.new parameters that are put into http message body.
25        _PARAMETERS: The requests.new parameters put into http parameters.
26        _ALL_KEYS: Union of above.
27    """
28    _BODY = {
29            "command_line",
30            "user"}
31    _PARAMETERS = {
32            "branch",
33            "build_flavor",
34            "build_id",
35            "build_os",
36            "cluster",
37            "no_build_args",
38            "run_target",
39            "shard_count"
40            "run_count"}
41    _ALL_KEYS = (_BODY | _PARAMETERS)
42
43    def __init__(self, cluster, command_line, run_target, user, **kwargs):
44        """Initializes the attributes.
45
46        Args:
47            cluster: The ID of the cluster to send this request to.
48            command_line: The command to execute on a host.
49            run_target: The target device to run the command.
50            user: The name of the user sending this request.
51            **kwargs: The optional attributes.
52        """
53        super(Request, self).__init__(self._ALL_KEYS,
54                                      cluster=cluster,
55                                      command_line=command_line,
56                                      run_target=run_target,
57                                      user=user,
58                                      **kwargs)
59
60    def GetBody(self):
61        """Returns the http message body.
62
63        Returns:
64            A JSON object.
65        """
66        return self.ToJson(self._BODY)
67
68    def GetParameters(self):
69        """Returns the http parameters.
70
71        Returns:
72            A dict of strings.
73        """
74        return self.ToJson(self._PARAMETERS)
75