
    W                      Z   S r SSK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  \R&                  " S5      r\R&                  " S5      r\R&                  " S5      rS rS rS r\R4                   " S S\R6                  5      5       rg)z+Implementation of buckets relocate command.    N)api_factory)errors)arg_parsers)base)errors_util)flags)operations_util)storage_url)log)
console_ioa5  
1. This move will involve write downtime.
2. In-flight resumable uploads not finished before the write downtime will be lost.
3. Bucket tags added to the bucket will result in the relocation being canceled.
4. Please ensure that you have sufficient quota in the destination before performing the relocation.
z
1. This is a policy change move (no write downtime).
2. Please ensure that you have sufficient quota in the destination before performing the relocation.
zl
1. Any ongoing, in-flight resumable uploads will be canceled and lost.
2. Write downtime will be incurred.
c                      U R                  UR                  5      $ ! [        R                   a  n[        R
                  " U5      UeSnAff = f)z=Fetches the bucket resource for the given bucket storage URL.N)
get_bucketbucket_name
api_errorsCloudApiErrorcommand_errors
FatalError)
gcs_client
bucket_urles      'lib/surface/storage/buckets/relocate.py_get_bucket_resourcer   6   sG    .  !7!788		!	! .

#
#A
&A-.s    AAAc                 (   UR                   (       a  gU R                   nU R                  (       a  USU R                   3-  nU R                  R                  5       UR                  R                  5       :X  a  [        nO[
        n[        R                  " SUR                   SU S35        [        R                  " U5        [        R                  " SUR                   S3SS	9  [        R                  R                  S
UR                   S35        g)z*Prompt the user to confirm the relocation.N zThe bucket z is in .zWPlease acknowledge that you've read the above warnings and want to relocate the bucket ?Tprompt_stringcancel_on_nozStarting bucket relocation for z...
)dry_runlocationdata_locationscasefold1_BUCKET_RELOCATION_WITHOUT_WRITE_DOWNTIME_WARNING*_BUCKET_RELCOCATION_WRITE_DOWNTIME_WARNINGr   warningurlr   PromptContinuestatusPrint)bucket_resourceargssource_locationwarning_messages       r   &_prompt_user_to_confirm_the_relocationr/   >   s    	\\
&//0/##?99:;;O&&(DMM,B,B,DDGO@O++DHH:W_,=Q?@++o""&((1.  **4TXXJeDE    c                 j    [         R                  " [        5        [        R                  " SU  S3SS9  g)z4Prompt the user to confirm advancing the relocation.z?This will start the write downtime for your relocation of gs://z$, are you sure you want to continue?Tr   N)r   r&   $_ADVANCING_BUCKET_RELOCATION_WARNINGr   r(   )r   s    r   0_prompt_user_to_confirm_advancing_the_relocationr3   Z   s2    ++23
KM=? r0   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
Relocateg   z-Relocates bucket between different locations.z=
      Relocates a bucket between different locations.
      a<  
      To move a bucket (``gs://my-bucket'') to the ``us-central1'' location, use
      the following command:

          $ {command} gs://my-bucket --location=us-central1

      To move a bucket to a custom dual-region, use the following command:

          $ {command} gs://my-bucket --location=us
              --placement=us-central1,us-east1

      To validate the operation without actually moving the bucket, use the
      following command:

          $ {command} gs://my-bucket --location=us-central1 --dry-run

      To schedule a write lock for the move, with ttl for reverting the write
      lock after 7h, if the relocation has not succeeded, use the following
      command:

          $ {command}
              --operation=projects/_/buckets/my-bucket/operations/C894F35J
              --finalize --ttl=7h
      )DESCRIPTIONEXAMPLESc                    UR                  S5        UR                  SS9nUR                  S5      nUR                  S5        UR                  S[        SS9  UR                  S[        SS	S
9  [
        R                  " U5        UR                  SSSS9  UR                  S5      nUR                  S5        UR                  S[        SSS
9  UR                  SSSSS9  UR                  S[        R                  " 5       SS9  g )NFT)requiredz7Arguments for initiating the bucket relocate operation.r'   z"The URL of the bucket to relocate.)typehelpz
--locationzThe final [location](https://cloud.google.com/storage/docs/locations) where the bucket will be relocated to. If no location is provided, Cloud Storage will use the default location, which is us.)r;   r:   r<   z	--dry-run
store_truezPrints the operations that the relocate command would perform without actually performing relocation. This is helpful to identify any issues that need to be detected asynchronously.)actionr<   z1Arguments for advancing the relocation operation.z--operationzSpecify the relocation operation name to advance the relocation operation.The relocation operation name must include the Cloud Storage bucket and operation ID.z
--finalizea  Schedules the write lock to occur. Once activated, no further writes will be allowed to the associated bucket. This helps minimize disruption to bucket usage. For certain types of moves(between Multi Region and Custom Dual Regions), finalize is not required.)r>   r:   r<   z--ttlzKTime to live for the relocation operation. Defaults to 12h if not provided.)	SetSortArgsadd_mutually_exclusive_group	add_groupadd_argumentstrr   add_placement_flagr   Duration)clsparserrelocate_arguments_groupbucket_relocate_group advance_relocate_operation_groups        r   ArgsRelocate.Args   sT   
u%BB  C   5>>A %%e,&&1 ' 
 &&C ' 
 
23&&L	 '  (@'I'I;($ %007$110 2 	 %11 2  %11!!#	 2 r0   c                    [         R                  " [        R                  R                  5      nUR
                  (       a  [        R                  " UR
                  5      n[        R                  " UR                  U5        [        X#5      n[        XA5        UR                  UR                  UR                  UR                  UR                   5      $ ["        R$                  " UR&                  5      u  pV[)        U5        UR+                  XVUR,                  5        [.        R0                  R3                  SU SU S35        g )Nz3Sent request to advance relocation for bucket gs://z with operation r   )r   get_apir
   ProviderPrefixGCSr'   storage_url_from_stringr   raise_error_if_not_gcs_bucketcommand_pathr   r/   relocate_bucketr   r!   	placementr    r	   %get_operation_bucket_and_id_from_name	operationr3   advance_relocate_bucketttlr   r)   r*   )selfr,   r   r'   r+   bucketoperation_ids          r   RunRelocate.Run   s    $$[%?%?%C%CDJxx//9c//0A0A3G,Z=o,_C''
//
--
..
,,	  	==dnnM F 5V<&&vTXXFJJ
=fX F"^1	&r0    N)
__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodrK   r]   __static_attributes__r_   r0   r   r5   r5   g   s2    5

	-< E ENr0   r5   )rd   textwrapgooglecloudsdk.api_lib.storager   r   r   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.storager   r   r   r	   r
   googlecloudsdk.corer   googlecloudsdk.core.consoler   dedentr%   r$   r2   r   r/   r3   DefaultUniverseOnlyCommandr5   r_   r0   r   <module>rq      s     2  6 ? / ( G : 4 > : # 2 .6__ > . * 5=OO E 5 1 (0 8 ( $.F8	 Bt|| B Br0   