
                             d Z ddlmZ ddlmZ ddlm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d
lmZ ddlmZ ddlmZ ddlZd ej*                  d      iZ G d dej.                        Zy)z)Command that saves environment snapshots.    )absolute_import)division)unicode_literalsN)environments_util)operations_util)util)base)resource_args)logEXAMPLESzi          To save a snapshot of the environment named env-1, run:

            $ {command} env-1
        c                   6    e Zd ZdZeZed        Zd Zd Z	d Z
y)SaveSnapshotz#Save a snapshot of the environment.c                     t        j                  | d       t        j                  j	                  |        | j                  dt        d       y )Nz where the snapshot must be savedz--snapshot-locationzThe Cloud Storage location where to save the snapshot. It must start with the prefix gs://. Default value is /snapshots directory in the Cloud Storage bucket of the environment.)typehelp)r
   AddEnvironmentResourceArgr	   
ASYNC_FLAGAddToParseradd_argumentstr)parsers    3lib/surface/composer/environments/snapshots/save.pyArgszSaveSnapshot.Args/   sF    ++F,NPOO'
7  8    c                 
   |j                   j                  j                         }t        j                  ||j
                  | j                               }|j                  r| j                  ||      S | j                  ||      S )Nrelease_track)
CONCEPTSenvironmentParseenvironments_api_utilr   snapshot_locationReleaseTrackasync__AsynchronousExecution_SynchronousExecution)selfargsenv_resource	operations       r   RunzSaveSnapshot.Run;   sn    ==,,224L%22d,,D<M<M<OQI{{((yAA''i@@r   c                    t        j                  |j                         dddj                  |j                               t         j
                  j                  d       t         j
                  j                  d|j                  z          |S )Nr   Tzwith operation [{}])kindis_asyncdetailsz#If you want to see the result, run:$gcloud composer operations describe )r   UpdatedResourceRelativeNameformatnamestatusPrint)r'   r)   r*   s      r   r%   z#SaveSnapshot._AsynchronousExecutionD   sk    !!#%,,Y^^<	> JJ:;JJ;innLMr   c           	         	 t        j                  |dj                  |j                         |j                        | j                                t        j                  | j                               j                  t        j                  | j                               j                  |j                              }t        j                  j                  d       t        j                  j                  d|j                  z   dz          t        j                  j                  d       t        j                  j                  d       t        j                  j                  d	       |j                  S # t        j                   $ rK}t        j                   d
j                  |j                         t#        j$                  |                  d }~ww xY w)Nz(Waiting for [{}] to be updated with [{}]r   )r4   z.
If you want to see the result once more, run:r0   
zoIf you want to see history of all operations to be able to display results of previous check-upgrade runs, run:z gcloud composer operations list
z
Response: z7Failed to save the snapshot of the environment [{}]: {})operations_api_utilWaitForOperationr3   r2   r4   r#   
GetServiceGetapi_utilGetMessagesModule-ComposerProjectsLocationsOperationsGetRequestr   r5   r6   responsecommand_utilErrorsix	text_type)r'   r)   r*   completed_operationes        r   r&   z"SaveSnapshot._SynchronousExecutionP   st   >**

4
;
;'')9>>;))+	- 0::



"s(():):)<=<< ~~ = ' (  
jjHI	jj=	N  
jjEF 
jj:;	jj|$ ))) >
C
J
J'')3==+;=> >>s   E1E4 4GAGGN)__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr   r+   r%   r&    r   r   r   r   *   s,    +-	8 	8A
>r   r   )rJ   
__future__r   r   r   textwrapgooglecloudsdk.api_lib.composerr   r!   r   r9   r   r=   googlecloudsdk.callioper	   #googlecloudsdk.command_lib.composerr
   rA   googlecloudsdk.corer   rC   dedentrK   Commandr   rN   r   r   <module>rW      s_    0 &  '  V R < ( = D # 
   	C>4<< C>r   