
                             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dlmZ ddlmZ ddlmZ ddlZd Zd Zy)zACommon utility functions for sql reschedule-maintenance commands.    )absolute_import)division)unicode_literals)
exceptions)tz)
operations)validate)log)
properties)resource_lex)resource_property)timesNc                 n    |r3| j                   j                  j                  |j                               S y )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           
         |j                   }|j                  }t        || j                        }| j                  }t        j                  | j                         |j                  j                  | j                  dt        j                  j                  j                  j                  id      }||j                  j                   j"                  k(  r|t%        j&                  d      	 |j(                  j+                  |j-                  |j                  |j                              }|jH                  t%        jJ                  d      |jH                  jL                  st%        jJ                  d      ||j                  j                   j"                  k(  rX	 tO        jP                  |jH                  jR                  tU        jV                               }
||
k  rt%        j&                  d      |BtO        jZ                  |tN        j\                        j_                         ja                  dd      nd}|jc                  |j                  |j                  |je                  |j                  ||                  }|jf                  ji                  |      }|j                  jk                  d|jl                  |j                        }tn        jp                  js                  ||d       t2        jt                  jw                  d       y# t.        j0                  $ r}t3        j4                  dt7        j8                  |             t;        j<                  |      }	t?        j*                  |	j@                  jB                  tE        jF                  d      d      d	k(  rt;        j<                  d
       d}~ww xY w# tX        $ r t%        jJ                  d      w xY w)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   (   *$$,'d6J6J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
 z!((
LN N *5 ((UYY  )	GG
C-;? 
 $0#`#`$$""3?33!,,,( - * 4 +	 $a $,   22HH$& ((// %%"" 0 $-
 //
M0KM **/0 
	&	& 
IIl ;<

"
"5
)CS[[00)223KL!#&56 $$  

8  =,,
;= ==s&   +A L =N? N<"BN77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   