Exemple #1
0
    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
Exemple #2
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
Exemple #3
0
    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
Exemple #4
0
    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
Exemple #5
0
    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
Exemple #6
0
    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
Exemple #7
0
    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
Exemple #8
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
Exemple #9
0
    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
Exemple #10
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
Exemple #11
0
    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
Exemple #12
0
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
Exemple #13
0
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
Exemple #14
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, 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
Exemple #15
0
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
Exemple #16
0
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
Exemple #17
0
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)
Exemple #18
0
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)
Exemple #20
0
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)
Exemple #21
0
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_non_existing_command(self):
     path = which("klajsflklj")
     assert_equal(path, None)
Exemple #23
0
 def test_which_with_existing_command(self):
     pythonPath = which('python') or which('python.exe')
     assert pythonPath is not None
Exemple #24
0
 def test_which_with_non_existing_command(self):
     path = which('klajsflklj')
     assert path is None