
    K                         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
Zedz   ZdZd Zd Zd Zd Zd Zd Zd Zd Zy)z?Common utility functions for Cloud Filestore snapshot commands.    )absolute_import)division)unicode_literals)encoding)filestore_client)update_util)util)
propertiesz%projects/{}/locations/{}/instances/{}z/snapshots/{}v1c                 &   ~ |j                   |_        t        j                  j                  j
                  j                  d      }|j                  |j                  n|j                  }t        j                  |||j                        |_        |S )zWPython hook for yaml commands to supply the snapshot create request with proper values.Trequired)snapshot
snapshotIdr
   VALUEScoreprojectGetinstance_regioninstance_locationPARENT_TEMPLATEformatinstanceparentrefargsreqr   location_ids        Dlib/googlecloudsdk/command_lib/filestore/instances/snapshots/util.pyFormatSnapshotCreateRequestr!       s}    	==#.""**...='*.*>*>*F&&
  %%{DMM+#* 
*    c                    ~ t         j                  j                  j                  j	                  d      }|j
                  |j                  n|j
                  }t        j                  |||j                  |j                        |_        |S )zVPython hook for yaml commands to supply snapshot access requests with the proper name.Tr   )r
   r   r   r   r   r   r   SNAPSHOT_NAME_TEMPLATEr   r   r   namer   s        r    FormatSnapshotAccessRequestr&   .   sx    	""**...='*.*>*>*F&&
  $**{DMM4==:#( 
*r"   c                    ~ t         j                  j                  j                  j	                  d      }|j
                  |j                  n|j
                  }t        j                  |||j                        |_
        |S )zVPython hook for yaml commands to supply the list snapshots request with proper values.Tr   )r
   r   r   r   r   r   r   r   r   r   r   r   s        r    FormatSnapshotsListRequestr(   ;   sr    	""**...='*.*>*>*F&&
  %%{DMM+#* 
*r"   c                 x    ~ t        j                  ||t         j                        }|r||j                  _        |S )zUpdate snapshot labels.)r   GetUpdatedLabelssnapshot_feature_namer   labels)r   r   r   
new_labelss       r    UpdateLabelsr.   H   s7    	++D#,7,M,MO*$CLL	*r"   c                 ^   t         j                  j                  j                  j	                  d      }t        j                  |       }t        j                  |      }| j                  | j                  n| j                  }|j                  d||| j                  | j                        }|S )z-Creates a Snapshot and returns its reference.Tr   z+file.projects.locations.instances.snapshots)
projectsIdlocationsIdinstancesIdsnapshotsId)r
   r   r   r   r   r	   GetApiVersionFromArgsr   GetFilestoreRegistryr   r   Creater   r   )r   r   api_versionregistryr   r   s         r    GetResourceRefr9   R   s    ""**...='**40+22;?(*.*>*>*F&&
  	3---- 	 	!# 
*r"   c                     ~ t        |      }t        j                  |      }t        j                  |      }|j                  |      }||_        |S )zHFetch existing Filestore instance to update and add it to Patch request.)r9   r	   r4   r   FilestoreClientGetInstanceSnapshotr   )r   r   patch_requestresource_refr7   clientorig_snapshots          r    GetExistingSnapshotrA   d   sM    	%,**40+++K8&,,\:-(-	r"   c                     ~ t        |      }t        j                  |      }t        j                  |      }t        j                  |j                  |            S )z3Python hook to generate the backup update response.)r9   r	   r4   r   r;   r   MessageToDictr<   )responser   r>   r7   r?   s        r    FormatSnapshotUpdateResponserE   o   sK    %,**40+++K8&			 : :< H	IIr"   c                 N    t        j                  | ||t         j                        S )z&Adds description to the patch request.)r   AddDescriptionr+   )unused_instance_refr   r=   s      r    rG   rG   y   s'    		#	#$7}$/$E$E
G Gr"   N)__doc__
__future__r   r   r   apitools.base.pyr    googlecloudsdk.api_lib.filestorer   $googlecloudsdk.command_lib.filestorer   r	   googlecloudsdk.corer
   r   r$   V1_API_VERSIONr!   r&   r(   r.   r9   rA   rE   rG    r"   r    <module>rQ      sb    F &  ' % = < 5 *9(?: 

$JGr"   