From 42ab9ac485f37d3a2ba2890e872b9e801b3ca35d Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sun, 19 Aug 2012 01:06:08 +0200
Subject: [PATCH] Add configure-time switch for split queries

And expand cli.GetClient() to allow opening the query socket, instead
of the main master socket.

Finally, enable the query socket use in gnt-cluster version, since
that is already implemented fully in Queryd.hs/hconfd.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Agata Murawska <agatamurawska@google.com>
---
 Makefile.am               |  2 ++
 configure.ac              | 27 ++++++++++++++++++++++++++-
 lib/cli.py                | 17 +++++++++++++++--
 lib/client/gnt_cluster.py |  2 +-
 lib/constants.py          |  1 +
 5 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0402bc9c2..8dc4380e2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1142,6 +1142,7 @@ lib/_autoconf.py: Makefile | stamp-directories
 	  echo "PY_CONFD = $(PY_CONFD)"; \
 	  echo "HS_CONFD = $(HS_CONFD)"; \
 	  echo "XEN_CMD = '$(XEN_CMD)'"; \
+	  echo "ENABLE_SPLIT_QUERY = $(ENABLE_SPLIT_QUERY)"; \
 	} > $@
 
 lib/_vcsversion.py: Makefile vcs-version | stamp-directories
@@ -1195,6 +1196,7 @@ $(REPLACE_VARS_SED): Makefile stamp-directories
 	  echo 's#@GNTDAEMONSGROUP@#$(DAEMONS_GROUP)#g'; \
 	  echo 's#@CUSTOM_ENABLE_CONFD@#$(ENABLE_CONFD)#g'; \
 	  echo 's#@MODULES@#$(strip $(lint_python_code))#g'; \
+	  echo 's#@ENABLE_SPLIT_QUERY@#$(ENABLE_SPLIT_QUERY)#g'; \
 	} > $@
 
 # Using deferred evaluation
diff --git a/configure.ac b/configure.ac
index ebc00b36c..9f73539d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -288,7 +288,7 @@ AC_ARG_ENABLE([htools-rapi],
         [],
         [enable_htools_rapi=no])
 
-# --enable-htools
+# --enable-confd
 ENABLE_CONFD=
 AC_ARG_ENABLE([confd],
   [AS_HELP_STRING([--enable-confd],
@@ -324,6 +324,31 @@ AM_CONDITIONAL([WANT_CONFD], [test x$enable_confd = xTrue])
 AM_CONDITIONAL([PY_CONFD], [test x$py_confd = xTrue])
 AM_CONDITIONAL([HS_CONFD], [test x$hs_confd = xTrue])
 
+# --enable-split-query
+ENABLE_SPLIT_QUERY=
+AC_ARG_ENABLE([split-query],
+  [AS_HELP_STRING([--enable-split-query],
+  [enable use of custom query daemon via Haskell confd])],
+  [[case "$enableval" in
+      no)
+        enable_split_query=False
+        ;;
+      yes)
+        enable_split_query=True
+        ;;
+      *)
+        echo "Invalid value for enable-confd '$enableval'"
+        exit 1
+        ;;
+    esac
+  ]],
+  [enable_split_query=False])
+AC_SUBST(ENABLE_SPLIT_QUERY, $enable_split_query)
+
+if test x$enable_split_query = xTrue -a x$hs_confd != xTrue; then
+  AC_MSG_ERROR([Split queries require the Haskell confd])
+fi
+
 # --with-disk-separator=...
 AC_ARG_WITH([disk-separator],
   [AS_HELP_STRING([--with-disk-separator=STRING],
diff --git a/lib/cli.py b/lib/cli.py
index 1ead82ee5..44d854dd4 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -2082,10 +2082,23 @@ def SetGenericOpcodeOpts(opcode_list, options):
       op.priority = _PRIONAME_TO_VALUE[options.priority]
 
 
-def GetClient():
+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
+
+  """
+  if query and constants.ENABLE_SPLIT_QUERY:
+    address = constants.QUERY_SOCKET
+  else:
+    address = None
   # TODO: Cache object?
   try:
-    client = luxi.Client()
+    client = luxi.Client(address=address)
   except luxi.NoMasterError:
     ss = ssconf.SimpleStore()
 
diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py
index 086702ead..680ced658 100644
--- a/lib/client/gnt_cluster.py
+++ b/lib/client/gnt_cluster.py
@@ -334,7 +334,7 @@ def ShowClusterVersion(opts, args):
   @return: the desired exit code
 
   """
-  cl = GetClient()
+  cl = GetClient(query=True)
   result = cl.QueryClusterInfo()
   ToStdout("Software version: %s", result["software_version"])
   ToStdout("Internode protocol: %s", result["protocol_version"])
diff --git a/lib/constants.py b/lib/constants.py
index 1646a04c9..0136e9963 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -175,6 +175,7 @@ CONF_DIR = SYSCONFDIR + "/ganeti"
 USER_SCRIPTS_DIR = CONF_DIR + "/scripts"
 ENABLE_CONFD = _autoconf.ENABLE_CONFD
 HS_CONFD = _autoconf.HS_CONFD
+ENABLE_SPLIT_QUERY = _autoconf.ENABLE_SPLIT_QUERY
 
 #: Lock file for watcher, locked in shared mode by watcher; lock in exclusive
 # mode to block watcher (see L{cli._RunWhileClusterStoppedHelper.Call}
-- 
GitLab