def _run_main(self, parsed_args, parsed_globals): try: master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('ssh') or emrutils.which('ssh.exe'))): command = ['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-ND', '8157', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns] else: command = ['putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-N', '-D', '8157'] print(' '.join(command)) rc = subprocess.call(command) return rc except KeyboardInterrupt: print('Disabling Socks Tunnel.') return 0
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('scp') or emrutils.which('scp.exe'))): command = [ 'scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns ] else: command = [ 'pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns ] # if the instance is not terminated if parsed_args.dest: command[-1] = command[-1] + ":" + parsed_args.dest else: command[-1] = command[-1] + ":" + parsed_args.src.split('/')[-1] print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('scp') or emrutils.which('scp.exe'))): command = ['scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src] else: command = ['pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src] if parsed_args.dest: command.append(parsed_args.dest) else: command.append(parsed_args.src.split('/')[-1]) print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main(self, parsed_args, parsed_globals): master_dns = emrutils.find_master_instance( self._session, parsed_globals, parsed_args.cluster_id)['PublicDnsName'] if not master_dns: raise exceptions.MasterDNSNotAvailableError key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('scp') or emrutils.which('scp.exe'))): command = ['scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src] else: command = ['pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src] if parsed_args.dest: command.append(parsed_args.dest) else: command.append(parsed_args.src.split('/')[-1]) print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main(self, parsed_args, parsed_globals): master_dns = emrutils.find_master_instance( self._session, parsed_globals, parsed_args.cluster_id)['PublicDnsName'] if not master_dns: raise exceptions.MasterDNSNotAvailableError key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('scp') or emrutils.which('scp.exe'))): command = [ 'scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src ] else: command = [ 'pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src ] if parsed_args.dest: command.append(parsed_args.dest) else: command.append(parsed_args.src.split('/')[-1]) print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main(self, parsed_args, parsed_globals): master_dns = emrutils.find_master_instance( self._session, parsed_globals, parsed_args.cluster_id)['PublicDnsName'] if not master_dns: raise exceptions.MasterDNSNotAvailableError key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('ssh') or emrutils.which('ssh.exe'))): command = [ 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns ] if parsed_args.command: command.append(parsed_args.command) else: command = [ 'putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t' ] if parsed_args.command: f.write(parsed_args.command) f.write('\nread -n1 -r -p "Command completed. Press any key."') command.append('-m') command.append(f.name) f.close() print(' '.join(command)) rc = subprocess.call(command) os.remove(f.name) return rc
def _run_main(self, parsed_args, parsed_globals): try: master_dns = emrutils.find_master_instance( self._session, parsed_globals, parsed_args.cluster_id)['PublicDnsName'] if not master_dns: raise exceptions.MasterDNSNotAvailableError key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('ssh') or emrutils.which('ssh.exe'))): command = [ 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-ND', '8157', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns ] else: command = [ 'putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-N', '-D', '8157' ] print(' '.join(command)) rc = subprocess.call(command) return rc except KeyboardInterrupt: print('Disabling Socks Tunnel.') return 0
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (emrutils.which('ssh') or emrutils.which('ssh.exe')): command = [ 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t' ] if parsed_args.command: command.append(parsed_args.command) else: command = [ 'putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t' ] if parsed_args.command: f.write(parsed_args.command) f.write('\nread -n1 -r -p "Command completed. Press any key."') command.append('-m') command.append(f.name) f.close() print(' '.join(command)) rc = subprocess.call(command) os.remove(f.name) return rc
def _run_main_command(self, parsed_args, parsed_globals): try: master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (emrutils.which('ssh') or emrutils.which('ssh.exe')): command = [ 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-ND', '8157', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns ] else: command = [ 'putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-N', '-D', '8157' ] print(' '.join(command)) rc = subprocess.call(command) return rc except KeyboardInterrupt: print('Disabling Socks Tunnel.') return 0
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (emrutils.which('scp') or emrutils.which('scp.exe')): command = [ 'scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src ] else: command = [ 'pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src ] if parsed_args.dest: command.append(parsed_args.dest) else: command.append(parsed_args.src.split('/')[-1]) print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('ssh') or emrutils.which('ssh.exe'))): command = ['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns] if parsed_args.command: command.append(parsed_args.command) else: command = ['putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t'] if parsed_args.command: f.write(parsed_args.command) f.write('\nread -n1 -r -p "Command completed. Press any key."') command.append('-m') command.append(f.name) f.close() print(' '.join(command)) rc = subprocess.call(command) os.remove(f.name) return rc
def check_ssh_key_format(key_file): # If only putty is present and the file format is incorrect if (emrutils.which('putty.exe') is not None and (emrutils.which('ssh.exe') or emrutils.which('ssh')) is None): if check_command_key_format(key_file, ['ppk']) is False: raise exceptions.WrongPuttyKeyError else: pass
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (emrutils.which('scp') or emrutils.which('scp.exe')): command = ['scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns] else: command = ['pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns] # if the instance is not terminated if parsed_args.dest: command[-1] = command[-1] + ":" + parsed_args.dest else: command[-1] = command[-1] + ":" + parsed_args.src.split('/')[-1] print(' '.join(command)) rc = subprocess.call(command) return rc
def check_scp_key_format(key_file): # If only pscp is present and the file format is incorrect if (emrutils.which('pscp.exe') is not None and (emrutils.which('scp.exe') or emrutils.which('scp')) is None): if check_command_key_format(key_file, ['ppk']) is False: raise exceptions.WrongPuttyKeyError # If only scp is present and the file format is incorrect elif (emrutils.which('pscp.exe') is None and (emrutils.which('scp.exe') or emrutils.which('scp')) is not None): if check_command_key_format(key_file, ['cer', 'pem']) is False: raise exceptions.WrongSSHKeyError else: pass
def validate_scp_with_key_file(key_file): if (emrutils.which('pscp.exe') or emrutils.which('scp') or emrutils.which('scp.exe')) is None: raise exceptions.SCPNotFoundError else: check_scp_key_format(key_file)
def validate_ssh_with_key_file(key_file): if (emrutils.which('putty.exe') or emrutils.which('ssh') or emrutils.which('ssh.exe')) is None: raise exceptions.SSHNotFoundError else: check_ssh_key_format(key_file)
def test_which_with_existing_command(self): pythonPath = which("python") or which("python.exe") assert_not_equal(pythonPath, None)
def test_which_with_non_existing_command(self): path = which("klajsflklj") assert_equal(path, None)
def test_which_with_existing_command(self): pythonPath = which('python') or which('python.exe') assert pythonPath is not None
def test_which_with_non_existing_command(self): path = which('klajsflklj') assert path is None