o
    !d3                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ dZ	G dd deZ
G d	d
 d
eZG dd deZG dd deZdS )    N)	constants)emrutils)sshutils)Commandz
A value for the variable Key Pair File can be set in the AWS CLI config file using the "aws configure set emr.key_pair_file <value>" command.
c                   @   s8   e Zd ZdZde ZddddddddgZd	d
 ZdS )SocksZsockszFCreate a socks tunnel on port 8157 from your machine to the master.
%s
cluster-idT*Cluster Id of cluster you want to ssh intonamerequired	help_textkey-pair-file!Private key file to use for loginc                 C   s   zTt j| j||jd}|j}t | tjdd}t	ds#t	dr6dddddd	d
d|jt
jd | g
}nddd|jt
jd | ddd
g}td| t|}|W S  tyb   td Y dS w )NZsessionparsed_globals
cluster_idFdeletesshssh.exe-oStrictHostKeyChecking=noServerAliveInterval=10z-NDZ8157-i@putty-sshz-Nz-D zDisabling Socks Tunnel.r   )r   validate_and_find_master_dns_sessionr   key_pair_filevalidate_ssh_with_key_filetempfileNamedTemporaryFiler   whichr   SSH_USERprintjoin
subprocesscallKeyboardInterruptselfparsed_argsr   
master_dnskey_filefcommandrc r3   Ausr/lib/python3.10/site-packages/awscli/customizations/emr/ssh.py_run_main_command'   s:   


zSocks._run_main_commandN__name__
__module____qualname__NAMEKEY_PAIR_FILE_HELP_TEXTZDESCRIPTIONZ	ARG_TABLEr5   r3   r3   r3   r4   r      s    r   c                   @   s@   e Zd ZdZde Zddddddddd	d
dgZdd ZdS )SSHr   z'SSH into master node of the cluster.
%sr   Tr   r	   r   r   r1   z!Command to execute on Master Noder
   r   c              	   C   s   t j| j||jd}|j}t | tjdd}t	ds"t	dr=dddddd	|jt
jd
 | dg	}|jr<||j n'ddd	|jt
jd
 | dg}|jrd||j |d |d ||j |  td| t|}t|j |S )Nr   Fr   r   r   r   r   r   r   r   z-tr   r   z3
read -n1 -r -p "Command completed. Press any key."z-mr   )r   r   r   r   r    r!   r"   r#   r   r$   r   r%   r1   appendwriter
   closer&   r'   r(   r)   osremover+   r3   r3   r4   r5   O   sD   




zSSH._run_main_commandNr6   r3   r3   r3   r4   r<   C   s    r<   c                   @   J   e Zd ZdZde Zddddddddd	dd
ddddgZdd ZdS )Putputz!Put file onto the master node.
%sr   Tz/Cluster Id of cluster you want to put file ontor	   r   r   srcz!Source file path on local machinedestz$Destination file path on remote hostr=   c                 C   s   t j| j||jd}|j}t | tdstdr-dddd|j|jt	j
d | g}ndd	dd|j|jt	j
d | g}|jrL|d
 d |j |d
< n|d
 d |jdd
  |d
< td| t|}|S )Nr   scpscp.exe-r-o StrictHostKeyChecking=nor   r   pscp-scp:/r   )r   r   r   r   r    validate_scp_with_key_filer   r$   rF   r   r%   rG   splitr&   r'   r(   r)   r,   r-   r   r.   r/   r1   r2   r3   r3   r4   r5   }   s*   

 
zPut._run_main_commandNr6   r3   r3   r3   r4   rD   o   s"    
rD   c                   @   rC   )GetgetzGet file from master node.
%sr   Tz/Cluster Id of cluster you want to get file fromr	   r   r   rF   zSource file path on remote hostrG   z%Destination file path on your machiner=   c                 C   s   t j| j||jd}|j}t | tdstdr0dddd|jtj	d | d |j
 g}nd	d
dd|jtj	d | d |j
 g}|jrM||j n||j
dd  td| t|}|S )Nr   rH   rI   rJ   rK   r   r   rO   rL   rM   rP   rN   r   )r   r   r   r   r    rQ   r   r$   r   r%   rF   rG   r>   rR   r&   r'   r(   r)   rS   r3   r3   r4   r5      s8   

zGet._run_main_commandNr6   r3   r3   r3   r4   rT      s    
rT   )rA   r(   r"   Zawscli.customizations.emrr   r   r   Z!awscli.customizations.emr.commandr   r;   r   r<   rD   rT   r3   r3   r3   r4   <module>   s   ',(