
    j$                     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rSr\\S.rS\R6                  S\R8                  S\R:                  4S jrS\R>                  S\R6                  SS4S jr \RB                  \RD                  " \RF                  RH                  \RF                  RJ                  \RF                  RL                  5       " S S\RN                  5      5       5       r(g)|Performs a point in time restore for a Cloud SQL instance managed by Google Cloud Backup and Disaster Recovery (DR) Service.    )absolute_import)division)unicode_literals)api_util)
operations)validate)arg_parsers)base)parser_extensions)	constants)flags)	instances)log)
properties)	resources)sqladmin_v1beta4_messagesz
    *{command}* performs a point in time restore for a Cloud SQL instance
    managed by Google Cloud Backup and Disaster Recovery (DR) Service.

    z    To perform a point in time restore from an earlier point in time:

      $ {command} datasource target-instance '2012-11-15T16:19:00.094Z'

    )DESCRIPTIONEXAMPLESargsclientreturnc                     [         R                  " U R                  5        UR                  R	                  U R                  S[
        R                  R                  R                  R                  0SS9$ )z4Get validated ref to destination instance from args.projectzsql.instances)params
collection)
r	   ValidateInstanceNametargetresource_parserParser   VALUEScorer   	GetOrFail)r   r   s     2lib/surface/sql/instances/point_in_time_restore.py_GetInstanceRefFromArgsr%   8   s^    
 ,				%	%
kk**//77AAB  
& 
     requestNc                    U R                   nUR                  (       a  UR                  /UR                  SS& UR                  (       a  UR                  Ul        UR
                  (       a  UR
                  Ul        UR                  (       a  UR                  Ul        UR                  (       a  UR                  Ul
        gg)z"Update request with clone options.N)pointInTimeRestoreContextrestore_database_namesdatabaseNamesprivate_networkprivateNetworkpreferred_zonepreferredZonepreferred_secondary_zonepreferredSecondaryZoneallocated_ip_range_nameallocatedIpRange)r'   r   pitr_contexts      r$   _UpdateRequestFromArgsr5   E   s    
 22,	  %)%@%@$ALq!	"&"6"6L	!%!4!4L	""*.*G*GL'	!!$($@$@L! "r&   c                   n    \ rS rSrSr\r\S\R                  SS4S j5       r
S\R                  4S jrS	rg)
PointInTimeRestore[   r   parserr   Nc                    [         R                  R                  U 5        U R                  R	                  [
        R                  " 5       5        U R                  SSS9  U R                  SSS9  U R                  S[        R                  R                  SS9  U R                  S	S
SS9  U R                  SS
SS9  U R                  SS
SS9  U R                  SS
SS9  U R                  SS
SS9  [
        R                  " U SS9  g)zArgs is called by calliope to gather arguments for this command.

Args:
  parser: An argparse parser that you can use it to add arguments that go on
    the command line after this command. Positional arguments are allowed.

datasourcez        The Google Cloud Backup and Disaster Recovery (DR) Service Datasource URI,
        of the form projects/{project}/locations/{region}/backupVaults/
        {backupvault}/dataSources/{datasource}.
        )helpr   z-Cloud SQL instance ID of the target instance.point_in_timez        The point in time in which to restore the instance to. Uses  RFC 3339
        format in UTC timezone. For example, '2012-11-15T16:19:00.094Z'.
        )typer<   z--private-networkFz        The resource link for the VPC network from which the Cloud SQL instance is
        accessible for private IP. For example,
        '/projects/myProject/global/networks/default'.
        )requiredr<   z--allocated-ip-range-namea2          The name of the IP range allocated for the target instance with
        private network connectivity. For example:
        'google-managed-services-default'. If set, the target instance
        IP is created in the allocated range represented by this name.
        Reserved for future use.
        z--preferred-zonez        The preferred zone for the target instance. If you specify a value for
        this flag, then the target instance uses the value as the primary
        zone.
        z--preferred-secondary-zonea          The preferred secondary zone for the cloned regional instance. If you
        specify a value for this flag, then the target instance uses the value
        as the secondary zone. The secondary zone can't be the same as the
        primary zone.
        z--restore-database-namesz      The name of the databases to be restored for a point-in-time restore. If
      set, the destination instance will only restore the specified databases.
      T)r9   for_pitrN)r   
ASYNC_FLAGAddToParserdisplay_info	AddFormatr   GetInstanceListFormatadd_argumentr
   Datetimer    AddSourceInstanceOverrideArgs)r9   s    r$   ArgsPointInTimeRestore.Argsd   sG    	OO'
!!%"="="?@
   <   !!''      #  
    $  	 "
   
''vEr&   r   c           
         [         R                  " [         R                  5      nUR                  nUR                  n[        USS5      nU Vs/ s H  nU[        R                  ;   d  M  UPM     nnUR                  S[        R                  R                  R                  R                  5        3UR                  UR                  UR                   UR"                  R%                  S5      S9S9n['        X5        [)        X5      n	U(       a/  [*        R,                  R/                  XAU	S9n
U
UR0                  l        UR4                  R7                  U5      nUR8                  R;                  SUR<                  U	R                  S	9nUR>                  (       aZ  URA                  S
5      (       d  SUl!        URD                  RG                  URI                  UR                  URJ                  S95      $ [D        RL                  RO                  X<S5        [P        RR                  " U	5        UR4                  RG                  URU                  U	R                  U	RV                  S95      nSUl,        U$ s  snf )a}  Performs a point in time restore for a Cloud SQL instance.

The instance is managed by Google Cloud Backup and Disaster Recovery
(DR) Service.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  A dict object representing if the point-in-time restore operation was
  successful.

Raises:
  ArgumentError: The arguments are invalid.
_specified_argsNz	projects/z%Y-%m-%dT%H:%M:%S.%fZ)r;   targetInstancepointInTime)parentr)   )instance_refzsql.operations)	operationr   formatdefault)r   rQ   z Performing point-in-time restore)r   instance)-r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesgetattrr   TARGET_INSTANCE_OVERRIDE_FLAGS%SqlInstancesPointInTimeRestoreRequestr   r!   r"   r   r#   PointInTimeRestoreContextr;   r   r=   strftimer5   r%   command_utilInstancesV1Beta4ConstructCreateInstanceFromArgsr)   targetInstanceSettingsr   r7   r   Createnameasync_IsSpecifiedrR   r   GetSqlOperationsGetRequestrQ   OperationsV1Beta4WaitForOperationr   CreatedResourceSqlInstancesGetRequestrT   kind)selfr   r   rW   rX   specified_args_dictkey	overridesr'   destination_instance_refinstance_resourceresponseoperation_refresources                 r$   RunPointInTimeRestore.Run   sW   "  < <=F""J&&L!$(94@ '&C)::: 	&   @@:,,1199CCEFG"."H"H;;**334KL #I #
 A G 7)6tD 

'
'
G
G/G H    ''> ##66w?H**11--(00 2 M {{h''""&&

.
.#++}7N7N /     11#E 01##''++,44-66 	, 	
H HMO{s   I.*I. )__name__
__module____qualname____firstlineno____doc__DETAILED_HELPdetailed_helpstaticmethodr   	NamespacerI   rv   __static_attributes__rx   r&   r$   r7   r7   [   sR    
 E-LF$.. LF4 LF LF\S'11 Sr&   r7   ))r}   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   r	   googlecloudsdk.callioper
   r   r   googlecloudsdk.command_lib.sqlr   r   r   r^   googlecloudsdk.corer   r   r   6googlecloudsdk.generated_clients.apis.sqladmin.v1beta4r   r   EXAMPLES_GAr~   r   rU   Resourcer%   r[   r5   DefaultUniverseOnlyReleaseTracksReleaseTrackBETAALPHAGACommandr7   rx   r&   r$   <module>r      s   C &  ' / 1 / / ( 5 4 0 D # * ) \ 


%
%
/7/A/A

A&LLA

%
%A 
A, D--33T5F5F5I5Ig g gr&   