
                             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R%                  SSSS5      S.r " S S\R(                  5      r\\l        g)zCommand for adding metadata.    )absolute_import)division)unicode_literals)encoding)base_classes)metadata_utils)base)
exceptions)flags)loga^            {command} can be used to add or update the metadata of a
        virtual machine instance. Every instance has access to a
        metadata server that can be used to query metadata that has
        been set through this tool. For information on metadata, see
        [](https://cloud.google.com/compute/docs/metadata)

        Only metadata keys that are provided are mutated. Existing
        metadata entries will remain unaffected.

        In order to retrieve custom metadata, run:

            $ gcloud compute instances describe example-instance --zone
            us-central1-a --format="value(metadata)"

        where example-instance is the name of the virtual machine instance
        you're querying custom metadata from. For more information about
        querying custom instance or project metadata through the Cloud Platform
        Console or the API, see
        [](https://cloud.google.com/compute/docs/storing-retrieving-metadata#querying_custom_metadata).


        If you are using this command to manage SSH keys for your project, please note
        the [risks](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#risks)
        of manual SSH key management as well as the required format for SSH key
        metadata, available at [](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys).
        a          To add metadata under key ``{0}'' to an instance
        named ``{1}'', run:

          $ {2} {1} --metadata={0}="{3}"

        To add multiple key-value pairs at once, separate them with commas:

          $ {2} {1} --metadata={0}="{3}",unimportant-data=zero

        zimportant-dataztest-instancez	{command}z2 plus 2 equals 4)DESCRIPTIONEXAMPLESc                   F    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	rg
)InstancesAddMetadataK   z Add or update instance metadata.c                 j    [         R                  R                  U SS9  [        R                  " U SS9  g )Nzset metadata on)operation_typeT)required)r   INSTANCE_ARGAddArgumentr   AddMetadataArgs)parsers    -lib/surface/compute/instances/add_metadata.pyArgsInstancesAddMetadata.ArgsN   s1    	""0 # 2""6D9    c                 f    [         R                  R                  X2[         R                  " U5      S9$ )N)scope_lister)r   r   ResolveAsResourceGetInstanceZoneScopeLister)selfclient	resourcesargss       r   CreateReference$InstancesAddMetadata.CreateReferenceT   s2    //e&F&Fv&N 0 P Pr   c                     UR                   R                  SUR                  R                  " S0 UR	                  5       D64$ )NGet )apitools_client	instancesmessagesComputeInstancesGetRequestAsDict)r!   r"   instance_refs      r   GetGetRequest"InstancesAddMetadata.GetGetRequestX   s>    "",,OO66O9L9L9NOQ Qr   c                     UR                   R                  SUR                  R                  " SSUR                  0UR                  5       D64$ )NSetMetadatametadatar)   )r*   r+   r,   "ComputeInstancesSetMetadataRequestr4   r.   )r!   r"   r/   replacements       r   GetSetRequest"InstancesAddMetadata.GetSetRequest]   sO    "",,OO>> )$--)%%')* *r   c                 
   [         R                  " U5      nUR                  n[        R                  " UR
                  UR                  UR                  US9Ul        [        R                  " XTR                  5      (       a  g U$ )N)r4   metadata_from_fileexisting_metadata)r   CopyProtoMessager4   r   ConstructMetadataMessager,   r:   MetadataEqual)r!   r"   r$   existing
new_objectr;   s         r   ModifyInstancesAddMetadata.Modifyd   sn    **84J ))(AA22+	-J ##$57J7JKKr   c                 ^   UR                   (       d*  UR                  (       d  [        R                  " SS/S5      e[        R
                  " U R                  5       5      nUR                  nU R                  X2R                  U5      nU R                  X45      nUR                  U/5      nU R                  X1US   5      nU(       a	  US   U:X  a=  [        R                  R                  SR!                  US   R"                  5      5        U$ UR                  U R%                  X4U5      /5      $ )Nz
--metadataz--metadata-from-filezHAt least one of [--metadata] or [--metadata-from-file] must be provided.r   z/No change requested; skipping update for [{0}].)r4   r:   calliope_exceptionsOneOfArgumentsRequiredExceptionr   ComputeApiHolderReleaseTrackr"   r%   r#   r0   MakeRequestsrA   r   statusPrintformatnamer7   )r!   r$   holderr"   project_refget_requestobjectsr@   s           r   RunInstancesAddMetadata.Runr   s   ==!8!8??/
0 
 **4+<+<+>?F]]F&&v/?/?FK$$V9K!!;-0GV71:6J
 z1	jj
;
B
Bajoo  n			F	<=? ?r   r)   N)__name__
__module____qualname____firstlineno____doc__staticmethodr   r%   r0   r7   rA   rQ   __static_attributes__r)   r   r   r   r   K   s2    (: :
PQ
*?r   r   N)rW   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper	   r
   rD   ,googlecloudsdk.command_lib.compute.instancesr   googlecloudsdk.corer   rK   DETAILED_HELPUpdateCommandr   detailed_helpr)   r   r   <module>rc      sq    # &  ' % 7 9 ( E > #	8
	 F#_k&(Q*ZB?4-- B?J &3  "r   