o
    !dO                     @   s   d Z ddlmZ dZdZdZdd Zdd	 Zd
d ZdefdefdefgZ	dd Z
dd ZG dd deZG dd deZG dd deZG dd deZdS )a=  
This customization adds two new parameters to the ``ec2 run-instance``
command.  The first, ``--secondary-private-ip-addresses`` allows a list
of IP addresses within the specified subnet to be associated with the
new instance.  The second, ``--secondary-ip-address-count`` allows you
to specify how many additional IP addresses you want but the actual
address will be assigned for you.

This functionality (and much more) is also available using the
``--network-interfaces`` complex argument.  This just makes two of
the most commonly used features available more easily.
    )CustomArgumenta$  [EC2-VPC] A secondary private IP address for the network interface or instance. You can specify this multiple times to assign multiple secondary IP addresses.  If you want additional private IP addresses but do not need a specific address, use the --secondary-private-ip-address-count option.z^[EC2-VPC] The number of secondary IP addresses to assign to the network interface or instance.zY[EC2-VPC] If specified a public IP address will be assigned to the new instance in a VPC.c                 K   s\   t dtd}|| d< tdtd}|| d< tdtddd}|| d< tdtd	dd}|| d< d S )
Nzsecondary-private-ip-addresses)name	help_textz"secondary-private-ip-address-countzassociate-public-ip-address
store_trueZassociate_public_ip)r   r   actionZ
group_namezno-associate-public-ip-addressstore_false)#SecondaryPrivateIpAddressesArgument#SECONDARY_PRIVATE_IP_ADDRESSES_DOCS&SecondaryPrivateIpAddressCountArgument'SECONDARY_PRIVATE_IP_ADDRESS_COUNT_DOCS AssociatePublicIpAddressArgument ASSOCIATE_PUBLIC_IP_ADDRESS_DOCS"NoAssociatePublicIpAddressArgument)Zargument_tablekwargsarg r   Jusr/lib/python3.10/site-packages/awscli/customizations/ec2/runinstances.py_add_params.   s,   r   c                 K   s6   t | }|d rdD ]}|| rd}t|q
d S d S )NZnetwork_interfaces)Zsecondary_private_ip_addressesZ"secondary_private_ip_address_countZassociate_public_ip_addresszXMixing the --network-interfaces option with the simple, scalar options is not supported.)vars
ValueError)Zparsed_argsr   Zarg_dictkeymsgr   r   r   _check_argsC   s   r   c                    s   g d}d| v rb| d d  t  fdd|D rdd| v r&| d  d< | d= d| v r3| d  d< | d= d	| v rF| d	 d
d}|g d< | d	= d| v rS| d  d< | d= d| v rf| d  d< | d= d S d S d S d S )N)PrivateIpAddressesSecondaryPrivateIpAddressCountAssociatePublicIpAddressNetworkInterfacesr   c                 3   s    | ]}| v V  qd S Nr   ).0paramZ	interfacer   r   	<genexpr>f   s    z_fix_args.<locals>.<genexpr>ZSubnetIdZSecurityGroupIdsZGroupsPrivateIpAddressTr"   ZPrimaryr   ZIpv6AddressCountZIpv6Addresses)any)paramsr   Znetwork_interface_paramsZip_addrr   r    r   	_fix_argsS   s2   

r&   z)building-argument-table.ec2.run-instancesz'operation-args-parsed.ec2.run-instancesz'before-parameter-build.ec2.RunInstancesc                 C   s   t D ]
\}}| || qd S r   )EVENTSregister)Zevent_handlereventhandlerr   r   r   register_runinstances   s   r+   c                 C   sZ   d| vrddig| d< |dkr#d| d d vr!|| d d d< d S d S || d d |< d S )Nr   ZDeviceIndexr   r   r   )r%   r   valuer   r   r   _build_network_interfaces   s   r-   c                   @      e Zd ZdddZdd ZdS )r   Nc                 C   s   |j | j| j| jdd d S )N*)destdefaultnargs)add_argumentcli_namepy_name_defaultselfparserr4   r   r   r   add_to_parser      
z1SecondaryPrivateIpAddressesArgument.add_to_parserc                 C   s&   |rdd |D }t |d| d S d S )Nc                 S   s   g | ]}|d dqS )Fr#   r   )r   vr   r   r   
<listcomp>   s    zESecondaryPrivateIpAddressesArgument.add_to_params.<locals>.<listcomp>r   r-   r8   
parametersr,   r   r   r   add_to_params   s   z1SecondaryPrivateIpAddressesArgument.add_to_paramsr   __name__
__module____qualname__r:   rA   r   r   r   r   r          
r   c                   @   r.   )r
   Nc                 C   s   |j | j| j| jtd d S )N)r0   r1   type)r3   r4   r5   r6   intr7   r   r   r   r:      r;   z4SecondaryPrivateIpAddressCountArgument.add_to_parserc                 C   s   |r
t |d| d S d S )Nr   r>   r?   r   r   r   rA      s
   z4SecondaryPrivateIpAddressCountArgument.add_to_paramsr   rB   r   r   r   r   r
      rF   r
   c                   @      e Zd Zdd ZdS )r   c                 C      |du rt |d| d S d S )NTr   r>   r?   r   r   r   rA      
   z.AssociatePublicIpAddressArgument.add_to_paramsNrC   rD   rE   rA   r   r   r   r   r          r   c                   @   rI   )r   c                 C   rJ   )NFr   r>   r?   r   r   r   rA      rK   z0NoAssociatePublicIpAddressArgument.add_to_paramsNrL   r   r   r   r   r      rM   r   N)__doc__Zawscli.argumentsr   r	   r   r   r   r   r&   r'   r+   r-   r   r
   r   r   r   r   r   r   <module>   s*   	(