
    '                     f   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 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 Zd Zd Z  ejB                  ejD                  jF                        ejH                   G d dejJ                                      Z& ejB                  ejD                  jN                         G d de&             Z( ejB                  ejD                  jR                         G d de&             Z*dddde&_+        y) zCommand for creating snapshots.    )absolute_import)division)unicode_literals)base_classes)
csek_utils)	kms_utils)poller)waiter)base)flags)scope)resource_args)labels_util)log)
properties)	resourcesc                    | j                  dd       t        j                  |        t        j                  |        t	        j
                  | dd       t	        j                  | d       t        j                  |        t        j                  | d       t        j                  j                  |        | j                  d	d
       t        j                  j                  |        t        j                   |        t        j"                  j                  |        t        j$                  j                  |        t        j&                  |        y)z Set Args based on Release Track.namezThe name of the snapshot.)helpsnapshotz
  Create an application-consistent snapshot by informing the OS
  to prepare for the snapshot process. Currently only supported
  for creating snapshots of disks attached to Windows instances.
  )custom_helpF)flags_about_creationz--descriptionz"Text to describe the new snapshot.N)add_argument
snap_flagsAddChainArgAddSourceDiskCsekKeyr   AddGuestFlushFlagAddStorageLocationFlagr   AddCreateLabelsFlagsr   AddCsekKeyArgsr   
ASYNC_FLAGAddToParserSOURCE_DISK_ARGAddArgumentAddSnapshotType'SOURCE_DISK_FOR_RECOVERY_CHECKPOINT_ARGSOURCE_INSTANT_SNAPSHOT_ARGAddSourceInstantSnapshotCsekKeyparsers    'lib/surface/compute/snapshots/create.py_GAArgsr,   %   s    	f#>? !!&) vz2""6*F?//f%@   ((0V$44@@H((44V<,,V4    c                 t    t        |        t        j                  |        t        j                  | dd       y Nr   T)region_fallthrough)r,   r   AddScopeArgkms_resource_argsAddKmsKeyResourceArgr)   s    r+   	_BetaArgsr4   C   s,    	&/ ((jTr-   c                     t        |        t        j                  |        t        j                  |        t	        j
                  | dd       y r/   )r,   r   AddMaxRetentionDaysr1   r2   r3   r)   s    r+   
_AlphaArgsr7   K   s:    	&/  ( ((jTr-   c                   4    e Zd ZdZed        Zd Z	 	 	 ddZy)Createz;Create snapshots of Google Compute Engine persistent disks.c                     t        |        y N)r,   r)   s    r+   ArgszCreate.ArgsY   s	    FOr-   c                 $    | j                  |      S r;   _Runselfargss     r+   Runz
Create.Run]   s    99T?r-   c                    t        j                  | j                               }|j                  j                  }|j                  j
                  }|r|j                  r|j                  j                  |j                  t        j                  j                  j                  j                  |j                  dd      }|j                  |j!                         |j"                  |j                        }	n|j                  j                  |j                  dt        j                  j                  j                  j                  id      }|j                  |j!                         |j"                        }	| j                         t$        j                  j&                  t$        j                  j(                  fv }
|j*                  rt,        j.                  j1                  ||j                  t3        j4                  |j                              }|j7                         |	_        |j:                  rHt<        j>                  jA                  |j:                  |
      }t=        jB                  |||      }||	_"        |jF                  rYt,        jH                  j1                  ||j                  tJ        jL                  jN                  	      }|j7                         |	_(        |jR                  r>t<        j>                  jU                  ||
      }t=        jB                  |||      }||	_+        |r6|jX                  r*t[        j\                  |||	jV                        }|r||	_+        t_        |d
      r@|ja                  d
      r/tc        jd                  ||j                  jf                        |	_4        |jj                  r|jj                  g|	_6        |jn                  rd|	_8        |jr                  r|jr                  |	_:        |jv                  rt,        jx                  j1                  ||j                  t3        j4                  |j                              }|j7                         |	_=        |j|                  rHt<        j>                  jA                  |j|                  |
      }t=        jB                  |||      }||	_?        |ja                  d      r |	j                  |j                        |	_B        |r+|ja                  d      rt        |j                        |	_E        |r|j                  r|j                  |	|j                  |j                        }|j                  j                  |      }t        j                  j                  |j                  |j                  |j                  dd      }np|j                  |	|j                        }|j                  j                  |      }t        j                  j                  |j                  d|j                  id      }|j                  r8t        j                  |dj                  |j!                               dd       |S |r-|j                  r!t        j                  |j                  |      }n t        j                  |j                  |      }t        j                  ||dj                  |j!                                     S )N)projectregionzcompute.regionSnapshots)params
collection)r   descriptionrF   rE   zcompute.snapshots)r   rI   )scope_lister)default_scopelabelsTsnapshot_typemax_retention_days)r   rE   rF   zcompute.regionOperations)r   rE   zcompute.globalOperationszgce snapshot {0}zWUse [gcloud compute operations describe] command to check the status of this operation.)kindis_asyncdetailszCreating gce snapshot {0})Tr   ComputeApiHolderReleaseTrackclientapitools_clientmessagesrF   r   Parser   r   VALUEScorerE   	GetOrFailSnapshotNamerI   r   ALPHABETAsource_diskr   r#   ResolveAsResourcer   GetDefaultScopeListerSelfLink
sourceDisksource_disk_key_filer   CsekKeyStoreFromFileMaybeLookupKeyMessagesourceDiskEncryptionKey#source_disk_for_recovery_checkpointr&   compute_scope	ScopeEnumREGIONsourceDiskForRecoveryCheckpointcsek_key_fileFromArgssnapshotEncryptionKeykms_keyr   MaybeGetKmsKeyhasattrIsSpecifiedr   ParseCreateArgsLabelsValuerL   storage_locationstorageLocationsguest_flush
guestFlush
chain_name	chainNamesource_instant_snapshotr'   sourceInstantSnapshot source_instant_snapshot_key_file"sourceInstantSnapshotEncryptionKeySnapshotTypeValueValuesEnumrM   snapshotTypeintrN   maxRetentionDays#ComputeRegionSnapshotsInsertRequestregionSnapshotsInsertREGISTRYComputeSnapshotsInsertRequest	snapshotsasync_r   UpdatedResourceformatr	   Pollerr
   WaitFor)rA   rB   support_max_retention_dayssupport_scope_argsupport_kmsholderrT   rV   snap_refsnapshot_messageallow_rsa_encrypteddisk_refsource_keysdisk_key_or_none'source_disk_for_recovery_checkpoint_ref	csek_keyssnap_key_or_nonekms_key_or_noneiss_refinstant_snapshot_key_or_nonerequestresultoperation_refoperation_pollers                           r+   r?   zCreate._Run`   s    **4+<+<+>?F]]**F}}%%HT[[!!''
))#**//77AA / ( h "**}}&& +  !!''
))**//77AA ) ( h "**}}&& +  ++-2  ++==



226==A > h
 %-$5$5$7!		"	" --66%%':
 &;;6
 4D0//

<
<
N
N)33:: O  . 2
:
:
< 6 ))2249LMi#99
Xv 0@,t||!00
*@@o 
1@.tX4#3#3H#= + ; ;
!!--! +/+@+@*A'$(!#'?? ##66HH



226==A I g
 07/?/?/A,		.	. --66113F
 (2'G'G&(
$ ) 	; (

6
6t7I7I
J # "d&6&67K&L*-d.E.E*F'T[[<<#"" = g
 %%,,W5f((..
++!))  0 / m 66#"" 7 g &&w/f((..
++X--./ / m
 {{	
!((97 mT[[v'='=xHv'7'7B>>#**8==?; r-   N)FFF)__name__
__module____qualname____doc__staticmethodr<   rC   r?    r-   r+   r9   r9   T   s0     D  "'br-   r9   c                   "    e Zd Zed        Zd Zy)
CreateBetac                     t        |        y r;   )r4   r)   s    r+   r<   zCreateBeta.Args  s
    fr-   c                 *    | j                  |dd      S )NT)r   r   r>   r@   s     r+   rC   zCreateBeta.Run  s!    99   r-   Nr   r   r   r   r<   rC   r   r-   r+   r   r     s      r-   r   c                   "    e Zd Zed        Zd Zy)CreateAlphac                     t        |        y r;   )r7   r)   s    r+   r<   zCreateAlpha.Args  s
    vr-   c                 ,    | j                  |ddd      S )NT)r   r   r   r>   r@   s     r+   rC   zCreateAlpha.Run  s$    99#'	   r-   Nr   r   r-   r+   r   r     s      r-   r   zCreate Compute Engine snapshotsz    *{command}* creates snapshot of persistent disk. Snapshots are useful for
    backing up persistent disk data and for creating custom images.
    For more information, see https://cloud.google.com/compute/docs/disks/create-snapshots.
    z    To create a snapshot 'my-snap' from a disk 'my-disk' in zone 'us-east1-a', run:

        $ {command} my-snap --source-disk=my-disk --source-disk-zone=us-east1-a
    )briefDESCRIPTIONEXAMPLESN),r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   )googlecloudsdk.api_lib.compute.operationsr	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r   rj   ,googlecloudsdk.command_lib.compute.snapshotsr   googlecloudsdk.command_lib.kmsr   r2   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   r,   r4   r7   ReleaseTracksrS   GAUniverseCompatibleCreateCommandr9   r^   r   r]   r   detailed_helpr   r-   r+   <module>r      s   & &  ' 7 5 4 < . ( 4 E L M < # * )5< D%%(()lT l  *l^ D%%**+  , D%%++,&  -  /
 r-   