Esempio n. 1
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
Esempio n. 2
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
Esempio n. 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_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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
    def test_ssh_scp_key_file_format(self, emrutils):
        def which_side_effect(program):
            if program == 'ssh' or program == 'scp':
                return '/some/path'
        emrutils.which.side_effect = which_side_effect

        key_file1 = 'key.abc'
        sshutils.validate_ssh_with_key_file(key_file1)
        sshutils.validate_scp_with_key_file(key_file1)

        key_file2 = 'key'
        sshutils.validate_ssh_with_key_file(key_file2)
        sshutils.validate_scp_with_key_file(key_file2)
Esempio n. 8
0
    def test_ssh_scp_key_file_format(self, emrutils):
        def which_side_effect(program):
            if program == 'ssh' or program == 'scp':
                return '/some/path'

        emrutils.which.side_effect = which_side_effect

        key_file1 = 'key.abc'
        sshutils.validate_ssh_with_key_file(key_file1)
        sshutils.validate_scp_with_key_file(key_file1)

        key_file2 = 'key'
        sshutils.validate_ssh_with_key_file(key_file2)
        sshutils.validate_scp_with_key_file(key_file2)