
    |$                     ,   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KJr  / SQr\R,                  \R.                  " \R0                  R2                  5       " S S\R4                  5      5       5       r\R.                  " \R0                  R8                  5       " S S\5      5       r\R.                  " \R0                  R<                  5       " S S\5      5       rSSSS.\l         g)zExport image command.    )absolute_import)division)unicode_literals)base_classes)daisy_utils)image_utils)storage_api)storage_util)base)
exceptions)flags)
properties)	resources)z[Daisyz[image-exportz  imageERRORc                   J    \ rS rSrSr\S 5       rS rS rS r	\S 5       r
Srg	)
Export#   zExport a Compute Engine image.c                 f   U R                  SS9nUR                  SSS9  UR                  SSS9  [        R                  " U 5        [        R
                  R                  U SS	S
S9  U R                  SSSS9  U R                  SSS9  U R                  SSS9  U R                  SSS9  [        R                  " U S[        R                  5        [        R                  " U S[        R                  5        [        R                  " U SSS9  U R                  R                  [        R                  5        g )NT)requiredz--imagez%The name of the disk image to export.)helpz--image-familyzThe family of the disk image to be exported. When a family is used instead of an image, the latest non-deprecated image associated with that family is used.imageexportzThe zone to use when exporting the image. When you export an image, the export tool creates and uses temporary VMs in your project for the export process. Use this flag to specify the zone to use for these temporary VMs.)	help_textz--destination-urizEThe Cloud Storage URI destination for the exported virtual disk file.)r   r   z--export-formatzKSpecify the format to export to, such as `vmdk`, `vhdx`, `vpc`, or `qcow2`.z	--networkzThe name of the network in your project to use for the image export. When you export an image, the export tool creates and uses temporary VMs in your project for the export process. Use this flag to specify the network to use for these temporary VMs.z--subnetaH        Name of the subnetwork in your project to use for the image export. When
      you export an image, the export tool creates and uses temporary VMs in
      your project for the export process. Use this flag to specify the
      subnetwork to use for these temporary VMs.
          * If the network resource is in legacy mode, do not provide this
            property.
          * If the network is in auto subnet mode, specifying the subnetwork is
            optional.
          * If the network is in custom subnet mode, then this field must be
            specified.
        zimage exportz	an exportz

          If you are exporting a large image that takes longer than 24 hours to
          export, either use the RAW disk format to reduce the time needed for
          converting the image, or split the data into several smaller images.
          )	operationextra_timeout_help)add_mutually_exclusive_groupadd_argumentr   AddImageProjectFlagr   compute_flagsAddZoneFlagr   AddComputeServiceAccountArg(EXPORT_ROLES_FOR_COMPUTE_SERVICE_ACCOUNTAddCloudBuildServiceAccountArg+EXPORT_ROLES_FOR_CLOUDBUILD_SERVICE_ACCOUNTAddCommonDaisyArgsdisplay_infoAddCacheUpdaterImagesCompleter)parserimage_groups     $lib/surface/compute/images/export.pyArgsExport.Args(   sn   55t5DK4   5   ##F+	##E $ F 0   3   Q       ++<<> ..?? "" ''(=(=>    c           	      \    [         R                  " UR                  5      nS/n/ n[         R                  " X5        [         R                  " US[        R                  R                  R                  R                  5       5        [         R                  " USSR!                  U R#                  U5      5      5        [         R                  " USSR!                  [         R$                  " U5      5      5        [         R                  " US	S
5        U R'                  UR(                  UR*                  UR,                  5      n[         R                  " USU5        [         R                  " USU5        UR.                  (       a0  [         R                  " USUR.                  R1                  5       5        SU;   a"  [         R                  " USUR2                  5        U R5                  XU[6        5      $ ! [        R                  [
        R                  4 a    [        R                  " SS5      ef = f)Nzdestination-uriz3must be a path to an object in Google Cloud Storagezgce-daisy-image-exportzonescratch_bucket_gcs_pathz	gs://{0}/timeoutz{}s	client_idgcloudsource_imagedestination_uriformatcompute_service_account)r   MakeGcsObjectUrir6   r
   InvalidObjectNameErrorcore_resourcesUnknownCollectionExceptionr   InvalidArgumentExceptionAppendNetworkAndSubnetArgs	AppendArgr   VALUEScomputer0   Getr7   _GetDaisyBucketGetDaisyTimeout_GetSourceImager   image_familyimage_projectexport_formatlowerr8   _RunImageExport_OUTPUT_FILTER)selfargsgcs_uritagsexport_argsr5   s         r+   Run
Export.Run~   s   A,,T-A-ABg %%DK**4=+v$++3388<<>@+'@%,,T-A-A$-GHJ+y,,{'B'B4'HIK +{H=''

D4E4E(,(:(:<L+~|D+'8'BK43E3E3K3K3MN D(K)B 88:4HH7 //557 A//

?A AAs    G/ /<H+c                     [         R                  " UUU[        U R                  5       (       a*  U R                  5       R                  R                  5       S9$ S S9$ )N)release_track)r   RunImageExportrK   ReleaseTrackidrI   rL   rM   rP   rO   output_filters        r+   rJ   Export._RunImageExport   s\    %% ''),,224* * %)* *r.   c                 t   [         R                  " U R                  5       5      nUR                  nUR                  n[
        R                  R                  R                  R                  5       n[        R                  " XV5      nUR                  XqUUSS9nUR                  US   SS9n	U	R                  5       $ )NF)user_projectr   rF   rG   return_image_resourcer   zcompute.images)
collection)r   ComputeApiHolderrV   clientr   r   r@   coreproject	GetOrFailr   ImageExpanderExpandImageFlagParseRelativeName)
rL   r   rF   rG   holderr`   r   rb   image_expander	image_refs
             r+   rE   Export._GetSourceImage   s    **4+<+<+>?F]]F  I$$,,668G ..vAN**#5 + BE a5EFI!!##r.   c                     [         R                  " 5       nUR                  U R                  5      n[        R
                  " UUSSS9$ )NTr   )enable_uniform_level_accesssoft_delete_duration)r	   StorageClientGetBucketLocationForFiler6   r   CreateDaisyBucketInProject)rM   storage_clientbucket_locations      r+   rC   Export._GetDaisyBucket   sH     ..0N$==O11$(	   r.    N)__name__
__module____qualname____firstlineno____doc__staticmethodr,   rQ   rJ   rE   rC   __static_attributes__ru   r.   r+   r   r   #   sA     'S? S?jI@*
$    r.   r   c                   <   ^  \ rS rSrSr\U 4S j5       rS rSrU =r	$ )
ExportBeta   z5Export a Compute Engine image for Beta release track.c                 X   > [         [        U ]  U5        [        R                  " U5        g )N)superr~   r,   r   AddExtraCommonDaisyArgs)clsr)   	__class__s     r+   r,   ExportBeta.Args   s     	*c'''/r.   c           	          [         R                  " UUU[        U R                  5       (       a(  U R                  5       R                  R                  5       OS UR                  S9$ )N)rT   docker_image_tag)r   rU   rK   rV   rW   rI   r   rX   s        r+   rJ   ExportBeta._RunImageExport   sY    %% ''),,224$(..0 0r.   ru   )
rv   rw   rx   ry   rz   classmethodr,   rJ   r|   __classcell__)r   s   @r+   r~   r~      s"    =0 00 0r.   r~   c                       \ rS rSrSrSrg)ExportAlpha   z6Export a Compute Engine image for Alpha release track.ru   N)rv   rw   rx   ry   rz   r|   ru   r.   r+   r   r      s    >r.   r   zExport a Compute Engine imagea          *{command}* exports virtual disk images from Compute Engine.

        By default, images are exported in the Compute Engine format,
        which is a `disk.raw` file that is tarred and gzipped.

        The `--export-format` flag exports the image to a format supported
        by QEMU using qemu-img. Valid formats include `vmdk`, `vhdx`, `vpc`,
        `vdi`, and `qcow2`.

        Before exporting an image, set up access to Cloud Storage and grant
        required roles to the user accounts and service accounts. For more
        information, see [](https://cloud.google.com/compute/docs/import/requirements-export-import-images).
        a          To export a VMDK file ``my-image'' from a project ``my-project'' to a
        Cloud Storage bucket ``my-bucket'', run:

          $ {command} --image=my-image --destination-uri=gs://my-bucket/my-image.vmdk --export-format=vmdk --project=my-project
    )briefDESCRIPTIONEXAMPLESN)!rz   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.api_lib.storager	   r
   googlecloudsdk.callioper   r   )googlecloudsdk.command_lib.compute.imagesr   googlecloudsdk.corer   r   r;   rK   DefaultUniverseOnlyReleaseTracksrV   GACreateCommandr   BETAr~   ALPHAr   detailed_helpru   r.   r+   <module>r      s     &  ' 7 6 6 6 7 ( . ; * ;@ D%%(()W T W  * W t D%%**+0 0 ,0& D%%++,?* ? -? 	(		' r.   