Commit 56bece1f authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent 4fbe765c
......@@ -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.
......
......@@ -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:
......
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