
    d                         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 ej                    G d dej"                               Zy)zGImplementation of create command for creating Anywhere Cache Instances.    )arg_parsers)base)errors_util)flags)plurality_checkable_iterator)progress_callbacks)storage_url)task_executor)task_graph_executor)task_status)create_anywhere_cache_taskc                   6    e Zd ZdZdddZed        Zd Zd Zy)	Createz-Create Anywhere Cache instances for a bucket.zv

      Create Anywhere Cache instances.
      Only one cache instance per zone can be created for each bucket.
      a  

      The following command creates an anywhere cache instance for bucket
      in ``asia-south2-b'' zone:

        $ {command} gs://my-bucket asia-south2-b

      The following command creates anywhere cache instances for bucket
      in ``asia-south2-b'', and ``asia-east1-a'' zone:

        $ {command} gs://my-bucket asia-south2-b asia-east1-a

      The following command creates an anywhere cache instance for bucket
      in ``asia-south2-b'' zone, with ttl for cache entry as 6 hours, and
      admission policy as ``ADMIT_ON_SECOND_MISS'':

        $ {command} gs://my-bucket asia-south2-b --ttl=6h --admission-policy='ADMIT_ON_SECOND_MISS'
      )DESCRIPTIONEXAMPLESc                     |j                  dt        d       |j                  dt        dd       |j                  dt        j                         d	       t	        j
                  |       y )
NurlzKSpecifies the URL of the bucket where the Anywhere Cache should be created.)typehelpzone+zUSpecifies the name of the zonal locations where the Anywhere Cache should be created.)r   nargsr   z--ttlz9Cache entry time-to-live. Default to 24h if not provided.)add_argumentstrr   Durationr   add_admission_policy_flag)clsparsers     5lib/surface/storage/buckets/anywhere_caches/create.pyArgszCreate.Args<   sz    
	   "   !!#H   
##F+    c              #     K   t        j                  |j                        }t        j                  |j
                  |       t        j                  |t        |j                               |j                  t        |j                        dz   |_
        |j                  D ]1  }t        j                  |||j                  |j                         3 y w)Ns)admission_policyttl)r	   storage_url_from_stringr   r   raise_error_if_not_gcs_bucketcommand_pathr   workload_estimator_callbacklenr   r%   r   r   CreateAnywhereCacheTaskr$   )selfargstask_status_queuer   r   s        r   get_task_iteratorzCreate.get_task_iteratorY   s     

-
-dhh
7C--d.?.?E223tyy> xxTXXs"dh		&>>
td&;&;  s   CCc           	      $   t         j                  j                         }| j                  ||      }t	        j
                  |      }t        j                  |d|t        j                  t        j                  j                  d             | _        y )NT)increment_typemanifest_path)parallelizabler.   progress_manager_args)r   multiprocessing_contextQueuer/   r   PluralityCheckableIteratorr
   execute_tasksr   ProgressManagerArgsIncrementTypeINTEGER	exit_code)r,   r-   r.   task_iterator!plurality_checkable_task_iterators        r   Runz
Create.Runi   sy    +CCIIK**41BCM$??N & #00)+)==&44<<D
	DNr!   N)	__name__
__module____qualname____doc__detailed_helpclassmethodr    r/   r?    r!   r   r   r      s4    5


-4 , ,8 r!   r   N)rC   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.storager   r   r   r   r	   (googlecloudsdk.command_lib.storage.tasksr
   r   r   @googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_cachesr   DefaultUniverseOnlyCreateCommandr   rF   r!   r   <module>rM      sV    N / ( : 4 K A : B H @ g WT W Wr!   