starcluster.commands.get

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

# Source Code for Module starcluster.commands.get

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