HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/boto_ec2.cpython-310.pyc
o

�N�g�<�@s:dZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
zddlZddlZddl
mZmZddlmZmZdZWneyIdZYnwe�e�Zdd	�Zd
d�Z	dkdd
�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�NetworkInterfaceSpecificationTFcCs0tjjjddd�}|durtdtdtd�|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__Ls�rcCstrtdtd�dSdS)Nrr	)�HAS_BOTOr
r)�optsrrr�__init__\s�rc
CsXt||||d�}z|j||d�WStjjy+}z
t�|�gWYd}~Sd}~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)rrrrrr�conn�errr�_get_all_eip_addressesas�
��r%cCsdd�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
    cS�g|]}|j�qSr)�	public_ip��.0�xrrr�
<listcomp>�s��z)get_all_eip_addresses.<locals>.<listcomp>)r%�rrrrrrrrr�get_all_eip_addresses|s
��r-�standardcCs�d}t||||d�D]:}t|||||d�d}|dr%t�d||d�q
|dr3t�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)rrrrrr�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)r1rrrrZeip�addressZaddress_inforrr�get_unassociated_eip_address�sF
�
������	
r5csNt|t�r|g}t|t�r|g}t||||||d�}gd���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_idr1r/r0Znetwork_interface_owner_idr'�private_ip_addresscsg|]��fdd��D��qS)c�i|]}|t�|��qSr��getattrr(�r4rr�
<dictcomp>�z3get_eip_address_info.<locals>.<listcomp>.<dictcomp>r)r)��interestingr=rr+sz(get_eip_address_info.<locals>.<listcomp>)�
isinstance�strr%)rrrrrr�retrr@rr2�s

�	r2c
s�|r
|dkr
td��t||||d�}z|j|d��Wntjjy4}zt�|�WYd}~dSd}~wwgd�}�fdd	�|D�S)
am
    Allocate a new Elastic IP address and associate it with your account.

    domain
        (string) Optional param - if set to exactly 'vpc', the address will be
        allocated to the VPC.  The default simply maps the EIP to your
        account container.

    returns
        (dict) dict of 'interesting' information about the newly allocated EIP,
        with probably the most interesting keys being 'public_ip'; and
        'allocation_id' iff 'domain=vpc' was passed.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.allocate_eip_address domain=vpc

    .. versionadded:: 2016.3.0
    Zvpcz9The only permitted value for the 'domain' param is 'vpc'.r)r1NFr6cr:rr;r(r=rrr>6r?z(allocate_eip_address.<locals>.<dictcomp>)rrZallocate_addressrrr r!r")r1rrrrr#r$rArr=r�allocate_eip_addresss�
��rEc
Csntjj�||f�s
td��t||||d�}z|�||�WStjj	y6}zt
�|�WYd}~dSd}~ww)a
    Free an Elastic IP address.  Pass either a public IP address to release an
    EC2 Classic EIP, or an AllocationId to release a VPC EIP.

    public_ip
        (string) - The public IP address - for EC2 elastic IPs.
    allocation_id
        (string) - The Allocation ID - for VPC elastic IPs.

    returns
        (bool) - True on success, False on failure

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.release_eip_address allocation_id=eipalloc-ef382c8a

    .. versionadded:: 2016.3.0
    z>Exactly one of 'public_ip' OR 'allocation_id' must be providedrNF)rr�data�exactly_onerrZrelease_addressrrr r!r")r'r7rrrrr#r$rrr�release_eip_address9s�
��rHc
CsDtjj�||||f�std��t||	|
|d�}|rIzt|||	|
|d�}Wntjj	y>}
zt
�|
�WYd}
~
dSd}
~
ww|sIt
�d|�dS|r{zt|||	|
|d�}Wntjj	yp}
zt
�|
�WYd}
~
dSd}
~
ww|s{t
�d|�dSz|j
||||||d�WStjj	y�}
zt
�|
�WYd}
~
dSd}
~
ww)	uP
    Associate an Elastic IP address with a currently running instance or a network interface.
    This requires exactly one of either 'public_ip' or 'allocation_id', depending
    on whether you’re associating a VPC address or a plain EC2 address.

    instance_id
        (string) – ID of the instance to associate with (exclusive with 'instance_name')
    instance_name
        (string) – Name tag of the instance to associate with (exclusive with 'instance_id')
    public_ip
        (string) – Public IP address, for standard EC2 based allocations.
    allocation_id
        (string) – Allocation ID for a VPC-based EIP.
    network_interface_id
        (string) - ID of the network interface to associate the EIP with
    network_interface_name
        (string) - Name of the network interface to associate the EIP with
    private_ip_address
        (string) – The primary or secondary private IP address to associate with the Elastic IP address.
    allow_reassociation
        (bool)   – Allow a currently associated EIP to be re-associated with the new instance or interface.

    returns
        (bool)   - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.associate_eip_address instance_name=bubba.ho.tep allocation_id=eipalloc-ef382c8a

    .. versionadded:: 2016.3.0
    zpExactly one of 'instance_id', 'instance_name', 'network_interface_id', 'network_interface_name' must be providedr��namerrrrNFz;Given instance_name '%s' cannot be mapped to an instance_id�MGiven network_interface_name '%s' cannot be mapped to an network_interface_id)r/r'r7r0r9�allow_reassociation)rrrFrGrr�get_idrrr r!r"�get_network_interface_idZassociate_address)r/�
instance_namer'r7r0�network_interface_namer9rLrrrrr#r$rrr�associate_eip_address^sr/
��

�
���
�
����
��rQc
CsTt||||d�}z|�||�WStjjy)}zt�|�WYd}~dSd}~ww)un
    Disassociate an Elastic IP address from a currently running instance. This
    requires exactly one of either 'association_id' or 'public_ip', depending
    on whether you’re dealing with a VPC or EC2 Classic address.

    public_ip
        (string) – Public IP address, for EC2 Classic allocations.
    association_id
        (string) – Association ID for a VPC-bound EIP.

    returns
        (bool)   - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.disassociate_eip_address association_id=eipassoc-e3ba2d16

    .. versionadded:: 2016.3.0
    rNF)rZdisassociate_addressrrr r!r")r'r8rrrrr#r$rrr�disassociate_eip_address�s
��rRc	
Cs�tjj�||f�s
td��t||||d�}	|rGzt|||||d�}Wntjj	y<}
zt
�|
�WYd}
~
dSd}
~
ww|sGt
�d|�dSz
|	j||||d�WStjj	yk}
zt
�|
�WYd}
~
dSd}
~
ww)u�
    Assigns one or more secondary private IP addresses to a network interface.

    network_interface_id
        (string) - ID of the network interface to associate the IP with (exclusive with 'network_interface_name')
    network_interface_name
        (string) - Name of the network interface to associate the IP with (exclusive with 'network_interface_id')
    private_ip_addresses
        (list) - Assigns the specified IP addresses as secondary IP addresses to the network interface (exclusive with 'secondary_private_ip_address_count')
    secondary_private_ip_address_count
        (int) - The number of secondary IP addresses to assign to the network interface. (exclusive with 'private_ip_addresses')
    allow_reassociation
        (bool)   – Allow a currently associated EIP to be re-associated with the new instance or interface.

    returns
        (bool)   - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.assign_private_ip_addresses network_interface_name=my_eni private_ip_addresses=private_ip
        salt myminion boto_ec2.assign_private_ip_addresses network_interface_name=my_eni secondary_private_ip_address_count=2

    .. versionadded:: 2017.7.0
    �PExactly one of 'network_interface_name', 'network_interface_id' must be providedrNFrK)r0�private_ip_addresses�"secondary_private_ip_address_count�allow_reassignment)
rrrFrGrrrNrrr r!r"�assign_private_ip_addresses)rPr0rTrUrVrrrrr#r$rrrrW�sJ%�
�
����
��rWc	
Cs�tjj�||f�s
td��t||||d�}|rGzt|||||d�}Wntjj	y<}zt
�|�WYd}~dSd}~ww|sGt
�d|�dSz|j||d�WStjj	yi}zt
�|�WYd}~dSd}~ww)a�
    Unassigns one or more secondary private IP addresses from a network interface

    network_interface_id
        (string) - ID of the network interface to associate the IP with (exclusive with 'network_interface_name')
    network_interface_name
        (string) - Name of the network interface to associate the IP with (exclusive with 'network_interface_id')
    private_ip_addresses
        (list) - Assigns the specified IP addresses as secondary IP addresses to the network interface.

    returns
        (bool)   - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.unassign_private_ip_addresses network_interface_name=my_eni private_ip_addresses=private_ip

    .. versionadded:: 2017.7.0
    rSrNFrK)r0rT)
rrrFrGrrrNrrr r!r"�unassign_private_ip_addresses)	rPr0rTrrrrr#r$rrrrX7sF�
�
����
��rXcCs"t||||d�}dd�|��D�S)z�
    Get a list of AZs for the configured region.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_zones
    rcSr&r)rJ)r)�zrrrr+��zget_zones.<locals>.<listcomp>)rZ
get_all_zones)rrrrr#rrr�	get_zones{s
r[c

st||||d�}
zidii}|r|g|d<|r||dd<|r0|��D]
\}}
|
|dd|��<q"|	r9|d�|	�|
jd
i|��}dd�|D�}t�d||��r`�fd	d�|D�}t�d
|�|ro|rg|WSdd�|D�WSgWStjjy�}z
t�	|�gWYd}~Sd}~ww)a�
    Given instance properties, find and return matching instance ids

    CLI Examples:

    .. code-block:: bash

        salt myminion boto_ec2.find_instances # Lists all instances
        salt myminion boto_ec2.find_instances name=myinstance
        salt myminion boto_ec2.find_instances tags='{"mytag": "value"}'
        salt myminion boto_ec2.find_instances filters='{"vpc-id": "vpc-12345678"}'

    r�filters�instance_ids�tag:Name�tag:cSsg|]
}|jD]}|�qqSr)�	instances)r)�r�irrrr+�sz"find_instances.<locals>.<listcomp>z:The filters criteria %s matched the following instances:%scsg|]	}|j�vr|�qSr)�state)r)rb��	in_statesrrr+�sz>Limiting instance matches to those in the requested states: %scSr&r��id)r)�instancerrrr+�rZNr)
r�items�updateZget_all_reservationsr!r3rrr r")r/rJ�tagsrrrr�return_objsrer\r#�filter_parameters�tag_name�	tag_valueZreservationsr`�excrrdr�find_instances�sF
��
��rqcCs�t|||||||d|d�	}|st�d�dSt|�dkr#t�d�dS|d}
z
|
j|||	|
d�WStjjyK}zt�|�WYd	}~dSd	}~ww)
aT
    Given instance properties that define exactly one instance, create AMI and return AMI-id.

    CLI Examples:

    .. code-block:: bash

        salt myminion boto_ec2.create_image ami_name instance_name=myinstance
        salt myminion boto_ec2.create_image another_ami_name tags='{"mytag": "value"}' description='this is my ami'

    T)	r/rJrkrrrrrlr\zSource instance not foundF�zVMultiple instances found, must match exactly only one instance to create an image fromr)�description�	no_reboot�dry_runN)rqr!r"�len�create_imagerrr )�ami_namer/rOrkrrrrrsrtrur\r`rhrprrrrw�s:�
��
��rwc

Cs4d}
t||||d�}|
r�zVdii}|r|g|d<|r|g|d<|r&|g|d<|r.||dd<|rB|��D]
\}
}||dd|
��<q4|jdi|��}t�d	||�|r`|	rX|WSd
d�|D�WSWdStjjy�}z'|jd
kr�t�d�t	�
d�|
d8}
WYd}~q
t�d||�WYd}~dSd}~wwdS)z�
    Given image properties, find and return matching AMI ids

    CLI Examples:

    .. code-block:: bash

        salt myminion boto_ec2.find_images tags='{"mytag": "value"}'

    �rr\�	image_ids�
executable_by�ownersrJr_z7The filters criteria %s matched the following images:%scSr&rrf)r)Zimagerrrr+7rZzfind_images.<locals>.<listcomp>FZ
Throttlingz0Throttled by AWS API, will retry in 5 seconds...�rrNz0Failed to convert AMI name `%s` to an AMI ID: %sr)rriZget_all_imagesr!r3rrr Z
error_code�time�sleepr")rxr{r|rzrkrrrrrl�retriesr#rmrnroZimagesrprrr�find_imagessL


�


��r�c
CsTt||||||d|d�}|ddgfvr|St|�dkr#|d��dSt�d�dS)z�
    Terminate the instance described by instance_id or name.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.terminate name=myinstance
        salt myminion boto_ec2.terminate instance_id=i-a46b9f
    T)r/rJrrrrrlr\FNrrrz0Refusing to terminate multiple instances at once)rqrv�	terminater!�warning)r/rJrrrrr\r`rrrr�Es"�

r�c	
CsXt||||||||d�}|r%t�dd�|��t|�dkr!|dStd��t�d�dS)	z�
    Given instance properties, return the instance id if it exists.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_id myinstance

    )rJrkrrrrrer\zInstance ids: %s� rrrz3Found more than one instance matching the criteria.zCould not find instance.N)rqr!�info�joinrvrr�)	rJrkrrrrrer\r]rrrrMms&�
�
rMc	CsXg}t||||d�}|jd|id�}|r$|D]}|�|j|ji�q|St�d|�|S)z�
    Given an instance_id, return a list of tags associated with that instance.

    returns
        (list) - list of tags as key/value pairs

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_tags instance_id
    )rrrrzresource-id�r\z No tags found for instance_id %s)r�get_all_tags�appendrJ�valuer!r�)	r/rrrrrk�client�result�tagrrr�get_tags�s
�r�c	
Cs:t|||||||||d�	}	|	rt�d�dSt�d�dS)a
    Given an instance id, check to see if the given instance id exists.

    Returns True if the given instance with the given id, name, or tags
    exists; otherwise, False is returned.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.exists myinstance
    )	r/rJrkrrrrrer\zInstance exists.TzInstance does not exist.F)rqr!r�r�)
r/rJrkrrrrrer\r`rrr�exists�s �

r�cCs�|sdSt|t�r|St|t�rtjj�|�}t|t�s't�	d|t
|��dSt�}|��D]:\}}t|�
d�|�
dd�|�
d�|�
d�|�
d�|�
d	�|�
d
d�|�
d�|�
d�|�
d
�|�
d�d�}|||<q.|S)a�
    Convert a string, or a json payload, or a dict in the right
    format, into a boto.ec2.blockdevicemapping.BlockDeviceMapping as
    needed by instance_present().  The following YAML is a direct
    representation of what is expected by the underlying boto EC2 code.

    YAML example:

    .. code-block:: yaml

        device-maps:
            /dev/sdb:
                ephemeral_name: ephemeral0
            /dev/sdc:
                ephemeral_name: ephemeral1
            /dev/sdd:
                ephemeral_name: ephemeral2
            /dev/sde:
                ephemeral_name: ephemeral3
            /dev/sdf:
                size: 20
                volume_type: gp2

    NzQCan't convert '%s' of type %s to a boto.ec2.blockdevicemapping.BlockDeviceMapping�ephemeral_name�	no_deviceF�	volume_id�snapshot_id�status�attach_time�delete_on_termination�size�volume_type�iops�	encrypted)r�r�r�r�r�r�r�r�r�r�r�)rBrrCrr�json�loads�dictr!r"�typerir�get)�thingZbdm�d�tZbdtrrr�_to_blockdev_map�s<


�

�

r��m1.smallc#.	Cs|t|
|f�r
td��|r(tdd|||| |!d�}#d|#vr$t�d|�dS|#d}
t||f�r2td��|rWg}|D]}$td	|$|||| |!d
�}#|#sQt�d|$�dS||#g7}q8ttt|du|du|"dug��}%t|%�d
krqtd��|r�t	|||| |!d�}&|&d}|s�t�d|�|r�t
|dd�}'nt
|
|dd�}'|"r�dd�|"D�}(t|(�})nt|'�})t||| |!d�}*|*j
|fid|�d|�d|�d|�d|�d|�d|	�d|
�d|�dt|��d |�d!|�d"|�d#|�d$|�d%|�d&|�d'|�d(|�d)|)��}+|+�st�d*�dS|+jd},d+}-|-d+k�rt�d,�|,��}-|-d+k�s
|-d-k�r6|�r)|,�d.|�|�r1|,�|�d/|,jiSt�d0|-�dS)1u�
    Create and start an EC2 instance.

    Returns True if the instance was created; otherwise False.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.run ami-b80c2b87 name=myinstance

    image_id
        (string) – The ID of the image to run.
    name
        (string) - The name of the instance.
    tags
        (dict of key: value pairs) - tags to apply to the instance.
    key_name
        (string) – The name of the key pair with which to launch instances.
    security_groups
        (list of strings) – The names of the EC2 classic security groups with
        which to associate instances
    user_data
        (string) – The Base64-encoded MIME user data to be made available to the
        instance(s) in this reservation.
    instance_type
        (string) – The type of instance to run.  Note that some image types
        (e.g. hvm) only run on some instance types.
    placement
        (string) – The Availability Zone to launch the instance into.
    kernel_id
        (string) – The ID of the kernel with which to launch the instances.
    ramdisk_id
        (string) – The ID of the RAM disk with which to launch the instances.
    monitoring_enabled
        (bool) – Enable detailed CloudWatch monitoring on the instance.
    vpc_id
        (string) - ID of a VPC to bind the instance to.  Exclusive with vpc_name.
    vpc_name
        (string) - Name of a VPC to bind the instance to.  Exclusive with vpc_id.
    subnet_id
        (string) – The subnet ID within which to launch the instances for VPC.
    subnet_name
        (string) – The name of a subnet within which to launch the instances for VPC.
    private_ip_address
        (string) – If you’re using VPC, you can optionally use this parameter to
        assign the instance a specific available IP address from the subnet
        (e.g. 10.0.0.25).
    block_device_map
        (boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping
        data structure describing the EBS volumes associated with the Image.
        (string) - A string representation of a BlockDeviceMapping structure
        (dict) - A dict describing a BlockDeviceMapping structure

        YAML example:

        .. code-block:: yaml

            device-maps:
                /dev/sdb:
                    ephemeral_name: ephemeral0
                /dev/sdc:
                    ephemeral_name: ephemeral1
                /dev/sdd:
                    ephemeral_name: ephemeral2
                /dev/sde:
                    ephemeral_name: ephemeral3
                /dev/sdf:
                    size: 20
                    volume_type: gp2

    disable_api_termination
        (bool) – If True, the instances will be locked and will not be able to
        be terminated via the API.
    instance_initiated_shutdown_behavior
        (string) – Specifies whether the instance stops or terminates on
        instance-initiated shutdown. Valid values are: stop, terminate
    placement_group
        (string) – If specified, this is the name of the placement group in
        which the instance(s) will be launched.
    client_token
        (string) – Unique, case-sensitive identifier you provide to ensure
        idempotency of the request. Maximum 64 ASCII characters.
    security_group_ids
        (list of strings) – The ID(s) of the VPC security groups with which to
        associate instances.
    security_group_names
        (list of strings) – The name(s) of the VPC security groups with which to
        associate instances.
    additional_info
        (string) – Specifies additional information to make available to the
        instance(s).
    tenancy
        (string) – The tenancy of the instance you want to launch. An instance
        with a tenancy of ‘dedicated’ runs on single-tenant hardware and can
        only be launched into a VPC. Valid values are:”default” or “dedicated”.
        NOTE: To use dedicated tenancy you MUST specify a VPC subnet-ID as well.
    instance_profile_arn
        (string) – The Amazon resource name (ARN) of the IAM Instance Profile
        (IIP) to associate with the instances.
    instance_profile_name
        (string) – The name of the IAM Instance Profile (IIP) to associate with
        the instances.
    ebs_optimized
        (bool) – Whether the instance is optimized for EBS I/O. This
        optimization provides dedicated throughput to Amazon EBS and an
        optimized configuration stack to provide optimal EBS I/O performance.
        This optimization isn’t available with all instance types.
    network_interfaces
        (boto.ec2.networkinterface.NetworkInterfaceCollection) – A
        NetworkInterfaceCollection data structure containing the ENI
        specifications for the instance.
    network_interface_id
        (string) - ID of the network interface to attach to the instance
    network_interface_name
        (string) - Name of the network interface to attach to the instance

    z5Only one of subnet_name or subnet_id may be provided.�boto_vpc.get_resource_id�subnetrrg� Couldn't resolve subnet name %s.FzGOnly one of security_group_ids or security_group_names may be provided.zboto_secgroup.get_group_id)�vpc_namerrrrz'Couldn't resolve security group name %sNrrz_Only one of network_interface_id, network_interface_name or network_interfaces may be provided.r�rKr)r0�device_index)�	subnet_id�groupsr�cSsg|]	}tdi|���qS)r)rr(rrrr+�s�zrun.<locals>.<listcomp>�key_name�security_groups�	user_data�
instance_type�	placement�	kernel_id�
ramdisk_id�monitoring_enabledr9�block_device_map�disable_api_termination�$instance_initiated_shutdown_behavior�placement_group�client_token�additional_info�tenancy�instance_profile_arn�instance_profile_name�
ebs_optimized�network_interfaceszInstance could not be reserved�pendingr}�running�Namer/z/Instance could not be started -- status is "%s")�allrrr!r��list�map�int�sumrNrrrZ
run_instancesr�r`r~rrj�add_tagZadd_tagsrg).Zimage_idrJrkr�r�r�r�r�r�r�r��vpc_idr�r��subnet_namer9r�r�r�r�r�Zsecurity_group_idsZsecurity_group_namesr�r�r�r�r�r0rPrrrrr�raZsgnZnetwork_interface_argsr�Z	interfaceZinterfaces_specsZ
interfacesr#Zreservationrhr�rrr�runs��������
�����
��������	�
���
���������




�


r�c
Csxt||||d�}z|�|�}t�d|�|durWdS|j|jfWStjjy;}zt�|�WYd}~dSd}~ww)z�
    Check to see if a key exists. Returns fingerprint and name if
    it does and False if it doesn't

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_key mykey
    r�the key to return is : %sNF)	rZget_key_pairr!r3rJ�fingerprintrrr �r�rrrrr#r$rrr�get_key.s

��r�c
Csnt||||d�}z|�|�}t�d|�|�|�|jWStjjy6}zt�|�WYd}~dSd}~ww)z�
    Creates a key and saves it to a given path.
    Returns the private key.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.create_key mykey /root/
    rr�NF)	rZcreate_key_pairr!r3ZsaveZmaterialrrr )r�Z	save_pathrrrrr#r$rrr�
create_keyFs


��r�c
Csft||||d�}z|�||�}t�d|�|jWStjjy2}zt�|�WYd}~dSd}~ww)a	
    Imports the public key from an RSA key pair that you created with a third-party tool.
    Supported formats:
    - OpenSSH public key format (e.g., the format in ~/.ssh/authorized_keys)
    - Base64 encoded DER format
    - SSH public key file format as specified in RFC4716
    - DSA keys are not supported. Make sure your key generator is set up to create RSA keys.
    Supported lengths: 1024, 2048, and 4096.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.import mykey publickey
    rr�NF)rZimport_key_pairr!r3r�rrr )r�Zpublic_key_materialrrrrr#r$rrr�
import_key]s
��r�c
Csbt||||d�}z|�|�}t�d|�|WStjjy0}zt�|�WYd}~dSd}~ww)z�
    Deletes a key. Always returns True

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.delete_key mykey
    rr�NF)rZdelete_key_pairr!r3rrr r�rrr�
delete_keyzs


��r�c

Cs�t||||d�}z|�||�}t�d|�g}|r$|D]}|�|j�q|WStjjy@}	zt�|	�WYd}	~	dSd}	~	ww)ai
    Gets all keys or filters them by name and returns a list.
    keynames (list):: A list of the names of keypairs to retrieve.
    If not provided, all key pairs will be returned.
    filters (dict) :: Optional filters that can be used to limit the
    results returned. Filters are provided in the form of a dictionary
    consisting of filter names as the key and filter values as the
    value. The set of allowable filter names/values is dependent on
    the request being performed. Check the EC2 API guide for details.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_keys
    rr�NF)	rZget_all_key_pairsr!r3r�rJrrr )
Zkeynamesr\rrrrr#�keysZ
key_valuesr$rrr�get_keys�s
��r�c

Cs�t||||d�}gd�}	t||f�std��|r|rtd��||	vr*td|	�d���z:|rSt||||||d�}
t|
�dkrEt�d	�Wd
S|
sOt�d�Wd
S|
d}|�||�}|s^Wd
S|||iWStj	j
y~}zt�|�WYd
}~d
Sd
}~ww)a
    Get an EC2 instance attribute.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_attribute sourceDestCheck instance_name=my_instance

    Available attributes:
        * instanceType
        * kernel
        * ramdisk
        * userData
        * disableApiTermination
        * instanceInitiatedShutdownBehavior
        * rootDeviceName
        * blockDeviceMapping
        * productCodes
        * sourceDestCheck
        * groupSet
        * ebsOptimized
        * sriovNetSupport
    r�
ZinstanceTypeZkernelZramdiskZuserDataZdisableApiTerminationZ!instanceInitiatedShutdownBehaviorZrootDeviceNameZblockDeviceMappingZproductCodes�sourceDestCheck�groupSetZebsOptimizedZsriovNetSupport�NAt least one of the following must be specified: instance_name or instance_id.�LBoth instance_name and instance_id can not be specified in the same command.�Attribute must be one of: �.�rJrrrrr\rr�7Found more than one EC2 instance matching the criteria.Fz,Found no EC2 instance matching the criteria.rN)r�anyrrqrvr!r"Zget_instance_attributerrr )
�	attributerOr/rrrrr\r#�attribute_listr`Zinstance_attributerprrr�
get_attribute�sL"���


��r�c	

Cs�t||||d�}	gd�}
t||f�std��|r|rtd��||
vr*td|
�d���z)|rEt||||||d�}t|�dkrAtd	��|d
}|	�|||�}|sQWdS|WStjj	ym}zt
�|�WYd}~dSd}~ww)
aE
    Set an EC2 instance attribute.
    Returns whether the operation succeeded or not.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.set_attribute sourceDestCheck False instance_name=my_instance

    Available attributes:
        * instanceType
        * kernel
        * ramdisk
        * userData
        * disableApiTermination
        * instanceInitiatedShutdownBehavior
        * rootDeviceName
        * blockDeviceMapping
        * productCodes
        * sourceDestCheck
        * groupSet
        * ebsOptimized
        * sriovNetSupport
    rr�r�r�r�r�r�rrr�rFN)rr�rrqrvrZmodify_instance_attributerrr r!r")
r�Zattribute_valuerOr/rrrrr\r#r�r`rprrr�
set_attribute
sL$�����
��r�c

Cs�t||||d�}i}z.|jd|id�}|sddi|d<W|St|�dkr-ddi|d<W|S|d	}|j|d
<W|StjjyU}	ztd|	�|d<WYd}	~	|Sd}	~	ww)
z�
    Get an Elastic Network Interface id from its name tag.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_network_interface_id name=my_eni
    rr^r��message�No ENIs found.r"rr�*Name specified is tagged on multiple ENIs.rr��boto.get_errorN)r�get_all_network_interfacesrvrgrr�EC2ResponseErrorr
)
rJrrrrr#ra�enis�enir$rrrrNes$�����rNc
Cs`t||||d�}i}t|||�}d|vr$|dddkr"d|d<|S|S|d}	t|	�|d<|S)z�
    Get an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_network_interface name=my_eni
    rr"r�r�Nr�)r�_get_network_interface�_describe_network_interface)
rJr0rrrrr#rar�r�rrr�get_network_interface�sr�c
Cs�i}|s
|s
td��z6|r|�|g�}n|jd|id�}|s'ddi|d<W|St|�dkr6ddi|d<W|S|d	}||d
<W|Stjjy]}ztd|�|d<WYd}~|Sd}~ww)N�5Either name or network_interface_id must be provided.r^r�r�r�r"rrr�rr�r�)rr�rvrrr�r
)r#rJr0rar�r�r$rrrr��s.���
���r�cCs�i}dD]}t||�rt||�||<q|jj|d<g|d<|jD]}|d�|j|jd��q g|d<|jD]}|d�|j|j	d��q6i|d<dD]}t|j
|�r]t|j
|�|d|<qK|S)	N)r�rsZavailability_zoneZrequesterIdZrequester_managedZmac_addressr9r�rg�source_dest_check�owner_idrkr�Z
associationIdZ
publicDnsNamer�Z	ipOwnerIdZpublicIpZallocationIdrr�)rJrgrT)r9�primary�
attachment)r�r�r�r�r/Zinstance_owner_idrg)�hasattrr<rrJr�r�rgrTr9r�r�)r�ra�attr�groupr4rrrr��s,
�

��	�r�c

CsVtjj�||f�s
td��|r+tdd|||||	d�}
d|
vr't�d|�dS|
d}t||||	d�}i}t	||�}
d|
vrFd	d
i|d<|Std|g||||	d�}|�
d
�}|sgd|�d�}d	|i|d<|Std||||||	d�}z|j||||d�}|�d|�Wnt
jjy�}ztd|�|d<|WYd}~Sd}~wwt|�|d<|S)��
    Create an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.create_network_interface my_eni subnet-12345 description=my_eni groups=['my_group']
    z@One (but not both) of subnet_id or subnet_name must be provided.r�r�rrgr�Fr�r�z)An ENI with this Name tag already exists.r"zboto_vpc.get_subnet_associationr�z
subnet_id z  does not map to a valid vpc id.�"boto_secgroup.convert_to_group_ids�r�rrrr)r9rsr�r�r�N)rrrFrGrrr!r�rr�r��create_network_interfacer�rrr�r
r�)rJr�r�r9rsr�rrrrZresourcer#rar�r��msgZ_groupsr�r$rrrr��sX��
�
����r�c
Cs�|s|std��t||||d�}i}t|||�}d|vr|S|d}	z
t|	�}
|
d}Wnty=ddi|d<|YSwz
|�|�|d<W|Stjjye}zt	d|�|d<WYd	}~|Sd	}~ww)
r�r�rr"r�rgr��(ID not found for this network interface.r�N)
rrr�r��KeyError�delete_network_interfacerrr�r
)rJr0rrrrr#rar�r�r�r$rrrr�2s2�����r�c	
CsDtjj�||f�s
td��tjj�||f�std��t||||d�}	i}
t|	||�}d|vr0|S|d}z
t|�}
|
d}WntyOddi|
d<|
YSw|rxzt	|||||d	�}Wnt
jjyw}zt
�|�WYd
}~dSd
}~wwz|	�|||�|
d<W|
St
jjy�}ztd|�|
d<WYd
}~|
Sd
}~ww)
z�
    Attach an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.attach_network_interface my_eni instance_name=salt-master device_index=0
    zPExactly one (but not both) of 'name' or 'network_interface_id' must be provided.zPExactly one (but not both) of 'instance_name' or 'instance_id' must be provided.rr"r�rgr�r�rINFr�)rrrFrGrrr�r�r�rMrrr r!r"�attach_network_interfacer�r
)r�rJr0rOr/rrrrr#rar�r�r�r$rrrr�\sR���

�
��
����r�c
Cs�|s
|s
|s
td��t||||d�}i}	|sDt|||�}
d|
vr"|
S|
d}t|�}z|dd}WntyCddi|	d<|	YSwz|�||�|	d<W|	Stjjyl}
zt	d	|
�|	d<WYd
}
~
|	Sd
}
~
ww)z�
    Detach an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.detach_network_interface my_eni
    zFEither name or network_interface_id or attachment_id must be provided.rr"r�r�rgr�z%Attachment id not found for this ENI.r�N)
rrr�r�r��detach_network_interfacerrr�r
)rJr0�
attachment_id�forcerrrrr#rar�r�r�r$rrrr��s4�����r�c
Csz|s|std��|dur|durtd��i}t||||d�}	t|	||�}
d|
vr*|
S|
d}t|�}|d}|dkr=d	}
n|d
krDd}
n	|dkrKd
}
n|}
|}|�d�rq|
d	krqtd||�d�||||d�}|sqddi|d<|Sd}|
d
kr�z|dd}Wnty�ddi|d<|YSwz|	j||
||d�|d<W|Stj	j
y�}ztd|�|d<WYd}~|Sd}~ww)a
    Modify an attribute of an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.modify_network_interface_attribute my_eni attr=description value='example description'
    r�Nz attr and value must be provided.rr"r�rgr�r�r�r�r�ZdeleteOnTerminationr�r�r�r�z6Security groups do not map to valid security group idsr�zjNo attachment id found for this ENI. The ENI must be attached before delete_on_termination can be modified)r�r�)rrr�r�r�rr��"modify_network_interface_attributerrr�r
)rJr0r�r�rrrrrar#r�r�r�Z_attr�_valueZ_attachment_idr$rrrr�sn�����	����rc

Cspt||||d�}z|j||d�}|r|WSdd�|D�WStjjy7}	z
t�|	�gWYd}	~	Sd}	~	ww)a�
    Get a list of all EBS volumes, optionally filtered by provided 'filters' param

    .. versionadded:: 2016.11.0

    volume_ids
        (list) - Optional list of volume_ids.  If provided, only the volumes
        associated with those in the list will be returned.
    filters
        (dict) - Additional constraints on which volumes to return.  Valid filters are:

    - attachment.attach-time - The time stamp when the attachment initiated.
    - attachment.delete-on-termination - Whether the volume is deleted on instance termination.
    - attachment.device - The device name that is exposed to the instance (for example, /dev/sda1).
    - attachment.instance-id - The ID of the instance the volume is attached to.
    - attachment.status - The attachment state (attaching | attached | detaching | detached).
    - availability-zone - The Availability Zone in which the volume was created.
    - create-time - The time stamp when the volume was created.
    - encrypted - The encryption status of the volume.
    - size - The size of the volume, in GiB.
    - snapshot-id - The snapshot from which the volume was created.
    - status - The status of the volume (creating | available | in-use | deleting | deleted | error).
    - tag:key=value - The key/value combination of a tag assigned to the resource.
    - volume-id - The volume ID.
    - volume-type - The Amazon EBS volume type. This can be ``gp2`` for General
      Purpose SSD, ``io1`` for Provisioned IOPS SSD, ``st1`` for Throughput
      Optimized HDD, ``sc1`` for Cold HDD, or ``standard`` for Magnetic volumes.

    return_objs
        (bool) - Changes the return type from list of volume IDs to list of
        boto.ec2.volume.Volume objects

    returns
        (list) - A list of the requested values: Either the volume IDs or, if
        return_objs is ``True``, boto.ec2.volume.Volume objects.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.get_all_volumes filters='{"tag:Name": "myVolume01"}'

    r)�
volume_idsr\cSr&rrf�r)rarrrr+SrZz#get_all_volumes.<locals>.<listcomp>N)r�get_all_volumesrrr r!r")
rr\rlrrrrr#rDr$rrrrs4
��rcsxddid�}d}i}	|D]�}
t|
�di��}t|
�di���d||||d�}i}
t�d|�d	}|
�d
|�}z7|��D]0\}}|dkrH||d<q;|dkrgt||||||d
�}|sbd|�d�}t|��||
d<q;||
|<q;Wnty�}zt�|�WYd	}~qd	}~ww|
|d<td,i|��}t�d|�|D]�|	�	�j
�dd�����d��d�
����q�qt�d|	�iid�}|	��D]�}|d|d��t�d�j
tt�di���ttt�di�����}t�d�j
��t����}t||�}��fdd�||@D�}t||�}|�s|�s|�r.|�r.tt�di��|d�j
<�|d�j
<nt�d�j
�|�rI�fdd �|D�}t�d!�j
|�|�r]�fd"d �|D�}t�d#�j
|�|�s�t�j
�||||d$��s}d%|d&<d'��j
��|d(<|S|�r�|�r�t�d)�j
|�t�j
|||||d$��s�d%|d&<d*��j
|�|d(<|Sq�|d�s�|d�r�|d+�
|�|S)-a�
    .. versionadded:: 2016.11.0

    tag_maps (list)
        List of dicts of filters and tags, where 'filters' is a dict suitable for passing to the
        'filters' argument of get_all_volumes() above, and 'tags' is a dict of tags to be set on
        volumes (via create_tags/delete_tags) as matched by the given filters.  The filter syntax
        is extended to permit passing either a list of volume_ids or an instance_name (with
        instance_name being the Name tag of the instance to which the desired volumes are mapped).
        Each mapping in the list is applied separately, so multiple sets of volumes can be all
        tagged differently with one call to this function.  If filtering by instance Name, You may
        additionally limit the instances matched by passing in a list of desired instance states.
        The default set of states is ('pending', 'rebooting', 'running', 'stopping', 'stopped').

    YAML example fragment:

    .. code-block:: yaml

        - filters:
            attachment.instance_id: i-abcdef12
          tags:
            Name: dev-int-abcdef12.aws-foo.com
        - filters:
            attachment.device: /dev/sdf
          tags:
            ManagedSnapshots: true
            BillingGroup: bubba.hotep@aws-foo.com
          in_states:
          - stopped
          - terminated
        - filters:
            instance_name: prd-foo-01.aws-foo.com
          tags:
            Name: prd-foo-01.aws-foo.com
            BillingGroup: infra-team@aws-foo.com
        - filters:
            volume_ids: [ vol-12345689, vol-abcdef12 ]
          tags:
            BillingGroup: infra-team@aws-foo.com

    authoritative (bool)
        If true, any existing tags on the matched volumes, and not explicitly requested here, will
        be removed.

    dry_run (bool)
        If true, don't change anything, just return a dictionary describing any changes which
        would have been applied.

    returns (dict)
        A dict describing status and any changes.

    T�)�success�comment�changes)r�Z	rebootingr�Zstopping�stoppedr\rk)rlrrrrzgot filters: %sNrerrO)rJrerrrrzCouldn't resolve instance Name z
 to an ID.zattachment.instance_idzgot volume list: %s�-�_)�volrkztag_sets after munging: %s)�old�newr
zcurrent tags on vol.id %s: %szrequested tags on vol.id %s: %scs"g|]
}�j|�|kr|�qSr�rkr�rkr
rrr+�s"z$set_volumes_tags.<locals>.<listcomp>rrzNo changes needed for vol.id %sc�i|]}|�|�qSrr�r)�krrrr>��z$set_volumes_tags.<locals>.<dictcomp>zNew tags for vol.id %s: %scrrrrrrrr>�rzUpdated tags for vol.id %s: %srFrz#Failed to set tags on vol.id {}: {}rzRemoved tags for vol.id %s: %sz&Failed to remove tags on vol.id {}: {}r	r)r�r�r!r3rirMrr�r�
setdefaultrg�replace�copyrj�valuesr<�setr�r��create_tags�format�delete_tags)Ztag_mapsZ
authoritativerurrrrrDZrunning_statesZtag_sets�tmr\�argsZnew_filtersr/rer�vr�r$Zvolumesr	Zvolume�currZreq�addrj�remover�rrr�set_volumes_tagsYs�=�
�

�
�����
�������r$c

Cs�t||||d�}z"|�|�}i}|D]}|j|vri||j<|j||j|j<q|WStjjyE}	z
t�	|	�iWYd}	~	Sd}	~	ww)a�
    Describe all tags matching the filter criteria, or all tags in the account otherwise.

    .. versionadded:: 2018.3.0

    filters
        (dict) - Additional constraints on which volumes to return.  Note that valid filters vary
        extensively depending on the resource type.  When in doubt, search first without a filter
        and then use the returned data to help fine-tune your search.  You can generally garner the
        resource type from its ID (e.g. `vol-XXXXX` is a volume, `i-XXXXX` is an instance, etc.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.get_all_tags '{"tag:Name": myInstanceNameTag, resource-type: instance}'

    rN)
rr�Zres_idr�rJrrr r!r")
r\rrrrr#rDrkr�r$rrrr��s



��r�c
C�ht|t�s|g}t||||d�}z	|�||�WdStjjy3}zt�|�WYd}~dSd}~ww)u
    Create new metadata tags for the specified resource ids.

    .. versionadded:: 2016.11.0

    resource_ids
        (string) or (list) – List of resource IDs.  A plain string will be converted to a list of one element.
    tags
        (dict) – Dictionary of name/value pairs. To create only a tag name, pass '' as the value.

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.create_tags vol-12345678 '{"Name": "myVolume01"}'

    rTNF)	rBr�rrrrr r!r"�Zresource_idsrkrrrrr#r$rrrr 	s

��rc
Cr%)uz
    Delete metadata tags for the specified resource ids.

    .. versionadded:: 2016.11.0

    resource_ids
        (string) or (list) – List of resource IDs.  A plain string will be converted to a list of one element.
    tags
        (dict) or (list) – Either a dictionary containing name/value pairs or a list containing just tag names.
                           If you pass in a dictionary, the values must match the actual tag values or the tag
                           will not be deleted. If you pass in a value of None for the tag value, all tags with
                           that name will be deleted.

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.delete_tags vol-12345678 '{"Name": "myVolume01"}'
        salt-call boto_ec2.delete_tags vol-12345678 '["Name","MountPoint"]'

    rTNF)	rBr�rrrrr r!r"r&rrrrA	s

��rc	

Cs�t||||d�}	z|	�||||�}
|
r$|r$t|	|�s$d}t�|�WdS|
WStjjy@}zt�|�WYd}~dSd}~ww)uu
    Detach an EBS volume from an EC2 instance.

    .. versionadded:: 2016.11.0

    volume_id
        (string) – The ID of the EBS volume to be detached.
    instance_id
        (string) – The ID of the EC2 instance from which it will be detached.
    device
        (string) – The device on the instance through which the volume is exposted (e.g. /dev/sdh)
    force
        (bool) – Forces detachment if the previous detachment attempt did not occur cleanly.
                 This option can lead to data loss or a corrupted file system. Use this option
                 only as a last resort to detach a volume from a failed instance. The instance
                 will not have an opportunity to flush file system caches nor file system meta data.
                 If you use this option, you must perform file system check and repair procedures.
    wait_for_detachement
       (bool) - Whether or not to wait for volume detachement to complete.

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.detach_volume vol-12345678 i-87654321

    r�4Timed out waiting for the volume status "available".FN)r�
detach_volume�_wait_for_volume_availabler!r"rrr )
r�r/�devicerZwait_for_detachementrrrrr#rD�timeout_msgr$rrrr(f	s$)���

��r(c

Cs�t||||d�}z|�|�WStjjy0}	z|s&t�|	�WYd}	~	dSWYd}	~	nd}	~	wwz
|j||d�|�|�WStjjyX}	zt�|	�WYd}	~	dSd}	~	ww)u�
    Detach an EBS volume from an EC2 instance.

    .. versionadded:: 2016.11.0

    volume_id
        (string) – The ID of the EBS volume to be deleted.
    force
        (bool) – Forces deletion even if the device has not yet been detached from its instance.

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.delete_volume vol-12345678

    rNF)r)r�
delete_volumerrr r!r"r()
r�r/r*rrrrrr#r$rrrr,�	s$
���
��r,r}cCsZd}	|d}t�|�|j|gd�}t|�dkrdS|d}|jdkr&dS||kr,dSq)NrTrr)rFZ	available)r~rrrvr�)r#r�r��intervalrbZvolsr
rrrr)�	s

�r)c	
CsVt||||d�}z|�|||�WStjjy*}zt�|�WYd}~dSd}~ww)u
    Attach an EBS volume to an EC2 instance.
    ..

    volume_id
        (string) – The ID of the EBS volume to be attached.
    instance_id
        (string) – The ID of the EC2 instance to attach the volume to.
    device
        (string) – The device on the instance through which the volume is exposed (e.g. /dev/sdh)

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.attach_volume vol-12345678 i-87654321 /dev/sdh

    rNF)r�
attach_volumerrr r!r")	r�r/r*rrrrr#r"rrrr.�	s
��r.c
Cs�|dur|durtd��i}t||	|
|d�}
z*|
j|||||||d�}|r9t|
|j�s9d}t�|�||d<W|S|j|d<W|Stjj	y]}zt
d|�|d<WYd}~|Sd}~ww)	u�
    Create an EBS volume to an availability zone.

    ..

    zone_name
        (string) – The Availability zone name of the EBS volume to be created.
    size
        (int) –  The size of the new volume, in GiB. If you're creating the
                 volume from a snapshot and don't specify a volume size, the
                 default is the snapshot size.
    snapshot_id
        (string) –  The snapshot ID from which the new volume will be created.
    volume_type
        (string) -  The type of the volume. Valid volume types for AWS can be found here:
                    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
    iops
        (int) - The provisioned IOPS you want to associate with this volume.
    encrypted
        (bool) - Specifies whether the volume should be encrypted.
    kms_key_id
        (string) - If encrypted is True, this KMS Key ID may be specified to
                   encrypt volume with this key
                   e.g.: arn:aws:kms:us-east-1:012345678910:key/abcd1234-a123-456a-a12b-a123b4cd56ef
    wait_for_creation
        (bool) - Whether or not to wait for volume creation to complete.

    returns
        (string) - created volume id on success, error message on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.create_volume us-east-1a size=10
        salt-call boto_ec2.create_volume us-east-1a snapshot_id=snap-0123abcd

    Nz3Size must be provided if not created from snapshot.r)r��zoneZsnapshotr�r�r��
kms_key_idr'r"r�r�)rr�
create_volumer)rgr!r"rrr r
)Z	zone_namer�r�r�r�r�r0Zwait_for_creationrrrrrDr#r
r+r"rrrr1�	s44�	

����r1)NNNNNN)r.NNNN)NNNNN)NNNNNNNFNNNN)	NNNNFNNNN)NNNNNNN)NNNN)
NNNNNNNFNN)NNNNNNNNFFN)
NNNNNNNNNF)NNNNNNNN)	NNNNNNNNN)"NNNNNr�NNNNNNNNNNNNNNNNNNNNNNNNNNNN)NN)NNNFNNNN)NNFNNNN)FFNNNN)NNFFNNNN)r}r})NNNNFNFNNNN)H�__doc__�loggingr~Zsalt.utils.compatrZsalt.utils.dataZsalt.utils.jsonZsalt.utils.versionsZsalt.exceptionsrrrZboto.ec2Zboto.ec2.blockdevicemappingrrZboto.ec2.networkinterfacerrr�ImportError�	getLoggerrr!rrr%r-r5r2rErHrQrRrWrXr[rqrwr�r�rMr�r�r�r�r�r�r�r�r�r�r�rNr�r�r�r�r�r�r�rrr$r�rrr(r,r)r.r1rrrr�<module>sJ.�

�
�!
�9
�
42
�&
�l
�"
�N
�
D
�F
�;
�>
�)
�
+
�*>
�


�

�$
�\
�
[
�
 6
�F
�,
�B
�.
�R
�@
�
'
!
!'
�<
�
-
�"�