
    n                      l   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r\R.                  " \R0                  R2                  5       " S S\R4                  5      5       rSSSR9                  SSSSSSSS9S.\l        \R.                  " \R0                  R<                  5       " S S\5      5       r\R:                  \l        \R.                  " \R0                  R@                  5       " S S\5      5       r!\R:                  \!l        g) z)Command for creating per-instance config.    )absolute_import)division)unicode_literals)base_classes)managed_instance_groups_utils)poller)waiter)base)flags)instance_configs_getter)instance_configs_messagesNc                   J    \ rS rSrSr\S 5       r\S 5       rS r	S r
S rSrg	)
CreateGA#   GCreate per-instance config for an instance in a managed instance group.c                     [         R                  " SS9R                  USS9  [         R                  " U5        [         R                  " U5        [         R
                  " U5        g )NT)region_flagz create a per-instance config for)operation_type)instance_groups_flagsGetInstanceGroupManagerArgAddArgument%AddMigStatefulFlagsForInstanceConfigs AddMigStatefulUpdateInstanceFlag(AddMigStatefulIPsFlagsForInstanceConfigsclsparsers     Flib/surface/compute/instance_groups/managed/instance_configs/create.pyArgsCreateGA.Args'   sS    44%+#E & G??G::6BBB6J    c                    UR                  S5      (       d  UR                  S5      (       a  U R                  R                  U5      $ [        R                  " XU/S9nU(       d%  [        R
                  " SR                  U5      5      eUS   $ )zDCreates reference to instance in instance group (zonal or regional).zhttps://zhttp://)holderigm_refinstance_namesz$Instance name {0} cannot be resolvedr   )
startswith	resourcesParseURLr   CreateInstanceReferences!ResourceCannotBeResolvedExceptionformat)r#   r$   instance_nameinstance_referencess       r   _CreateInstanceReference!CreateGA._CreateInstanceReference0   s     
++}/G/G0 0&&}55%>>M?L )KK
0
7
7
FH Hq!!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[        R                  " U5      nUR                  XVSS9  U R!                  X&U5      n["        R$                  " UUUS9n	UR'                  5       S:X  a  UR(                  R*                  n
OSUR'                  5       S:X  a  UR(                  R,                  n
O([/        SR1                  UR'                  5       5      5      e[2        R4                  " U
5      n[6        R8                  " XS	5      nUR:                  (       aM  ["        R<                  " UU[>        R@                  " U5      /URB                  S
9n[6        R8                  " XS5      $ U$ )N)scope_lister)r#   r$   r,   F)r$   instance_refshould_exist)r#   r$   per_instance_config_messagezcompute.instanceGroupManagersz#compute.regionInstanceGroupManagerszUnknown reference type {0}zCreating instance config.)r#   r$   	instancesminimal_actionzApplying updates to instances.)"(_ValidateStatefulFlagsForInstanceConfigsr   ComputeApiHolderReleaseTrackclientr'   r   %MULTISCOPE_INSTANCE_GROUP_MANAGER_ARGResolveAsResourcecompute_flagsGetDefaultScopeListerr.   instancer   $InstanceConfigsGetterWithSimpleCachecheck_if_instance_config_exists_CreatePerInstanceConfigMessager   CallPerInstanceConfigUpdate
Collectionapitools_clientinstanceGroupManagersregionInstanceGroupManagers
ValueErrorr+   r   Pollerr	   WaitForupdate_instanceCallApplyUpdatesToInstancessix	text_typeinstance_update_minimal_action)selfargsr#   r:   r'   r$   r2   configs_getterr4   operation_refserviceoperation_pollercreate_resultapply_operation_refs                 r   RunCreateGA.Run>   s   11$7**4+<+<+>?F]]F  I$JJ   - C CF K !   00dmm 1 EL 	 DDN 22 3 H #'"F"Fd#$ .II$?AM
 >>&&<<g				!F	F&&BBg3::



  ! ! }}W-NN#3#>@M 
#
?
?|45!@@B ^^,<> > r!   c                 \    [         R                  " U5        [         R                  " U/ / S9  g )N)rQ   current_internal_addressescurrent_external_addresses)r   *ValidateMigStatefulFlagsForInstanceConfigs,ValidateMigStatefulIPFlagsForInstanceConfigs)rP   rQ   s     r   r7   1CreateGA._ValidateStatefulFlagsForInstanceConfigsu   s&    DDTJFFbRQr!   c                     [         R                  " UUUR                  UR                  UR                  UR
                  5      $ N)r   %CreatePerInstanceConfigMessageWithIPsstateful_diskstateful_metadatastateful_internal_ipstateful_external_ip)rP   r#   r2   rQ   s       r   rB   (CreateGA._CreatePerInstanceConfigMessagez   s?    $JJ!!!! r!    N)__name__
__module____qualname____firstlineno____doc__classmethodr   staticmethodr.   rX   r7   rB   __static_attributes__rh   r!   r   r   r   #   s>    OK K " "5nQ
r!   r   zICreate a per-instance config for an instance in a managed instance group.a          *{command}* creates a per-instance config for an instance controlled by
        a Compute Engine managed instance group. An instance with a per-instance
        config preserves the specified metadata and/or disks during
        instance recreation and deletion.

        Once created, the config is applied immediately to the corresponding
        instance, by performing the necessary action (for example, REFRESH),
        unless overridden by providing the ``--no-update-instance'' flag.
        ae          To create a per-instance config with a stateful disk ``my-disk'' and to
        add stateful metadata ``my-key:my-value'', on instance
        ``my-instance'', run:

          $ {{command}} {group} {region} {instance} {disk} {metadata}

        If ``my-disk'' did not exist previously in the per-instance config,
        and if it does not exist in the group's instance template, then the
        command adds ``my-disk'' to my-instance.

        To create a per-instance config with a stateful internal IP
        ``192.168.0.10'' and a stateful external IP reserved in address
        ``my-address'', on instance ``my-instance'', run:

          $ {{command}} {group} {region} {instance} {internal_ip} {external_ip}

        If the provided IP address is not yet reserved, the MIG automatically
        creates a corresponding IP address reservation.
        zmy-groupz--region=europe-west4z--instance=my-instancezb--stateful-disk=device-name=my-disk,source=projects/my-project/zones/us-central1-a/disks/my-disk-3z%--stateful-metadata="my-key=my-value"z?--stateful-internal-ip=address=192.168.0.10,interface-name=nic0zv--stateful-external-ip=address=/projects/example-project/regions/europe-west4/addresses/my-address,interface-name=nic0)groupregionr?   diskmetadatainternal_ipexternal_ip)briefDESCRIPTIONEXAMPLESc                   (    \ rS rSrSr\S 5       rSrg)
CreateBeta   r   c                 .    [         R                  U5        g ra   )r   r   r   s     r   r   CreateBeta.Args   s    MM&r!   rh   Nri   rj   rk   rl   rm   rn   r   rp   rh   r!   r   r{   r{      s    O r!   r{   c                   (    \ rS rSrSr\S 5       rSrg)CreateAlpha   r   c                 .    [         R                  U5        g ra   )r{   r   r   s     r   r   CreateAlpha.Args   s    OOFr!   rh   Nr   rh   r!   r   r   r      s    O r!   r   )"rm   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   "googlecloudsdk.command_lib.computer   r=   2googlecloudsdk.command_lib.compute.instance_groupsr   Kgooglecloudsdk.command_lib.compute.instance_groups.managed.instance_configsr   r   rM   ReleaseTracksr9   GACreateCommandr   r+   detailed_helpBETAr{   ALPHAr   rh   r!   r   <module>r      s9    0 &  ' 7 H < . ( E ] o q 
 D%%(()^t!! ^ *^F	"	& F&)F 9M#  E5 p D%%**+  , $11
  D%%++,*  - '44 r!   