def setup_manager(self, hosts, args, opts): localargs = args[0:-1] remote = args[-1] if not re.match("^/", remote): print("Remote path %s must be an absolute path" % remote) sys.exit(3) manager = ScpManager(opts) for host, port, user in hosts: cmd = ['scp', '-qC'] if opts.options: for opt in opts.options: cmd += ['-o', opt] if port: cmd += ['-P', port] if opts.recursive: cmd.append('-r') if opts.extra: cmd.extend(opts.extra) cmd.extend(localargs) if user: cmd.append('%s@%s:%s' % (user, host, remote)) else: cmd.append('%s:%s' % (host, remote)) t = Task(host, port, user, cmd, opts) manager.add_task(t) return manager
def do_pscp(pssh_config): rtn_code = 0 options = PSSHOptions(pssh_config) hosts = psshutil.read_host_files(options.host_files, default_user='******') manager = Manager(options) for host, port, user in hosts: cmd = ['scp', '-qC'] if port: cmd += ['-P', port] if options.recursive: cmd.append('-r') if user: cmd.append('%s@%s:%s' % (user, host, options.remote)) else: cmd.append('%s:%s' % (host, options.remote)) cmd.append('%s' % options.outdir) t = Task(host, port, user, cmd, options) manager.add_task(t) try: statuses = manager.run() except FatalError: rtn_code = 1 if min(statuses) < 0: # At least one process was killed. rtn_code = 3 for status in statuses: if status != 0: rtn_code = 4 return rtn_code
def setup_manager(self, hosts, args, opts): pattern = args[0] manager = Manager(opts) for host, port, user in hosts: cmd = ['ssh', host, '-o', 'NumberOfPasswordPrompts=1'] if opts.options: for opt in opts.options: cmd += ['-o', opt] if user: cmd += ['-l', user] if port: cmd += ['-p', port] if opts.extra: cmd.extend(opts.extra) cmd.append('pkill -9 %s' % pattern) t = Task(host, port, user, cmd, opts) manager.add_task(t) return manager
def do_pssh(l, opts): ''' Adapted from psshlib. Perform command across list of hosts. l = [(host, command), ...] ''' if opts.outdir and not os.path.exists(opts.outdir): os.makedirs(opts.outdir) if opts.errdir and not os.path.exists(opts.errdir): os.makedirs(opts.errdir) if opts.send_input: stdin = sys.stdin.read() else: stdin = None manager = Manager(opts) user = "" port = "" hosts = [] for host, cmdline in l: cmd = ['ssh', host, '-o', 'PasswordAuthentication=no', '-o', 'SendEnv=PSSH_NODENUM', '-o', 'StrictHostKeyChecking=no'] if opts.options: for opt in opts.options: cmd += ['-o', opt] if user: cmd += ['-l', user] if port: cmd += ['-p', port] if opts.extra: cmd.extend(opts.extra) if cmdline: cmd.append(cmdline) hosts.append(host) t = Task(host, port, user, cmd, opts, stdin) manager.add_task(t) try: return manager.run() # returns a list of exit codes except FatalError: common_err("pssh to nodes failed") show_output(opts.errdir, hosts, "stderr") return False
def setup_manager(self, hosts, args, opts): remote = args[0] local = args[1] if not re.match("^/", remote): print("Remote path %s must be an absolute path" % remote) sys.exit(3) for host, port, user in hosts: if opts.localdir: dirname = "%s/%s" % (opts.localdir, host) else: dirname = host if not os.path.exists(dirname): os.mkdir(dirname) manager = ScpManager(opts) for host, port, user in hosts: if opts.localdir: localpath = "%s/%s/%s" % (opts.localdir, host, local) else: localpath = "%s/%s" % (host, local) cmd = ['scp', '-qC'] if opts.options: for opt in opts.options: cmd += ['-o', opt] if port: cmd += ['-P', port] if opts.recursive: cmd.append('-r') if opts.extra: cmd.extend(opts.extra) if user: cmd.append('%s@%s:%s' % (user, host, remote)) else: cmd.append('%s:%s' % (host, remote)) cmd.append(localpath) t = Task(host, port, user, cmd, opts) manager.add_task(t) return manager
def do_pssh(cmdline, pssh_config): rtn_code = 0 options = PSSHOptions(pssh_config) hosts = psshutil.read_host_files(options.host_files, default_user='******') manager = Manager(options) for host, port, user in hosts: cmd = [ 'ssh', host, '-o', 'NumberOfPasswordPrompts=1', '-o', 'SendEnv=PSSH_NODENUM PSSH_HOST' ] if user: cmd += ['-l', user] if port: cmd += ['-p', port] if cmdline: cmd.append(cmdline) t = Task(host, port, user, cmd, options) manager.add_task(t) try: statuses = manager.run() except FatalError: rtn_code = 1 if min(statuses) < 0: # At least one process was killed. rtn_code = 3 for status in statuses: if status == 255: rtn_code = 4 for status in statuses: if status != 0: rtn_code = 5 return rtn_code
def _maketask(self, node, cmd): """ assemble command and return a pssh task object suitable for submitting to psshlib manager """ opts = self.opts cmd = [ 'ssh', node, '-o', 'NumberOfPasswordPrompts=1', '-o', 'SendEnv=PSSH_NODENUM PSSH_HOST' ] if opts.options: for opt in opts.options: cmd += ['-o', opt] if opts.user: cmd += ['-l', opts.user] if opts.port: cmd += ['-p', opts.port] if opts.cmdline: cmd.append(opts.cmdline) log.debug('full command compiled as: %s' % ' '.join(cmd)) return Task(node, opts.port, opts.user, cmd, opts, opts.stdin)
def setup_manager(self, hosts, args, opts): local = args[0] remote = args[1] if not re.match("^/", remote): print("Remote path %s must be an absolute path" % remote) sys.exit(3) manager = ScpManager(opts) for host, port, user in hosts: ssh = ['ssh'] if opts.options: for opt in opts.options: ssh += ['-o', opt] if port: ssh += ['-p', port] if opts.ssh_args: ssh += [opts.ssh_args] cmd = ['rsync', '-e', ' '.join(ssh)] if opts.verbose: cmd.append('-v') if opts.recursive: cmd.append('-r') if opts.archive: cmd.append('-a') if opts.compress: cmd.append('-z') if opts.extra: cmd.extend(opts.extra) cmd.append(local) if user: cmd.append('%s@%s:%s' % (user, host, remote)) else: cmd.append('%s:%s' % (host, remote)) t = Task(host, port, user, cmd, opts) manager.add_task(t) return manager
def do_pssh(hosts, cmdline, opts): if opts.outdir and not os.path.exists(opts.outdir): os.makedirs(opts.outdir) if opts.errdir and not os.path.exists(opts.errdir): os.makedirs(opts.errdir) stdin = buffer_input() manager = Manager(opts) for host, port, user in hosts: cmd = ['ssh', host, '-o', 'NumberOfPasswordPrompts=1', '-o', 'SendEnv=PSSH_NODENUM', '-o', 'StrictHostKeyChecking=no'] if not opts.verbose: cmd.append('-q') if opts.options: cmd += ['-o', opts.options] if user: cmd += ['-l', user] if port: cmd += ['-p', port] cmd.append(cmdline) t = Task(host, port, cmd, opts, stdin) manager.add_task(t) manager.run() if opts.report: manager.report()