
                            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 Ze	j(                   e	j*                  e	j,                  j.                         G d de	j0                                      Z e	j*                  e	j,                  j4                         G d de             Z e	j*                  e	j,                  j8                         G d de             Zy)zCreates a new AlloyDB backup.    )absolute_import)division)unicode_literals)api_util)backup_operations)base)flags)resource_args)log)
properties)	resourcesc                 n    |r3| j                   j                  j                  |j                               S y N)BackupTypeValueValuesEnumlookup_by_nameupper)alloydb_messagesbackup_types     %lib/surface/alloydb/backups/create.py_ParseBackupTyper       s3    ""66EE 	    c                   6    e Zd ZdZdddZed        Zd Zd Zy)	Createz4Creates a new AlloyDB backup within a given project.z{description}a%          To create a new backup, run:

          $ {command} my-backup --cluster=my-cluster --region=us-central1

        To create a new cross-region backup, run:

          $ {command} projects/my-project/locations/us-west1/backups/my-backup --cluster=my-cluster --region=us-central1
        )DESCRIPTIONEXAMPLESc                 *   t         j                  j                  |       |j                  ddt        d       |j                  dt        d       t        j                  |d       t        j                  |       t        j                  |dd	
       y)zySpecifies additional command flags.

    Args:
      parser: argparse.Parser: Parser object for command line inputs.
    z--regionTz$The region of the cluster to backup.)requiredtypehelpbackupaT  The AlloyDB backup to create. This must either be the backup ID (myBackup) or the full backup path (projects/myProject/locations/us-central1/backups/myBackup). In the first case, the project and location are assumed to be the same as the cluster being backed up. The second form can be used to create cross-region and cross-project backups.)r   r    FzjThe 'AlloyDB Service Agent' service account must hold permission 'Cloud KMS CryptoKey Encrypter/Decrypter')permission_infoN)
r   
ASYNC_FLAGAddToParseradd_argumentstrr	   
AddClusterAddTagskms_resource_argsAddKmsKeyResourceArg)clsparsers     r   ArgszCreate.Args<   s     	OO'
3	   F	   
VU#	MM&**9	r   c                 d   |j                         }|j                         |_        t        |d      |_        |j                         |_        t        j                  ||j                   j                        |_	        t        j                  |      }|r|j                         }||_        ||_        |S )N	ON_DEMAND)r   RelativeNamenamer   r   clusterNamer	   GetTagsFromArgs	TagsValuetagsGetAndValidateKmsKeyNameEncryptionConfig
kmsKeyNameencryptionConfig)selfr   cluster_ref
backup_refargsbackup_resourcekms_keyencryption_configs           r   ConstructResourceFromArgsz Create.ConstructResourceFromArgsa   s     '--/O%224O+,<kJO"-":":"<O 00%%//1O,,T2G*;;=%,"):o&r   c                    t        j                  | j                               }|j                  }|j                  }|j
                  j                  dt        j                  j                  j                  j                  |j                  |j                        }|j
                  j                  d|j                  t        j                  j                  j                  j                  |j                  d      }| j!                  ||||      }|j#                  ||j%                         |j'                         j)                               }|j*                  j                  |      }	t,        j.                  j1                  |	j2                  d      }
t4        j6                  j9                  d	j;                  |
j%                                      |j<                  s%t?        j@                  |
d
| j                                |	S )zConstructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
          arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    z#alloydb.projects.locations.clusters)
projectsIdlocationsId
clustersIdz"alloydb.projects.locations.backups)rC   rD   )
collectionlineparams)r!   backupIdparentz%alloydb.projects.locations.operations)rF   zOperation ID: {}zCreating backup)!r   AlloyDBClientReleaseTrackalloydb_clientr   resource_parserr   r   VALUEScoreproject	GetOrFailregionclusterParser!   rA   ,AlloydbProjectsLocationsBackupsCreateRequestNameParentr0   projects_locations_backupsr   REGISTRYParseRelativeNamer1   r   statusPrintformatasync_r   Await)r:   r=   clientrM   r   r;   r<   r>   reqopop_refs              r   Runz
Create.Runq   s    ##D$5$5$78F**N..((//-$$))11;;KK<<	 0 !K
 ''--7[[$++0088BB;;
 . J 44+z4O 
G
G"  "//1 H C
 
	2	2	9	9#	>B11
C 2 EFJJ'..v{{}=>;;f&79J9J9LMIr   N)	__name__
__module____qualname____doc__detailed_helpclassmethodr-   rA   re    r   r   r   r   *   s7     = %- " "H *r   r   c                   6     e Zd ZdZe fd       Z fdZ xZS )
CreateBeta3Create a new AlloyDB backup within a given project.c                 V    t         t        |   |       t        j                  |       y r   )superrn   r-   r	   AddEnforcedRetentionr+   r,   	__class__s     r   r-   zCreateBeta.Args   s     	*c'	v&r   c                 Z    t         t        |   ||||      }|j                  rd|_        |S )NT)rq   rn   rA   enforced_retentionenforcedRetention)r:   r   r;   r<   r=   r>   rt   s         r   rA   z$CreateBeta.ConstructResourceFromArgs   s8     JG+z4O *.o'r   )rf   rg   rh   ri   rk   r-   rA   __classcell__rt   s   @r   rn   rn      s"    ;' ' r   rn   c                   ,     e Zd ZdZe fd       Z xZS )CreateAlpharo   c                 ,    t         t        |   |       y r   )rq   r{   r-   rs   s     r   r-   zCreateAlpha.Args   s    	+s (r   )rf   rg   rh   ri   rk   r-   rx   ry   s   @r   r{   r{      s    ;) )r   r{   N)ri   
__future__r   r   r   googlecloudsdk.api_lib.alloydbr   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.alloydbr	   googlecloudsdk.command_lib.kmsr
   r)   googlecloudsdk.corer   r   r   r   DefaultUniverseOnlyReleaseTracksrL   GACreateCommandr   BETArn   ALPHAr{   rl   r   r   <module>r      s    $ '  ' 3 < ( 4 M # * ) D%%(()oT o * od D%%**+  ,& D%%++,)* ) -)r   