
                             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rS rS rg)zACommon utility functions for sql reschedule-maintenance commands.    )absolute_import)division)unicode_literals)
exceptions)tz)
operations)validate)log)
properties)resource_lex)resource_property)timesNc                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g )N)
RescheduleRescheduleTypeValueValuesEnumlookup_by_nameupper)sql_messagesreschedule_types     Alib/googlecloudsdk/command_lib/sql/reschedule_maintenance_util.pyParseRescheduleTyper   #   s3    ""@@OO! !	    c                    UR                   nUR                  n[        X0R                  5      nU R                  n[
        R                  " U R                  5        UR                  R                  U R                  S[        R                  R                  R                  R                  0SS9nXCR                  R                   R"                  :X  a  Uc  [$        R&                  " S5      e UR(                  R+                  UR-                  UR                  UR                  S95      nURH                  c  [$        RJ                  " S5      eURH                  RL                  (       d  [$        RJ                  " S5      eXCR                  R                   R"                  :X  aX   [N        RP                  " URH                  RR                  [T        RV                  " 5       S9n
XZ:  a  [$        R&                  " S5      eUbC  [N        RZ                  " U[N        R\                  5      R_                  5       Ra                  SS5      OSnURc                  UR                  UR                  URe                  UR                  UUS9S9S9nURf                  Ri                  U5      nUR                  Rk                  SURl                  UR                  S9n[n        Rp                  Rs                  X-S5        [2        Rt                  Rw                  S5        g! [.        R0                   a  n[2        R4                  " S[6        R8                  " U5      5        [:        R<                  " U5      n	[>        R*                  " U	R@                  RB                  [D        RF                  " S5      S5      S	:X  a  [:        R<                  " S
5      ee SnAff = f! [X         a    [$        RJ                  " S5      ef = f)a  Reschedule maintenance for a Cloud SQL instance.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  client: SqlClient instance, with sql_client and sql_messages props, for use
    in generating messages and making API calls.

Returns:
  None

Raises:
  HttpException: An HTTP error response was received while executing API
      request.
  ArgumentError: The schedule_time argument was missing, in an invalid format,
      or not within the reschedule maintenance bounds.
  InvalidStateException: The Cloud SQL instance was not in an appropriate
      state for the requested command.
  ToolException: Any other error that occurred while executing the command.
projectzsql.instances)params
collectionNz>argument --schedule-time: Must be specified for SPECIFIC_TIME.)r   instancezoperation : %szerror.errors[0].reasonnotAuthorizedzJYou are either not authorized to access the instance or it does not exist.zCThis instance does not have any scheduled maintenance at this time.z.Cannot reschedule this instance's maintenance.)tzinfoz@argument --schedule-time: Must be after original scheduled time.z+00:00Z)rescheduleTypescheduleTime)
reschedule)r   r   ,sqlInstancesRescheduleMaintenanceRequestBodyzsql.operations)	operationr   zRescheduling maintenance.zMaintenance rescheduled.
)<
sql_clientr   r   r   schedule_timer	   ValidateInstanceNamer   resource_parserParser   VALUEScorer   	GetOrFailr   r   SPECIFIC_TIMEsql_exceptionsArgumentError	instancesGetSqlInstancesGetRequestapitools_exceptions	HttpErrorr
   debugsix	text_typer   HttpExceptionr   payloadcontentr   ParseKeyscheduledMaintenanceInvalidStateErrorcanRescheduler   ParseDateTime	startTimer   tzutc
ValueErrorLocalizeDateTimeUTC	isoformatreplace0SqlProjectsInstancesRescheduleMaintenanceRequest,SqlInstancesRescheduleMaintenanceRequestBodyprojects_instancesRescheduleMaintenanceCreatenamer   OperationsV1Beta4WaitForOperationstatuswrite)argsclientr&   r   r   r'   instance_refinstance_resourceerrorexc
start_timereschedule_maintenance_requestresult_operationoperation_refs                 r   RunRescheduleMaintenanceCommandr\   *   s   (   *$$,'6J6JK/$$- .''--
mm**//77AAB  . ",
 //MM[[[((
JL L
",,00++ ((<3H3H 	, 	JK" ++3

*
*MO O 
	/	/	=	=

*
*9; ; //MM[[[=&&

0
0
:
:288:Oj
 !((
LN N *5 ((UYY  )	GG
C-;? 
 $0#`#`$$""3?33!,,,( - * 4 +	 $a $,   22HH$& ((// %%"" 0 $-
 //
0KM **/0 
	&	& 
IIl ;<

"
"5
)CS[[00)223KL!#&56 $$  

8  =,,
;= ==s%   *=L <O  N=BN88N= !O!)__doc__
__future__r   r   r   apitools.base.pyr   r4   dateutilr   googlecloudsdk.api_lib.sqlr/   r   r	   googlecloudsdk.calliopegooglecloudsdk.corer
   r   googlecloudsdk.core.resourcer   r   googlecloudsdk.core.utilr   r7   r   r\    r   r   <module>rg      sC    H &  ' >  C 1 / . # * 5 : * 
j	r   