o
    .&ßaO  ã                   @   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_trueÚassociate_public_ip)r   r   ÚactionÚ
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)Úargument_tableÚkwargsÚarg© r   úH/usr/lib/python3/dist-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 )NÚnetwork_interfaces)Úsecondary_private_ip_addressesÚ"secondary_private_ip_address_countÚassociate_public_ip_addresszXMixing the --network-interfaces option with the simple, scalar options is not supported.)ÚvarsÚ
ValueError)Úparsed_argsr   Ú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©Ú	interfacer   r   Ú	<genexpr>f   s   € z_fix_args.<locals>.<genexpr>ÚSubnetIdÚSecurityGroupIdsÚGroupsÚPrivateIpAddressT©r/   ÚPrimaryr"   ÚIpv6AddressCountÚIpv6Addresses)Úany)Úparamsr   Únetwork_interface_paramsÚip_addrr   r)   r   Ú	_fix_argsS   s2   ÿ

ír8   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)Ú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%   ÚDeviceIndexr   r"   r   )r5   r   Úvaluer   r   r   Ú_build_network_interfaces‡   s   ÿrA   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ÚparserrH   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 )Fr0   r   )r'   Úvr   r   r   Ú
<listcomp>›   s    zESecondaryPrivateIpAddressesArgument.add_to_params.<locals>.<listcomp>r"   ©rA   ©rL   Ú
parametersr@   r   r   r   Úadd_to_params™   s   ÿþz1SecondaryPrivateIpAddressesArgument.add_to_paramsr&   ©Ú__name__Ú
__module__Ú__qualname__rN   rU   r   r   r   r   r
   “   ó    
r
   c                   @   rB   )r   Nc                 C   s   |j | j| j| jtd� d S )N)rD   rE   Útype)rG   rH   rI   rJ   ÚintrK   r   r   r   rN   ¢   rO   z4SecondaryPrivateIpAddressCountArgument.add_to_parserc                 C   s   |r
t |d|ƒ d S d S )Nr#   rR   rS   r   r   r   rU   ¦   s
   ÿÿz4SecondaryPrivateIpAddressCountArgument.add_to_paramsr&   rV   r   r   r   r   r       rZ   r   c                   @   ó   e Zd Zdd„ ZdS )r   c                 C   ó   |du rt |d|ƒ d S d S )NTr$   rR   rS   r   r   r   rU   ®   ó
   ÿÿz.AssociatePublicIpAddressArgument.add_to_paramsN©rW   rX   rY   rU   r   r   r   r   r   ¬   ó    r   c                   @   r]   )r   c                 C   r^   )NFr$   rR   rS   r   r   r   rU   ¶   r_   z0NoAssociatePublicIpAddressArgument.add_to_paramsNr`   r   r   r   r   r   ´   ra   r   N)Ú__doc__Úawscli.argumentsr   r   r   r   r   r!   r8   r9   r>   rA   r
   r   r   r   r   r   r   r   Ú<module>   s*   ÿ	ÿÿ(ý