
    =                         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  G d de
j                        Zy)z"Command for spanner backup create.    )absolute_import)division)unicode_literalsN)backup_operations)backups)base)resource_args)logc                   N    e Zd ZdZd ej
                  d      iZed        Zd Z	y)CreatezaCreates a backup of a Cloud Spanner database.

  Creates a backup of a Cloud Spanner database.
  EXAMPLESaI          To create a backup asynchronously, run:

          $ {command} BACKUP_ID --instance=INSTANCE_NAME --database=DATABASE --expiration-date=2020-03-29T10:49:41Z --async

        To create a backup synchronously, run:

          $ {command} BACKUP_ID --instance=INSTANCE_NAME --database=DATABASE --retention-period=2w
        c                    t        j                  | d       | j                  ddd       | j                  dd      }|j                  dd	       |j                  d
d	       | j                  ddd       t        j
                  j                  |        | j                         }t        j                  |       t        j                  |d       y)z Register flags for this command.z	to createz
--databaseTz9ID of the database from which the backup will be created.)requiredhelp)mutexr   z--expiration-datezExpiration time of the backup, must be at least 6 hours and at most 30 days from the time the request is received. See `$ gcloud topic datetimes` for information on date/time formats.)r   z--retention-periodzRetention period of the backup relative from now, must be at least 6 hours and at most 30 days. See `$ gcloud topic datetimes` for information on duration formats.z--version-time	TIMESTAMPzThe backup will contain an externally consistent copy of the database at the timestamp specified by `--version-time`. If `--version-time` is not specified, the system will use the creation time of the backup.)metavarr   z"to create the Cloud Spanner backupN)	r	   AddBackupResourceArgadd_argumentadd_argument_groupr   
ASYNC_FLAGAddToParser AddCreateBackupEncryptionTypeArgAddKmsKeyResourceArg)parsergroup_parserencryption_group_parsers      %lib/surface/spanner/backups/create.pyArgszCreate.Args1   s     &&v{;
H  J
 ,,4$,GLK  L
 :  ;    	OO'$779223JK&&'>'KM    c                    |j                   j                  j                         }t        j                  |      }t        j
                  |      }t        j                  ||||      }|j                  rEt        j                  j                  dj                  |j                  |j                               |S t        j                  |dj                  |j                              }|j                   t        j"                  |       |S )z9This is what gets called when the user runs this command.z@Create request issued for: [{}]
Check operation [{}] for status.z&Waiting for operation [{}] to complete)CONCEPTSbackupParser	   GetCreateBackupEncryptionTypeGetAndValidateKmsKeyNamer   CreateBackupasync_r
   statusPrintformatnamer   AwaiterrorCreatedResource)selfargs
backup_refencryption_typekms_keyop	op_results          r   Runz
Create.RunU   s     %%++-J#AA$GO44T:G			j$	IB{{	jj ::@&;;;12 i!''
4;;BGGDFI	xx	)$r    N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpstaticmethodr   r7    r    r   r   r      sB     
(//  - !M !MFr    r   )r;   
__future__r   r   r   r<   googlecloudsdk.api_lib.spannerr   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.spannerr	   googlecloudsdk.corer
   CreateCommandr   r@   r    r   <module>rG      s9    ) &  '  < 2 ( < #HT Hr    