command-line tool multiput #171

Open
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+39 −7
Split
@@ -23,6 +23,11 @@ To copy files to a different cluster node, use the ``--node`` (``-n``) option::
$ starcluster put mycluster --node node001 /local/path /remote/path
+To copy files to multiple cluster nodes, provide comma separated nodes to the
+``--multi`` (``-m``) option::
+
+ $ starcluster put mycluster --multi master,node001 /local/path /remote/path
+
*********************************
Copying Data from a Cluster (get)
*********************************
@@ -4,6 +4,18 @@
from completers import ClusterCompleter
+def list_csv(csv_string):
+ """
+ For parsing comma separated values in --multi e.g. --multi master,node001
+ CommaSeparatedValues -> Nodename Generator
+
+ Removes any empty strings from trailing commas
+ >>> list_csv("master,node001,")
+ ["master", "node001"]
+ """
+ return filter(bool, [name.strip() for name in csv_string.split(',')])
+
+
class CmdPut(ClusterCompleter):
"""
put [options] <cluster_tag> [<local_file_or_dir> ...] <remote_destination>
@@ -24,6 +36,10 @@ class CmdPut(ClusterCompleter):
# Copy a file or dir to a node (node001 in this example)
$ starcluster put mycluster --node node001 /local/path /remote/path
+ # Copy a file or dir to multiple nodes (master and node001 in this
+ # example)
+ $ starcluster put mycluster -m master,node001 /local/path /remote/path
+
This will copy a file or directory to the remote server
"""
@@ -34,6 +50,17 @@ def addopts(self, parser):
help="Transfer files as USER ")
parser.add_option("-n", "--node", dest="node", default="master",
help="Transfer files to NODE (defaults to master)")
+ parser.add_option("-m", "--multi", dest="multi", default=None,
+ help="Transfer files to multiple NODEs (defaults to"
+ + "master)")
+
+ def put(self, node, rpath, lpaths):
+ if self.opts.user:
+ node.ssh.switch_user(self.opts.user)
+ if len(lpaths) > 1 and not node.ssh.isdir(rpath):
+ msg = "Remote path in %s does not exist: %s" % (node, rpath)
+ raise exception.BaseException(msg)
+ node.ssh.put(lpaths, rpath)
def execute(self, args):
if len(args) < 3:
@@ -47,10 +74,10 @@ def execute(self, args):
raise exception.BaseException(
"Local file or directory does not exist: %s" % lpath)
cl = self.cm.get_cluster(ctag)
- node = cl.get_node_by_alias(self.opts.node)
- if self.opts.user:
- node.ssh.switch_user(self.opts.user)
- if len(lpaths) > 1 and not node.ssh.isdir(rpath):
- raise exception.BaseException("Remote path does not exist: %s" %
- rpath)
- node.ssh.put(lpaths, rpath)
+ if self.opts.multi:
+ nodes = [cl.get_node_by_alias(nodename) for nodename in
+ list_csv(self.opts.multi)]
+ else:
+ nodes = [cl.get_node_by_alias(self.opts.node)]
+ for node in nodes:
+ self.put(node, rpath, lpaths)