
    W                        S r SSKJr  SSKJr  SSKJr  SSK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rSr " S S\R6                  5      r " S S\R6                  5      r " S S\R<                  5      r " S S\R@                  5      r!ShS jr"ShS jr#\RH                  " S\RJ                  SS\RL                  \RN                  S9r(\RH                  " S\SS \RL                  \RN                  S9r)\RH                  " SS!S"\SS \RL                  \RN                  S#9r*S$ r+S% r,S& r-S' r.S( r/S) r0S* r1S+ r2S, r3SiS- jr4S. r5S/r6S0r7S1r8\Rr                  Rt                  \6\Rr                  Rv                  \7\Rr                  Rx                  \80r=/ S2Qr>\Rr                  Rx                  \>0r? " S3 S45      r@\Rr                  Rx                  4S5\\A   4S6 jjrBS7 rC\Rr                  Rx                  4S5\A4S8 jjrD\Rr                  Rt                  4S9 jrES:rF\FS;-   rG\GS<-   rHS=rIS>rJS?rKS@rLSArMSBrNSCrOSDrP\OSE-   rQ\QSF-   rRSGrSSHrTSIrUSJrVSK\V-   rWSL\V-   SM-   rXSNrYSO rZSP r[SQ r\SR r]SS r^ST r_SU r`SV raSW rbSX rc  SjSY jrdSZ reS[ rfS\ rgS] rh  SjS^ jri ShS_ jrjShS` jrkSa rlSb rmSc rnSd roSe rpSf rqSg rrg)kz;Flags and helpers for the compute instance groups commands.    )absolute_import)division)unicode_literalsN)List)managed_instance_groups_utils)utils)arg_parsers)base)
exceptions)
completers)flags)scopenic0c                   (   ^  \ rS rSrU 4S jrSrU =r$ )&RegionalInstanceGroupManagersCompleter)   c                 4   > [         [        U ]
  " SSSS.UD6  g )N#compute.regionInstanceGroupManagersz<compute instance-groups managed list --uri --filter=region:*
collectionlist_command )superr   __init__selfkwargs	__class__s     ?lib/googlecloudsdk/command_lib/compute/instance_groups/flags.pyr   /RegionalInstanceGroupManagersCompleter.__init__,   s*    	
0$@ 8* 	    r   __name__
__module____qualname____firstlineno__r   __static_attributes____classcell__r   s   @r   r   r   )        r!   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )#ZonalInstanceGroupManagersCompleter4   c                 4   > [         [        U ]
  " SSSS.UD6  g )Ncompute.instanceGroupManagersz:compute instance-groups managed list --uri --filter=zone:*r   r   )r   r,   r   r   s     r   r   ,ZonalInstanceGroupManagersCompleter.__init__7   s*    	
-t= 2( 	r!   r   r"   r)   s   @r   r,   r,   4   r*   r!   r,   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )InstanceGroupManagersCompleter?   c                 F   > [         [        U ]
  " SS[        [        /0UD6  g )Nr   r   )r   r2   r   r   r,   r   s     r   r   'InstanceGroupManagersCompleter.__init__A   s-    	
($8 :79 r!   r   r"   r)   s   @r   r2   r2   ?   s     r!   r2   c                   F    \ rS rSrSrSrSrS r\S 5       r	\S 5       r
Srg	)
AutoDeleteFlagH   z'CLI flag values for `auto-delete' flag.neverzon-permanent-instance-deletionc                 &    U" U R                   5      $ N)name)r   	base_enums     r   GetAutoDeleteEnumValue%AutoDeleteFlag.GetAutoDeleteEnumValueN   s    TYYr!   c                     [          Vs/ s H  nUR                  PM     nnX;  a$  [        R                  " USR	                  U 5      S9e[        U 5      $ s  snf )NzVValue for [auto-delete] must be [never] or [on-permanent-instance-deletion], not [{0}]parameter_namemessage)r7   valuer   InvalidArgumentExceptionformat)
flag_value	flag_nameauto_delete_flag_valuevaluess       r   ValidateAutoDeleteFlag%AutoDeleteFlag.ValidateAutoDeleteFlagQ   sl     '5&4" 	$$&4   //"88>z8JL L *%%s   Ac                    ^  U 4S jnU$ )Nc                 0   > [         R                  U T5      $ r;   )r7   rK   )rG   rH   s    r   	Validator7AutoDeleteFlag.ValidatorWithFlagName.<locals>.Validator`   s    22:yIIr!   r   )rH   rO   s   ` r   ValidatorWithFlagName$AutoDeleteFlag.ValidatorWithFlagName^   s    Jr!   r   N)r#   r$   r%   r&   __doc__NEVERON_PERMANENT_INSTANCE_DELETIONr>   staticmethodrK   rQ   r'   r   r!   r   r7   r7   H   s=    /
%#C   
& 
&  r!   r7   c                 j    [         R                  " S[        R                  U S[         R                  S9$ )Ninstance groupcompute.instanceGroups)resource_name	completerpluralzonal_collectionzone_explanation)r   ResourceArgumentcompute_completersInstanceGroupsCompleterZONE_PROPERTY_EXPLANATIONr\   s    r   MakeZonalInstanceGroupArgrd   e   s0    			$"::/66
8 8r!   c           	      X    [         R                  " SS[        U S[         R                  S9$ )NINSTANCE_GROUP_MANAGERmanaged instance groupr/   )r<   rZ   r[   r\   r]   r^   )r   r_   r,   rb   rc   s    r    MakeZonalInstanceGroupManagerArgrh   n   s-    			#,3666
8 8r!   rX   rY   zcompute.regionInstanceGroupsrZ   r[   r]   regional_collectionr^   region_explanationrg   r/   r   Tnames)rZ   r\   r<   r[   r]   rj   r^   rk   c                 $    U R                  SSS9  g )NgroupzThe name of the instance group.helpadd_argumentparsers    r   AddGroupArgru      s    ,  .r!   c                 P    U R                  SS[        R                  " 5       SSS9  g)z$Adds flags for handling named ports.z--named-portsTz	NAME:PORTa/            The comma-separated list of key:value pairs representing
          the service name and the port that it is running on.

          To clear the list of named ports pass empty list as flag value.
          For example:

            $ {command} example-instance-group --named-ports ""
          )requiredtypemetavarrp   N)rr   r	   ArgListrs   s    r   AddNamedPortsArgsr{      s/       r!   c                     U(       a[  U R                  5       n[        R                  " USS[        R                  S9  [        R                  " USS[        R
                  S9  g[        R                  " U SSS9  g)zAdds flags for group scope.rX   zset named ports for)resource_typeoperation_typeexplanation)r}   r~   N)add_mutually_exclusive_groupr   AddRegionFlag&REGION_PROPERTY_EXPLANATION_NO_DEFAULTAddZoneFlag$ZONE_PROPERTY_EXPLANATION_NO_DEFAULT)rt   
multizonalscope_parsers      r   AddScopeArgsr      sp    668L	&,@@	B
 
&,>>	@ 
&,.r!   c           	      l    U R                  SSS[        R                  " SS9[        R                  / S9  g)zAAdd flags for choosing zones for regional managed instance group.--zonesZONEa            If this flag is specified a regional managed instance group will be
          created. The managed instance group will be in the same region as
          specified zones and will spread instances in it between specified
          zones.

          All zones must belong to the same region. You may specify --region
          flag but it must be the region to which zones belong. This flag is
          mutually exclusive with --zone flag.   
min_length)ry   rp   rx   r[   defaultN)rr   r	   rz   r`   ZonesCompleterrs   s    r   AddZonesFlagr      s<    2 !,"11  r!   c                    SS0nU R                   (       a(  U R                  (       a  [        R                  " SS5      e/ nU R                    H3  nUR	                  USUS9nUR                  UR                  5       5        M5     [        U Vs/ s H  n[        R                  " U5      PM     sn5      n[        U5      S:  a  [        R                  " SS5      e[        U5      S:X  aj  U R                  (       aX  UR                  5       nUR	                  U R                  S	US9n	U	R                  5       n
X:w  a  [        R                  " SS
5      egggs  snf )zBValidate arguments specifying scope of the managed instance group.projectfakez--zoner   zcompute.zones)r   paramsr   z%All zones must be in the same region.zcompute.regionsz(Specified zones not in specified region.N)zoneszoner   ConflictingArgumentsExceptionParseappendNamesetr   ZoneNameToRegionNamelenrE   regionpop)args	resourcesignored_required_params
zone_namesr   zone_refzzone_regionszone_region
region_refr   s              r   %ValidateManagedInstanceGroupScopeArgsr      s=   &/	ZZDII

2
28Y
GG*jjd1H  JHhmmo& 
 ZHZe003ZHI,

-
-:< <
<A$++""$K9J(? ! AJ__F//
?A A  #.	 Is    Ec           	      b   [        5       nU =(       d    /  H  nUR                  S5      (       d  [        R                  " USS9eUR                  S5      U;   a3  [        R                  " USR	                  UR                  S5      5      S9eUR                  UR                  S5      5        M     g)z>Validate device-name and auto-delete flags in a stateful disk.device-name[device-name] is requiredrA   3[device-name] `{0}` is not unique in the collectionNr   getr   rE   rF   add)stateful_disksrH   device_namesstateful_disks       r   ValidateStatefulDisksDictr      s    ,%++m]++//",GI I'<7//"GNN.01 1 ]&&}56 ,r!   c                 >   [        5       nU =(       d    /  H  nUR                  S5      (       d  SU;   d  [        R                  " USS9eUR                  S[        5      nXB;   a$  [        R                  " USR                  U5      S9eUR                  U5        M     g)zHValidate enabled, interface-name and auto-delete flags in a stateful IP.interface-nameenabledz0one of: [interface-name], [enabled] is required.rA   6[interface-name] `{0}` is not unique in the collectionN)r   r   r   rE   "STATEFUL_IP_DEFAULT_INTERFACE_NAMErF   r   )stateful_ipsrH   interface_namesstateful_ipinterface_names        r   ValidateStatefulIPDictsr      s    E/!'R'k__-..[(//"@C C
 !__%5%GIN (//"
B
I
I 
 '' (r!   c                 0    [        U R                  S5        g )N--stateful-disk)r   r   r   s    r   3ValidateManagedInstanceGroupStatefulDisksPropertiesr     s    D..0ABr!   c                 \    [        U R                  S5        [        U R                  S5        g )N--stateful-internal-ip--stateful-external-ip)r   stateful_internal_ipstateful_external_ipr   s    r   1ValidateManagedInstanceGroupStatefulIPsPropertiesr     s$    $335MN$335MNr!   c           	          U (       a  Sn[         R                  U-   nO[         R                  nU(       a  SnOSn[         R                  " S[        SU[         R                  US9$ )zBReturns ResourceArgument for working with instance group managers.zy

If you specify `--zones` flag this flag must be unspecified or specify the region to which the zones you listed belong.r   Nrg   r/   ri   )r   r   r_   r2   r   )
zones_flagregion_flag"extra_region_info_about_zones_flagrk   rj   s        r   GetInstanceGroupManagerArgr     sn    	F '  FF<= EE?			,.6-AA+
- -r!   c                     [        5       n[        R                  R                  n[        R
                  " U 5      nUR                  X!UUS9$ )N)default_scopescope_lister)r   compute_scope	ScopeEnumr   r   GetDefaultScopeListerResolveAsResource)clientr   r   resource_argr   r   s         r   CreateGroupReferencer   4  sK    +-,))..-,,V4,		'	'
] 
( 
! !r!   a          table(name:label=NAME,
              instance.scope().segment(0):label=ZONE,
              instanceStatus:label=STATUS,
              instanceHealth[0].detailedHealthState:label=HEALTH_STATE,
              currentAction:label=ACTION,
              version.instanceTemplate.basename():label=INSTANCE_TEMPLATE,
              version.name:label=VERSION_NAME,
              lastAttempt.errors.errors.map().format(
                "Error {0}: {1}", code, message).list(separator=", ")
                :label=LAST_ERROR
        )aI          table(name:label=NAME,
              instance.scope().segment(0):label=ZONE,
              instanceStatus:label=STATUS,
              instanceHealth[0].detailedHealthState:label=HEALTH_STATE,
              currentAction:label=ACTION,
              preservedState():label=PRESERVED_STATE,
              version.instanceTemplate.basename():label=INSTANCE_TEMPLATE,
              version.name:label=VERSION_NAME,
              lastAttempt.errors.errors.map().format(
                "Error {0}: {1}", code, message).list(separator=", ")
                :label=LAST_ERROR
        )a          table(name:label=NAME,
              instance.scope().segment(0):label=ZONE,
              instanceStatus:label=STATUS,
              instanceHealth[0].detailedHealthState:label=HEALTH_STATE,
              currentAction:label=ACTION,
              preservedState():label=PRESERVED_STATE,
              version.instanceTemplate.basename():label=INSTANCE_TEMPLATE,
              version.name:label=VERSION_NAME,
              lastAttempt.errors.errors.map().format(
                "Error {0}: {1}", code, message).list(separator=", ")
                :label=LAST_ERROR,
              scheduling.terminationTimestamp:label=TERMINATION_TIMESTAMP
        ))	NAMEr   STATUSHEALTH_STATEACTIONPRESERVED_STATEINSTANCE_TEMPLATEVERSION_NAME
LAST_ERRORc                   x    \ rS rSrSrSr\\R                  R                  4S\
\   4S jj5       r\S 5       rSrg)	DynamicFieldi  z;Represents dynamic fields in list managed instances output.TERMINATION_TIMESTAMPreturnc                     / nU[         R                  R                  :X  a  U$ U[         R                  R                  :X  a  U$ U R	                  U5      (       a  UR                  U R                  5        U$ )zReturns dynamic fields for a managed instance based on its properties.

Args:
  instance: Managed instance.
  release_track: Release track.
Returns:
  List of dynamic fields.
)r
   ReleaseTrackGABETA_HasTerminationTimestampr   r   )clsinstancerelease_trackdynamic_fieldss       r   GetManagedInstanceDynamicFields,DynamicField.GetManagedInstanceDynamicFields  sh     N)),,,))...
##H--C556r!   c                 T    [        US5      =(       a    [        UR                  S5      $ )N
schedulingterminationTimestamp)hasattrr   )r   r   s     r   r   %DynamicField._HasTerminationTimestamp  s)    8\* w30 r!   r   N)r#   r$   r%   r&   rS   r   classmethodr
   r   ALPHAr   strr   r   r'   r   r!   r   r   r     sL    C1#'#4#4#:#:Cy ,  r!   r   r   c                     [        5       nU  H'  nUR                  [        R                  X15      5        M)     [	        U5      $ )a  Returns dynamic fields for a list of managed instances.

Dynamic fields are determined based on the properties of the instances
and the release track.

Args:
  managed_instances: List of managed instances.
  release_track: Release track.
Returns:
  List of dynamic fields.
)r   updater   r   list)managed_instancesr   r   r   s       r   _GetIgmDynamicFieldsr     s@     5.#h,FF  $ 
n	r!   c                     SnSU ;   a  U S   (       a  US-  nSU ;   a  U S   (       a  US-  nUR                  S5      (       a  USS nU$ )	aP  Transform for the PRESERVED_STATE field in the table output.

PRESERVED_STATE is generated from the fields preservedStateFromPolicy and
preservedStateFromConfig fields in the managedInstance message.

Args:
  instance: instance dictionary for transform

Returns:
  Preserved state status as one of ('POLICY', 'CONFIG', 'POLICY,CONFIG')
 preservedStateFromPolicyzPOLICY,preservedStateFromConfigCONFIG,N)endswith)r   preserved_state_values     r   _TransformPreservedStater    sf      H,)*Y& H,)*X%##C((1#26	r!   c                 ^    [         U   n[        X5      nX#-   nSSR                  U5      -  nU$ )a>  Builds an output format string with dynamic fields (if they are present).

The output format is a projection `(field1,field2)` which is then
applied to the default `table(...)` format.

Args:
    managed_instances: List of managed instances.
    release_track: Release track.

Returns:
    The complete output format.
z(%s)r  )3_RELEASE_TRACK_TO_LIST_INSTANCES_BASE_STATIC_FIELDSr   join)r   r   static_fieldsr   complete_fieldscomplete_formats         r   'GetListInstancesOutputWithDynamicFieldsr    s@     F- ((9I.!2/SXXo66/	r!   c                     U R                   R                  S[        05        U R                   R                  [        U   5        g )NpreservedState)display_infoAddTransformsr  	AddFormat'_RELEASE_TRACK_TO_LIST_INSTANCES_FORMAT)rt   r   s     r   AddListInstancesOutputFormatr    s?    ##0%  	-m<>r!   z
      Disks considered stateful by the instance group. Managed instance groups
      preserve and reattach stateful disks on VM autohealing, update, and
      recreate events.
      z
      You can also attach and preserve disks, not defined in the group's
      instance template, to a given instance.

      The same disk can be attached to more than one instance but only in
      read-only mode.
      aI  
      Use this argument multiple times to update multiple disks.

      If stateful disk with given `device-name` exists in current instance
      configuration, its properties will be replaced by the newly provided ones.
      In other case new stateful disk definition will be added to the instance
      configuration.
      zL
      *device-name*::: Name under which disk is or will be attached.
      z
      *source*::: Optional argument used to specify the URI of an existing
      persistent disk to attach under specified `device-name`.
      a  
      *mode*::: Specifies the mode of the disk to attach. Supported options are
      `ro` for read-only and `rw` for read-write. If omitted when source is
      specified, `rw` is used as a default. `mode` can only be specified if
      `source` is given.
      a  
      *auto-delete*::: (Optional) Specifies the auto deletion policy of the
      stateful disk. The following options are available:
      - ``never'': (Default) Never delete this disk. Instead, detach the disk
          when its instance is deleted.
      - ``on-permanent-instance-deletion'': Delete the stateful disk when the
          instance that it's attached to is permanently deleted from the group;
          for example, when the instance is deleted manually or when the group
          size is decreased.
      a  
      Additional metadata to be made available to the guest operating system
      in addition to the metadata defined in the instance template.

      Stateful metadata may be used to define a key/value pair specific for
      the one given instance to differentiate it from the other instances in
      the managed instance group.

      Stateful metadata key/value pairs are preserved on instance recreation,
      autohealing, updates, and any other lifecycle transitions of the
      instance.

      Stateful metadata have priority over the metadata defined in the
      instance template. This means that stateful metadata that is defined for a
      key that already exists in the instance template overrides the instance
      template value.

      Each metadata entry is a key/value pair separated by an equals sign.
      Metadata keys must be unique and less than 128 bytes in length. Multiple
      entries can be passed to this flag, e.g.,
      ``{argument_name} key-1=value-1,key-2=value-2,key-3=value-3''.
      a  
      If stateful metadata with the given key exists in current instance
      configuration, its value will be overridden with the newly provided one.
      If the key does not exist in the current instance configuration, a new
      key/value pair will be added.
      zq
      Managed instance groups preserve stateful IPs on VM autohealing, update,
      and recreate events.
      a\  
      Use this argument multiple times to update more IPs.

      If a stateful {ip_type} IP with the given interface name already exists in
      the current instance configuration, its properties are replaced by the
      newly provided ones. Otherwise, a new stateful {ip_type} IP definition
      is added to the instance configuration.
      z
      You can preserve the IP address that's specified in a network interface
      for a specific managed instance, even if that network interface is not
      defined in the group's instance template.
      aT  
      Use this argument multiple times to update multiple IPs.

      If a stateful IP with the given network interface name exists in the
      current per-instance configuration, its properties are replaced by
      the newly provided ones. Otherwise, a new stateful IP definition is
      added to the per-instance configuration.
      z
      *enabled*::: Marks the IP address as stateful. The network interface
      named ``nic0'' is assumed by default when ``interface-name'' is not
      specified. This flag can be omitted when ``interface-name'' is provided
      explicitly.
      z
      *interface-name*::: Marks the IP address from this network interface as
      stateful. This flag can be omitted when ``enabled'' is provided.
      z
      *interface-name*::: (Optional) Network interface name. If omitted,
      the default network interface named ``nic0'' is assumed.
      a  
      + Address: URL of a static IP address reservation. For example:
      ``projects/example-project/regions/us-east1/addresses/example-ip-name''.

      + Literal: For example: ``130.211.181.55''.

      If the provided IP address is not yet reserved, the managed instance group
      automatically creates the corresponding IP address reservation. If the
      provided IP address is reserved, the group assigns the reservation to
      the instance.
      zs
        *address*::: Static IP address to assign to the instance in one of
        the following formats:
        zx
      *address*::: (Optional) Static IP address to assign to the instance in
      one of the following formats:
      z
      The ``address'' flag is optional if an address is already defined in
      the instance's per-instance configuration. Otherwise it is required.

      If omitted, the currently configured address remains unchanged.
      aI  
      *auto-delete*::: (Optional) Prescribes what should happen to an associated
      static Address resource when a VM instance is permanently deleted.
      Regardless of the value of the delete rule, stateful IP addresses are
      always preserved on instance autohealing, update, and recreation
      operations. The following options are available:
      - ``never'': (Default) Never delete the static IP address. Instead,
          unassign the address when its instance is permanently deleted and
          keep the address reserved.
      - ``on-permanent-instance-deletion'': Delete the static IP
          address reservation when the instance that it's assigned to is
          permanently deleted from the instance group; for example, when the
          instance is deleted manually or when the group size is decreased.
      c           	          [         R                  " [        S-   [        -   5      nU R	                  S[
        R                  " [        [        R                  S5      S.S9SUS9  g)	z8Adding stateful flags for disks and names to the parser.z
      Use this argument multiple times to attach more disks.

      *device-name*::: (Required) Device name of the disk to mark stateful.
      r   z--stateful_diskr   auto-deletespecr   rx   actionrp   N)
textwrapdedentSTATEFUL_DISKS_HELP_BASE"STATEFUL_DISK_AUTO_DELETE_ARG_HELPrr   r	   ArgDictr   r7   rQ   )rt   stateful_disks_helps     r   AddMigCreateStatefulFlagsr!    sr     (@ D
 )
 /	)/ 0
 	 +AA#%   r!   c                    [         R                  " SR                  [        [        [
        [        5      5      nU R                  S[        R                  " SS[        [        R                  S5      S.S9SUS9  [         R                  " S	R                  [        [        [
        [        5      5      nU R                  S
[        R                  " SS[        [        R                  S
5      S.S9SUS9  g)z(Adding stateful IPs flags to the parser.z
      Internal IPs considered stateful by the instance group. {}
      Use this argument multiple times to make more internal IPs stateful.

      At least one of the following is required:
      {}
      {}

      Additional arguments:
      {}
      r   TNr   r   r  allow_key_onlyr  r   r  z
      External IPs considered stateful by the instance group. {}
      Use this argument multiple times to make more external IPs stateful.

      At least one of the following is required:
      {}
      {}

      Additional arguments:
      {}
      r   )r  r  rF   STATEFUL_IPS_HELP_BASESTATEFUL_IP_ENABLED_ARG_HELP0STATEFUL_IP_INTERFACE_NAME_ARG_WITH_ENABLED_HELP STATEFUL_IP_AUTO_DELETE_ARG_HELPrr   r	   r  r   r7   rQ   )rt   stateful_internal_ips_helpstateful_external_ips_helps      r   AddMigCreateStatefulIPsFlagsr,    s    '

 &'-A13 4 	 #+AA*, %    (

 &'-A13 4 	 #+AA*, %  r!   c                 &    U R                  SSSS9  g )N
--instanceTzO
        URI/name of an existing instance in the managed instance group.
      rw   rp   rq   rs   s    r   )_AddMigStatefulInstanceConfigsInstanceArgr0    s     
  r!   c                    [        U 5        Sn[        R                  " [        [        -   [
        -   [        -   [        -   5      nU R                  U[        R                  " [        [        [        [        R                  U5      S.S9SUS9  U R                  SS[        R                  " SS	9S
S9  Sn[        R                  " [        [         -   R#                  US95      nU R                  U[        R                  " SS	90 [        R$                  S[        R                  " U5      S9  U R                  SS[        R                  " SS	9SS9  g)1Add args for per-instance configs update command.r   r   sourcemoder  r  r   r  --remove-stateful-disksDEVICE_NAMEr   r   zXRemove stateful configuration for the specified disks from the instance's configuration.ry   rx   rp   --stateful-metadataargument_name	KEY=VALUErx   r   r  ry   rp   --remove-stateful-metadataKEYz`Remove stateful configuration for the specified metadata keys from the instance's configuration.N)r0  r  r  +STATEFUL_DISKS_HELP_INSTANCE_CONFIGS_UPDATE"STATEFUL_DISK_DEVICE_NAME_ARG_HELPSTATEFUL_DISK_SOURCE_ARG_HELPSTATEFUL_DISK_MODE_ARG_HELPr  rr   r	   r  r   r7   rQ   rz   STATEFUL_METADATA_HELPSTATEFUL_METADATA_HELP_UPDATErF   StoreOnceAction)rt   stateful_disk_argument_namedisk_help_textstateful_metadata_argument_namemetadata_help_texts        r   +AddMigStatefulFlagsForUpdateInstanceConfigsrK    sg   +F3 !2??2)*,IJ"#%GHJ. 	!  6613
   $ 	!,)	   %:! ==EE7 F 9: 	%!,((??-.  0 	"!,2	  r!   c           
          U R                  U[        R                  " [        [        [        R                  U5      S.S9SUS9  U R                  US[        R                  " SS9US9  g	)
r2  r   addressr  r  r   r  r?  r   r   r8  N)rr   r	   r  r   r7   rQ   rz   )rt   ip_argument_nameip_help_textremove_ip_argument_nameremove_ip_help_texts        r   _AddMigStatefulIPsFlagsrS  6  sx     	  667GH    	!,	  r!   c                     [         R                  " [        [        -   [        -   [
        -   5      nSn[        U SUSU5        [        U SUSU5        g)r2  z}
      List of all stateful IP network interface names to remove from
      the instance's per-instance configuration.
      r   --remove-stateful-internal-ipsr   --remove-stateful-external-ipsN)r  r  )STATEFUL_IPS_HELP_INSTANCE_CONFIGS_UPDATE0STATEFUL_IP_INTERFACE_NAME_ARG_WITH_ADDRESS_HELP%STATEFUL_IP_ADDRESS_ARG_OPTIONAL_HELPr)  rS  )rt   rP  rR  s      r   .AddMigStatefulIPsFlagsForUpdateInstanceConfigsrZ  P  se    078,- ((*,

 &2L:<OQ &2L:<OQr!   c                    [        U 5        Sn[        R                  " [        S-   [        -   [
        -   [        -   [        -   5      nU R                  U[        R                  " [        [        [        [        R                  U5      S.S9SUS9  Sn[        R                  " [        R                  US95      nU R                  U[        R                  " S	S
90 [        R                   SUS9  g)z4Adding stateful flags for creating instance configs.r   zW
        Use this argument multiple times to attach and preserve multiple disks.
      r3  r  r   r  r9  r:  r   r   r<  r=  N)r0  r  r  $STATEFUL_DISKS_HELP_INSTANCE_CONFIGSrA  rB  rC  r  rr   r	   r  r   r7   rQ   rD  rF   rF  )rt   rG  r   rI  rJ  s        r   %AddMigStatefulFlagsForInstanceConfigsr]  c  s
   +F3 !2 + /
 
./1NO ## &HHJ
 	!  6613
   & %:!##7 $ 9: 	%!,((  r!   c           
         [         R                  " SR                  [        [        [
        [        5      5      nSnU R                  U[        R                  " [        [        [        R                  U5      S.S9SUS9  SnU R                  U[        R                  " [        [        [        R                  U5      S.S9SUS9  g)	z8Adding stateful IPs flags for creating instance configs.zx
      {}
      Use this argument multiple times to attach and preserve multiple IPs.

      {}
      {}
      {}
      r   rM  r  r   r  r   N)r  r  rF   "STATEFUL_IPS_HELP_INSTANCE_CONFIGSrX  STATEFUL_IP_ADDRESS_ARG_HELPr)  rr   r	   r  r   r7   rQ   )rt   stateful_ip_help"stateful_internal_ip_argument_name"stateful_external_ip_argument_names       r   (AddMigStatefulIPsFlagsForInstanceConfigsrd    s     __
 &3A-134 (@$(  668:	   " (@$(  668:	   r!   c                 P   U R                  SSSS9  U R                  S[        R                  " [        [        [        [        R                  S5      S.S9S[        R                  " [        5      S	9  S
nU R                  U[        R                  " SS90 [        R                  S[        R                  " [        R                  US95      S9  [        R                  " [        [        -   [        -   [        -   [         -   5      nSnU R                  U[        R                  " [        [        [        R                  U5      S.S9SUR                  SS9S	9  SnU R                  U[        R                  " [        [        [        R                  U5      S.S9SUR                  SS9S	9  g)zAAdding stateful flags for creating and updating instance configs.r.  Tz#Name of the new instance to create.r/  r   r3  r  r   r  r9  r   r   r<  r:  r=  r   rM  internalip_typer   externalN)rr   r	   r  r   r7   rQ   r  r  r\  rF  rD  rF   r&  STATEFUL_IPS_HELP_TEMPLATErX  r`  r)  )rt   rI  stateful_ips_help_text_templatestateful_internal_ip_flag_namestateful_external_ip_flag_names        r   AddCreateInstancesFlagsrn    s   4  6 	  667HI	
 ???@    %:!%!,((??
 
'
'; ( =>  ? %-OO"#89 	%% 	)	)%! $< $ #+AA0 *11*1E   $< $ #+AA0 *11*1E  r!   c                 r    U R                  SSSSS9  U R                  S[        R                  " 5       SSS	9  g
)z-Add flags for applying updates on PIC change.z--update-instanceT
store_truea  
          Apply the configuration changes immediately to the instance. If you
          disable this flag, the managed instance group will apply the
          configuration update when you next recreate or update the instance.

          Example: say you have an instance with a disk attached to it and you
          created a stateful configuration for the disk. If you decide to
          delete the stateful configuration for the disk and you provide this
          flag, the group immediately refreshes the instance and removes the
          stateful configuration for the disk. Similarly if you have attached
          a new disk or changed its definition, with this flag the group
          immediately refreshes the instance with the new configuration.)r   r  rp   z --instance-update-minimal-actionnonezz
          Perform at least this action on the instance while updating, if
          `--update-instance` is set to `true`.)choicesr   rp   N)rr   	mig_flagsInstanceActionChoicesWithNoners   s    r    AddMigStatefulUpdateInstanceFlagru    sQ    L	  M  	(5573	  4r!   c           	         [        5       nU =(       d    /  GHJ  nUR                  S5      (       d  [        R                  " USS9eUR                  S5      U;   a3  [        R                  " USR	                  UR                  S5      5      S9eUR                  UR                  S5      5        UR                  S5      nU(       a*  US;  a$  [        R                  " USR	                  U5      S9eU(       a+  UR                  S5      (       d  [        R                  " US	S9eU(       a  GM  U(       d  GM  UR                  S5      (       a  GM8  [        R                  " US
S9e   g)zAValidates the values of stateful disk flags for instance configs.r   r   rA   r   r5  )rwroz0Value for [mode] must be [rw] or [ro], not [{0}]r4  z+[source] is required for all stateful disksz;[mode] can be set then and only then when [source] is givenNr   )r   rH   
for_updateneed_disk_sourcer   r   
mode_values          r   -ValidateMigStatefulDiskFlagForInstanceConfigsr|  '  sR   
 ,%++m]++//",GI I '<7//"GNN.01 1 ]&&}56""6*Jj4//"DKK 
  1 1( ; ;//"?A A :**]->->x-H-H//"OQ Q3 ,r!   c                    [        5       nU=(       d    /  Hs  nUR                  S[        5      nSU;   d  XR;   d  [        R                  " U SS9eXS;   a$  [        R                  " U SR                  U5      S9eUR                  U5        Mu     g)z?Validates the values of stateful IP flags for instance configs.r   rN  z[address] is requiredrA   r   N)r   r   r   r   rE   rF   r   )rH   r   current_addressesr   r   r   s         r   +ValidateMigStatefulIpFlagForInstanceConfigsr  K  s     E/"(b(k __%5%GIN$2//",CE E (//"J6.!# # ' )r!   c           	          [        U =(       d    / 5      nU=(       d    /  HK  nUR                  S5      U;   d  M  [        R                  " SSR	                  UR                  S5      5      S9e   g )Nr   r6  zNthe same [device-name] `{0}` cannot be updated and removed in one command callrA   r   r   r   rE   rF   )disks_to_removedisks_to_updateremove_stateful_disks_setstateful_disk_to_updates       r   5ValidateMigStatefulDisksRemovalFlagForInstanceConfigsr  _  so    !/"7R8!0!6B!6""=15NN//2228&.22=A3CE E "7r!   c                     [        U =(       d    / 5      n[        UR                  5       5      nUR                  U5      nU(       a3  [        R                  " SSR                  SR                  U5      5      S9eg )Nr>  zPthe same metadata key(s) `{0}` cannot be updated and removed in one command callz, rA   )r   keysintersectionr   rE   rF   r  )entries_to_removeentries_to_updateremove_stateful_metadata_setupdate_stateful_metadata_setkeys_intersections        r   8ValidateMigStatefulMetadataRemovalFlagForInstanceConfigsr  k  sv    !$%6%<"!=!$%6%;%;%=!>2??"$

-
-3006YY01135 5 r!   c           	          [        U=(       d    / 5      nU=(       d    /  HK  nUR                  S5      U;   d  M  [        R                  " U SR	                  UR                  S5      5      S9e   g )Nr   zQthe same [interface-name] `{0}` cannot be updated and removed in one command callrA   r  )rH   ips_to_removeips_to_updateremove_ips_setip_to_updates        r   3ValidateMigStatefulIpsRemovalFlagForInstanceConfigsr  y  sm     }*+.#)r)l()^;//"228&#''(893;= = *r!   c                     [        U R                  SX5        U(       a=  [        U R                  U R                  S9  [	        U R
                  U R                  S9  gg)z<Validates the values of stateful flags for instance configs.r   )r  r  )r  r  N)r|  r   r  remove_stateful_disksr  remove_stateful_metadatastateful_metadata)r   ry  rz  s      r   *ValidateMigStatefulFlagsForInstanceConfigsr    s[     00B0B0A0:N 922**, =77002	 r!   c                     [        SU R                  U5        [        SU R                  U5        U(       a?  [        SU R                  U R                  S9  [        SU R
                  U R                  S9  gg)zFValidates the values of stateful flags for instance configs, with IPs.r   r   rU  )rH   r  r  rV  N)r  r   r   r  remove_stateful_internal_ipsremove_stateful_external_ips)r   current_internal_addressescurrent_external_addressesry  s       r   ,ValidateMigStatefulIPFlagsForInstanceConfigsr    s|    
 ..F.2.G.G.HJ ..F.2.G.G.HJ 7277//1 8277//1 r!   c                 <    U R                  SSU(       a  SOS-   S9  g)z Add --description to the parser.z--descriptionz'An optional description for this group.z< To clear the description, set the value to an empty string.r   ro   Nrq   )rt   ry  s     r   AddDescriptionFlagr    s,    4
 F  r!   c           	         [         R                  " [        S-   [        -   5      nSnU R	                  U[
        R                  " [        [        R                  U5      S.S9SUS9  U R	                  SS[
        R                  " S	S
9SS9  g)z>Add --stateful-disk and --remove-stateful-disks to the parser.a  
      Use this argument multiple times to update more disks.

      If a stateful disk with the given device name already exists in the
      current instance configuration, its properties will be replaced by the
      newly provided ones. Otherwise, a new stateful disk definition will be
      added to the instance configuration.

      *device-name*::: (Required) Device name of the disk to mark stateful.
      r   r  r  r   r  r6  r7  r   r   z6Remove stateful configuration for the specified disks.r8  N)r  r  r  r  rr   r	   r  r   r7   rQ   rz   )rt   r   stateful_disk_flag_names      r   AddMigUpdateStatefulFlagsr    s     (@ 	D
 	)
 /	)/ 	0 .  667NO	    	!,C	  r!   c                    [         R                  " [        [        -   SR	                  [
        [        [        5      -   5      nSnU R                  U[        R                  " SS[        [        R                  U5      S.S9SUR	                  SS	9S
9  SnU R                  U[        R                  " SS[        [        R                  U5      S.S9SUR	                  SS	9S
9  SnU R                  SS[        R                  " SS9UR	                  SS	9S9  U R                  SS[        R                  " SS9UR	                  SS	9S9  g)z%Add stateful IPs flags to the parser.zp
      At least one of the following is required:
      {}
      {}

      Additional arguments:
      {}
      r   TNr#  r$  r   rf  rg  r  r   ri  za
      Remove stateful configuration for the specified interfaces for
      {ip_type} IPs.
      rU  INTERFACE_NAMEr   r   r8  rV  )r  r  r&  rj  rF   r'  r(  r)  rr   r	   r  r   r7   rQ   rz   )rt   rk  rl  rm  &remove_stateful_ips_help_text_templates        r   AddMigUpdateStatefulFlagsIPsr    sy   $,OO !
 &-A133%4! $< $ #+AA02 *11*1E   $< $ #+AA02 *11*1E  ,
( 	&!,1888L	   	&!,1888L	  r!   c                    ^  [        [        R                  " U5      5      n/ nT R                  (       a@  [	        T R                  S5        T R                   Vs/ s H  oDR                  S5      PM     nnT R                  (       a9  [        U 4S jT R                   5       5      (       a  [        R                  " SSS9e[        U5      n[        T R                  =(       d    / 5      nUR                  U5      nU(       a8  [        R                  " SSR                  [        R                  " U5      5      S9eXb-
  nU(       a8  [        R                  " SSR                  [        R                  " U5      5      S9eg	s  snf )
,Check stateful properties of update request.r   r   c              3   `   >#    U  H#  nTR                   R                  U5      S :  v   M%     g7fr   N)r  count).0xr   s     r   	<genexpr>5ValidateUpdateStatefulPolicyParams.<locals>.<genexpr>$  s.      -+A 	""((+a/+s   +.r   zWWhen removing device names from Stateful Policy, please provide each name exactly once.rA   zUYou cannot simultaneously add and remove the same device names {} to Stateful Policy.z]Disks [{}] are not currently set as stateful, so they cannot be removed from Stateful Policy.N)r   r    GetDeviceNamesFromStatefulPolicyr   r   r   r  anyr   rE   r  rF   six	text_type)	r   current_stateful_policycurrent_device_namesupdate_disk_namesr   
update_set
remove_setr  not_current_device_namess	   `        r   "ValidateUpdateStatefulPolicyParamsr    sh   #DD
!#$ 	d002CD>B>P>P>P]-(>P   

 -++- - - //!(* * $%*4--34*((4,

-
-
"F3==#>?	B B
 (>

-
-CCI6]]#;<D>@ @ 1s   E;c                 r  ^ / nU(       a9  [        X15        U H(  nUR                  UR                  S[        5      5        M*     U=(       d    / m[	        U4S jT 5       5      (       a$  [
        R                  " SSR                  U5      S9e[        U5      n[        T5      n	UR                  U	5      n
U
(       a9  [
        R                  " SSR                  [        R                  " U
5      U5      S9eX-
  nU(       a9  [
        R                  " SSR                  [        R                  " U5      U5      S9eg)	r  r   c              3   L   >#    U  H  nTR                  U5      S :  v   M     g7fr  )r  )r  r  remove_interface_namess     r   r  C_ValidateUpdateStatefulPolicyParamsWithIPsCommon.<locals>.<genexpr>P  s(      	'%! ""1%)%s   !$r   zlWhen removing stateful {} IPs from Stateful Policy, please provide each network interface name exactly once.rA   zeYou cannot simultaneously add and remove the same interface {} to stateful {} IPs in Stateful Policy.ziInterfaces [{}] are not currently set as stateful {} IPs, so they cannot be removed from Stateful Policy.N)r   r   r   r   r  r   rE   rF   r   r  r  r  )current_interface_namesupdate_flag_nameremove_flag_name
update_ips
remove_ipsip_type_nameupdate_interface_namesr   r  r  r  not_current_interface_namesr  s               @r   0_ValidateUpdateStatefulPolicyParamsWithIPsCommonr  @  s<    J9!##
//*,N
OQ " &+ 	'%	' ' ' 
-
-@@FA	    )**)**((4,

-
-
//5v]]<(,08	: : !+ D 

-
-CCI6]]#>?DOQ Q !r!   c                     [        [        R                  " U5      5      n[        USSU R                  U R
                  S5        g)z9Check stateful internal IPs properties of update request.r   rU  rf  N)r   r   1GetInterfaceNamesFromStatefulPolicyForInternalIPsr  r   r  r   r  r  s      r   2_ValidateUpdateStatefulPolicyParamsWithInternalIPsr  n  L      #889
!#$ 3 @
!B!BJPr!   c                     [        [        R                  " U5      5      n[        USSU R                  U R
                  S5        g)z9Check stateful external IPs properties of update request.r   rV  ri  N)r   r   1GetInterfaceNamesFromStatefulPolicyForExternalIPsr  r   r  r  s      r   2_ValidateUpdateStatefulPolicyParamsWithExternalIPsr  {  r  r!   c                 4    [        U U5        [        U U5        g)r  N)r  r  )r   r  s     r   )ValidateUpdateStatefulPolicyParamsWithIPsr    s    4T5LN4T5LNr!   )F)FT)FF)srS   
__future__r   r   r   enumr  typingr   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper	   r
   r   "googlecloudsdk.command_lib.computer   r`   r   r   r   :googlecloudsdk.command_lib.compute.instance_groups.managedrs  googlecloudsdk.command_lib.utilr  r   ListCommandCompleterr   r,   MultiResourceCompleterr2   Enumr7   rd   rh   r_   ra   r   r   MULTISCOPE_INSTANCE_GROUP_ARG%MULTISCOPE_INSTANCE_GROUP_MANAGER_ARG&MULTISCOPE_INSTANCE_GROUP_MANAGERS_ARGru   r{   r   r   r   r   r   r   r   r   r   _LIST_INSTANCES_FORMAT_LIST_INSTANCES_FORMAT_BETA_LIST_INSTANCES_FORMAT_ALPHAr   r   r   r   r  #_LIST_INSTANCES_STATIC_FIELDS_ALPHAr  r   r   r   r  r  r  r  r\  r@  rA  rB  rC  r  rD  rE  r&  rj  r_  rW  r'  r(  rX  "STATEFUL_IP_ADDRESS_ARG_HELP_INFIXr`  rY  r)  r!  r,  r0  rK  rS  rZ  r]  rd  rn  ru  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!   r   <module>r     s   B &  '    H 0 / ( . O 4 E Y 6 
 &, "++++Z%F%F TYY :88 !& 6 6" 88-6??CC!E  ).(>(>*,4=??CC)E % */)?)?*	,4=??CC*E &.$.*&A27(2CO
-0!      	079+ '
' # 	@7 3
   H &*%6%6%<%<	#Y,2 &*%6%6%<%<2 8<7H7H7K7K >
  (@ C
 (
 $ ) ,
 
 ,&
 "!
 

 	&
 "
 .!
 
 

  &< ?
 &
 " ' *
 
 * 
 4
 04
 0

&
 "  1 1 
)
 /)/2
)
 %$
   *:z6r4Q&(V1hGT4: >CCH!QH((	E5
= ;@@E2( =B1,B=@%@P+Q\
P
PNr!   