
                            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 e
j(                  e
j*                  j,                         G d de
j.                               Z e
j(                  e
j*                  j2                         G d de             Zd Zee_        y)z-Bare Metal Solution NFS share update command.    )absolute_import)division)unicode_literals)	BmsClient)waiter)base)flags)util)labels_util)log)	resourcesa  
          Update a Bare Metal Solution NFS share.

          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 NFS share.
        a  
          To update an NFS share called ``my-share'' in region ``us-central1'' with
          a new label ``key1=value1'', run:

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

          To clear all labels, run:

          $ {command} my-share --region=us-central1 --clear-labels

          To remove label ``key1'', run:

          $ {command} my-share --region=us-central1 --remove-labels=key1
        )DESCRIPTIONEXAMPLESc                   &    e Zd ZdZed        Zd Zy)Update'Update a Bare Metal Solution NFS share.c                     t        j                  | d       t        j                  |        t        j
                  j                  |        t        j                  | d       y)z Register flags for this command.T)
positionalF)parserhiddenN)r	   AddNfsShareArgToParserr   AddUpdateLabelsFlagsr   
ASYNC_FLAGAddToParserAddNfsUpdateAllowedClientArgsr   s    $lib/surface/bms/nfs_shares/update.pyArgszUpdate.Args=   sD     
  D9$$V,OO'	''veD    c                    t         j                  j                  |      }|j                  j                  j                         }t               }|j                  |      }|j                  |j                  j                  j                  |j                        j                         }t        ||||      }|j                  |||      }|j                   r't#        j$                  |j'                         d       |S |j(                  rIt"        j*                  j-                  dj/                  |j'                         |j0                               |S t2        j4                  j7                  |j0                  dd      }	t9        j:                  |j<                        }
t9        j>                  |
|	d	j/                  |j0                              }t#        j$                  |j'                         d       |S )
N)clientargsexisting_nfsnfs_share_resource)r$   labelsallowed_clientsz	NFS share)kindz@Update request issued for: [{}]
Check operation [{}] for status.z/baremetalsolution.projects.locations.operationsv2)
collectionapi_versionz&Waiting for operation [{}] to complete) r   DiffFromUpdateArgsCONCEPTS	nfs_shareParser   GetNfsShareApplymessagesNfsShareLabelsValuer%   	GetOrNone_ApplyNFSAllowedClientsUpdatesUpdateNfsSharedoner   UpdatedResourceNameasync_statusPrintformatnamer   REGISTRYParseRelativeNamer   CloudOperationPollerNoResourcesoperation_serviceWaitFor)selfr"   labels_diffr.   r!   orig_resourcelabels_updateupdated_allowed_clientsop_refop_resourcepollerress               r   Runz
Update.RunE   s   ""11$7K''--/I[F&&y1M%%foo&>&>&J&J&3&:&:<<EIK <"$	& ""i*73J # LF {{	)..*=m{{	jj **0&1A17+>? m$$66D 7 K 33F4L4LMF
..077DFC 	({;Jr   N)__name__
__module____qualname____doc__staticmethodr   rN    r   r   r   r   9   s    /E E$r   r   c                        e Zd ZdZed        Zy)UpdateAlphar   c                 .    t         j                  |        y )N)r   r   r   s    r   r   zUpdateAlpha.Argsp   s     KKr   N)rO   rP   rQ   rR   rS   r   rT   r   r   rV   rV   l   s    / r   rV   c                 6   |j                  d      r|j                  rg S |j                  d      r,| j                  ||j                        }|j                  |z   S |j                  d      r,t        j                  ||j                  |j                        S y)a  Applies the changes in args to the allowed_clients in existing_nfs.

  Returns None if no changes were to be applied.

  Args:
    client: BmsClient.
    args: The arguments passed to the command.
    existing_nfs: The existing nfs.
    nfs_share_resource: The ref to the NFS share.

  Returns:
    List of allowed clients after applying updates or None if there are
    no changes.
  clear_allowed_clientsadd_allowed_client)r$   allowed_clients_dictsremove_allowed_client)r$   r&   remove_key_dictsN)IsKnownAndSpecifiedrY   ParseAllowedClientsDictsrZ   allowedClientsr
   RemoveAllowedClientsr\   )r!   r"   r#   r$   new_clientss        r   r6   r6   v   s    " 
#'#=#=I	2311-"55 2 7K &&44	56$$-$33335 5 7r   N)rR   
__future__r   r   r   %googlecloudsdk.api_lib.bms.bms_clientr   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   ALPHArV   r6   detailed_helprT   r   r   <module>rq      s    4 &  ' ; . ( 0 / < # )		6 D%%(()/T / */d D%%++,&  -5B % r   