| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """The main task entrypoint.""" | 6 """The main client_controller code. |
| 7 |
| 8 This code is the main entry point for the client machines and handles |
| 9 registering with the host server and running the local RPC server. |
| 10 """ |
| 7 | 11 |
| 8 import argparse | 12 import argparse |
| 9 import logging | 13 import logging |
| 10 import socket | 14 import socket |
| 11 import sys | 15 import sys |
| 12 import time | 16 import time |
| 13 | 17 |
| 14 #pylint: disable=relative-import | 18 #pylint: disable=relative-import |
| 19 import client_rpc_server |
| 15 import common_lib | 20 import common_lib |
| 16 import rpc_server | |
| 17 | 21 |
| 18 | 22 |
| 19 def main(): | 23 def main(): |
| 20 print ' '.join(sys.argv) | 24 print ' '.join(sys.argv) |
| 21 common_lib.InitLogging() | 25 common_lib.InitLogging() |
| 22 logging.info('Task starting') | 26 logging.info('Client controller starting') |
| 23 | 27 |
| 24 parser = argparse.ArgumentParser() | 28 parser = argparse.ArgumentParser() |
| 25 parser.add_argument('--otp', | 29 parser.add_argument('--otp', |
| 26 help='One time token used to authenticate with the host') | 30 help='One time token used to authenticate with the host') |
| 27 parser.add_argument('--controller', | 31 parser.add_argument('--host', |
| 28 help='The ip address of the controller machine') | 32 help='The ip address of the host') |
| 29 parser.add_argument('--idle-timeout', type=int, | 33 parser.add_argument('--idle-timeout', type=int, |
| 30 default=common_lib.DEFAULT_TIMEOUT_SECS, | 34 default=common_lib.DEFAULT_TIMEOUT_SECS, |
| 31 help='The idle timeout for the rpc server in seconds') | 35 help='The idle timeout for the rpc server in seconds') |
| 32 args, _ = parser.parse_known_args() | 36 args, _ = parser.parse_known_args() |
| 33 | 37 |
| 34 logging.info( | 38 logging.info( |
| 35 'Registering with registration server at %s using OTP "%s"', | 39 'Registering with discovery server at %s using OTP %s', args.host, |
| 36 args.controller, args.otp) | 40 args.otp) |
| 37 server = common_lib.ConnectToServer(args.controller).RegisterTask( | 41 server = common_lib.ConnectToServer(args.host).RegisterClient( |
| 38 args.otp, common_lib.MY_IP) | 42 args.otp, common_lib.MY_IP) |
| 39 | 43 |
| 40 server = rpc_server.RPCServer(args.controller, args.idle_timeout) | 44 server = client_rpc_server.RPCServer(args.host, args.idle_timeout) |
| 41 | 45 |
| 42 server.serve_forever() | 46 server.serve_forever() |
| 43 return 0 | 47 return 0 |
| 44 | 48 |
| 45 | 49 |
| 46 if __name__ == '__main__': | 50 if __name__ == '__main__': |
| 47 sys.exit(main()) | 51 sys.exit(main()) |
| OLD | NEW |