
                            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 dddZddZ e	j*                  e	j,                  j.                         G d de	j0                               Z e	j*                  e	j,                  j4                         G d de             Z e	j*                  e	j,                  j8                         G d de             Zy)z$Command for labels update to images.    )absolute_import)division)unicode_literals)base_classes)arg_parsers)base)flags)labels_util)
exceptions)logz6*{command}* updates labels for a Compute Engine image.a        To update labels ``k0'' and ``k1'' and remove labels with key ``k3'', run:

        $ {command} example-image --update-labels=k0=value1,k1=value2 --remove-labels=k3

        k0 and k1 will be added as new labels if not already present.

      Labels can be used to identify the image and to filter them like:

        $ {parent_command} list --filter='labels.k1:value2'

      To list only the labels when describing a resource, use --format:

        $ {parent_command} describe example-image --format="default(labels)"

    )DESCRIPTIONEXAMPLESc                    t        j                  d      |_        |j                  j                  |d       t	        j
                  |       |j                  dd       |j                  dd	       | j                  j                  }|j                  j                  g}t        |j                         D cg c]	  }||vs| c}      }|j                  d
|d       |r[|j                         }|j                  dt        j                         dt        j                   d       |j                  ddd       yyc c}w )z5Add arguments used for parsing in all command tracks.F)pluralupdate)operation_typez--descriptionz+An optional text description for the image.)helpz--familyzName of the image family to use. If an image family is specified when you create an instance or disk, the latest non-deprecated image in the family is used.z--architecturezSpecifies the architecture or processor type that this image can support. For available processor types on Compute Engine, see https://cloud.google.com/compute/docs/cpu-platforms.)choicesr   z--update-user-licensesLICENSEzList of user licenses to be updated on an image. These user licenses replace all existing user licenses. If this flag is not provided, all existing user licenses remain unchanged.)typemetavaractionr   z--clear-user-licenses
store_truez.Remove all existing user licenses on an image.)r   r   N)images_flagsMakeDiskImageArgDISK_IMAGE_ARGAddArgumentr
   AddUpdateLabelsFlagsadd_argumentImageArchitectureValueValuesEnumARCHITECTURE_UNSPECIFIEDnamesortednamesadd_mutually_exclusive_groupr   ArgListUpdateAction)	messagesclsparsersupport_user_licensesarchitecture_enum_typeexcluded_enumsearchitecture_choicesscopes	            $lib/surface/compute/images/update.py_CommonArgsr3   5   sX   #44EB#   A""6*9  < 	:   $>>EE*CCHHI.(..0L0QA^4Kq0LN" @	  	 //1E	   "''E  G 
=  ?  Ms   8	D?D?c                   H    e Zd ZdZdZeZed        Zd Z	ddZ
edd       Zy)	UpdateUpdate a Compute Engine image.Nc                 n    | j                  d      j                  j                  }t        || |d       y )NTno_httpFr,   _GetApiHolderclientr)   r3   r*   r+   r)   s      r2   ArgszUpdate.Argsi   s/       .55>>H#vUC    c                 (    | j                  |d      S )NFr:   _Run)selfargss     r2   Runz
Update.Runn   s    99T977r@   c                    t        j                  | j                               }|j                  }|j                  j                  }| j
                  j                  ||j                  t        j                  |            }g }d }t        j                  j                  |      }	|	j                         r|j                  j                  j                  j!                   |j"                  di |j%                               }
|	j'                  |j(                  j*                  |
j,                        }|j.                  ru|j1                  |j2                  |j4                  |j)                  |
j6                  |j,                              }|j9                  |j                  j                  d|f       d}|j;                         }|j=                  d      r|j>                  |_        d}|j=                  d      r|j@                  |_         d}|j=                  d	      r,|j:                  jC                  |jD                        |_"        d}|rN|j=                  d
      s|j=                  d      r,|j=                  d
      r|jF                  |_$        ng |_$        d}|rT|jK                  |j2                  ||jM                               }|j9                  |j                  j                  d|f       g }|jO                  ||      }|rtQ        jR                  |      |r.tT        jV                  jY                  dj[                  |             |S )N)scope_lister)labelFingerprintlabels)projectresourceglobalSetLabelsRequest	SetLabelsFfamilyTdescriptionarchitectureupdate_user_licensesclear_user_licenses)rK   imageResourceimagePatchzUpdated [{0}]. ).r   ComputeApiHolderReleaseTrackr=   r)   r   ResolveAsResource	resourcesr	   GetDefaultScopeListerr
   DiffFromUpdateArgsMayHaveUpdatesapitools_clientimagesGetComputeImagesGetRequestAsDictApplyGlobalSetLabelsRequestLabelsValuerJ   needs_updateComputeImagesSetLabelsRequestrK   rU   rI   appendr    IsSpecifiedrO   rP   r!   rQ   rR   userLicensesComputeImagesPatchRequestNameAsyncRequestsr   
MultiErrorr   statusPrintformat)rD   rE   r,   holderr=   r)   	image_refrequestsresultlabels_diffrU   labels_updaterequestshould_patchimage_resourceerrors_to_collects                   r2   rC   zUpdate._Runq   s   **4+<+<+>?F]]F}}%%H##55f008 6 :I HF ""11$7K!!#mm++2266
*(
*
*
@Y-=-=-?
@Be!''

)
)
5
5u||Em 
	#	#88%%__++!&!7!7$++ , -	 9 . 	//66WMNL^^%N!"kknl&#'#3#3n l'$,NN$N$N


%n!l$"2"23I"J"&"2"23H"I			0	1&*&?&?#&(#l22##&  3 "g oov--44gwGH!!(,=>F!!"344	jj'..y9:Mr@   c                 J    t        j                  | j                         |      S N)r   rX   rY   )r*   r9   s     r2   r<   zUpdate._GetApiHolder   s    (()9)9);WEEr@   TF)__name__
__module____qualname____doc__r   DETAILED_HELPdetailed_helpclassmethodr?   rF   rC   r<   rW   r@   r2   r5   r5   b   sE    &.-D D8EN F Fr@   r5   c                   0    e Zd ZdZdZeZed        ZddZ	y)
UpdateBetar6   Nc                 n    | j                  d      j                  j                  }t        || |d       y NTr8   r:   r;   r>   s      r2   r?   zUpdateBeta.Args   /       .55>>H#vTBr@   c                 $    | j                  |      S r   rB   rD   rE   support_update_architectures      r2   rF   zUpdateBeta.Run       99T?r@   r   
r   r   r   r   r   r   r   r   r?   rF   rW   r@   r2   r   r      (    &.-C Cr@   r   c                   0    e Zd ZdZdZeZed        ZddZ	y)UpdateAlphar6   Nc                 n    | j                  d      j                  j                  }t        || |d       y r   r;   r>   s      r2   r?   zUpdateAlpha.Args   r   r@   c                 $    | j                  |      S r   rB   r   s      r2   rF   zUpdateAlpha.Run   r   r@   r   r   rW   r@   r2   r   r      r   r@   r   Nr   )r   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   )googlecloudsdk.command_lib.compute.imagesr   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.corer   r   r   r3   ReleaseTracksrY   GAUpdateCommandr5   BETAr   ALPHAr   rW   r@   r2   <module>r      s    + &  ' 7 0 ( 4 K < * # 	A		.*?Z D%%(()WFT WF *WFt D%%**+  , D%%++,*  -r@   