Commit bc57fa8d authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Use a query client for node queries where necessary



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: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 1211c6ed
......@@ -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 = []
......
......@@ -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 = []
......
......@@ -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
......
......@@ -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.
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment