Package starcluster :: Package commands :: Module put
[hide private]
[frames] | no frames]

Source Code for Module starcluster.commands.put

 1  import os 
 2   
 3  from starcluster import exception 
 4  from completers import ClusterCompleter 
 5   
 6   
7 -class CmdPut(ClusterCompleter):
8 """ 9 put [options] <cluster_tag> [<local_file_or_dir> ...] <remote_destination> 10 11 Copy files to a running cluster 12 13 Examples: 14 15 # Copy a file or dir to the master as root 16 $ starcluster put mycluster /path/to/file/or/dir /path/on/remote/server 17 18 # Copy one or more files or dirs to the master as root 19 $ starcluster put mycluster /local/dir /local/file /remote/dir 20 21 # Copy a file or dir to the master as normal user 22 $ starcluster put mycluster --user myuser /local/path /remote/path 23 24 # Copy a file or dir to a node (node001 in this example) 25 $ starcluster put mycluster --node node001 /local/path /remote/path 26 27 28 This will copy a file or directory to the remote server 29 """ 30 names = ['put'] 31
32 - def addopts(self, parser):
33 parser.add_option("-u", "--user", dest="user", default=None, 34 help="Transfer files as USER ") 35 parser.add_option("-n", "--node", dest="node", default="master", 36 help="Transfer files to NODE (defaults to master)")
37
38 - def execute(self, args):
39 if not self.cfg.globals.enable_experimental: 40 raise exception.ExperimentalFeature("The 'put' command") 41 if len(args) < 3: 42 self.parser.error("please specify a cluster, local files or " + 43 "directories, and a remote destination path") 44 ctag = args[0] 45 rpath = args[-1] 46 lpaths = args[1:-1] 47 for lpath in lpaths: 48 if not os.path.exists(lpath): 49 raise exception.BaseException( 50 "Local file or directory does not exist: %s" % lpath) 51 cl = self.cm.get_cluster(ctag) 52 node = cl.get_node_by_alias(self.opts.node) 53 if self.opts.user: 54 node.ssh.switch_user(self.opts.user) 55 if len(lpaths) > 1 and not node.ssh.isdir(rpath): 56 raise exception.BaseException("Remote path does not exist: %s" % 57 rpath) 58 node.ssh.put(lpaths, rpath)
59