Index: testing/legion/client_controller.py |
diff --git a/testing/legion/client_controller.py b/testing/legion/client_controller.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..8fbc10abc106ea261cef00ee2ab922cee70e0dc4 |
--- /dev/null |
+++ b/testing/legion/client_controller.py |
@@ -0,0 +1,68 @@ |
+#!/usr/bin/env python |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+"""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.
|
+ |
+This code is the main entry point for the client machines and handles |
+registering with the host server and running the local RPC server. |
+""" |
+import argparse |
+import logging |
+import socket |
+import sys |
+import time |
+ |
+#pylint: disable=relative-import |
+import client_rpc_server |
+import common_lib |
+import discovery_server |
+ |
+ |
+def RegisterClient(host, otp): |
+ """Register this client with the host's discovery server.""" |
+ server = discovery_server.DiscoveryServer.Connect(host) |
+ logging.info( |
+ 'Registering with discovery server using OTP %s', otp) |
+ server.RegisterClient(otp, common_lib.MY_IP) |
+ |
+ |
+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
|
+ """Parse the command line arguments.""" |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument('--otp') |
+ parser.add_argument('--host') |
+ parser.add_argument('--idle-timeout', type=int) |
+ args, _ = parser.parse_known_args() |
+ return args |
+ |
+ |
+def CreateRPCServer(host, idle_timeout=None): |
+ """Create the client RPC server. |
+ |
+ Args: |
+ host: The address of the host machine. |
+ idle_timeout: The timeout in seconds to set. |
+ |
+ Returns: |
+ An instance of client_rpc_server.RPCServer. |
+ """ |
+ 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.
|
+ server.AddAuthorizedAddress(host) |
+ if idle_timeout: |
+ server.SetIdleTimeout(idle_timeout) |
+ return server |
+ |
+ |
+def main(): |
+ common_lib.InitLogging() |
+ common_lib.LogCommandLine() |
+ logging.info('Client controller starting') |
+ args = GetArgs() |
+ RegisterClient(args.host, args.otp) |
+ server = CreateRPCServer(args.host, args.idle_timeout) |
+ server.serve_forever() |
+ |
+ |
+if __name__ == '__main__': |
+ main() |