
    }                     R   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ej0                   ej2                  ej4                  j6                         G d dej8                                      Zy)9Performs a storage size decrease of a Cloud SQL instance.    )absolute_import)division)unicode_literals)
exceptions)api_util)	constants)
operations)validate)base)flags)
properties)
console_ioNc                   &    e Zd ZdZed        Zd Zy)PerformStorageShrinkr   c                     t         j                  j                  |        | j                  dt        j
                  d       t	        j                  |        y)zArgs is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use to add arguments that go
          on the command line after this command. Positional arguments are
          allowed.
    instancezCloud SQL instance ID.)	completerhelpN)r   
ASYNC_FLAGAddToParseradd_argumentr   InstanceCompleterAddStorageSizeForStorageShrink)parsers    3lib/surface/sql/instances/perform_storage_shrink.pyArgszPerformStorageShrink.Args)   sH     	OO'
))%  ' 
((0    c           
         t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }t        j                   d      sy	 |j#                  |j                  |j                  |j%                  t'        |j(                  t*        j,                  z                    }|j.                  j1                  |      }|j                  j3                  d|j4                  |j                  	      }|j6                  r/|j                  |j                  |j4                  |j8                  d
S t:        j<                  j?                  ||dd       |j@                  jC                  |jE                  |j                  |j                              }	|j                  |j                  |	jF                  jH                  dS # tJ        jL                  $ r}}
|
jN                  tP        jR                  jT                  jV                  k(  r2tY        jZ                  dj]                  |j_                                     ta        jb                  |
      d}
~
ww xY w)a~  Performs a storage size decrease of a Cloud SQL instance.

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

    Returns:
      A dict object representing the operations resource describing the perform
      storage shrink operation if the decrease was successful.

    Raises:
      HttpException: A http error response was received while executing api
          request.
      ResourceNotFoundError: The SQL instance wasn't found.
      RequiredArgumentException: A required argument was not supplied by the
      user, such as omitting --root-password on a SQL Server instance.
    projectzsql.instances)params
collectionzConfirm that you have already run `gcloud alpha sql instances get-storage-shrink-config $instance_name` and understand that this operation will restart your database and might take a long time to complete (y/n)N)targetSizeGb)r   r    performDiskShrinkContextzsql.operations)	operationr    )NameProjectOperationIdStatusz;Performing a storage size decrease on a Cloud SQL instance.i)r    r   )r&   r'   StorageSizeGbzFThere's no instance found at {} or you're not authorized to access it.)2r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserParser   VALUEScorer    	GetOrFailr   PromptContinue,SqlProjectsInstancesPerformDiskShrinkRequestPerformDiskShrinkContextintstorage_sizer	   BYTES_TO_GBprojects_instancesPerformDiskShrinkCreatenameasync_statusr
   OperationsV1Beta4WaitForOperation	instancesGetSqlInstancesGetRequestsettingsdataDiskSizeGbapitools_exceptions	HttpErrorstatus_codesixmoveshttp_client	FORBIDDENr   ResourceNotFoundErrorformatRelativeNamecalliope_exceptionsHttpException)selfargsclientr-   r.   instance_refrequestresult_operationoperation_refchanged_instance_resourceerrors              r   RunzPerformStorageShrink.Run9   s   $  < <=F""J&&L!!$--0))//:,,1199CCD" 0 L $$	 +5II((&&#/#H#Ht0093H3HHI $I $ J g $66HH
 ,,33
$))&& 4 (m
 
$--,:N:N/44*113 	3 ""33


G
	 #-"6"6":":

-
-"**\5J5J . L#M
 ''!))4==LL 
 (( 5			cii33==	=.. 9 9 ;<> 	>  --e445s!   C#H< ,BH< <KA8KKN)__name__
__module____qualname____doc__staticmethodr   r]    r   r   r   r   $   s      B1 1P5r   r   )ra   
__future__r   r   r   apitools.base.pyr   rH   googlecloudsdk.api_lib.sqlr   r	   r
   r   googlecloudsdk.callioper   rR   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   googlecloudsdk.core.consoler   six.moves.http_clientrK   HiddenReleaseTracksReleaseTrackALPHACommandr   rc   r   r   <module>rq      s    @ &  ' > / 0 1 1 / ( E 0 * 2  D%%++,c54<< c5 - c5r   