
    s                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ  G d de
j"                        Zy)z)The `app instances enable-debug` command.    )absolute_import)division)unicode_literals)appengine_api_client)env)instances_util)base)
properties)	resources)
console_io)progress_trackerc                   .    e Zd ZdZddiZed        Zd Zy)EnableDebuga,  Enable debug mode for an instance (only works on the flexible environment).

  When in debug mode, SSH will be enabled on the VMs, and you can use
  `gcloud compute ssh` to login to them. They will be removed from the health
  checking pools, but they still receive requests.

  Note that any local changes to an instance will be *lost* if debug mode is
  disabled on the instance. New instance(s) may spawn depending on the app's
  scaling settings.

  Additionally, debug mode doesn't work for applications using the
  App Engine standard environment.
  EXAMPLESz          To enable debug mode for a particular instance, run:

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

          To enable debug mode for an instance chosen interactively, run:

              $ {command}
          c                 |    | j                  ddd       | j                  ddd       | j                  d	d
d       y )Ninstance?z        Instance ID to enable debug mode on. If not specified,
        select instance interactively. Must uniquely specify (with other
        flags) exactly one instance)nargshelpz	--servicez-sz        If specified, only match instances belonging to the given service.
        This affects both interactive and non-interactive selection.)r   z	--versionz-vz        If specified, only match instances belonging to the given version.
        This affects both interactive and non-interactive selection.)add_argument)parsers    )lib/surface/app/instances/enable_debug.pyArgszEnableDebug.Args;   sa    
#'  ( TH  I TH  I    c                    t        j                  | j                               }t        |j	                  |j
                  |j                  d             }	 t        j                  j                  |j                        }t        j                  ||j                  |j                  |j                        }t#        j$                  dj'                  |      d       dj'                  |      }t        j                  j                  |j(                  t*        j,                  j.                  j0                  j2                  |j                  |j(                  |j
                  dd	
      }t5        j6                  |      5  |j9                  |       d d d        y # t         $ r; t        j                  ||j
                  |j                  |j                        }Y %w xY w# 1 sw Y   y xY w)Nc                 Z    | j                   t        j                  t        j                  fv S )N)environmentr   FLEXMANAGED_VMS)vs    r   <lambda>z!EnableDebug.Run.<locals>.<lambda>T   s    388S__2M!Mr   )version_filter)serviceversionr   z.About to enable debug mode for instance [{0}].T)cancel_on_noz&Enabling debug mode for instance [{0}])appsId
versionsIdinstancesId
servicesIdz*appengine.apps.services.versions.instances)params
collection)r   GetApiClientForTrackReleaseTracklistGetAllInstancesr#   r$   r   REGISTRYParser   r   GetMatchingInstancer)   r'   r(   	Exceptionr   PromptContinueformatidr
   VALUEScoreproject	GetOrFailr   ProgressTrackerDebugInstance)selfargs
api_clientall_instancesresr   messages          r   RunzEnableDebug.RunP   s   %::4;L;L;NOJ33dllM 4 O PM
$$$T]]3c  33
??$h 8??I 7==hGG



"
" '',,44>>"**#;;"**	
 @ # AC 
	)	)'	2s# 
3	2/  "33
t||=="h". 
3	2s   )F >G A GG G)N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   rC    r   r   r   r       s3      
- I I($r   r   N)rG   
__future__r   r   r   googlecloudsdk.api_lib.appr   r   r   googlecloudsdk.callioper	   googlecloudsdk.corer
   r   googlecloudsdk.core.consoler   r   Commandr   rJ   r   r   <module>rQ      s=     0 &  ' ; * 5 ( * ) 2 8O$$,, O$r   