Use a query client for node queries where necessary
authorHelga Velroyen <helgav@google.com>
Tue, 19 Nov 2013 12:41:45 +0000 (13:41 +0100)
committerHelga Velroyen <helgav@google.com>
Tue, 26 Nov 2013 09:13:08 +0000 (10:13 +0100)
To remove the node query's python implementation soon, this
patch makes all users of the queries call the haskell
implementation instead of the python one.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>

lib/cli.py
lib/client/gnt_cluster.py
lib/client/gnt_node.py
lib/rapi/rlib2.py
test/py/ganeti.client.gnt_cluster_unittest.py

index d5f97d7..b213e4f 100644 (file)
@@ -2872,15 +2872,18 @@ def RunWhileClusterStopped(feedback_fn, fn, *args):
 
   # This ensures we're running on the master daemon
   cl = GetClient()
+  # Query client
+  qcl = GetClient(query=True)
 
   (cluster_name, master_node) = \
     cl.QueryConfigValues(["cluster_name", "master_node"])
 
-  online_nodes = GetOnlineNodes([], cl=cl)
-  ssh_ports = GetNodesSshPorts(online_nodes, cl)
+  online_nodes = GetOnlineNodes([], cl=qcl)
+  ssh_ports = GetNodesSshPorts(online_nodes, qcl)
 
   # Don't keep a reference to the client. The master daemon will go away.
   del cl
+  del qcl
 
   assert master_node in online_nodes
 
@@ -3491,7 +3494,7 @@ def GetOnlineNodes(nodes, cl=None, nowarn=False, secondary_ips=False,
 
   """
   if cl is None:
-    cl = GetClient()
+    cl = GetClient(query=True)
 
   qfilter = []
 
index 6733f49..53cd46c 100644 (file)
@@ -570,15 +570,17 @@ def ClusterCopyFile(opts, args):
                                errors.ECODE_INVAL)
 
   cl = GetClient()
+  qcl = GetClient(query=True)
   try:
     cluster_name = cl.QueryConfigValues(["cluster_name"])[0]
 
-    results = GetOnlineNodes(nodes=opts.nodes, cl=cl, filter_master=True,
+    results = GetOnlineNodes(nodes=opts.nodes, cl=qcl, filter_master=True,
                              secondary_ips=opts.use_replication_network,
                              nodegroup=opts.nodegroup)
-    ports = GetNodesSshPorts(opts.nodes, cl)
+    ports = GetNodesSshPorts(opts.nodes, qcl)
   finally:
     cl.Close()
+    qcl.Close()
 
   srun = ssh.SshRunner(cluster_name)
   for (node, port) in zip(results, ports):
@@ -599,11 +601,12 @@ def RunClusterCommand(opts, args):
 
   """
   cl = GetClient()
+  qcl = GetClient(query=True)
 
   command = " ".join(args)
 
-  nodes = GetOnlineNodes(nodes=opts.nodes, cl=cl, nodegroup=opts.nodegroup)
-  ports = GetNodesSshPorts(nodes, cl)
+  nodes = GetOnlineNodes(nodes=opts.nodes, cl=qcl, nodegroup=opts.nodegroup)
+  ports = GetNodesSshPorts(nodes, qcl)
 
   cluster_name, master_node = cl.QueryConfigValues(["cluster_name",
                                                     "master_node"])
@@ -1520,7 +1523,7 @@ def _EpoOff(opts, node_list, inst_map):
     return constants.EXIT_FAILURE
 
 
-def Epo(opts, args, cl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
+def Epo(opts, args, cl=None, qcl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
         _confirm_fn=ConfirmOperation,
         _stdout_fn=ToStdout, _stderr_fn=ToStderr):
   """EPO operations.
@@ -1541,6 +1544,9 @@ def Epo(opts, args, cl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
 
   if cl is None:
     cl = GetClient()
+  if qcl is None:
+    # Query client
+    qcl = GetClient(query=True)
 
   if opts.groups:
     node_query_list = \
@@ -1548,9 +1554,9 @@ def Epo(opts, args, cl=None, _on_fn=_EpoOn, _off_fn=_EpoOff,
   else:
     node_query_list = args
 
-  result = cl.QueryNodes(node_query_list, ["name", "master", "pinst_list",
-                                           "sinst_list", "powered", "offline"],
-                         False)
+  result = qcl.QueryNodes(node_query_list, ["name", "master", "pinst_list",
+                                            "sinst_list", "powered", "offline"],
+                          False)
 
   all_nodes = map(compat.fst, result)
   node_list = []
index 4e20117..68fcdbd 100644 (file)
@@ -232,6 +232,7 @@ def AddNode(opts, args):
 
   """
   cl = GetClient()
+  query_cl = GetClient(query=True)
   node = netutils.GetHostname(name=args[0]).name
   readd = opts.readd
 
@@ -247,9 +248,10 @@ def AddNode(opts, args):
     pass
 
   try:
-    output = cl.QueryNodes(names=[node],
-                           fields=["name", "sip", "master", "ndp/ssh_port"],
-                           use_locking=False)
+    output = query_cl.QueryNodes(names=[node],
+                                 fields=["name", "sip", "master",
+                                         "ndp/ssh_port"],
+                                 use_locking=False)
     node_exists, sip, is_master, ssh_port = output[0]
   except (errors.OpPrereqError, errors.OpExecError):
     node_exists = ""
@@ -438,8 +440,8 @@ def FailoverNode(opts, args):
   # these fields are static data anyway, so it doesn't matter, but
   # locking=True should be safer
   qcl = GetClient(query=True)
-  result = cl.QueryNodes(names=args, fields=selected_fields,
-                         use_locking=False)
+  result = qcl.QueryNodes(names=args, fields=selected_fields,
+                          use_locking=False)
   qcl.Close()
   node, pinst = result[0]
 
@@ -480,7 +482,7 @@ def MigrateNode(opts, args):
   selected_fields = ["name", "pinst_list"]
 
   qcl = GetClient(query=True)
-  result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=False)
+  result = qcl.QueryNodes(names=args, fields=selected_fields, use_locking=False)
   qcl.Close()
   ((node, pinst), ) = result
 
index d8d9b8c..14cbcf2 100644 (file)
@@ -901,7 +901,7 @@ class R_2_instances(baserlib.OpcodeResource):
     """Returns a list of all available instances.
 
     """
-    client = self.GetClient()
+    client = self.GetClient(query=True)
 
     use_locking = self.useLocking()
     if self.useBulk():
@@ -981,7 +981,7 @@ class R_2_instances_name(baserlib.OpcodeResource):
     """Send information about an instance.
 
     """
-    client = self.GetClient()
+    client = self.GetClient(query=True)
     instance_name = self.items[0]
 
     result = baserlib.HandleItemQueryErrors(client.QueryInstances,
@@ -1411,7 +1411,8 @@ class R_2_query(baserlib.ResourceBase):
   PUT_OPCODE = opcodes.OpQuery
 
   def _Query(self, fields, qfilter):
-    return self.GetClient().Query(self.items[0], fields, qfilter).ToDict()
+    client = self.GetClient()
+    return client.Query(self.items[0], fields, qfilter).ToDict()
 
   def GET(self):
     """Returns resource information.
index 288eff5..c4b3593 100755 (executable)
@@ -216,7 +216,7 @@ class TestEpo(unittest.TestCase):
 
       off_fn = compat.partial(self._Off, ["node1.example.com"])
 
-      result = self._Test(opts, [], cl=client, _off_fn=off_fn,
+      result = self._Test(opts, [], cl=client, qcl=client, _off_fn=off_fn,
                           _confirm_fn=confirm_fn)
       if force or confirm_result:
         self.assertEqual(result, self._OFF_EXITCODE)
@@ -246,7 +246,7 @@ class TestEpo(unittest.TestCase):
         self.assertFalse(inst_map)
         return self._ON_EXITCODE
 
-      result = self._Test(opts, [], cl=client, _on_fn=_On,
+      result = self._Test(opts, [], cl=client, qcl=client, _on_fn=_On,
                           _confirm_fn=self._ConfirmForce)
       self.assertEqual(result, self._ON_EXITCODE)
 
@@ -256,7 +256,8 @@ class TestEpo(unittest.TestCase):
     client = _ClientForEpo(NotImplemented, [
       ("node1.example.com", True, [], [], True, False),
       ])
-    result = self._Test(opts, [], cl=client, _confirm_fn=self._ConfirmForce)
+    result = self._Test(opts, [], cl=client, qcl=client,
+                        _confirm_fn=self._ConfirmForce)
     self.assertEqual(result, constants.EXIT_FAILURE)