
    "%                     ~    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ZdZd	Zd
ZdZdZd Zd Z G d de      Zy)z,Utilities for Package Rollouts Releases API.    )
exceptions)
list_pager)util)variants)waiterpageSizez'configdelivery-variant-storage-strategynestedz.configdelivery-skip-creating-variant-resourcestruez:configdelivery.projects.locations.resourceBundles.releasesc                     d|  d| d| S )N	projects//locations//resourceBundles/ )projectlocationparent_bundles      ?lib/googlecloudsdk/api_lib/container/fleet/packages/releases.py_ParentPathr   !   s    '+hZ/@P    c                 B    |j                  dd      }d|  d| d| d| S )N.-r   r   r   z
/releases/)replace)r   r   resource_bundlereleasenames        r   _FullyQualifiedPathr   '   s6    	c	"$WI[
2COCTT^_c^d	eer   c                   P    e Zd ZdZd
dZd ZddZ	 	 	 ddZddZd Z		 	 	 dd	Z
y)ReleasesClientz<Client for Releases in Config Delivery Package Rollouts API.Nc                 n   |xs t         j                  | _        |xs t        j                  | j                        | _        |xs t        j
                  | j                        | _        | j                  j                  | _        t        j                  | j                  j                  d       | _        y )Nc                     | j                   S )Nr   )xs    r   <lambda>z)ReleasesClient.__init__.<locals>.<lambda>6   s    r   )operation_serviceget_name_func)r   DEFAULT_API_VERSION_api_versionGetClientInstanceclientGetMessagesModulemessages+projects_locations_resourceBundles_releases_servicer   CloudOperationPollerNoResourcesprojects_locations_operationsrelease_waiter)selfapi_versionr*   r,   s       r   __init__zReleasesClient.__init__/   s    #?t'?'?DED2243D3DEDKC 6 6t{{ CDMKKKKDM @@++CC&Dr   c                     |r=|j                         dk(  r*| j                  j                  j                  j                  S | j                  j                  j                  j
                  S )z1Converts input-format lifecycle to internal enum.DRAFT)upperr,   ReleaseLifecycleValueValuesEnumr6   	PUBLISHED)r2   lifecycle_strs     r   GetLifecycleEnumzReleasesClient.GetLifecycleEnum9   sM    ,,.'9]]"";;AAA]]"";;EEEr   c                     | j                   j                  t        |||            }t        j                  | j
                  |d||t              S )a  List Releases of a ResourceBundle.

    Args:
      project: GCP project id.
      location: Valid GCP location (e.g. us-central1).
      parent_bundle: Name of parent ResourceBundle.
      limit: int or None, the total number of results to return.
      page_size: int, the number of entries in each batch (affects requests
        made, but not the yielded results).

    Returns:
      Generator of matching devices.
    )parentreleases)field
batch_sizelimitbatch_size_attribute)r,   AConfigdeliveryProjectsLocationsResourceBundlesReleasesListRequestr   r   YieldFromListr.   "_LIST_REQUEST_BATCH_SIZE_ATTRIBUTE)r2   r   r   r   rB   	page_sizelist_requests          r   ListzReleasesClient.List@   sU     ==bb7Hm< c L ##? r   c           	      N   t        ||||      }|s|t        d      | j                  j                  j	                  | j                  j                  j                  j                  t        t              g      }	|rR|	j                  j                  | j                  j                  j                  j                  t        t                     | j                  j                  ||	| j                  d      |      }
| j                  j                  t        |||      |
|j                  dd      	      }t!        j"                  | j$                  | j&                  j)                  |      d
|       }|j+                         D ]L  \  }}t-        j.                  | j0                        }	 |j)                  ||j                  dd      ||||       N | j;                  |||||	|      S # t2        j4                  $ r'}dt7        |      j9                         v rn Y d}~d}~ww xY w)a  Create Release for a ResourceBundle.

    Args:
      resource_bundle: Name of parent ResourceBundle.
      version: Version of the Release.
      project: GCP Project ID.
      location: Valid GCP location (e.g., uc-central1)
      lifecycle: Lifecycle of the Release.
      variants: Variants of the Release.
      skip_creating_variant_resources: Whether to use the crane upload strategy
        to upload variant images.

    Returns:
      Created Release resource.
    NzNo variants found in source directory. Please check the source directory and variants pattern, or create the release with --lifecycle=DRAFT.)keyvalue)additionalPropertiesr6   r   labels	lifecycleversionr   r   )r>   r   	releaseIdzCreating Release )r   r   r   r   r   variant_resourcesalready_exists)r   r   r   r   rO   rP   )r   
ValueErrorr,   r8   LabelsValueAdditionalProperty#_VARIANT_STORAGE_STRATEGY_LABEL_KEY,_VARIANT_STORAGE_STRATEGY_LABEL_VALUE_NESTEDrM   append*_SKIP_CREATING_VARIANT_RESOURCES_LABEL_KEY,_SKIP_CREATING_VARIANT_RESOURCES_LABEL_VALUEr<   CConfigdeliveryProjectsLocationsResourceBundlesReleasesCreateRequestr   r   r   WaitForr1   r.   Createitemsvariants_apisVariantsClientr(   apitools_exceptionsHttpConflictErrorstrlowerUpdate)r2   r   rQ   r   r   rP   r   skip_creating_variant_resourcesfully_qualified_pathrO   r   create_request_variantrS   variants_clientes                    r   r_   zReleasesClient.CreateZ   s-   2 /?G 	)  
 ]]""..MM!!--@@7B A 
 / F '!!((
--


+
+
>
><@ ?  mm##!''0	 $ G ]]ff7Ho>//#s+ g N
 	^,
012	A
 '/nn&6""%44T5F5FGo+OOC-/ 	 	
 '7$ ;;'    !22 s1v||~-
  s   *'G**H$=HH$c                     t        ||||      }| j                  j                  ||      }t        j                  | j
                  | j                  j                  |      d|       S )a+  Delete a Release resource.

    Args:
      project: GCP project ID.
      location: GCP location of Release.
      resource_bundle: Name of ResourceBundle.
      release: Name of Release.
      force: Whether to force deletion of any child variants.

    Returns:
      Empty Response Message.
    )r   forcezDeleting Release )r   r,   CConfigdeliveryProjectsLocationsResourceBundlesReleasesDeleteRequestr   r^   r1   r.   Delete)r2   r   r   r   r   rp   ri   
delete_reqs           r   rr   zReleasesClient.Delete   sw     /	 bb! c J >>Z(
012 r   c                     t        ||||      }| j                  j                  |      }| j                  j	                  |      S )zDescribe a Release resource.

    Args:
      project: GCP project ID.
      location: GCP location of Release.
      resource_bundle: Name of ResourceBundle.
      release: Name of Release.

    Returns:
      Requested Release resource.
    r"   )r   r,   @ConfigdeliveryProjectsLocationsResourceBundlesReleasesGetRequestr.   Get)r2   r   r   r   r   ri   describe_reqs          r   DescribezReleasesClient.Describe   sN     /?G ==aa! b L ==\**r   c                 0   t        ||||      }| j                  j                  ||| j                  |      |      }| j                  j	                  |||      }	t        j                  | j                  | j                  j                  |	      d|       S )a  Update Release for a ResourceBundle.

    Args:
      release: Name of Release (e.g., v1).
      project: GCP project ID.
      location: GCP location of Release.
      resource_bundle: Name of parent ResourceBundle.
      labels: Labels of the Release.
      lifecycle: Lifecycle of the Release.
      update_mask: Fields to be updated.

    Returns:
      Updated Release resource.
    rN   )r   r   
updateMaskzUpdating Release )
r   r,   r8   r<   BConfigdeliveryProjectsLocationsResourceBundlesReleasesPatchRequestr   r^   r1   r.   Patch)
r2   r   r   r   r   rO   rP   update_maskri   update_requests
             r   rg   zReleasesClient.Update   s    0 /?G mm##!''	2	 $ G ]]ee!7{ f N >>N+
012 r   )NN)Nd   )NNF)F)NNN)__name__
__module____qualname____doc__r4   r<   rI   r_   rr   rx   rg   r   r   r   r   r   ,   sB    DF@ &+^@:+4 (r   r   N)r   apitools.base.pyr   rc   r   /googlecloudsdk.api_lib.container.fleet.packagesr   r   ra   googlecloudsdk.api_lib.utilr   rF   rX   rY   r[   r\   RELEASE_COLLECTIONr   r   objectr   r   r   r   <module>r      sY    3 > ' @ U .%/ "&O #/7 ,-] */5 , R f
gV gr   