
    Q                        S r SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSS.r   S"S jrS rS rS rS rS rS r S r!S r"S r#\RH                  \RJ                  " \RL                  RN                  5       " S S\RP                  5      5       5       r)\RH                  \RJ                  " \RL                  RT                  5       " S S\)5      5       5       r+\RH                  \RJ                  " \RL                  RX                  5       " S  S!\+5      5       5       r-\\)l.        \)R\                  \+l.        \+R\                  \-l.        g)#z#Command for labels update to disks.    N)List)base_classes)
disks_util)utils)poller)waiter)arg_parsers)base)
exceptions)flags)labels_util)logz5*{command}* updates a Compute Engine persistent disk.a          To update labels 'k0' and 'k1' and remove label 'k3' of a disk, run:

            $ {command} example-disk --zone=us-central1-a --update-labels=k0=value1,k1=value2 --remove-labels=k3

            ``k0'' and ``k1'' are added as new labels if not already present.

        Labels can be used to identify the disk. To list disks with the 'k1:value2' label, run:

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

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

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

        To append licenses to the disk, run:

            $ {command} example-disk --zone=us-central1-a --append-licenses=projects/license-project/global/licenses/license-1,projects/license-project/global/licenses/license-2

        To remove licenses from the disk, run:

            $ {command} example-disk --zone=us-central1-a --replace-licenses=projects/license-project/global/licenses/license-1,projects/license-project/global/licenses/license-2

        To replace a license on the disk, run:

            $ {command} example-disk --zone=us-central1-a --replace-license=projects/license-project/global/licenses/old-license,projects/license-project/global/licenses/new-license
        )DESCRIPTIONEXAMPLESc                    [         R                  " SS9Ul        UR                  R                  USS9  [        R
                  " U5        U(       aU  UR                  5       nUR                  S[        R                  " 5       S[        R                  SS9  UR                  S	S
SS9  U(       a  UR                  5       nUR                  S[        R                  " SS9S[        R                  SS9  UR                  S[        R                  " SS9S[        R                  SS9  UR                  S[        R                  " SSS9S[        R                  SS9  UR                  5       nU R                  R                  nUR                  R                  /n[!        UR#                  5        V	s/ s H  oU;  d  M
  U	PM     sn	5      n
UR                  SU
SS9  UR                  SS
SS9  U(       a  [         R$                  " X 5        [         R&                  " X 5        UR                  S[        R(                  " 5       SS9  UR                  S[        R(                  " 5       S S9  UR                  S![        R*                  " / S"QS#9S$S9  g%s  sn	f )&z5Add arguments used for parsing in all command tracks.F)pluralupdate)operation_typez--update-user-licensesLICENSEzList of user licenses to be updated on a disk. These user licenses will replace all existing user licenses. If this flag is not provided, all existing user licenses will remain unchanged.)typemetavaractionhelpz--clear-user-licenses
store_truez,Remove all existing user licenses on a disk.)r   r   --append-licenses   )
min_lengthz"A list of license URIs or license codes. These licenses will be appended to the existing licenses on the disk. Provided licenses can be either license URIs or license codes but not a mix of both.--remove-licenseszA list of license URIs or license codes. If present in the set of existing licenses, these licenses will be removed. If not present, this is a no-op. Provided licenses can be either license URIs or license codes but not a mix of both.--replace-license   )r   
max_lengthzA list of license URIs or license codes. The first license is the license to be replaced and the second license is the replacement license. Provided licenses can be either license URIs or license codes but not a mix of both.z--update-architecturezUpdates the architecture or processor type that this disk can support. For available processor types on Compute Engine, see https://cloud.google.com/compute/docs/cpu-platforms.)choicesr   z--clear-architecturezDRemoves the architecture or processor type annotation from the disk.z--provisioned-iopszVProvisioned IOPS of disk to update. Only for use with disks of type hyperdisk-extreme.)r   r   z--provisioned-throughputzNProvisioned throughput of disk to update. The throughput unit is  MB per sec. z--size)GBGiBTBTiBPiBPB)suggested_binary_size_scalesa3          Size of the disks. The value must be a whole
        number followed by a size unit of ``GB'' for gigabyte, or ``TB''
        for terabyte. If no size unit is specified, GB is
        assumed. For details about disk size limits, refer to:
        https://cloud.google.com/compute/docs/disks
        N)disks_flagsMakeDiskArgDISK_ARGAddArgumentr   AddUpdateLabelsFlagsadd_mutually_exclusive_groupadd_argumentr	   ArgListUpdateAction	add_groupDiskArchitectureValueValuesEnumARCHITECTURE_UNSPECIFIEDnamesortednamesAddGuestOsFeatureArgsAddAccessModeFlag
BoundedInt
BinarySize)messagesclsparsersupport_user_licensessupport_licensessupport_add_guest_os_featuresscopearchitecture_enum_typeexcluded_enumsearchitecture_choicess              #lib/surface/compute/disks/update.py_CommonArgsrJ   A   s    ((6#,,,6(;""6*//1E	   "''J  L 
;  =
 E	  A.''"   
  A.''   
  A!<''D   
-
-
/%#==DD*CCHHI.(..0L0Q^4Kq0LN"E	  	 -   #%%f71!!#	   	0&113A  C 	!!'NP	  
K Ms   +	J8Jc                     U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )Nupdate_labelsclear_labelsremove_labelsIsSpecifiedargss    rI   _LabelsFlagsIncludedrS      s=    			/	* 
;d.>.>/ 
;))/:;    c                 T    U R                  S5      =(       d    U R                  S5      $ )Nupdate_user_licensesclear_user_licensesrO   rQ   s    rI   _UserLicensesFlagsIncludedrX      s+    			0	1 
T5E5E6 rT   c                     U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )Nappend_licensesremove_licensesreplace_licenserO   rQ   s    rI   _LicensesFlagsIncludedr]      s>    
() -			+	,-			+	,rT   c                 T    U R                  S5      =(       d    U R                  S5      $ )Nupdate_architectureclear_architecturerO   rQ   s    rI   _ArchitectureFlagsIncludedra      s+    			/	0 
D4D4D5 rT   c                 $    U R                  S5      $ )Naccess_moderO   rQ   s    rI   _AccessModeFlagsIncludedrd      s    			-	((rT   c                 $    U R                  S5      $ )Nprovisioned_iopsrO   rQ   s    rI   _ProvisionedIopsIncludedrg      s    			,	--rT   c                 $    U R                  S5      $ )Nprovisioned_throughputrO   rQ   s    rI   _ProvisionedThroughputIncludedrj      s    			2	33rT   c                 $    U R                  S5      $ )NsizerO   rQ   s    rI   _SizeIncludedrm      s    			&	!!rT   c                 $    U R                  S5      $ )Nadd_guest_os_features)IsKnownAndSpecifiedrQ   s    rI   _GuestOsFeatureFlagsIncludedrq      s    		!	!"9	::rT   c                       \ rS rSrSrSr\R                   " S S5      5       r\	S 5       r
\	SS j5       rS rS	 rS
 rS rS rS rS rS r  SS jrSrg)Update   (Update a Compute Engine persistent disk.Nc                   @    \ rS rSr% \\S'   \\   \S'   \\   \S'   Sr	g)Update.LicenseUpdateData   update_via_license_codelicenseslicense_codes N)
__name__
__module____qualname____firstlineno__bool__annotations__r   strint__static_attributes__r|   rT   rI   LicenseUpdateDatarw      s    !!3i9rT   r   c                 d    U R                  SS9R                  R                  n[        X US5        g )NTno_httpF_GetApiHolderclientr>   rJ   r?   r@   r>   s      rI   ArgsUpdate.Args   s0       .55>>Hvu&rT   c                 L    [         R                  " U R                  5       U5      $ Nr   ComputeApiHolderReleaseTrackr?   r   s     rI   r   Update._GetApiHolder       (()9)9);WEErT   c                 <     [        U5        g! [         a     gf = f)NTF)r   
ValueError)selflicense_codes     rI   _isIntUpdate._isInt   s$    	, s    
c                 N    U=(       a    [        U5      =(       d    [        U5      $ r   )r]   rq   )r   rR   rB   s      rI   _UpdateRequiresDiskReadUpdate._UpdateRequiresDiskRead  s"    93D9,	%d	+,rT   c                   ^  / nUR                  S5      (       a  UR                  UR                  5        UR                  S5      (       a  UR                  UR                  5        UR                  S5      (       a  UR                  UR                  5        [        U 4S jU 5       5      =(       a    [        U 4S jU 5       5      nU(       a  UR                  S5      (       a  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      eUR                  S5      (       a  [        R                  " S	S5      eg
g
)a  Verifies that license args do not mix licenses and license codes.

Args:
  args: The arguments that were provided by the user, which contains the
    license mutations.

Raises:
  exceptions.InvalidArgumentException: If the user provided a mix of
  licenses and license codes.
rZ   r[   r\   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   r   .0licenser   s     rI   	<genexpr>KUpdate._VerifyLicenseArgsDoNotMixLicensesAndLicenseCodes.<locals>.<genexpr>  s       /,8GL   !c              3   P   >#    U  H  nTR                  U5      (       + v   M     g 7fr   r   r   s     rI   r   r   !  s      Cl7$++g&&&ls   #&r   zKValues must be either all license codes or all licenses, not a mix of both.r   r   N)rP   extendrZ   r[   r\   anyr   InvalidArgumentException)r   rR   all_licenses$is_mixing_licenses_and_license_codess   `   rI   1_VerifyLicenseArgsDoNotMixLicensesAndLicenseCodes8Update._VerifyLicenseArgsDoNotMixLicensesAndLicenseCodes  sD    L)**$../)**$../)**$../+. /,8/ , ,D
ClC
C ) ,			+	,	,11
 	

 
		+	,	,11
 	

 
		+	,	,11
 	
 
- ,rT   c                 f   ^  [        U 4S jU 5       5      =(       a    [        U 4S jU 5       5      $ )Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   r   r   s     rI   r   4Update._LicenseUpdateFormatIsCode.<locals>.<genexpr>8  s     E3Dt{{7##3Dr   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   r   r   s     rI   r   r   8  s"      N,<G,<r   )all)r   appended_licensesremoved_licensess   `  rI   _LicenseUpdateFormatIsCode!Update._LicenseUpdateFormatIsCode7  s3    E3DEE # N,<N K rT   c                 @   [         R                  " S5        U Vs/ s H  n[        U5      PM     nnU Vs/ s H  n[        U5      PM     nnX-   nU H  nXe;   d  M
  UR                  U5        M     [         R                  " S[	        U5      -   5        U$ s  snf s  snf )Nz#Updating licenses via license codeszLicense codes sent to api: )r   debugr   remover   )r   current_license_codesr   r   r   result_licensesremoved_licenses          rI   _ParseLicenseCodesForUpdate"Update._ParseLicenseCodesForUpdate<  s     II345FG5F'W5FG4DE4DG4DE+?O+		+/ , II+c/.BBC HEs
   BBc           	         [         R                  " S5        UR                  U-    Vs/ s H8  nUR                  R	                  USSUR
                  0S9R                  5       PM:     nn[         R                  " S[        U5      -   5        U Vs/ s H8  nUR                  R	                  USSUR
                  0S9R                  5       PM:     nn[         R                  " S[        U5      -   5        U H  nXt;   d  M
  UR                  U5        M     [         R                  " S[        U5      -   5        U$ s  snf s  snf )Nz#Updating licenses via license nameszcompute.licensesproject)
collectionparamsz'appended_licenses & existing licenses: zremoved_licenses: zLicenses sent to API: )	r   r   rz   	resourcesParser   RelativeNamer   r   )r   holderdisk_refdiskr   r   r   r   s           rI   _ParseLicensesForUpdateUpdate._ParseLicensesForUpdateI  sU    II34 (99 :G 	)x//0 	 	
 ,.		
 :   II1C8I4JJ ( (G 	)x//0 	 	
 ,.		
 (   II"S)9%::;+		-  1 , II&->)??@5s   ?D7?D<c                 ,   / n/ nUR                   (       a8  [        R                  " S[        UR                   5      -   5        UR                   nUR                  (       a8  [        R                  " S[        UR                  5      -   5        UR                  nUR
                  (       a  [        R                  " S[        UR
                  S   5      -   S-   [        UR
                  S   5      -   5        UR                  UR
                  S   5        UR                  UR
                  S   5        U R                  XV5      (       a-  U R                  UR                  XV5      nU R                  S/ US9$ U R                  X$X5U5      nU R                  S	U/ S9$ )
NzAppending licenses: zRemoving licenses: zReplacing license r   z with r   T)ry   rz   r{   F)rZ   r   r   r   r[   r\   appendr   r   licenseCodesr   r   )	r   rR   r   r   r   r   r   r{   license_namess	            rI   _ConstructLicenseUpdateData"Update._ConstructLicenseUpdateDataj  s   	ii&T-A-A)BBC..	ii%D,@,@(AAB--	ii
$$Q'() $$Q'() t33A67d22156&&'8KK66


.m ##"&% $   22
D5Em ##"'  $  rT   c                 $    U R                  USSS9$ )NFTrA   rB   _Runr   rR   s     rI   Run
Update.Run  s!    99#   rT   c                    [         R                  " U R                  5       5      nUR                  R                  nUR                  R
                  nU R                  R                  XR                  [        R                  " UR                  5      S9n[        R                  " XuU5      nUR                  5       n	[        U5      (       d  [        U5      (       do  [!        U5      (       d_  [#        U5      (       dO  U(       a  [%        U5      (       d8  U(       a  ['        U5      (       d!  [)        U5      (       d  [+        U5      (       Ga  UR-                  UR/                  5       S9n
S nUR1                  5       S:X  a6  UR3                  UR4                  UR/                  5       U
UR6                  / S9nO5UR9                  UR4                  UR/                  5       U
UR:                  / S9nS nU R=                  X5      (       a  UR?                  5       nU(       aM  [%        U5      (       a=  UR@                  (       a  UR@                  U
l!        URD                  RG                  S5        U(       a  ['        U5      (       a  U RI                  U5        U RK                  XX5      nURL                  (       a-  URN                  U
l(        URD                  RG                  S5        O,URR                  U
l)        URD                  RG                  S5        [!        U5      (       aL  URT                  (       a   U
RW                  URT                  5      U
l,        URD                  RG                  S	5        [)        U5      (       a;  U
R[                  UR\                  5      U
l/        URD                  RG                  S
5        [        U5      (       a=  UR`                  (       a,  UR`                  U
l1        URD                  RG                  S5        [        U5      (       a=  URd                  (       a,  URd                  U
l3        URD                  RG                  S5        [#        U5      (       aQ  URh                  (       a@  [j        Rl                  " URh                  5      U
l7        URD                  RG                  S5        [+        U5      (       aq  URp                  (       a`  URs                  URr                  Ru                  URp                  5      S9/URv                  -   U
l;        URD                  RG                  S5        U	Ry                  U5      nUR                  R{                  UR|                  UR                  5       S9n[        R                  " U	5      n[        R                  " UUSR                  UR/                  5       5      5      n[        U5      (       d  U$ [        R                  " U5      nUR?                  5       nUR                  5       nUR                  UR                  UR                  5      nUR                  UUR                  5       5      nUR                  (       d  U$ U	R                  U5      nUR                  R{                  UR|                  UR                  5       S9n[        R                  " U	5      n[        R                  " UUSR                  UR/                  5       5      5      $ )N)scope_lister)r7   zcompute.disks)r   r   diskResourcezonepaths)r   r   r   regionr   userLicensesr   rz   architecture
accessModeprovisionedIopsprovisionedThroughputsizeGb)r   guestOsFeatures)r   zUpdating fields of disk [{0}]zUpdating labels of disk [{0}])Pr   r   r   r   apitools_clientr>   r,   ResolveAsResourcer   r   GetDefaultScopeListerapi_utilGetDiskInfo
GetServicerg   rj   ra   rm   rX   r]   rd   rq   r4   Name
CollectionComputeDisksUpdateRequestr   r   ComputeRegionDisksUpdateRequestr   r   GetDiskResourcerV   r   r   r   r   r   ry   r{   r   rz   r_   r5   r   AccessModeValueValuesEnumrc   r   rf   r   ri   r   rl   r   	BytesToGbr   ro   GuestOsFeatureTypeValueValuesEnumr   rs   r   selfLinkGetOperationCollectionr   Pollerr   WaitForformatrS   r   GetAndValidateOpsFromArgsGetSetLabelsRequestMessageApplyLabelsValuelabelsGetSetDiskLabelsRequestMessage	GetOrNoneneeds_update	SetLabels)r   rR   rA   rB   r   r   r>   r   	disk_infoservicedisk_resdisk_update_requestr   license_update_dataupdate_operationupdate_operation_refupdate_operation_pollerresultlabels_diffset_label_reqlabels_updaterequest	operationoperation_refoperation_pollers                            rI   r   Update._Run  s    **4+<+<+>?F]]**F}}%%H}}..00? / AH $$Xx@I""$G 	!&&)$//%d++!&@&F&F!7!=!=#D))'--HMMO4h 				/	1&@@$$! A  'FF$$!?? G  d		%	%d	=	=((*	#=d#C#C$$"&";";(
!!((8	4T::>>tD">>$
 66"5"C"C(


#
#
*
*>
:1::(


#
#
*
*:
6	#D	)	)##"*"F"F&&#((
!!((8	!$	'	'&@@
 	!!((6	!$	'	'  %)%:%:(
"

#
#
*
*+<
=	'

 
&&+/+F+F(
(

#
#
*
*+B
C	t		//$))4!!((2	%d	+	+%%%%..BB00 & & ""&#(
" 
#
#
*
*+<
= (;<#--33

#
#557 4 9 !'g 6~~
!#7
)
0
0
ACf "$''77=K$$&D88:M%%m&?&?MM66m%%')G %%k!!'*I$$**y'G'G'I + KM }}W->>-'..MMO	 rT   r|   F)FT)r}   r~   r   r   __doc__r,   dataclasses	dataclassr   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r|   rT   rI   rs   rs      s     2(  
 & &
 F F,
*
X
B#J "	FrT   rs   c                   F    \ rS rSrSrSr\S 5       r\SS j5       rS r	Sr
g)	
UpdateBetai  ru   Nc                 `    U R                  SS9R                  R                  n[        X USS9  g )NTr   )rA   r   r   s      rI   r   UpdateBeta.Args&  s0       .55>>HvT;rT   c                 L    [         R                  " U R                  5       U5      $ r   r   r   s     rI   r   UpdateBeta._GetApiHolder,  r   rT   c                 $    U R                  USSS9$ NTr   r   r   s     rI   r   UpdateBeta.Run0  s!    99"   rT   r|   r  r}   r~   r   r   r  r,   r  r   r   r   r   r|   rT   rI   r  r    s9     2(; ;
 F FrT   r  c                   F    \ rS rSrSrSr\S 5       r\SS j5       rS r	Sr
g)	UpdateAlphai7  ru   Nc           	      f    U R                  SS9R                  R                  n[        UU USSSS9  g )NTr   )rA   rB   rC   r   r   s      rI   r   UpdateAlpha.Args>  s;       .55>>H"&*rT   c                 L    [         R                  " U R                  5       U5      $ r   r   r   s     rI   r   UpdateAlpha._GetApiHolderJ  r   rT   c                 $    U R                  USSS9$ r#  r   r   s     rI   r   UpdateAlpha.RunN  s    99T9MMrT   r|   r  r%  r|   rT   rI   r'  r'  7  s:     2(	 	 F FNrT   r'  )FTF)/r  r  typingr   googlecloudsdk.api_lib.computer   r   r   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   r
   r   "googlecloudsdk.command_lib.computer   (googlecloudsdk.command_lib.compute.disksr*   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   DETAILED_HELPrJ   rS   rX   r]   ra   rd   rg   rj   rm   rq   DefaultUniverseOnlyReleaseTracksr   GAUpdateCommandrs   BETAr  ALPHAr'  detailed_helpr|   rT   rI   <module>r?     sy   *   7 A 0 < . / ( . 4 I < # KH  "'yx;


).4"; D%%(()rT r * rj	 D%%**+  , , D%%++,N* N - N2 % !//
 &44 rT   