예제 #1
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
예제 #2
0
    def test_validate_and_find_master_dns_waits(self, emrutils):
        emrutils.get_cluster_state.return_value = 'STARTING'
        session = mock.Mock()
        client = mock.Mock()
        emrutils.get_client.return_value = client

        sshutils.validate_and_find_master_dns(session, None, 'cluster-id')

        # We should have:
        # 1. Waiter for the cluster to be running.
        client.get_waiter.assert_called_with('cluster_running')
        client.get_waiter.return_value.wait.assert_called_with(
            ClusterId='cluster-id')

        # 2. Found the master public DNS
        self.assertTrue(emrutils.find_master_dns.called)
예제 #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 프로젝트: 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
예제 #5
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
예제 #6
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
예제 #7
0
    def test_validate_and_find_master_dns_waits(self, emrutils):
        emrutils.get_cluster_state.return_value = 'STARTING'
        session = mock.Mock()
        client = mock.Mock()
        emrutils.get_client.return_value = client

        sshutils.validate_and_find_master_dns(session, None, 'cluster-id')

        # We should have:
        # 1. Waiter for the cluster to be running.
        client.get_waiter.assert_called_with('cluster_running')
        client.get_waiter.return_value.wait.assert_called_with(
            ClusterId='cluster-id')

        # 2. Found the master public DNS
        self.assertTrue(emrutils.find_master_dns.called)
예제 #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_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
예제 #9
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
예제 #10
0
    def test_validate_and_find_master_dns_waits(self, emrutils):
        emrutils.get_cluster_state.return_value = 'STARTING'
        session = mock.Mock()
        fake_endpoint = mock.sentinel.fake_endpoint
        emrutils.get_endpoint.return_value = fake_endpoint

        sshutils.validate_and_find_master_dns(session, None, 'cluster-id')

        # We should have:
        # 1. Waiter for the cluster to be running.
        session.get_service.return_value.get_waiter.assert_called_with(
            'ClusterRunning', fake_endpoint)
        service = session.get_service.return_value
        service.get_waiter.return_value.wait.assert_called_with(
            ClusterId='cluster-id')

        # 2. Found the master public DNS
        self.assertTrue(emrutils.find_master_public_dns.called)
예제 #11
0
    def test_validate_and_find_master_dns_waits(self, emrutils):
        emrutils.get_cluster_state.return_value = 'STARTING'
        session = mock.Mock()
        fake_endpoint = mock.sentinel.fake_endpoint
        emrutils.get_endpoint.return_value = fake_endpoint

        sshutils.validate_and_find_master_dns(session, None, 'cluster-id')

        # We should have:
        # 1. Waiter for the cluster to be running.
        session.get_service.return_value.get_waiter.assert_called_with(
            'ClusterRunning', fake_endpoint)
        service = session.get_service.return_value
        service.get_waiter.return_value.wait.assert_called_with(
            ClusterId='cluster-id')

        # 2. Found the master public DNS
        self.assertTrue(emrutils.find_master_public_dns.called)
예제 #12
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
예제 #13
0
 def test_cluster_in_terminated_states(self, emrutils):
     emrutils.get_cluster_state.return_value = 'TERMINATED'
     with self.assertRaises(exceptions.ClusterTerminatedError):
         sshutils.validate_and_find_master_dns(
             mock.Mock(), None, 'cluster-id')
예제 #14
0
 def test_cluster_in_terminated_states(self, emrutils):
     emrutils.get_cluster_state.return_value = 'TERMINATED'
     with self.assertRaises(exceptions.ClusterTerminatedError):
         sshutils.validate_and_find_master_dns(mock.Mock(), None,
                                               'cluster-id')