
    k,                     &   S r SSKJr  SSKJr  SSKJr  SSK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SKJr  / SQr\R<                  \R>                  " \R@                  RB                  5       " S S\RD                  5      5       5       r#\R>                  " \R@                  RH                  \R@                  RJ                  5       " S S\#5      5       r&SSSS.\#l'        g)z7Command for importing instances in OVF format into GCE.    )absolute_import)division)unicode_literalsN)base_classes)daisy_utils)image_utils)instance_utils)base)
exceptions)
completers)
os_choices)flags)labels_util)log)
properties)	resources)z[Daisyz[import-zstarting buildz  importERRORc                   l    \ rS rSrSr\R                  r\S 5       r	\SS j5       r
S rS rS rS rS	rg
)Import)   0Import an instance into Compute Engine from OVF.c                 @   U R                  SS9nUR                  R                  n[        R                  " U5        [        R
                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " U5        [        R                  " USS9  [        R                  " U5        [        R                  " U5        [         R"                  " USS9  [         R$                  " U5        [        R&                  R)                  USS9  [         R*                  " U5        UR-                  SS	[/        U R0                  5      S
S9  [         R2                  " U5        [4        R6                  " X5        UR-                  SSS9  [         R8                  " U5        UR:                  R=                  [>        R@                  5        [B        RD                  " U5        UR-                  SSS9  [         RF                  " US[         RH                  5        [        RJ                  " US	SSS9  [         RL                  " US[         RN                  5        g )NT)no_http)instancez	an import)	operationimport)operation_typez--osFz-Specifies the OS of the image being imported.)requiredchoiceshelpz--descriptionz4Specifies a textual description of the VM instances.)r    z
--hostnameaP        Specify the hostname of the VM instance to be imported. The specified
      hostname must be RFC1035 compliant. If hostname is not specified, the
      default hostname is [INSTANCE_NAME].c.[PROJECT_ID].internal when using
      the global DNS, and [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal
      when using zonal DNS.
      zinstance importaw  However, if neither `--scopes` nor `--no-scopes` are specified and the project has no default service account, then the VM instance 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   )(_GetComputeApiHolderclientmessagesinstances_flagsAddCanIpForwardArgsAddMachineTypeArgsAddNoRestartOnFailureArgsAddTagsArgsAddCustomMachineTypeArgsAddNetworkArgsAddPrivateNetworkIpArgsAddDeletionProtectionFlagAddNetworkTierArgsAddNoAddressArgr   AddCreateLabelsFlagsr   AddCommonDaisyArgsAddExtraCommonDaisyArgsINSTANCES_ARG_FOR_IMPORTAddArgumentAddOVFSourceUriArgadd_argumentsorted_OS_CHOICES
AddByolArgr   AddGuestOsFeaturesArgForImportAddGuestEnvironmentArgdisplay_infoAddCacheUpdaterr   InstancesCompletersole_tenancy_flagsAddNodeAffinityFlagToParserAddComputeServiceAccountArg(IMPORT_ROLES_FOR_COMPUTE_SERVICE_ACCOUNTAddServiceAccountAndScopeArgsAddCloudBuildServiceAccountArg+IMPORT_ROLES_FOR_CLOUDBUILD_SERVICE_ACCOUNT)clsparsercompute_holderr$   s       'lib/surface/compute/instances/import.pyArgsImport.Args0   s   --d-;N$$--H''/&&v.--f5',,V4""6*++F3--f5&&v=##F+$$V,""6[A''/,,88x 9 )""6*
s'<	  >
 6"..v@
C  E &&v.
''
(E(EF226:

   ++!<<> 11   ..??    c                 L    [         R                  " U R                  5       U5      $ N)r   ComputeApiHolderReleaseTrack)rF   r   s     rI   r"   Import._GetComputeApiHoldert   s    (()9)9);WEErL   c                     [         R                  " S5      nUR                  UR                  5      (       d  [        R
                  " SS5      eg)z9Raise an exception if requested instance name is invalid.z!^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$INSTANCE_NAMEzName must start with a lowercase letter followed by up to 63 lowercase letters, numbers, or hyphens, and cannot end with a hyphen.N)recompilematchinstance_namer   InvalidArgumentException)selfargsinstance_name_patterns      rI   _ValidateInstanceNameImport._ValidateInstanceNamex   sI    JJ'JK &&t'9'9:://
  ;rL   c                    [         R                  R                  R                  R	                  5       nUR
                  R                  SUR                  R                  U[         R                  R                  R                  R	                  5       US94n/ nUR                  U/US9nU(       d.  U(       a&  SR                  XS9n[        R                  " SU5      egg)z:Check that the destination instances do not already exist.Get)r   projectzone)errors_to_collectzBThe VM instance [{instance_name}] already exists in zone [{zone}].)rW   ra   rS   N)r   VALUEScomputera   	GetOrFailapitools_client	instancesr$   ComputeInstancesGetRequestcorer`   MakeRequestsformatr   rX   )rY   rW   r#   ra   requesterrorsrg   messages           rI   _CheckForExistingInstances!Import._CheckForExistingInstances   s     $$))335D%%//99)%,,1199CCE : G
 F##WI#HIi$f#0 % =  //II	  6rL   c                    U R                  U5        U R                  UR                  U5        [        R                  " U5        [        R
                  " U5        [        R                  " X5        [        R                  " U5        g rN   )	r\   ro   rW   r%   ValidateNicFlagsValidateNetworkTierArgsr   ValidateZone"ValidateServiceAccountAndScopeArgs)rY   rZ   compute_clients      rI   _ValidateArgsImport._ValidateArgs   s^    t$##D$6$6G$$T*++D1T266t<rL   c                 ~   U R                  5       nUR                  nUR                  nU R                  X5        [        R
                  " S5        S nUR                  (       d"  UR                  (       d  UR                  (       aL  [        R                  " UR                  UR                  UR                  [        USS 5      [        USS 5      S9n [        R                  " UR                  5      n[        USS 5      =(       d    SnUR&                  R(                  R*                  R,                  U;   n[        R.                  " S0 S	U_S
U_SUR0                  _SU_SUR2                  (       + _SUR4                  _SUR6                  _SUR8                  _SUR:                  _SU_SUR<                  _SUR>                  _SUR@                  _SURB                  _SURD                  (       + _SURF                  _S[        USS5      _SU_SURH                  _S[J        RL                  RN                  RP                  RS                  5       _SURT                  _S[V        _S U RY                  5       (       a(  U RY                  5       RZ                  R]                  5       OS _S![        US!S 5      _S"[        US"S5      _S#[        US#S$5      _S%[        US%S$5      _S&[        US&S 5      _S'[        US'S5      _S([        US(S 5      _S)[        US)S5      _6$ ! [        R                    a    ["        R$                  " SS5      ef = f)*NzeImporting OVF. This may take 40 minutes for smaller OVFs and up to a couple of hours for larger OVFs.custom_extensionscustom_vm_type)machine_type
custom_cpucustom_memoryextvm_typez
source-uriz;must be a path to an object or a directory in Cloud Storageguest_os_features rZ   rv   rW   
source_urino_guest_environmentcan_ip_forwarddeletion_protectiondescriptionlabelsr|   networknetwork_tiersubnetprivate_network_ipno_restart_on_failureosbyolFuefi_compatibletagsra   r`   output_filterrelease_trackhostname
no_addresscompute_service_account cloudbuild_service_accountscopes	no_scopesservice_accountno_service_account)/r"   r#   r$   rw   r   warningr|   r}   r~   r	   InterpretMachineTypegetattrr   
MakeGcsUrir   r   UnknownCollectionExceptionr   rX   GuestOsFeatureTypeValueValuesEnumUEFI_COMPATIBLEnameRunInstanceOVFImportBuildrW   guest_environmentr   r   r   r   r   r   r   r   restart_on_failurer   r   r   rc   rd   ra   r_   r`   _OUTPUT_FILTERrP   idlower)	rY   rZ   rH   rv   r$   r|   r   r   r   s	            rI   Run
Import.Run   sm   ..0N#**N&&Ht,KK ? @ LDOOt/A/A#88((__**d/6$ 0$79lI))$//:j  &94@FB33CCHH	  00 $$%$ (($ 	$
 "&!7!77$ **$ !44$ $$$ {{$ "$ $ &&$ {{$  22$ #'"9"99$  77!$" T65)#$$ (%$& YY'$( &&++//1)$* +$, %-$0 /3.?.?.A.AD""((*t1$4 z405$6 4u57$8 !(.G L9$: $+.$
;$@ tXt,A$B $U3C$D  &7>E$F #4)=uEG$ $! // I//

GI IIs    L ,L<r   N)F)__name__
__module____qualname____firstlineno____doc__r   OS_CHOICES_INSTANCE_IMPORT_GAr8   classmethodrJ   r"   r\   ro   rw   r   __static_attributes__r   rL   rI   r   r   )   sS     988+A AF F FJ"=IrL   r   c                   Z   ^  \ rS rSrSr\R                  r\U 4S j5       r	U 4S jr
SrU =r$ )
ImportBeta   r   c                 ,   > [         [        U ]  U5        g rN   )superr   rJ   )rF   rG   	__class__s     rI   rJ   ImportBeta.Args   s    	*c'rL   c                 ,   > [         [        U ]  X5        g rN   )r   r   rw   )rY   rZ   rv   r   s      rI   rw   ImportBeta._ValidateArgs   s    	*d)$?rL   r   )r   r   r   r   r   r   OS_CHOICES_INSTANCE_IMPORT_BETAr8   r   rJ   rw   r   __classcell__)r   s   @rI   r   r      s/    8::+( (@ @rL   r   zYCreate Compute Engine virtual machine instances from virtual appliance in OVA/OVF format.a+          *{command}* creates Compute Engine virtual machine instances 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 VM instance using OVF metadata and imported disks and boot it.

        OVF import tool requires Cloud Build to be enabled. See [](https://cloud.google.com/compute/docs/import/import-ovf-files#enable-cloud-build)
        Virtual machine instances, 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 VM named
        `my-instance`, run:

          $ {command} my-instance --source-uri=gs://my-bucket/my-dir
        )briefDESCRIPTIONEXAMPLES)(r   
__future__r   r   r   rT   googlecloudsdk.api_lib.computer   r   r   r	   googlecloudsdk.callioper
   r   "googlecloudsdk.command_lib.computer   )googlecloudsdk.command_lib.compute.imagesr   ,googlecloudsdk.command_lib.compute.instancesr   r%   /googlecloudsdk.command_lib.compute.sole_tenancyr?   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   r   DefaultUniverseOnlyReleaseTracksrP   GACreateCommandr   BETAALPHAr   detailed_helpr   rL   rI   <module>r      s    > &  ' 	 7 6 6 9 ( . 9 @ Q W < # * )N D%%(()zT z * zz D%%**D,=,=,C,CD@ @ E@ 	'		) rL   