
    !                        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lmZ ddlmZ ddlmZ ddlmZ ddlmZ g dZ e
j6                  e
j8                  j:                         e
j<                  ddd      e
j>                   G d de
j@                                             Z! e
j6                  e
j8                  jD                         G d de!             Z# e
j6                  e
j8                  jH                         G d de!             Z%dddde!_&        y) z<Command for importing machine images in OVF format into GCE.    )absolute_import)division)unicode_literals)base_classes)daisy_utils)image_utils)base)
exceptions)
completers)flags)
os_choices)labels_util)log)	resources)z[Daisyz[import-zstarting buildz  importERRORFzThis command is being deprecated. Instead, use the `gcloud migration vms machine-image-imports` command. For more information, See "gcloud alpha migration vms machine-image-imports --help".zThis command has been deprecated. Instead, use the `gcloud migration vms machine-image-imports` command. For more information, See "gcloud alpha migration vms machine-image-imports --help".)
is_removedwarningerrorc                   >    e Zd ZdZed        Zedd       Zd Zd Zy)Importz4Import a machine image into Compute Engine from OVF.c                    | j                  d      }|j                  j                  }|j                  j	                  t
        j                         t        j                         t        _	        t        j                  j                  |d       |j                  dd       t        j                  |d       t        j                  |d	       t        j                  |       t        j                   |       t        j"                  |       t        j$                  |       t        j&                  |       t)        j*                  |       t)        j,                  |       t/        j0                  |       t3        j4                  |d
       t3        j6                  |       t9        j:                  ||       |j                  ddt=        t>        j@                        d       t3        jB                  |       t        jD                  |d	ddt        jF                  z          t3        jH                  |d	       |j                  jK                  tL        jN                         t3        jP                  |dd       t3        jR                  |dt2        jT                         t3        jV                  |dt2        jX                         t)        jZ                  |dddd	       |j                  dddd       y )NT)no_httpimport)operation_typez--descriptionz2Specifies a text description of the machine image.)helpzmachine image'szmachine imagez	an import)	operationz--osFz5Specifies the OS of the machine image being imported.)requiredchoicesr   z>The zone in which to perform the import of the machine image. )explanationzmachine image importzyhttps://cloud.google.com/nat/docs/gce-example#create-nat and https://cloud.google.com/vpc/docs/private-access-options#pga)docs_urlay  However, if neither `--scopes` nor `--no-scopes` are specified and the project has no default service account, then the machine image is imported with no scopes. Note that the level of access that a service account has is determined by a combination of access scopes and IAM roles so you must configure both access scopes and IAM roles for the service account to work properly.r   )extra_scopes_helpr   resourcez--cmd-deprecated
store_trueaE  
        The command you're using is deprecated and will be removed by December 31,
        2025. We recommend using `gcloud compute migration image-imports` instead.
        See our official documentation for more information.
        https://cloud.google.com/migrate/virtual-machines/docs/5.0/migrate/image_import.
        )actionr   r   )._GetComputeApiHolderclientmessagesdisplay_info	AddFormatmachine_image_flagsDEFAULT_LIST_FORMATMakeMachineImageArgr   MACHINE_IMAGE_ARGAddArgumentadd_argumentr   AddStorageLocationFlagAddGuestFlushFlagAddNoRestartOnFailureArgsAddTagsArgsAddCanIpForwardArgsAddNetworkArgsAddNetworkTierArgsinstances_flagsAddMachineTypeArgsAddCustomMachineTypeArgsr   AddCreateLabelsFlagsr   AddCommonDaisyArgsAddOVFSourceUriArgr   AddGuestOsFeaturesArgForImportsortedr   OS_CHOICES_INSTANCE_IMPORT_BETA
AddByolArgAddZoneFlagZONE_PROPERTY_EXPLANATIONAddGuestEnvironmentArgAddCacheUpdaterr   InstancesCompleterAddNoAddressArgAddComputeServiceAccountArg(IMPORT_ROLES_FOR_COMPUTE_SERVICE_ACCOUNTAddCloudBuildServiceAccountArg+IMPORT_ROLES_FOR_CLOUDBUILD_SERVICE_ACCOUNTAddServiceAccountAndScopeArgs)clsparsercompute_holderr'   s       ,lib/surface/compute/machine_images/import.pyArgszImport.Args8   st   --d-;N$$--H
!!"5"I"IJ2FFHF
(((I
A  C 
  ):;	FO411&9##F+++F3&&v.**62&&v.,,V4$$V,""6[A""6*..vx@
zAABD	  F
 6"	T

)
)*	+ &&v?
''
(E(EFO	Q ++&<<> ..??
 11   " 	  
    c                 J    t        j                  | j                         |      S N)r   ComputeApiHolderReleaseTrack)rL   r   s     rO   r%   zImport._GetComputeApiHolder   s    (()9)9);WEErQ   c                 R   t        j                  |       t        j                  |       t        j                  ||       t        j
                  |       	 t        j                  |j                        |_        y # t        j                  $ r t        j                  dd      w xY w)Nz
source-uriz;must be a path to an object or a directory in Cloud Storage)r7   ValidateNicFlagsValidateNetworkTierArgsr   ValidateZone"ValidateServiceAccountAndScopeArgs
MakeGcsUri
source_urir   UnknownCollectionExceptionr
   InvalidArgumentException)selfargscompute_clients      rO   _ValidateArgszImport._ValidateArgs   s    $$T*++D1T>266t<I#..t?do// I//

GI IIs   $A< <*B&c                 F   | j                         }|j                  }| j                  ||       t        j                  d       t        j                  |t        | j                         r(| j                         j                  j                         nd |j                        S )NzeImporting OVF. This may take 40 minutes for smaller OVFs and up to a couple of hours for larger OVFs.)r`   output_filterrelease_trackr'   )r%   r&   rb   r   r   r   RunMachineImageOVFImportBuild_OUTPUT_FILTERrU   idlowerr'   )r_   r`   rN   ra   s       rO   Runz
Import.Run   s    ..0N#**Nt^,KK ? @ 44$++- ((*--33537((* *rQ   N)F)	__name__
__module____qualname____doc__classmethodrP   r%   rb   rj    rQ   rO   r   r   &   s=      =P Pd F F
I*rQ   r   c                   ,     e Zd ZdZe fd       Z xZS )
ImportBetaz=Import a machine image into Compute Engine from OVF for Beta.c                 V    t         t        |   |       t        j                  |       y rS   )superrr   rP   r   AddExtraCommonDaisyArgsrL   rM   	__class__s     rO   rP   zImportBeta.Args   s     	*c'''/rQ   rk   rl   rm   rn   ro   rP   __classcell__rw   s   @rO   rr   rr      s    E0 0rQ   rr   c                   ,     e Zd ZdZe fd       Z xZS )ImportAlphaz>Import a machine image into Compute Engine from OVF for Alpha.c                 V    t         t        |   |       t        j                  |       y rS   )rt   r|   rP   r   ru   rv   s     rO   rP   zImportAlpha.Args   s     	+s (''/rQ   rx   rz   s   @rO   r|   r|      s    F0 0rQ   r|   zOCreate a Compute Engine machine image from virtual appliance in OVA/OVF format.a          *{command}* creates Compute Engine machine image from virtual appliance
        in OVA/OVF format.

        Importing OVF involves:
        *  Unpacking OVF package (if in OVA format) to Cloud Storage.
        *  Import disks from OVF to Compute Engine.
        *  Translate the boot disk to make it bootable in Compute Engine.
        *  Create a machine image using OVF metadata and imported disks.

        Virtual instances, images, machine images, and disks in Compute engine
        and files stored on Cloud Storage incur charges. See [](https://cloud.google.com/compute/docs/images/importing-virtual-disks#resource_cleanup).
        z        To import an OVF package from Cloud Storage into a machine image named
        `my-machine-image`, run:

          $ {command} my-machine-image --source-uri=gs://my-bucket/my-dir
        )briefDESCRIPTIONEXAMPLESN)'rn   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   r   )googlecloudsdk.command_lib.compute.imagesr   ,googlecloudsdk.command_lib.compute.instancesr7   1googlecloudsdk.command_lib.compute.machine_imagesr*   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   rg   ReleaseTracksrU   GA	DeprecateDefaultUniverseOnlyCreateCommandr   BETArr   ALPHAr|   detailed_helprp   rQ   rO   <module>r      s/   C &  ' 7 6 6 ( . 9 4 @ Q Z < # )N D%%(()	>
	> t*T t*  *t*n D%%**+0 0 ,0 D%%++,0& 0 -0			' rQ   