diff --git a/lib/cmdlib.py b/lib/cmdlib.py index cf028bcd54e916f8bc249fd706118af2965da3f7..cc1ead5f4b1f481185e9620c08d2a720551d3f64 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -1763,45 +1763,6 @@ class LUQueryClusterInfo(NoHooksLU): return result -class LUClusterCopyFile(NoHooksLU): - """Copy file to cluster. - - """ - _OP_REQP = ["nodes", "filename"] - - def CheckPrereq(self): - """Check prerequisites. - - It should check that the named file exists and that the given list - of nodes is valid. - - """ - if not os.path.exists(self.op.filename): - raise errors.OpPrereqError("No such filename '%s'" % self.op.filename) - - self.nodes = _GetWantedNodes(self, self.op.nodes) - - def Exec(self, feedback_fn): - """Copy a file from master to some nodes. - - Args: - opts - class with options as members - args - list containing a single element, the file name - Opts used: - nodes - list containing the name of target nodes; if empty, all nodes - - """ - filename = self.op.filename - - myname = utils.HostInfo().name - - for node in self.nodes: - if node == myname: - continue - if not self.ssh.CopyFileToNode(node, filename): - logger.Error("Copy of file %s to node %s failed" % (filename, node)) - - class LUDumpClusterConfig(NoHooksLU): """Return a text-representation of the cluster-config. @@ -1821,38 +1782,6 @@ class LUDumpClusterConfig(NoHooksLU): return self.cfg.DumpConfig() -class LURunClusterCommand(NoHooksLU): - """Run a command on some nodes. - - """ - _OP_REQP = ["command", "nodes"] - - def CheckPrereq(self): - """Check prerequisites. - - It checks that the given list of nodes is valid. - - """ - self.nodes = _GetWantedNodes(self, self.op.nodes) - - def Exec(self, feedback_fn): - """Run a command on some nodes. - - """ - # put the master at the end of the nodes list - master_node = self.sstore.GetMasterNode() - if master_node in self.nodes: - self.nodes.remove(master_node) - self.nodes.append(master_node) - - data = [] - for node in self.nodes: - result = self.ssh.Run(node, "root", self.op.command) - data.append((node, result.output, result.exit_code)) - - return data - - class LUActivateInstanceDisks(NoHooksLU): """Bring up an instance's disks. diff --git a/lib/mcpu.py b/lib/mcpu.py index 2e7f3039c5b93d8cf0044f42224863314870f9d7..ff2c80ccf94d8ce302ff621c5dcadfebb88039a9 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -45,8 +45,6 @@ class Processor(object): # Cluster opcodes.OpDestroyCluster: cmdlib.LUDestroyCluster, opcodes.OpQueryClusterInfo: cmdlib.LUQueryClusterInfo, - opcodes.OpClusterCopyFile: cmdlib.LUClusterCopyFile, - opcodes.OpRunClusterCommand: cmdlib.LURunClusterCommand, opcodes.OpVerifyCluster: cmdlib.LUVerifyCluster, opcodes.OpMasterFailover: cmdlib.LUMasterFailover, opcodes.OpDumpClusterConfig: cmdlib.LUDumpClusterConfig, diff --git a/lib/opcodes.py b/lib/opcodes.py index 11385c013d989236d52d5e74de57c03292c27762..906573880dc9290cd59dc61588544a1ae1434f93 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -171,18 +171,6 @@ class OpQueryClusterInfo(OpCode): __slots__ = [] -class OpClusterCopyFile(OpCode): - """Copy a file to multiple nodes.""" - OP_ID = "OP_CLUSTER_COPYFILE" - __slots__ = ["nodes", "filename"] - - -class OpRunClusterCommand(OpCode): - """Run a command on multiple nodes.""" - OP_ID = "OP_CLUSTER_RUNCOMMAND" - __slots__ = ["nodes", "command"] - - class OpVerifyCluster(OpCode): """Verify the cluster state.""" OP_ID = "OP_CLUSTER_VERIFY" diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 9f4b493aafe2c9af1fef4f127f3f95880369aee1..c980ae7df91496ea03ef4975b3ef364b8b52bba3 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -22,6 +22,7 @@ import sys from optparse import make_option import pprint +import os.path from ganeti.cli import * from ganeti import opcodes @@ -29,6 +30,8 @@ from ganeti import constants from ganeti import errors from ganeti import utils from ganeti import bootstrap +from ganeti import ssh +from ganeti import ssconf def InitCluster(opts, args): @@ -156,8 +159,20 @@ def ClusterCopyFile(opts, args): nodes - list containing the name of target nodes; if empty, all nodes """ - op = opcodes.OpClusterCopyFile(filename=args[0], nodes=opts.nodes) - SubmitOpCode(op) + filename = args[0] + if not os.path.exists(filename): + raise errors.OpPrereqError("No such filename '%s'" % filename) + + myname = utils.HostInfo().name + + op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) + results = [row[0] for row in SubmitOpCode(op) if row[0] != myname] + srun = ssh.SshRunner() + for node in results: + if not srun.CopyFileToNode(node, filename): + print >> sys.stderr, ("Copy of file %s to node %s failed" % + (filename, node)) + return 0 @@ -172,14 +187,25 @@ def RunClusterCommand(opts, args): """ command = " ".join(args) - nodes = opts.nodes - op = opcodes.OpRunClusterCommand(command=command, nodes=nodes) - result = SubmitOpCode(op) - for node, output, exit_code in result: + op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) + nodes = [row[0] for row in SubmitOpCode(op)] + + sstore = ssconf.SimpleStore() + master_node = sstore.GetMasterNode() + srun = ssh.SshRunner(sstore=sstore) + + if master_node in nodes: + nodes.remove(master_node) + nodes.append(master_node) + + for name in nodes: + result = srun.Run(name, "root", command) print ("------------------------------------------------") - print ("node: %s" % node) - print ("%s" % output) - print ("return code = %s" % exit_code) + print ("node: %s" % name) + print ("%s" % result.output) + print ("return code = %s" % result.exit_code) + + return 0 def VerifyCluster(opts, args):