From 56bece1f2ac970b9de478e9e8a117445a3a769ef Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 6 Oct 2008 11:48:59 +0000
Subject: [PATCH] Change SshRunner usage

Currently the SshRunner uses a SimpleConfigReader instance, however this
is not best. We change it to use the cluster name directly (and its
constructor now takes this as parameter, instead of SCR), and its
callers are change to pass the name directly.

As a consequence, we can now remove the initialization of SCR in
gnt-cluster (copyfile and command), and instead we query the master for
the cluster name).

Reviewed-by: imsnah
---
 lib/ssh.py          |  6 +++---
 scripts/gnt-cluster | 24 ++++++++++++------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/lib/ssh.py b/lib/ssh.py
index c9cc1806f..71d30eda4 100644
--- a/lib/ssh.py
+++ b/lib/ssh.py
@@ -71,8 +71,8 @@ class SshRunner:
   """Wrapper for SSH commands.
 
   """
-  def __init__(self, cfg):
-    self.cfg = cfg
+  def __init__(self, cluster_name):
+    self.cluster_name = cluster_name
 
   def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
                        strict_host_check):
@@ -84,7 +84,7 @@ class SshRunner:
       ]
 
     if use_cluster_key:
-      options.append("-oHostKeyAlias=%s" % self.cfg.GetClusterName())
+      options.append("-oHostKeyAlias=%s" % self.cluster_name)
 
     # TODO: Too many boolean options, maybe convert them to more descriptive
     # constants.
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index 1b397dbbd..02019c074 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -160,20 +160,20 @@ def ClusterCopyFile(opts, args):
     nodes - list containing the name of target nodes; if empty, all nodes
 
   """
-  # TODO: Query master
-  cfg = ssconf.SimpleConfigReader()
-
   filename = args[0]
   if not os.path.exists(filename):
     raise errors.OpPrereqError("No such filename '%s'" % filename)
 
+  cl = GetClient()
+
   myname = utils.HostInfo().name
 
+  cluster_name = cl.QueryConfigValues(["cluster_name"])[0]
+
   op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes)
-  results = [row[0] for row in SubmitOpCode(op) if row[0] != myname]
+  results = [row[0] for row in SubmitOpCode(op, cl=cl) if row[0] != myname]
 
-  # TODO: Potential inconsistency between local node and master
-  srun = ssh.SshRunner(cfg)
+  srun = ssh.SshRunner(cluster_name=cluster_name)
   for node in results:
     if not srun.CopyFileToNode(node, filename):
       print >> sys.stderr, ("Copy of file %s to node %s failed" %
@@ -192,16 +192,16 @@ def RunClusterCommand(opts, args):
     nodes: list containing the name of target nodes; if empty, all nodes
 
   """
-  # TODO: Query master
-  cfg = ssconf.SimpleConfigReader()
+  cl = GetClient()
 
   command = " ".join(args)
   op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes)
-  nodes = [row[0] for row in SubmitOpCode(op)]
+  nodes = [row[0] for row in SubmitOpCode(op, cl=cl)]
+
+  cluster_name, master_node = cl.QueryConfigValues(["cluster_name",
+                                                    "master_node"])
 
-  # TODO: Potential inconsistency between local node and master
-  master_node = cfg.GetMasterNode()
-  srun = ssh.SshRunner(cfg)
+  srun = ssh.SshRunner(cluster_name=cluster_name)
 
   # Make sure master node is at list end
   if master_node in nodes:
-- 
GitLab