
    /                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr	  SSK
Jr  SSKJr  SS	KJr  SSKJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  S r\R<                  " \R>                  R@                  5      \RB                   " S S\RD                  5      5       5       r#\R<                  " \R>                  RH                  5      \RB                   " S S\#5      5       5       r%g)z The `app instances ssh` command.    )absolute_import)division)unicode_literalsN)
exceptions)appengine_api_client)base_classes)base)flags)
iap_tunnel)
ssh_common)
containers)ssh)log)
properties)	resourcesc                     U R                  SSS9  U R                  SSS9  U R                  S[        R                  SS9  g )	NinstancezThe instance ID.)helpz--containerz2Name of the container within the VM to connect to.commandz$Remote command to execute on the VM.)nargsr   )add_argumentargparse	REMAINDERparsers     lib/surface/app/instances/ssh.py_ArgsCommonr   (   s[       	?  A 	1  3    c                   r    \ rS rSrSr\R                  " S5      \R                  -   SS.r	\
S 5       rS rSrg	)
SshGa5   3SSH into the VM of an App Engine Flexible instance.a          *{command}* lets you remotely log in to your running App Engine Flexible
        instances under two conditions:
        * The instance is running.
        * The instance has an external IP address. To check from the Cloud
        Console, go to the Instances page and confirm that there is an IP
        address listed in the VM IP column. To check from your app.yaml, open
        your app.yaml and look at the network settings. The *instance_ip_mode*
        field must be either not listed or set to ``external''.a            To SSH into an App Engine Flexible instance, run:

              $ {command} --service=s1 --version=v1 i1

          To SSH into the app container within an instance, run:

              $ {command} --service=s1 --version=v1 i1 --container=gaeapp

          To SSH into the app container and run a remote command, run:

              $ {command} --service=s1 --version=v1 i1 --container=gaeapp -- echo hello
          )DESCRIPTIONEXAMPLESc                 r    [         R                  " U 5        [        U 5        [        R                  " U 5        g )Nr
   AddServiceVersionSelectArgsr   r   AddSshTunnelArgsr   s    r   Args
SshGa.ArgsV   s&    	%%f-'r   c                 	   [         R                  " U R                  5       5      n [        R                  R                  UR                  SS9nUR                  nUR                  nUR                  n[        R                  R                  5       nUR!                  5         [        R"                  R%                  5       nUR'                  SS9   UR)                  XE5      n	[4        R6                  R8                  R:                  R=                  5       n
[        R                  R                  UU
UUUS.SS9n UR?                  U5      n[D        RF                  " UUU R                  5       U
U	U5      nSRI                  URJ                  RM                  S5      S	S
 5      n[        RN                  " 5       n[P        RR                  " U R                  5       5      n
[        RT                  " S	U
UURW                  5       RY                  5       S	U R                  5       U
RZ                  UUUU	R\                  (       a  U	R\                  OSUS.[^        R`                  " U R                  5       5      Rb                  Rd                  S9nS	nURf                  (       d  URh                  (       a"  [        Rj                  " U
RZ                  XEU5      n[P        Rl                  " UUUUURW                  5       URn                  URp                  5      n[r        Rt                  " URv                  URx                  5      n[r        Rz                  " URv                  URx                  5      n [P        R|                  " [P        R~                  " 5       5      nU(       d  [        R                  " S5        [        R                  " UR                  UR                  UUUUR                  US9R                  U5      $ ! [        R                   a(    UR                  nUR                  nUR                  n GNf = f! [*        R,                   a&    [.        R0                  " SR3                  XE5      5      ef = f! [*        R,                   a%    [.        R@                  " URC                  5       5      ef = f! [*        R                   a    [        R                  " S5      ef = f)]  Connect to a running App Engine flexible instance.

Args:
  args: argparse.Namespace, the args the command was invoked with.

Raises:
  InvalidInstanceTypeError: The instance is not supported for SSH.
  MissingVersionError: The version specified does not exist.
  MissingInstanceError: The instance specified does not exist.
  UnattendedPromptError: Not running in a tty.
  OperationCancelledError: User cancelled the operation.
  ssh.CommandError: The SSH command exited with SSH exit code, which
    usually implies that a connection problem occurred.

Returns:
  int, The exit code of the SSH command.
*appengine.apps.services.versions.instances
collectionF	overwrite{}/{}appsId
versionsIdinstancesId
servicesIdparamsr/   -N r4   r7   r5   r6   serviceAccountregionapp_engine_paramsmessageszxNo ingress firewall rule that allows ingress to port 22. User should add a firewall rule that allows ingress to port 22.zUnable to fetch firewall rulesidentity_file	cert_filettyremote_commandoptionsiap_tunnel_args)Ir   GetApiClientForTrackReleaseTrackr   REGISTRYParser   r7   r5   r6   RequiredFieldOmittedExceptionserviceversionr   EnvironmentCurrent
RequireSSHKeysFromFilenameEnsureKeysExistGetVersionResourceapitools_exceptionsHttpNotFoundErrorcommand_exceptionsMissingVersionErrorformatr   VALUEScoreproject	GetOrFailGetInstanceResourceMissingInstanceErrorRelativeNamer   CreateSshTunnelArgsjoin
vmZoneNamesplitGetDefaultSshUsernamer   GetComputeProjectGetOsloginStateGetPublicKeyToEntrynamer>   compute_base_classesComputeApiHolderclientrB   third_party_userrequire_certificatesCertFileFromAppEngineInstancePopulatePublicKeyuseroslogin_enabledr   GetRemoteCommand	containerr   GetTtyFilterFirewallRulesFetchFirewallRulesr   warningNotFoundError	exception
SSHCommandremotekey_filerH   Run)selfargs
api_clientresrO   rP   r   envkeysversion_resourcer_   instance_resourcerI   r?   ru   oslogin_staterE   connection_detailsrG   rF   filtered_firewall_ruless                        r   r   	SshGa.Run\   s   $ &::4;L;L;NOJ
$$
--A % Cc ggh //
!
!
#CNN88  "D5)#66wH
 $$,,668G



"
"!#!	
 @ # 	CH$88= !44O XX'2288=crBCF$$&D**4+<+<+>?G''##%ll!!# $22 !//
 &66

&+M0 I%%)K)K33
,,(i $55%%  00NN


DNNDLL
9C
< * > >

'
'
)! %N	
 >>!!mm%"**') *-S2 22 ggh 00 227>>
4  " 00 H33C4D4D4FGGH@ ,, <MM:;;<s7   AO' P& 6Q# AR '8P#"P#&:Q #9R+S
 N)__name__
__module____qualname____firstlineno____doc__textwrapdedentr   DETAILED_HELPdetailed_helpstaticmethodr)   r   __static_attributes__r   r   r   r    r    5   sR     < // C D 
"
"	#-8 ( (
A2r   r    c                   .    \ rS rSrSr\S 5       rS rSrg)SshBeta   r"   c                 p    [         R                  " U SS9  [        U 5        [        R                  " U 5        g )NT)short_flagsr&   r   s    r   r)   SshBeta.Args   s(    	%%f$?'r   c                    [         R                  " S5        [        R                  " U R	                  5       5      n [
        R                  R                  UR                  SS9nUR                  nUR                  nUR                  n[        R                   R#                  5       nUR%                  5         [        R&                  R)                  5       nUR+                  SS9   UR-                  XE5      n	[8        R:                  R<                  R>                  RA                  5       n
[
        R                  R                  UU
UUUS.SS9n URC                  U5      n[H        RJ                  " XU R	                  5       XU5      nS	RM                  URN                  RQ                  S	5      S
S 5      n[        RR                  " 5       n[T        RV                  " U R	                  5       5      n
[        RX                  " S
U
UUR[                  5       R]                  5       S
U R	                  5       U
R^                  UUUU	R`                  (       a  U	R`                  OSUS.[b        Rd                  " U R	                  5       5      Rf                  Rh                  S9nS
nURj                  (       d  URl                  (       a"  [        Rn                  " U
R^                  XEU5      n[T        Rp                  " UUUUUR[                  5       URr                  URt                  5      n[v        Rx                  " URz                  UR|                  5      n[v        R~                  " URz                  UR|                  5      n[        R                  " UR                  UR                  UUUUR                  US9R                  U5      $ ! [
        R                   a(    UR                  nUR                  nUR                  n GNgf = f! [.        R0                   a&    [2        R4                  " SR7                  XE5      5      ef = f! [.        R0                   a%    [2        RD                  " URG                  5       5      ef = f)r,   zFor `gcloud beta app instances ssh`, the short flags `-s` and `-v` are deprecated and will be removed 2017-09-27. For the GA command, they are not available. Please use `--service` and `--version` instead.r-   r.   Fr0   r2   r3   r8   r:   Nr;   r<   r=   r@   rC   )Er   r|   r   rJ   rK   r   rL   rM   r   r7   r5   r6   rN   rO   rP   r   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r   r]   r^   r_   r`   ra   rb   rc   r   rd   re   rf   rg   rh   r   ri   rj   rk   rl   rm   r>   rn   ro   rp   rB   rq   rr   rs   rt   ru   rv   r   rw   rx   r   ry   r   r   r   rH   r   )r   r   r   r   rO   rP   r   r   r   r   r_   r   rI   r?   ru   r   rE   r   rG   rF   s                       r   r   SshBeta.Run   s   $ KK	
 &::4;L;L;NOJ
$$
--A % Cc ggh //
!
!
#CNN88  "D5)#66wH
 $$,,668G



"
"!#!	
 @ # ACH$88= !44T595F5F5H5<5FHO
 XX'2288=crBCF$$&D**4+<+<+>?G''##%ll!!# $22 !//
 &66

&+M. I%%)K)K33
,,(i $55%%  00NN


DNNDLL
9C>>!!mm%"**') *-S2_ 22 ggh 00 227>>
4    00 H33C4D4D4FGGHs*   AN4 $O3 P0 48O0/O03:P-09Q)r   N)	r   r   r   r   r   r   r)   r   r   r   r   r   r   r      s     <( (
v2r   r   )&r   
__future__r   r   r   r   r   apitools.base.pyr   rX   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.computer   rn   googlecloudsdk.callioper	   googlecloudsdk.command_lib.apprZ   r
   r   r   #googlecloudsdk.command_lib.util.sshr   r   googlecloudsdk.corer   r   r   r   ReleaseTracksrK   GADefaultUniverseOnlyCommandr    BETAr   r   r   r   <module>r      s     ' &  '   > ; O ( K 0 5 5 : 3 # * )
3 D%%(()f2DLL f2  *f2R D%%**+2e 2  ,2r   