
                         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  G d	 d
e      Zy)z)Common classes and functions for regions.    )absolute_import)division)unicode_literals)request_helper)utils)
exceptions)
console_ioc                   "    e Zd ZdZd Zd Zd Zy)RegionResourceFetcherz&Helper class for working with regions.c                     |j                   | _        |j                  | _        | j                  j                  | _        |j                  | _        y )N)apitools_clientcomputemessageshttp	batch_url)selfclients     3lib/googlecloudsdk/api_lib/compute/regions/utils.py__init__zRegionResourceFetcher.__init__   s8    ))DLOODM!!DI%%DN    c           	         g }g }t               }|D ]  }|j                  |j                  f|vs|j                  |j                  |j                  f       |j	                  | j
                  j                  d| j                  j                  |j                  |j                        f        |r7t        t        j                  || j                  | j                  |            }ny|ry|S )zFetches region resources.Get)projectregion)requestsr   r   errorsN)setr   r   addappendr   regionsr   ComputeRegionsGetRequestlistr   MakeRequestsr   r   )r   resource_refsr   r   region_namesresource_refress          r   
GetRegionsz RegionResourceFetcher.GetRegions$   s     FH5L%


 3 3	4L	H,..0C0CDELL  MM22$,,#** 3 ,- 	. & ,,yyNN	 c jr   c                    | j                  |      }|syg }g }|D ]   }|j                  s|j                  |       " |sy|rg }t        |      dk(  rd}nd}dj	                  |d   |d   |d         }g }|D ]  }|j                  j
                  r@|j                  dj	                  |j                  |j                  j
                               Y|j                  d	j	                  |j                                |j                  t        j                  ||             d
j                  |      }	t        j                  |	      st        j                  d      y)z4Warns the user if a region has upcoming deprecation.N   )z	region iszthis regionthe)zregions arezthese regionstheirzn
WARNING: The following selected {0} deprecated. All resources in {1} will be deleted after {2} turndown date.r      z	[{0}] {1}z[{0}] )messagezCreation aborted by user.)r(   
deprecatedr   lenformatdeletednamer   ConstructListjoinr	   PromptContinuer   AbortedError)
r   r$   r    promptsregions_with_deprecatedr   phrasestitleprintable_deprecated_regionsfinal_messages
             r   WarnForRegionalCreationz-RegionResourceFetcher.WarnForRegionalCreationA   sM   oom,GG 			&&v.  #g	$	%	*5;% &,VGAJ
GAJ%O  &("+&$$
&
-
-{.B.Bkk6,,44/6 7 '
-
-gnnV[[.I
J , nnU((0LMNHHW%M$$];##$?@@ <r   N)__name__
__module____qualname____doc__r   r(   r?    r   r   r   r      s    .&:$Ar   r   N)rC   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   "googlecloudsdk.command_lib.computer   googlecloudsdk.core.consoler	   objectr   rD   r   r   <module>rJ      s/    0 &  ' 9 0 9 2JAF JAr   