File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/boto_ec2.cpython-310.pyc
o
�N�g�< � @ s: d Z ddlZddlZddlZddlZddlZddlZddlm Z m
Z
zddlZddlZddl
mZmZ ddlmZmZ dZW n eyI dZY nw e�e�Zdd � Zd
d� Z dkdd
�Z dkdd�Z dldd�Z dkdd�Zdmdd�Z dkdd�Z dndd�Z dkdd�Z! dodd�Z" dpdd �Z#dqd!d"�Z$ drd#d$�Z% dsd%d&�Z& dtd'd(�Z' dpd)d*�Z( dud+d,�Z)dmd-d.�Z* dvd/d0�Z+d1d2� Z, 3 dwd4d5�Z-dqd6d7�Z.dqd8d9�Z/ dqd:d;�Z0dqd<d=�Z1 dkd>d?�Z2 dpd@dA�Z3 dpdBdC�Z4dqdDdE�Z5 dkdFdG�Z6dxdHdI�Z7dJdK� Z8 dvdLdM�Z9 dkdNdO�Z: dudPdQ�Z; dydRdS�Z< dudTdU�Z= dzdVdW�Z> d{dXdY�Z?dmdZd[�Z@dqd\d]�ZAdqd^d_�ZB d|d`da�ZC dzdbdc�ZDd}dedf�ZE dqdgdh�ZF d~didj�ZGdS )a}
Connection module for Amazon EC2
.. versionadded:: 2015.8.0
:configuration: This module accepts explicit EC2 credentials but can also
utilize IAM roles assigned to the instance through Instance Profiles.
Dynamic credentials are then automatically obtained from AWS API and no
further configuration is necessary. More Information available here__.
.. __: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
If IAM roles are not used you need to specify them either in a pillar or
in the minion's config file:
.. code-block:: yaml
ec2.keyid: GKTADJGHEIQSXMKKRBJ08H
ec2.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
A region may also be specified in the configuration:
.. code-block:: yaml
ec2.region: us-east-1
If a region is not specified, the default is us-east-1.
It's also possible to specify key, keyid, and region via a profile, either
as a passed in dict, or as a string to pull from pillars or minion config:
.. code-block:: yaml
myprofile:
keyid: GKTADJGHEIQSXMKKRBJ08H
key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
region: us-east-1
:depends: boto
� N)�CommandExecutionError�SaltInvocationError)�BlockDeviceMapping�BlockDeviceType)�NetworkInterfaceCollection�NetworkInterfaceSpecificationTFc C s0 t jjjddd�} | du rtd tdtd� | S )zg
Only load if boto libraries exist and if boto libraries are greater than
a given version.
z2.8.0F)Zboto_verZcheck_boto3T�boto.assign_funcs�ec2)�pack)�salt�utilsZversionsZcheck_boto_reqs� __utils__�__name__�__salt__)Z
has_boto_reqs� r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/boto_ec2.py�__virtual__L s �r c C s t rtd td� d S d S )Nr r )�HAS_BOTOr
r )�optsr r r �__init__\ s �r c
C sX t ||||d�}z|j| |d�W S tjjy+ } z
t�|� g W Y d}~S d}~ww )a�
Get all EIP's associated with the current credentials.
addresses
(list) - Optional list of addresses. If provided, only those those in the
list will be returned.
allocation_ids
(list) - Optional list of allocation IDs. If provided, only the
addresses associated with the given allocation IDs will be returned.
returns
(list) - The requested Addresses as a list of :class:`boto.ec2.address.Address`
��region�key�keyid�profile)� addresses�allocation_idsN)� _get_connZget_all_addresses�boto� exception�BotoServerError�log�error)r r r r r r �conn�er r r �_get_all_eip_addressesa s �
��r% c C s dd� t | |||||�D �S )a\
Get public addresses of some, or all EIPs associated with the current account.
addresses
(list) - Optional list of addresses. If provided, only the addresses
associated with those in the list will be returned.
allocation_ids
(list) - Optional list of allocation IDs. If provided, only the
addresses associated with the given allocation IDs will be returned.
returns
(list) - A list of the requested EIP addresses
CLI Example:
.. code-block:: bash
salt-call boto_ec2.get_all_eip_addresses
.. versionadded:: 2016.3.0
c S � g | ]}|j �qS r )� public_ip��.0�xr r r �
<listcomp>� s ��z)get_all_eip_addresses.<locals>.<listcomp>)r% �r r r r r r r r r �get_all_eip_addresses| s
��r- �standardc C s� d}t ||||d�D ]:}t|||||d�d }|d r%t�d||d � q
|d r3t�d||d � q
|d | krDt�d
| |� |} nq
|sLt�d� |S )a
Return the first unassociated EIP
domain
Indicates whether the address is an EC2 address or a VPC address
(standard|vpc).
CLI Example:
.. code-block:: bash
salt-call boto_ec2.get_unassociated_eip_address
.. versionadded:: 2016.3.0
Nr )r r r r r r �instance_idz-%s is already associated with the instance %s�network_interface_idz6%s is already associated with the network interface %s�domainz;The first unassociated EIP address in the domain '%s' is %sz!No unassociated Elastic IP found!)r- �get_eip_address_infor! �debug)r1 r r r r Zeip�addressZaddress_infor r r �get_unassociated_eip_address� sF
�
������
r5 c sN t | t�r| g} t |t�r|g}t| |||||d�}g d�� � fdd�|D �S )a�
Get 'interesting' info about some, or all EIPs associated with the current account.
addresses
(list) - Optional list of addresses. If provided, only the addresses
associated with those in the list will be returned.
allocation_ids
(list) - Optional list of allocation IDs. If provided, only the
addresses associated with the given allocation IDs will be returned.
returns
(list of dicts) - A list of dicts, each containing the info for one of the requested EIPs.
CLI Example:
.. code-block:: bash
salt-call boto_ec2.get_eip_address_info addresses=52.4.2.15
.. versionadded:: 2016.3.0
r, ��
allocation_id�association_idr1 r/ r0 Znetwork_interface_owner_idr'