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

Source Code for Module starcluster.commands.get

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