o .&a3@sddlZddlZddlZddlmZddlmZddlmZddlmZdZ GdddeZ Gd d d eZ Gd d d eZ Gd ddeZ dS)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 " command. c@s8eZdZdZdeZddddddddgZd d Zd S) SockssockszFCreate a socks tunnel on port 8157 from your machine to the master. %s cluster-idT*Cluster Id of cluster you want to ssh intonamerequired help_text key-pair-file!Private key file to use for loginc CszTtj|j||jd}|j}t|tjdd}t ds#t dr6dddddd d d |jt j d |g }nd dd |jt j d |ddd g}t d |t|}|WStybt dYdSw)Nsessionparsed_globals cluster_idFdeletesshssh.exe-oStrictHostKeyChecking=noServerAliveInterval=10z-ND8157-i@putty-sshz-Nz-D zDisabling Socks Tunnel.r)rvalidate_and_find_master_dns_sessionr key_pair_filevalidate_ssh_with_key_filetempfileNamedTemporaryFilerwhichrSSH_USERprintjoin subprocesscallKeyboardInterruptself parsed_argsr master_dnskey_filefcommandrcr6?/usr/lib/python3/dist-packages/awscli/customizations/emr/ssh.py_run_main_command's:     zSocks._run_main_commandN__name__ __module__ __qualname__NAMEKEY_PAIR_FILE_HELP_TEXT DESCRIPTION ARG_TABLEr8r6r6r6r7rs rc@s@eZdZdZdeZddddddddd d d gZd d ZdS)SSHrz'SSH into master node of the cluster. %srTr r rrr4z!Command to execute on Master Noder r c Cstj|j||jd}|j}t|tjdd}t ds"t dr=dddddd |jt j d |d g }|j r<| |j n'd d d |jt j d |d g}|j rd||j |d| d| |j|td|t|}t|j|S)NrFrrrrrrrrz-trrz3 read -n1 -r -p "Command completed. Press any key."z-mr )rr!r"rr#r$r%r&rr'rr(r4appendwriter closer)r*r+r,osremover.r6r6r7r8OsD          zSSH._run_main_commandNr9r6r6r6r7rACs rAc@JeZdZdZdeZddddddddd dd dd d d gZddZdS)Putputz!Put file onto the master node. %srTz/Cluster Id of cluster you want to put file ontor rrsrcz!Source file path on local machinedestz$Destination file path on remote hostrBcCstj|j||jd}|j}t|tdstdr-dddd|j|jt j d|g}ndd dd|j|jt j d|g}|j rL|d d |j |d <n|d d |j d d |d <t d |t|}|S)Nrscpscp.exe-r-o StrictHostKeyChecking=norrpscp-scp:/r )rr!r"rr#validate_scp_with_key_filerr'rKrr(rLsplitr)r*r+r,r/r0rr1r2r4r5r6r6r7r8}s*      zPut._run_main_commandNr9r6r6r6r7rIos" rIc@rH)GetgetzGet file from master node. %srTz/Cluster Id of cluster you want to get file fromr rrrKzSource file path on remote hostrLz%Destination file path on your machinerBcCstj|j||jd}|j}t|tdstdr0dddd|jtj d|d|j g}nd d dd|jtj d|d|j g}|j rM| |j n | |j d d td |t|}|S)NrrMrNrOrPrrrTrQrRrUrSr )rr!r"rr#rVrr'rr(rKrLrCrWr)r*r+r,rXr6r6r7r8s8    zGet._run_main_commandNr9r6r6r6r7rYs rY)rFr+r%awscli.customizations.emrrrr!awscli.customizations.emr.commandrr>rrArIrYr6r6r6r7s     ',(