
                         H   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  \R*                  " \R,                  R.                  5       " S S\R0                  5      5       rSSSS.\l        \R*                  " \R,                  R6                  5       " S S\5      5       r\R4                  \l        \R*                  " \R,                  R:                  5       " S S\5      5       r\R4                  \l         " S S\5      r g)z7Command for creating instance with per instance config.    )absolute_import)division)unicode_literals)base_classes)managed_instance_groups_utils)poller)waiter)base)flags)instance_configs_messagesc                   J    \ rS rSrSr\S 5       r\S 5       rS r	S r
S rSrg	)
CreateInstanceGA   BCreate a new virtual machine instance in a managed instance group.c                 t    [         R                  " SS9R                  USS9  [         R                  " U5        g )NT)region_flagzcreate instance in)operation_type)instance_groups_flagsGetInstanceGroupManagerArgAddArgumentAddCreateInstancesFlags)clsparsers     >lib/surface/compute/instance_groups/managed/create_instance.pyArgsCreateInstanceGA.Args#   s6    44%+#7 & 911&9    c                    UR                  5       S:X  a3  U R                  R                  UUR                  UR                  S.SS9nOrUR                  5       S:X  a6  U R                  R                  UUR                  UR
                  S-   S.SS9nO([        SR                  UR                  5       5      5      eU(       d%  [        R                  " SR                  U5      5      eU$ )	zDCreates reference to instance in instance group (zonal or regional).zcompute.instanceGroupManagers)projectzonezcompute.instances)params
collectionz#compute.regionInstanceGroupManagersz-azUnknown reference type {0}z%Instance name {0} cannot be resolved.)

Collection	resourcesParser   r    region
ValueErrorformatr   !ResourceCannotBeResolvedException)holderigm_refinstance_nameinstance_refs       r   _CreateNewInstanceReference,CreateInstanceGA._CreateNewInstanceReference*   s     >>%%++
 ll ) , *l 
			!F	F%%++
 nnt+ ) , *l 3::



  ! !)KK
1
8
8
GI Ir   c                    U R                  U5        [        R                  " U R                  5       5      nUR                  nUR
                  n[        R                  R                  UU[        R                  " U5      S9nU R                  X%UR                  S9nU R                  X&U5      n[        R                  " UUUS9u  p[         R"                  " U	5      n
[$        R&                  " XS5      nU$ )N)scope_lister)r*   r+   r,   )r*   r+   per_instance_config_messagezCreating instance.)(_ValidateStatefulFlagsForInstanceConfigsr   ComputeApiHolderReleaseTrackclientr$   r   %MULTISCOPE_INSTANCE_GROUP_MANAGER_ARGResolveAsResourcecompute_flagsGetDefaultScopeListerr.   instance_CreatePerInstanceConfgMessager   CallCreateInstancesr   Pollerr	   WaitFor)selfargsr*   r6   r$   r+   r-   r2   operation_refserviceoperation_pollercreate_results               r   RunCreateInstanceGA.RunE   s    11$7**4+<+<+>?F]]F  I$JJ!! - C CF K " M  33dmm 4 EL #'"E"Ed#$ 7JJ$?AM
 }}W-NN#3#79Mr   c                 Z    [         R                  " USS9  [         R                  " U/ / S9  g )NT)need_disk_source)current_internal_addressescurrent_external_addresses)r   *ValidateMigStatefulFlagsForInstanceConfigs,ValidateMigStatefulIPFlagsForInstanceConfigs)r@   rA   s     r   r3   9CreateInstanceGA._ValidateStatefulFlagsForInstanceConfigsb   s*    DDt%FFr   c           
          [         R                  " UUUR                  UR                  UR                  UR
                  [        5       S9$ )N)disk_getter)r   %CreatePerInstanceConfigMessageWithIPsstateful_diskstateful_metadatastateful_internal_ipstateful_external_ipNonExistentDiskGetter)r@   r*   r-   rA   s       r   r<   /CreateInstanceGA._CreatePerInstanceConfgMessagei   sE    $JJ!!!!)+ r    N)__name__
__module____qualname____firstlineno____doc__classmethodr   staticmethodr.   rF   r3   r<   __static_attributes__rX   r   r   r   r      s:    J: :  4:	r   r   zCreate a new virtual machine instance in a managed instance group with a defined name and optionally its stateful configuration.aK        *{command}* creates a  virtual machine instance with a defined name and
      optionally its stateful configuration: stateful disk, stateful
      metadata key-values, and stateful IP addresses. Stateful configuration
      is stored in the corresponding newly created per-instance config.
      An instance with a per-instance config will preserve its given name,
      specified disks, specified metadata key-values, and specified internal
      and external IPs during instance recreation, auto-healing, updates,
      and any other lifecycle transitions of the instance.
      a        To create an instance `instance-1` in `my-group`
      (in region europe-west4) with metadata `my-key: my-value`, a disk
      `disk-1` attached to it as the device `device-1`,
      stateful internal IP `192.168.0.10` on the default interface (nic0),
      and existing address reservation `my-address` for stateful external IP
      on interface `nic1`, run:

          $ {command} \
                my-group --region=europe-west4 \
                --instance=instance-1 \
                --stateful-disk='device-name=foo,source=https://compute.googleapis.com/compute/alpha/projects/my-project/zones/europe-west4/disks/disk-1,mode=rw,auto-delete=on-permanent-instance-deletion' \
                --stateful-metadata='my-key=my-value' \
                --stateful-internal-ip=address=192.168.0.10,auto-delete=on-permanent-instance-deletion \
                --stateful-external-ip=address=/projects/example-project/regions/europe-west4/addresses/my-address,interface-name=nic1
      )briefDESCRIPTIONEXAMPLESc                       \ rS rSrSrSrg)CreateInstanceBeta   r   rX   NrY   rZ   r[   r\   r]   r`   rX   r   r   re   re          Jr   re   c                       \ rS rSrSrSrg)CreateInstanceAlpha   r   rX   Nrg   rX   r   r   rj   rj      rh   r   rj   c                   $    \ rS rSrSrS rS rSrg)rV      z!Placeholder class returning None.c                     SU l         g )NFinstance_exists)r@   s    r   __init__NonExistentDiskGetter.__init__   s
     Dr   c                     g )NrX   )r@   device_names     r   get_diskNonExistentDiskGetter.get_disk   s    
r   ro   N)rY   rZ   r[   r\   r]   rq   ru   r`   rX   r   r   rV   rV      s    )!r   rV   N)!r]   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   "googlecloudsdk.command_lib.computer   r9   2googlecloudsdk.command_lib.compute.instance_groupsr   Kgooglecloudsdk.command_lib.compute.instance_groups.managed.instance_configsr   ReleaseTracksr5   GACreateCommandr   detailed_helpBETAre   ALPHArj   objectrV   rX   r   r   <module>r      s   > &  ' 7 H < . ( E ] q D%%(()Rt)) R *Rn	I	

"  D D%%**+K) K ,K $4#A#A    D%%++,K, K -K %7$D$D  !F r   