starcluster.commands.put

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

# Source Code for Module starcluster.commands.put

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