
    r                     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 zones.    )absolute_import)division)unicode_literals)request_helper)utils)
exceptions)
console_ioc                   "    e Zd ZdZd Zd Zd Zy)ZoneResourceFetcherz5A (small) collection of utils for working with zones.c                     |j                   | _        |j                  | _        |j                   j                  | _        |j                  | _        y)a  Instantiate ZoneResourceFetcher and embed all required data into it.

    ZoneResourceFetcher is a class depending on "base_classes"
    class layout (properties side-derived from one of base_class class). This
    function can be used to avoid unfeasible inheritance and use composition
    instead when refactoring away from base_classes into stateless style.

    This constructor embeds following properties into ZoneResourceFetcher
    instance:
     - compute
     - messages
     - http
     - batch_url

    Example:
      compute_holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
      client = compute_holder.client

      zone_resource_fetcher = ZoneResourceFetcher(client)
        or
      zone_resource_fetcher = ZoneResourceFetcher(self.compute_client)
        to use in a class derived from some of base_classes

      zone_resource_fetcher.WarnForZonalCreation(...)

    Args:
      compute_client: compute_holder.client
    N)apitools_client_computemessages	_messageshttp_http	batch_url
_batch_url)selfcompute_clients     0lib/googlecloudsdk/api_lib/compute/zone_utils.py__init__zZoneResourceFetcher.__init__   s>    : #22DM#,,DN//44DJ$..DO    c           	         g }g }t               }|D ]  }|j                  |vs|j                  |j                         |j                  | j                  j
                  d| j                  j                  |j                  |j                        f        t        t        j                  || j                  | j                  |            }|ry|S )zFetches zone resources.Get)projectzone)requestsr   r   errorsN)setr   addappendr   zonesr   ComputeZonesGetRequestr   listr   MakeRequestsr   r   )r   resource_refsr   r   
zone_namesresource_refress          r   GetZoneszZoneResourceFetcher.GetZones@   s    FHJ%			*	,|(()MMNN11$,,!&& 2 () 	* & ~**ZZ//	 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)z2Warns the user if a zone has upcoming deprecation.N   )zzone isz	this zonethe)z	zones arezthese zones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zones_with_deprecatedr   phrasestitleprintable_deprecated_zonesfinal_messages
             r   WarnForZonalCreationz(ZoneResourceFetcher.WarnForZonalCreationZ   sH   MM-(EG	$$T*  !g	"	#q	(17% &,VGAJ
GAJ%O  $& '$??""
$
+
+[,@,@AEBI'-K L %
+
+GNN499,E
F ( nnU((0JKLHHW%M$$];##$?@@ <r   N)__name__
__module____qualname____doc__r   r+   rB    r   r   r   r      s    = /D4%Ar   r   N)rF   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   "googlecloudsdk.command_lib.computer   googlecloudsdk.core.consoler	   objectr   rG   r   r   <module>rM      s/    . &  ' 9 0 9 2dA& dAr   