예제 #1
0
파일: ssh.py 프로젝트: Ajaxman/aws-cli
    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
예제 #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
예제 #3
0
파일: ssh.py 프로젝트: Ajaxman/aws-cli
    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
예제 #4
0
파일: ssh.py 프로젝트: AWSRandall/aws-cli
    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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #11
0
파일: ssh.py 프로젝트: Ajaxman/aws-cli
    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
예제 #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
예제 #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
예제 #14
0
파일: ssh.py 프로젝트: Athena88/aws-cli
    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
예제 #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
예제 #16
0
파일: sshutils.py 프로젝트: Frame02/aws-cli
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
예제 #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)
예제 #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)
예제 #19
0
 def test_which_with_existing_command(self):
     pythonPath = which("python") or which("python.exe")
     assert_not_equal(pythonPath, None)
예제 #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)
예제 #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)
예제 #22
0
 def test_which_with_non_existing_command(self):
     path = which("klajsflklj")
     assert_equal(path, None)
예제 #23
0
 def test_which_with_existing_command(self):
     pythonPath = which('python') or which('python.exe')
     assert pythonPath is not None
예제 #24
0
 def test_which_with_non_existing_command(self):
     path = which('klajsflklj')
     assert path is None