1 # 2 # Copyright (C) 2018 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 17 from host_controller.command_processor import base_command_processor 18 from host_controller.tfc import request 19 20 21 class CommandRequest(base_command_processor.BaseCommandProcessor): 22 """Command processor for request command. 23 24 Attributes: 25 arg_parser: ConsoleArgumentParser object, argument parser. 26 console: cmd.Cmd console object. 27 command: string, command name which this processor will handle. 28 command_detail: string, detailed explanation for the command. 29 """ 30 31 command = "request" 32 command_detail = "Send TFC a request to execute a command." 33 34 # @Override 35 def SetUp(self): 36 """Initializes the parser for request command.""" 37 self.arg_parser.add_argument( 38 "--cluster", 39 required=True, 40 help="The cluster to which the request is submitted.") 41 self.arg_parser.add_argument( 42 "--run-target", 43 required=True, 44 help="The target device to run the command.") 45 self.arg_parser.add_argument( 46 "--user", 47 required=True, 48 help="The name of the user submitting the request.") 49 self.arg_parser.add_argument( 50 "command", 51 metavar="COMMAND", 52 nargs="+", 53 help='The command to be executed. If the command contains ' 54 'arguments starting with "-", place the command after ' 55 '"--" at end of line.') 56 57 # @Override 58 def Run(self, arg_line): 59 """Sends TFC a request to execute a command.""" 60 args = self.arg_parser.ParseLine(arg_line) 61 req = request.Request( 62 cluster=args.cluster, 63 command_line=" ".join(args.command), 64 run_target=args.run_target, 65 user=args.user) 66 self.console._tfc_client.NewRequest(req) 67