Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 """The main client_controller code. | |
|
Marc-Antoine Ruel (Google)
2015/01/30 18:00:21
FYI, we generally keep an empty line in between th
Mike Meade
2015/01/30 21:04:04
Done.
| |
| 6 | |
| 7 This code is the main entry point for the client machines and handles | |
| 8 registering with the host server and running the local RPC server. | |
| 9 """ | |
| 10 import argparse | |
| 11 import logging | |
| 12 import socket | |
| 13 import sys | |
| 14 import time | |
| 15 | |
| 16 #pylint: disable=relative-import | |
| 17 import client_rpc_server | |
| 18 import common_lib | |
| 19 import discovery_server | |
| 20 | |
| 21 | |
| 22 def RegisterClient(host, otp): | |
| 23 """Register this client with the host's discovery server.""" | |
| 24 server = discovery_server.DiscoveryServer.Connect(host) | |
| 25 logging.info( | |
| 26 'Registering with discovery server using OTP %s', otp) | |
| 27 server.RegisterClient(otp, common_lib.MY_IP) | |
| 28 | |
| 29 | |
| 30 def GetArgs(): | |
|
Marc-Antoine Ruel (Google)
2015/01/30 18:00:21
Is there value in making it a function vs embeddin
Mike Meade
2015/01/30 21:04:04
Not explicitly. I was just trying to group by oper
| |
| 31 """Parse the command line arguments.""" | |
| 32 parser = argparse.ArgumentParser() | |
| 33 parser.add_argument('--otp') | |
| 34 parser.add_argument('--host') | |
| 35 parser.add_argument('--idle-timeout', type=int) | |
| 36 args, _ = parser.parse_known_args() | |
| 37 return args | |
| 38 | |
| 39 | |
| 40 def CreateRPCServer(host, idle_timeout=None): | |
| 41 """Create the client RPC server. | |
| 42 | |
| 43 Args: | |
| 44 host: The address of the host machine. | |
| 45 idle_timeout: The timeout in seconds to set. | |
| 46 | |
| 47 Returns: | |
| 48 An instance of client_rpc_server.RPCServer. | |
| 49 """ | |
| 50 server = client_rpc_server.RPCServer() | |
|
Marc-Antoine Ruel (Google)
2015/01/30 18:00:21
same
Mike Meade
2015/01/30 21:04:04
Done.
| |
| 51 server.AddAuthorizedAddress(host) | |
| 52 if idle_timeout: | |
| 53 server.SetIdleTimeout(idle_timeout) | |
| 54 return server | |
| 55 | |
| 56 | |
| 57 def main(): | |
| 58 common_lib.InitLogging() | |
| 59 common_lib.LogCommandLine() | |
| 60 logging.info('Client controller starting') | |
| 61 args = GetArgs() | |
| 62 RegisterClient(args.host, args.otp) | |
| 63 server = CreateRPCServer(args.host, args.idle_timeout) | |
| 64 server.serve_forever() | |
| 65 | |
| 66 | |
| 67 if __name__ == '__main__': | |
| 68 main() | |
| OLD | NEW |