
    %                     X   S 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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SS.rS r \RB                  " \RD                  RF                  5       " S S\RH                  5      5       r%\RB                  " \RD                  RL                  5       " S S\%5      5       r'\RB                  " \RD                  RP                  5       " S S\'5      5       r)\\%l*        g)zCommand for snapshotting disks.    )absolute_import)division)unicode_literals)base_classes)
csek_utils)name_generator)poller)waiter)arg_parsers)base)
exceptions)flags)labels_util)log)
properties)zipz4Create snapshots of Compute Engine persistent disks.a  
        *{command}* creates snapshots of persistent disks. Snapshots are useful
        for backing up data, copying a persistent disk, and even, creating a
        custom image. Snapshots can be created from persistent disks even while
        they are attached to running instances. Once created, snapshots may be
        managed (listed, deleted, etc.) via `gcloud compute snapshots`.

        Refer to the Snapshot best practices guide. https://cloud.google.com/compute/docs/disks/snapshot-best-practices

        {command} waits until the operation returns a status of `READY` or
        `FAILED`, or reaches the maximum timeout, and returns the last known
        details of the snapshot.

        Note: To create snapshots, the following IAM permissions are necessary
        ``compute.disks.createSnapshot'', ``compute.snapshots.create'',
        ``compute.snapshots.get'', and ``compute.zoneOperations.get''.
        z
        To create a snapshot named `snapshot-test` of a persistent disk named `test`
        in zone `us-central1-a`, run:

          $ {command} test --zone=us-central1-a --snapshot-names=snapshot-test --description="This is an example snapshot"
    )briefDESCRIPTIONEXAMPLESc                    [         R                  R                  U 5        U R                  SSS9  U R                  S[        R
                  " SS9SSS	9  [        R                  " U 5        [        R                  " U S
5        [        R                  " U S
5        [        R                  " U SS9  [        R                  R                  U 5        g)z*Add parser arguments common to all tracks.z--descriptionz-Text to describe the snapshots being created.)help--snapshot-names   )
min_lengthSNAPSHOT_NAMEa5        Names to assign to the created snapshots. Without this option, the
      name of each snapshot will be a random 12-character alphanumeric
      string that starts with a letter. The values of
      this option run parallel to the disks specified. For example,

          {command} my-disk-1 my-disk-2 my-disk-3 --snapshot-names snapshot-1,snapshot-2,snapshot-3

      will result in `my-disk-1` being snapshotted as
      `snapshot-1`, `my-disk-2` as `snapshot-2`, and so on. The name must match
      the `(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)` regular expression, which
      means it must start with an alphabetic character followed by one or more
      alphanumeric characters or dashes. The name must not exceed 63 characters
      and must not contain special symbols. All characters must be lowercase.
      )typemetavarr   snapshotF)flags_about_creationN)SnapshotDisks	disks_argAddArgumentadd_argumentr   ArgList
snap_flagsAddChainArgr   AddGuestFlushFlagAddStorageLocationFlagr   AddCsekKeyArgsr   
ASYNC_FLAGAddToParser)parsers    %lib/surface/compute/disks/snapshot.py_CommonArgsr.   C   s    %%f-;  > 	!,
	  &  &*-vz2F?//f%    c                   4    \ rS rSrSr\S 5       rS rS rSr	g)r    e   z;Create snapshots of Google Compute Engine persistent disks.c                     [         R                  " SS9[        l        [        R
                  " U5        [        U5        g NT)pluraldisks_flagsMakeDiskArgr    r!   r   AddCreateLabelsFlagsr.   clsr,   s     r-   ArgsSnapshotDisks.Argsi   +    )55TBM$$V,r/   c                 $    U R                  U5      $ N_Runselfargss     r-   RunSnapshotDisks.Runo       99T?r/   c           
      
   [         R                  " U R                  5       5      n[        R                  R                  XR                  [        R                  " UR                  5      S9nUR                  (       aF  [        U5      [        UR                  5      :w  a  [        R                  " SS5      eUR                  nO%U Vs/ s H  n[        R                  " 5       PM     nnU Vs/ s HL  nUR                  R!                  US["        R$                  R&                  R(                  R*                  0SS9PMN     nnUR                  R,                  nUR                  R.                  n	/ n
[1        X75       GH  u  p[2        R4                  R7                  US5      n[2        R8                  " XU5      n[2        R8                  " XU5      nU	R;                  UR=                  5       UR>                  UUUR@                  S9n[C        US	5      (       a(  URE                  S	5      (       a  URF                  /Ul$        [C        US
5      (       aE  URE                  S
5      (       a/  [J        RL                  " XR:                  RN                  5      Ul(        URS                  5       S:X  a`  U	RU                  UR=                  5       UUR(                  URV                  URX                  S9nU
R[                  UR\                  SU45        GM  URS                  5       S:X  d  GM  U	R_                  UR=                  5       UUR(                  UR`                  S9n[C        US5      (       a  [c        USS5      nUb  UUl2        U
R[                  URf                  SU45        GM      / nUR                  Ri                  U
U5      nU HH  n[c        USS5      nU(       d  M  UR[                  [j        Rl                  " URn                  5      5        MJ     U(       a  [p        Rr                  " U5      eU Vs/ s H(  nUR                  R!                  URt                  5      PM*     nnURv                  (       af  U H?  n[x        Rz                  R}                  SR                  UR                  5       5      5        MA     [x        Rz                  R}                  S5        U$ [j        R                  " UR                  UR                  U5      n[        R                  " U[j        R                  " U5      SR                  SR                  S U 5       5      5      SS9$ s  snf s  snf s  snf )z<Returns a list of requests necessary for snapshotting disks.)scope_listerr   zR[--snapshot-names] must have the same number of values as disks being snapshotted.projectzcompute.snapshots)params
collectionT)namedescriptionsnapshotEncryptionKeysourceDiskEncryptionKey	chainNamestorage_locationlabelszcompute.disks)diskr   rJ   zone
guestFlushCreateSnapshotzcompute.regionDisks)rT   r   rJ   regionrV   guest_flushNerrorz#Disk snapshot in progress for [{}].z]Use [gcloud compute operations describe URI] command to check the status of the operation(s).zCreating snapshot(s) {0}z, c              3   @   #    U  H  oR                  5       v   M     g 7fr?   )Name).0ss     r-   	<genexpr>%SnapshotDisks._Run.<locals>.<genexpr>   s     :Mq&&((Ms   )max_wait_ms)Gr   ComputeApiHolderReleaseTrackr    r!   ResolveAsResource	resourcesr   GetDefaultScopeListerclientsnapshot_nameslenr   InvalidArgumentExceptionr   GenerateRandomNameParser   VALUEScorerJ   	GetOrFailapitools_clientmessagesr   r   CsekKeyStoreFromArgsMaybeLookupKeyMessageSnapshotr\   rN   
chain_namehasattrIsSpecifiedrR   storageLocationsr   ParseCreateArgsLabelsValuerS   
Collection!ComputeDisksCreateSnapshotRequestrU   rY   appenddisks'ComputeRegionDisksCreateSnapshotRequestrX   getattrrV   regionDisksAsyncRequestsr	   OperationErrorserrorscore_exceptions
MultiErrorselfLinkasync_r   statusPrintformatSelfLinkBatchPoller	snapshotsr
   WaitForOperationBatchjoin)rC   rD   holder	disk_refsrh   _snapshot_namesnapshot_refsrg   rq   requestsdisk_refsnapshot_ref	csek_keyssnapshot_key_or_nonedisk_key_or_nonesnapshot_messagerequestrY   errors_to_collect	responsesrerroperation_refsoperation_refoperation_pollers                             r-   rA   SnapshotDisks._Runr   s   **4+<+<+>?F''9900? : AI 	Y3t223	311!" 	" **n "+,!*A '99;!*  , ,- ,M 	:,,1199CC + 	 	, ,  - ]]**F}}%%HH"%i"?))224>i'==
6+#99
v' "**  "&& 4"2OO + % $*
+
+


-
.
.-1-B-B,C)
$
!
!d&6&6x&@&@"-"="=##//#1 
			/	1<<%$$'' = ) 	'7AB $99BB%$$??	 C $
 7L))mT:+$!,G++-=wGHO #@R ++H6GHIAw%c	  !7!7

!CD  &&'899BKL)Qf&&,,QZZ8)NL{{)-

> &!7!7!9:	< * 
jj B C))v''8>>&//?"			:M::	;	 _,-@ Ms   U+AU(/U N)
__name__
__module____qualname____firstlineno____doc__classmethodr;   rE   rA   __static_attributes__r   r/   r-   r    r    e   s"    C 
dr/   r    c                   (    \ rS rSrSr\S 5       rSrg)SnapshotDisksBeta   z@Create snapshots of Google Compute Engine persistent disks beta.c                     [         R                  " SS9[        l        [        R
                  " U5        [        U5        g r3   r5   r9   s     r-   r;   SnapshotDisksBeta.Args   r=   r/   r   N)r   r   r   r   r   r   r;   r   r   r/   r-   r   r      s    H r/   r   c                   .    \ rS rSrSr\S 5       rS rSrg)SnapshotDisksAlpha   zACreate snapshots of Google Compute Engine persistent disks alpha.c                     [         R                  " SS9[        l        [        R
                  " U5        [        U5        g r3   r5   r9   s     r-   r;   SnapshotDisksAlpha.Args   r=   r/   c                 $    U R                  U5      $ r?   r@   rB   s     r-   rE   SnapshotDisksAlpha.Run   rG   r/   r   N)	r   r   r   r   r   r   r;   rE   r   r   r/   r-   r   r      s    I 
r/   r   N)+r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   )googlecloudsdk.api_lib.compute.operationsr	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   r   r   "googlecloudsdk.command_lib.computer   (googlecloudsdk.command_lib.compute.disksr6   ,googlecloudsdk.command_lib.compute.snapshotsr%   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   	six.movesr   DETAILED_HELPr.   ReleaseTracksrc   GASilentCommandr    BETAr   ALPHAr   detailed_helpr   r/   r-   <module>r      s   & &  ' 7 5 9 < . / ( . 4 I L < = # *  D"'8&D D%%(()pD&& p *pf D%%**+  , D%%++,
* 
 -
 , r/   