commit a51b19deef7387616c3614ab2e6d8297290d5c1d
Author: Helga Velroyen <helgav@google.com>
Date:   Wed Nov 20 10:23:37 2013 +0000

    Move GetClient() to runtime module
    
    Soon both, the cli and the masterd, will use a luxi
    client to run queries. The method to obtain and configure
    the luxi client with the right address can be reused from
    cli to masterd here. Therefore, this patch moves the
    function to the common runtime module.
    
    Signed-off-by: Helga Velroyen <helgav@google.com>
    Reviewed-by: Hrvoje Ribicic <riba@google.com>

diff --git a/lib/cli.py b/lib/cli.py
index b213e4f..f0327b1 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -37,7 +37,6 @@ from ganeti import errors
 from ganeti import constants
 from ganeti import opcodes
 from ganeti import luxi
-from ganeti import ssconf
 from ganeti import rpc
 from ganeti import ssh
 from ganeti import compat
@@ -46,6 +45,8 @@ from ganeti import qlang
 from ganeti import objects
 from ganeti import pathutils
 
+from ganeti.runtime import (GetClient)
+
 from optparse import (OptionParser, TitledHelpFormatter,
                       Option, OptionValueError)
 
@@ -2361,51 +2362,6 @@ def SetGenericOpcodeOpts(opcode_list, options):
     _InitReasonTrail(op, options)
 
 
-def GetClient(query=False):
-  """Connects to the a luxi socket and returns a client.
-
-  @type query: boolean
-  @param query: this signifies that the client will only be
-      used for queries; if the build-time parameter
-      enable-split-queries is enabled, then the client will be
-      connected to the query socket instead of the masterd socket
-
-  """
-  override_socket = os.getenv(constants.LUXI_OVERRIDE, "")
-  if override_socket:
-    if override_socket == constants.LUXI_OVERRIDE_MASTER:
-      address = pathutils.MASTER_SOCKET
-    elif override_socket == constants.LUXI_OVERRIDE_QUERY:
-      address = pathutils.QUERY_SOCKET
-    else:
-      address = override_socket
-  elif query:
-    address = pathutils.QUERY_SOCKET
-  else:
-    address = None
-  # TODO: Cache object?
-  try:
-    client = luxi.Client(address=address)
-  except luxi.NoMasterError:
-    ss = ssconf.SimpleStore()
-
-    # Try to read ssconf file
-    try:
-      ss.GetMasterNode()
-    except errors.ConfigurationError:
-      raise errors.OpPrereqError("Cluster not initialized or this machine is"
-                                 " not part of a cluster",
-                                 errors.ECODE_INVAL)
-
-    master, myself = ssconf.GetMasterAndMyself(ss=ss)
-    if master != myself:
-      raise errors.OpPrereqError("This is not the master node, please connect"
-                                 " to node '%s' and rerun the command" %
-                                 master, errors.ECODE_INVAL)
-    raise
-  return client
-
-
 def FormatError(err):
   """Return a formatted error message for a given error.
 
diff --git a/lib/runtime.py b/lib/runtime.py
index bb586f1..a3d2812 100644
--- a/lib/runtime.py
+++ b/lib/runtime.py
@@ -26,10 +26,14 @@
 import grp
 import pwd
 import threading
+import os
 import platform
 
 from ganeti import constants
 from ganeti import errors
+from ganeti import luxi
+from ganeti import pathutils
+from ganeti import ssconf
 from ganeti import utils
 
 
@@ -235,3 +239,48 @@ def GetArchInfo():
                                  " initialized")
 
   return _arch
+
+
+def GetClient(query=False):
+  """Connects to the a luxi socket and returns a client.
+
+  @type query: boolean
+  @param query: this signifies that the client will only be
+      used for queries; if the build-time parameter
+      enable-split-queries is enabled, then the client will be
+      connected to the query socket instead of the masterd socket
+
+  """
+  override_socket = os.getenv(constants.LUXI_OVERRIDE, "")
+  if override_socket:
+    if override_socket == constants.LUXI_OVERRIDE_MASTER:
+      address = pathutils.MASTER_SOCKET
+    elif override_socket == constants.LUXI_OVERRIDE_QUERY:
+      address = pathutils.QUERY_SOCKET
+    else:
+      address = override_socket
+  elif query:
+    address = pathutils.QUERY_SOCKET
+  else:
+    address = None
+  # TODO: Cache object?
+  try:
+    client = luxi.Client(address=address)
+  except luxi.NoMasterError:
+    ss = ssconf.SimpleStore()
+
+    # Try to read ssconf file
+    try:
+      ss.GetMasterNode()
+    except errors.ConfigurationError:
+      raise errors.OpPrereqError("Cluster not initialized or this machine is"
+                                 " not part of a cluster",
+                                 errors.ECODE_INVAL)
+
+    master, myself = ssconf.GetMasterAndMyself(ss=ss)
+    if master != myself:
+      raise errors.OpPrereqError("This is not the master node, please connect"
+                                 " to node '%s' and rerun the command" %
+                                 master, errors.ECODE_INVAL)
+    raise
+  return client
