
                            S 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\R*                  " \R,                  R.                  5       " S S\R0                  5      5       r\R*                  " \R,                  R4                  5       " S S\5      5       rS rS rS rS r\\l         g)z+Bare Metal Solution network update command.    )absolute_import)division)unicode_literals)	BmsClient)IpRangeReservation)waiter)base)
exceptions)flags)labels_util)log)	resourcesa	  
          Update a Bare Metal Solution network.

          This call returns immediately, but the update operation may take
          several minutes to complete. To check if the operation is complete,
          use the `describe` command for the network.
        aH  
          To update an network called ``my-network'' in region ``us-central1'' with
          a new label ``key1=value1'', run:

          $ {command} my-network  --region=us-central1 --update-labels=key1=value1

          To clear all labels, run:

          $ {command} my-network --region=us-central1 --clear-labels
        )DESCRIPTIONEXAMPLESc                   .    \ rS rSrSr\S 5       rS rSrg)Update6   %Update a Bare Metal Solution network.c                     [         R                  " U SS9  [        R                  " U 5        [        R
                  R                  U 5        [         R                  " U SS9  g)z Register flags for this command.T)
positionalF)hiddenN)r   AddNetworkArgToParserr   AddUpdateLabelsFlagsr	   
ASYNC_FLAGAddToParserAddNetworkIpReservationToParserparsers    "lib/surface/bms/networks/update.pyArgsUpdate.Args:   sD     
48$$V,OO'	))&?    c                    [        5       nUR                  R                  R                  5       nS n[        R
                  R                  U5      nUR                  U5      nUR                  UR                  R                  R                  UR                  5      R                  5       n[        X5      nUR                  X4US9nUR                   (       a%  ["        R$                  " UR'                  5       SS9  U$ UR(                  (       aI  ["        R*                  R-                  SR/                  UR'                  5       UR0                  5      5        U$ [2        R4                  R7                  UR0                  SSS9n	[8        R:                  " UR<                  5      n
[8        R>                  " XSR/                  UR0                  5      5      n["        R$                  " UR'                  5       SS9  U$ )	N)network_resourcelabelsip_reservationsnetwork)kindz@Update request issued for: [{}]
Check operation [{}] for status.z/baremetalsolution.projects.locations.operationsv2)
collectionapi_versionz&Waiting for operation [{}] to complete) r   CONCEPTSr'   Parser   DiffFromUpdateArgs
GetNetworkApplymessagesNetworkLabelsValuer%   	GetOrNone_ApplyIpReservationsUpdatesUpdateNetworkdoner   UpdatedResourceNameasync_statusPrintformatnamer   REGISTRYParseRelativeNamer   CloudOperationPollerNoResourcesoperation_serviceWaitFor)selfargsclientr'   labels_updatelabels_difforig_resourcer&   op_refop_resourcepollerress               r   Run
Update.RunB   s   [Fmm##))+GM""11$7K%%g.M%%++'ik  2$FO!! ' " )F {{	',,.y9m{{	jj **0&*MOm$$66D 7 K 33  "F
..AHH#[[*+C Y7Jr"    N)	__name__
__module____qualname____firstlineno____doc__staticmethodr    rO   __static_attributes__rQ   r"   r   r   r   6   s    -@ @#r"   r   c                   (    \ rS rSrSr\S 5       rSrg)UpdateAlphah   r   c                 .    [         R                  U 5        g N)r   r    r   s    r   r    UpdateAlpha.Argsl   s     KKr"   rQ   N)rR   rS   rT   rU   rV   rW   r    rX   rQ   r"   r   rZ   rZ   h   s    - r"   rZ   c                    [        U S5      (       a  / $ UR                   Vs/ s H.  n[        UR                  UR                  UR
                  5      PM0     nn[        U S5      (       aA  U R                  n[        U[        R                  S5        U[        US   US   US   5      /-   $ [        U S5      (       a  [        UU R                  5      $ gs  snf )	a7  Applies the changes in args to the reservations in existing_network.

Returns None if no changes were to be applied.

Args:
  args: The arguments passed to the command.
  existing_network: The existing network.

Returns:
  List of IP range reservations after applying updates or None if there are
  no changes.
clear_ip_range_reservationsadd_ip_range_reservationzadd-ip-range-reservationstart-addressend-addressnoteremove_ip_range_reservationN)_IsSpecifiedreservationsr   startAddress
endAddressrd   ra   _ValidateAgainstSpecr   IP_RESERVATION_SPEC_RemoveReservationre   )rF   existing_networkrN   existing_reservationsres_dicts        r   r6   r6   r   s     $566I "...# ))3>>388D.  
 $233,,H5#<#<35 8O4h}6M#F+	-$  
 $5663">>@ @ 7s   5Cc                    [        U[        R                  S5        US   nUS   n[        U 5       H6  u  pEUR                  U:X  d  M  UR
                  U:X  d  M)  U S U XS-   S  -   s  $    [        SR                  UU5      5      e)Nzremove-ip-range-reservationrb   rc      zPCannot find an IP range reservation with start-address [{}] and end-address [{}])rj   r   IP_RESERVATION_KEY_SPEC	enumeratestart_addressend_addressLookupErrorr>   )rg   remove_key_dictrt   ru   irN   s         r   rl   rl      s    (E(E46!/2-.+,'fa
M)coo.L"1UV 444 ( 	 1178C2E	F Fr"   c                 h    UR                  5        H  nX0;  d  M
  [        R                  " X#5      e   g r]   )keysr
   MissingPropertyError)dict_to_validatespec	flag_nameprops       r   rj   rj      s)    iikd#++I<< r"   c                 $    U R                  U5      $ )zAReturns true if an arg is defined and specified, false otherwise.)IsKnownAndSpecified)rF   r?   s     r   rf   rf      s    		!	!$	''r"   N)!rV   
__future__r   r   r   %googlecloudsdk.api_lib.bms.bms_clientr   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   googlecloudsdk.command_lib.bmsr
   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   DETAILED_HELPReleaseTracksReleaseTrackGAUpdateCommandr   ALPHArZ   r6   rl   rj   rf   detailed_helprQ   r"   r   <module>r      s    2 &  ' ; D . ( 5 0 < # )			. D%%(().T . *.b D%%++,&  -!@H
F=( % r"   