
    
                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
  ej                  dd	d
g      Zd Zd Zd Zy)z5Utilities for edge-cloud container location commands.    )absolute_import)division)unicode_literalsN)encoding)
exceptionsEdgeContainerZonenameregionc                 V    ~ ~t        j                  dd|j                        |_        |S )zGReplaces the request.name 'locations/{zone}' with 'locations/{region}'.zF(projects/[-a-z0-9]+/locations/[a-z]+-[a-z]+[0-9])[-a-z0-9]*((?:/.*)?)z\1\2)resubr	   )refargsrequests      @lib/googlecloudsdk/command_lib/edge_cloud/container/locations.pyReplaceResourceZoneWithRegionr      s*    	4Ow||', 
.    c              #      K   | D ]^  }|j                   st        j                  |j                         }|j                  dg       D ]  }t	        ||j
                          ` yw)z.Returns the zones from a ListLocationResponse.availableZones)r	   r
   N)metadatar   MessageToDictget_Zone
locationId)response_r
   r   zones        r   ExtractZonesFromLocationsr   '   sW     f??%%foo6H-r2tF$5$566 3 s   A%A'c                    t        j                  | j                        }|j                  j	                  d      d   }|j                  di       j                         D ]  \  }}||k(  sd|v ru|j                  d      }g }|j                         D ]J  \  }}	|	dk(  r|j                  |dz           |	dk(  r|j                  |dz          :|j                  |       L ||d	<   |c S  t        j                  d
j                  |            )z?Returns the argument-specified zone from a GetLocationResponse./r   	rackTypesBASEz (BASE)	EXPANSIONz (EXPANSION)rackszZone not found: {})r   r   r   r   splitr   itemspopappendr   Errorformat)
r   r   r   	want_zone	zone_namer   r%   populated_rackrack	rack_types
             r   ExtractZoneFromLocationr1   2   s   ##H$5$56(iiooc"2&)!&6;AACoiI		%${{}OD) & !!$"23 K'!!$"78 !!$'  - 'Wk' D( 	-44Y?@@r   )__doc__
__future__r   r   r   collectionsr   apitools.base.pyr   googlecloudsdk.corer   
namedtupler   r   r   r1    r   r   <module>r9      sI    < &  '  	 % *2VX4FG7Ar   