%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/boto_ec2.pyc

�
���^c#@@spdZddlmZmZmZddlZddlZddlZddl	Zddl
ZddlZddlm
Z
ddlmZddlmZmZyNddlZddlZddlmZmZddlmZmZeZWnek
reZnXeje �Z!d	�Z"d
�Z#ddddddd�Z%ddddddd�Z&d
ddddd�Z'ddddddd�Z(dddddd�Z)ddddddd�Z*dddddddeddddd�Z+ddddddd�Z,ddddeddddd�	Z-dddddddd�Z.ddddd�Z/dddddddeddd�
Z0ddddddddeedd�Z1ddddddddded�
Z2dddddddd�Z3ddddddddd�Z4dddddd�Z5dddddddddd�	Z6d�Z7ddddddddddddddddddddddddddddddddddd �"Z8ddddd!�Z9ddddd"�Z:ddddd#�Z;ddddd$�Z<ddddddd%�Z=dddddddd&�Z>dddddddd'�Z?ddddd(�Z@ddddddd)�ZAddd*�ZBd+�ZCdddddddddd,�	ZDddddddd-�ZEddddddddd.�ZFdddeddddd/�ZGddddddddd0�ZHddeddddd1�ZIeeddddd2�ZJdddddd3�ZKddddd4�ZLddddd5�ZMddeeddddd6�ZNddeddddd7�ZOd8d8d9�ZPddddd:�ZQddddededdddd;�ZRdS(<u}
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

i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tmap(tSaltInvocationErrortCommandExecutionError(tBlockDeviceMappingtBlockDeviceType(tNetworkInterfaceSpecificationtNetworkInterfaceCollectioncC@sHtjjjdddt�}|tkrDtdtddt�n|S(ug
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    tboto_veru2.8.0tcheck_boto3uboto.assign_funcsuec2tpack(	tsalttutilstversionstcheck_boto_reqstFalsetTruet	__utils__t__name__t__salt__(t
has_boto_reqs((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt__virtual__Ls	cC@s1tjjjt�tr-tdtd�ndS(Nuboto.assign_funcsuec2(RRtcompattpack_dunderRtHAS_BOTOR(topts((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt__init__]sc	C@sitd|d|d|d|�}y|jd|d|�SWn'tjjk
rd}tj|�gSXdS(u�
    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`
    tregiontkeytkeyidtprofilet	addressestallocation_idsN(t	_get_conntget_all_addressestbotot	exceptiontBotoServerErrortlogterror(R"R#RRR R!tconnte((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt_get_all_eip_addressescs!
cC@s/gt||||||�D]}|j^qS(u\
    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
    (R-t	public_ip(R"R#RRR R!tx((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytget_all_eip_addresses{sustandardcC@s�d}x�td|d|d|d|�D]�}td|d|d|d|d|�d}|dr�tjd||d�q(n|d	r�tjd
||d	�q(n|d|kr(tjd||�|}Pq(q(W|s�tjd
�n|S(u
    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
    RRR R!R"iuinstance_idu-%s is already associated with the instance %sunetwork_interface_idu6%s is already associated with the network interface %sudomainu;The first unassociated EIP address in the domain '%s' is %su!No unassociated Elastic IP found!N(tNoneR0tget_eip_address_infoR)tdebug(tdomainRRR R!teiptaddresstaddress_info((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytget_unassociated_eip_address�s.


	
	
c

C@s�t|�td�kr$|g}nt|�td�krH|g}ntd|d|d|d|d|d|�}dd	d
ddd
ddg}g|D]4}tg|D]}	|	t||	�f^q��^q�S(u�
    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
    ustringR"R#RRR R!u
allocation_iduassociation_idudomainuinstance_idunetwork_interface_idunetwork_interface_owner_idu	public_ipuprivate_ip_address(ttypeR-tdicttgetattr(
R"R#RRR R!trettinterestingR6R/((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR2�s		c

C@s�|r!|dkr!td��ntd|d|d|d|�}y|jd|�}Wn'tjjk
r�}tj|�tSXdd	d
ddd
ddg}t	g|D]}	|	t
||	�f^q��S(um
    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
    uvpcu9The only permitted value for the 'domain' param is 'vpc'.RRR R!R4u
allocation_iduassociation_idudomainuinstance_idunetwork_interface_idunetwork_interface_owner_idu	public_ipuprivate_ip_address(RR$tallocate_addressR&R'R(R)R*RR:R;(
R4RRR R!R+R6R,R=R/((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytallocate_eip_address�s!
		c	C@s�tjjj||f�s*td��ntd|d|d|d|�}y|j||�SWn'tjj	k
r�}t
j|�tSXdS(u
    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
    u>Exactly one of 'public_ip' OR 'allocation_id' must be providedRRR R!N(
RRtdatatexactly_oneRR$trelease_addressR&R'R(R)R*R(R.t
allocation_idRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytrelease_eip_addresss!
c
C@s�tjjj||||f�s0td��ntd|d|	d|
d|�}|r�y+td|d|d|	d|
d|�}Wn'tjj	k
r�}
t
j|
�tSX|s�t
jd|�tSn|r>y(t
|d|d|	d|
d|�}Wn'tjj	k
r }
t
j|
�tSX|s>t
jd|�tSny2|jd	|d
|d|d|d
|d|�SWn'tjj	k
r�}
t
j|
�tSXdS(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
    upExactly one of 'instance_id', 'instance_name', 'network_interface_id', 'network_interface_name' must be providedRRR R!tnameu;Given instance_name '%s' cannot be mapped to an instance_iduMGiven network_interface_name '%s' cannot be mapped to an network_interface_idtinstance_idR.RCtnetwork_interface_idtprivate_ip_addresstallow_reassociationN(RRR@RARR$tget_idR&R'R(R)R*Rtget_network_interface_idtassociate_address(RFt
instance_nameR.RCRGtnetwork_interface_nameRHRIRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytassociate_eip_address6sN&!


	
c	C@sctd|d|d|d|�}y|j||�SWn'tjjk
r^}tj|�tSXdS(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
    RRR R!N(R$tdisassociate_addressR&R'R(R)R*R(R.tassociation_idRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytdisassociate_eip_address�s!
c	
C@stjjj||f�s*td��ntd|d|d|d|�}	|r�y(t|d|d|d|d|�}Wn'tjj	k
r�}
t
j|
�tSX|s�t
jd|�tSny&|	j
d|d|d	|d
|�SWn'tjj	k
r}
t
j|
�tSXdS(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
    uPExactly one of 'network_interface_name', 'network_interface_id' must be providedRRR R!uMGiven network_interface_name '%s' cannot be mapped to an network_interface_idRGtprivate_ip_addressest"secondary_private_ip_address_counttallow_reassignmentN(RRR@RARR$RKR&R'R(R)R*Rtassign_private_ip_addresses(RNRGRSRTRURRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyRV�s0!

	
c	
C@stjjj||f�s*td��ntd|d|d|d|�}|r�y(t|d|d|d|d|�}Wn'tjj	k
r�}t
j|�tSX|s�t
jd|�tSny|j
d|d|�SWn'tjj	k
r}t
j|�tSXd	S(
u�
    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
    uPExactly one of 'network_interface_name', 'network_interface_id' must be providedRRR R!uMGiven network_interface_name '%s' cannot be mapped to an network_interface_idRGRSN(RRR@RARR$RKR&R'R(R)R*Rtunassign_private_ip_addresses(	RNRGRSRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyRW�s,!

	
c	C@sAtd|d|d|d|�}g|j�D]}|j^q.S(u�
    Get a list of AZs for the configured region.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_zones
    RRR R!(R$t
get_all_zonesRE(RRR R!R+tz((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt	get_zoness
!c
	C@s�td|d|d|d|�}
yRiid6}|rG|g|d<n|r^||dd<n|r�x7tj|�D]#\}}
|
|ddj|�<qtWn|	r�|dj|	�n|
j|�}g|D]}|jD]}|^q�q�}tjd	||�|rDg|D]}|j	|kr|^q}tjd
|�n|rn|rT|Sg|D]}|j
^q[SgSWn'tjj
k
r�}tj|�gSXdS(u�
    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"}'

    RRR R!ufiltersuinstance_idsutag:Nameutag:{0}u:The filters criteria %s matched the following instances:%su>Limiting instance matches to those in the requested states: %sN(R$Rt	iteritemstformattupdatetget_all_reservationst	instancesR)R3tstatetidR&R'R(R*(RFREttagsRRR R!treturn_objst	in_statestfiltersR+tfilter_parametersttag_namet	tag_valuetreservationstrtiR_tinstancetexc((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytfind_instances+s:!
)	
(

cC@s�td|d|d|d|d|d|d|dtd	|�	}|sVtjd
�tSt|�dkrytjd�tS|d
}
y#|
j|d|d|	d|
�SWn'tjj	k
r�}tj|�tSXdS(uT
    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'

    RFRERbRRR R!RcReuSource instance not foundiuVMultiple instances found, must match exactly only one instance to create an image fromitdescriptiont	no_reboottdry_runN(
RnRR)R*Rtlentcreate_imageR&R'R((tami_nameRFRMRbRRR R!RoRpRqReR_RlRm((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyRsds 



c
	C@s�d}
td|d|d|d|�}xm|
r�y�iid6}|rV|g|d<n|rl|g|d<n|r�|g|d	<n|r�||dd
<n|r�x7tj|�D]#\}
}||ddj|
�<q�Wn|j|�}tjd||�|r%|	r|Sg|D]}|j^qStSWq*t	j
jk
r�}|jd
kr{tjd�t
jd�|
d8}
q*ntjd||�tSXq*WtS(u�
    Given image properties, find and return matching AMI ids

    CLI Examples:

    .. code-block:: bash

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

    iRRR R!ufiltersu	image_idsu
executable_byuownersunameutag:{0}u7The filters criteria %s matched the following images:%su
Throttlingu0Throttled by AWS API, will retry in 5 seconds...iiu0Failed to convert AMI name `%s` to an AMI ID: %s(R$RR[R\tget_all_imagesR)R3RaRR&R'R(t
error_codettimetsleepR*(Rtt
executable_bytownerst	image_idsRbRRR R!RctretriesR+RfRgRhtimagestimageRm((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytfind_images�sB
!	
	



	cC@s�td|d|d|d|d|d|dtd|�}|tdgfkrR|St|�d	krv|d
j�tStjd�tSdS(
u�
    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
    RFRERRR R!RcReiiu0Refusing to terminate multiple instances at onceN(RnRRR1Rrt	terminateR)twarning(RFRERRR R!ReR_((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR��s	
c	C@s�td|d|d|d|d|d|d|d|�}|r�tjd	d
j|��t|�dkrr|dStd
��ntjd�dSdS(u�
    Given instance properties, return the instance id if it exists.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_id myinstance

    RERbRRR R!RdReuInstance ids: %su iiu3Found more than one instance matching the criteria.uCould not find instance.N(RnR)tinfotjoinRrRR�R1(	RERbRRR R!RdRetinstance_ids((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyRJ�s
	
c		C@s�g}td|d|d|d|�}|jdi|d6�}t|�dkr�x;|D] }|ji|j|j6�qYWntjd|�|S(	u�
    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
    RR R!RReuresource-idiu No tags found for instance_id %s(R$tget_all_tagsRrtappendtvalueRER)R�(	RFR RR!RRbtclienttresultttag((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytget_tags�s!
!c	
C@sktd|d|d|d|d|d|d|d|d	|�	}	|	rVtjd
�tStjd�tSdS(
u
    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
    RFRERbRRR R!RdReuInstance exists.uInstance does not exist.N(RnR)R�RR�R(
RFRERbRRR R!RdReR_((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytexistss

cC@s^|s
dSt|t�r|St|tj�rGtjjj|�}nt|t	�sst
jd|t|��dSt�}x�tj
|�D]�\}}td|jd�d|jdt�d|jd�d|jd	�d
|jd�d|jd
�d|jdt�d|jd�d|jd�d|jd�d|jd��}|||<q�W|S(u�
    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

    uQCan't convert '%s' of type %s to a boto.ec2.blockdevicemapping.BlockDeviceMappingtephemeral_nameuephemeral_namet	no_deviceu	no_devicet	volume_idu	volume_idtsnapshot_idusnapshot_idtstatusustatustattach_timeuattach_timetdelete_on_terminationudelete_on_terminationtsizeusizetvolume_typeuvolume_typetiopsuiopst	encryptedu	encryptedN(R1t
isinstanceRRtstring_typesRRtjsontloadsR:R)R*R9R[RtgetR(tthingtbdmtdtttbdt((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt_to_blockdev_map!s2		um1.smallc#/*C@s�t|
|f�r!td��n|rtdd|d|d|d| d|!�}#d|#krrtjd	|�tS|#d}
nt||f�r�td
��n|rg}xf|D][}$td|$d|d|d|d| d|!�}#|#stjd
|$�tS||#g7}q�Wnttt|d2k	|d2k	|"d2k	g��}%t
|%�dkrftd��n|r�t|d|d|d| d|!�}&|&d}|s�tjd|�q�n|r�td|dd�}'ntd|
d|dd�}'|"r#g|"D]}(t|(�^q�})t
|)�}*nt
|'�}*td|d|d| d|!�}+|+j|d|d|d|d|d|d|d|	d|
d|d t|�d!|d"|d#|d$|d%|d&|d'|d(|d)|d*|*�},|,s�tjd+�tS|,jd}-d,}.x)|.d,kr2tjd-�|-j�}.q
W|.d.kr||rX|-jd/|�n|rn|-j|�ni|-jd06Stjd1|.�d2S(3u�
    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

    u5Only one of subnet_name or subnet_id may be provided.uboto_vpc.get_resource_idusubnetRRR R!uidu Couldn't resolve subnet name %s.uGOnly one of security_group_ids or security_group_names may be provided.uboto_secgroup.get_group_idtvpc_nameu'Couldn't resolve security group name %siu_Only one of network_interface_id, network_interface_name or network_interfaces may be provided.uresultuMGiven network_interface_name '%s' cannot be mapped to an network_interface_idRGtdevice_indexit	subnet_idtgroupstkey_nametsecurity_groupst	user_datat
instance_typet	placementt	kernel_idt
ramdisk_idtmonitoring_enabledRHtblock_device_maptdisable_api_terminationt$instance_initiated_shutdown_behaviortplacement_grouptclient_tokentadditional_infottenancytinstance_profile_arntinstance_profile_namet
ebs_optimizedtnetwork_interfacesuInstance could not be reservedupendingiurunninguNameuinstance_idu/Instance could not be started -- status is "%s"N(tallRRR)R�RtlistRtintR1tsumRKR	R
R$t
run_instancesR�R_RwRxR]tadd_tagtadd_tagsRa(/timage_idRERbR�R�R�R�R�R�R�R�tvpc_idR�R�tsubnet_nameRHR�R�R�R�R�tsecurity_group_idstsecurity_group_namesR�R�R�R�R�RGRNRRR R!R�Rjtsgntnetwork_interface_argsR�t	interfaceR/tinterfaces_specst
interfacesR+treservationRlR�((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytrunVs��

			

	!	


c	C@s�td|d|d|d|�}yC|j|�}tjd|�|dkrStS|j|jfSWn'tj	j
k
r�}tj|�tSXdS(u�
    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
    RRR R!uthe key to return is : %sN(R$tget_key_pairR)R3R1RREtfingerprintR&R'R((R�RRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytget_key<s
!
c	C@s�td|d|d|d|�}y7|j|�}tjd|�|j|�|jSWn'tjjk
r�}tj|�t	SXdS(u�
    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/
    RRR R!uthe key to return is : %sN(
R$tcreate_key_pairR)R3tsavetmaterialR&R'R(R(R�t	save_pathRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt
create_keySs!

c	C@s|td|d|d|d|�}y-|j||�}tjd|�|jSWn'tjjk
rw}tj|�tSXdS(u	
    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
    RRR R!uthe key to return is : %sN(	R$timport_key_pairR)R3R�R&R'R(R(R�tpublic_key_materialRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt
import_keyks!
c	C@svtd|d|d|d|�}y'|j|�}tjd|�|SWn'tjjk
rq}tj|�tSXdS(u�
    Deletes a key. Always returns True

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.delete_key mykey
    RRR R!uthe key to return is : %sN(R$tdelete_key_pairR)R3R&R'R(R(R�RRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt
delete_key�s
!
c
	C@s�td|d|d|d|�}yZ|j||�}tjd|�g}|rvx!|D]}|j|j�qYWn|SWn'tjjk
r�}	tj|	�t	SXdS(ui
    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
    RRR R!uthe key to return is : %sN(
R$tget_all_key_pairsR)R3R�RER&R'R(R(
tkeynamesReRRR R!R+tkeyst
key_valuesR,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytget_keys�s!

c
C@s�td|d|d|d|�}ddddd	d
ddd
ddddg
}	t||f�sotd��n|r�|r�td��n||	kr�tdj|	���ny�|r7td|d|d|d|d|d|�}
t|
�dkrtjd�tSt|
�dkr*tjd�tS|
d}n|j	||�}|sStSi|||6SWn't
jjk
r�}tj|�tSXdS(u
    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
    RRR R!uinstanceTypeukerneluramdiskuuserDataudisableApiTerminationu!instanceInitiatedShutdownBehaviorurootDeviceNameublockDeviceMappinguproductCodesusourceDestCheckugroupSetuebsOptimizedusriovNetSupportuNAt least one of the following must be specified: instance_name or instance_id.uLBoth instance_name and instance_id can not be specified in the same command.uAttribute must be one of: {0}.REReiu7Found more than one EC2 instance matching the criteria.u,Found no EC2 instance matching the criteria.iN(
R$tanyRR\RnRrR)R*Rtget_instance_attributeR&R'R((
t	attributeRMRFRRR R!ReR+tattribute_listR_tinstance_attributeRm((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt
get_attribute�s8!$	



c	
C@sdtd|d|d|d|�}	ddddd	d
ddd
ddddg
}
t||f�sotd��n|r�|r�td��n||
kr�tdj|
���ny�|rtd|d|d|d|d|d|�}t|�dkrtd��n|d}n|	j|||�}|s1tS|SWn't	j
jk
r_}tj
|�tSXdS(uE
    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
    RRR R!uinstanceTypeukerneluramdiskuuserDataudisableApiTerminationu!instanceInitiatedShutdownBehaviorurootDeviceNameublockDeviceMappinguproductCodesusourceDestCheckugroupSetuebsOptimizedusriovNetSupportuNAt least one of the following must be specified: instance_name or instance_id.uLBoth instance_name and instance_id can not be specified in the same command.uAttribute must be one of: {0}.REReiu7Found more than one EC2 instance matching the criteria.iN(R$R�RR\RnRrRtmodify_instance_attributeRR&R'R(R)R*(
R�tattribute_valueRMRFRRR R!ReR+R�R_Rm((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt
set_attribute�s0!$	

c
	C@s�td|d|d|d|�}i}yt|jdi|d6�}|s]idd6|d	<n=t|�d
kr�idd6|d	<n|d}|j|d
<Wn-tjjk
r�}	td|	�|d	<nX|S(u�
    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
    RRR R!Reutag:NameuNo ENIs found.umessageuerroriu*Name specified is tagged on multiple ENIs.iuresultuboto.get_error(R$tget_all_network_interfacesRrRaR&R'tEC2ResponseErrorR(
RERRR R!R+RjtenisteniR,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyRK-s
!
c
	C@s�td|d|d|d|�}i}t|||�}d|krk|dddkrgd	|d<|S|S|d}	t|	�|d<|S(
u�
    Get an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.get_network_interface name=my_eni
    RRR R!uerrorumessageuNo ENIs found.uresultN(R$t_get_network_interfaceR1t_describe_network_interface(
RERGRRR R!R+RjR�R�((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytget_network_interfaceJs
!

cC@s�i}|p|s!td��ny�|r?|j|g�}n|jdi|d6�}|sridd6|d<n:t|�dkr�idd6|d<n|d	}||d
<Wn-tjjk
r�}td|�|d<nX|S(Nu5Either name or network_interface_id must be provided.Reutag:NameuNo ENIs found.umessageuerroriu*Name specified is tagged on multiple ENIs.iuresultuboto.get_error(RR�RrR&R'R�R(R+RERGRjR�R�R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR�ds"
cC@sni}xlddddddddd	d
ddd
ddddddgD]+}t||�rFt||�||<qFqFW|jj|d<g|d<x6|jD]+}|dji|jd6|jd	6�q�Wg|d<x6|jD]+}|dji|jd6|j	d6�q�Wi|d<xRddddddd	gD]5}t|j
|�r1t|j
|�|d|<q1q1W|S(Nustatusudescriptionuavailability_zoneurequesterIdurequester_managedumac_addressuprivate_ip_addressuvpc_iduidusource_dest_checkuowner_idutagsu	subnet_idu
associationIdu
publicDnsNameu	ipOwnerIdupublicIpuallocationIduregionugroupsunameuprivate_ip_addressesuprimaryu
attachmentuattach_timeudevice_indexudelete_on_terminationuinstance_iduinstance_owner_id(thasattrR;RRER�R�RaRSRHtprimaryt
attachment(R�RjtattrtgroupR6((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR�|s0	
)



!c
C@s�tjjj||f�s*td��n|r�tdd|d|d|d|d|	�}
d|
kr{tjd	|�tS|
d}nt	d|d|d|d|	�}i}t
||�}
d
|
kr�idd6|d
<|Std|gd|d|d|d|	�}|jd�}|sCdj|�}i|d6|d
<|Std|d|d|d|d|d|	�}y5|j
|d|d|d|�}|jd|�Wn.tjjk
r�}td|�|d
<|SXt|�|d
<|S(u�
    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']
    u@One (but not both) of subnet_id or subnet_name must be provided.uboto_vpc.get_resource_idusubnetRRR R!uidu Couldn't resolve subnet name %s.uresultu)An ENI with this Name tag already exists.umessageuerroruboto_vpc.get_subnet_associationuvpc_idu-subnet_id {0} does not map to a valid vpc id.u"boto_secgroup.convert_to_group_idsR�RHRoR�uNameuboto.get_error(RRR@RARRR)R�RR$R�R�R\tcreate_network_interfaceR�R&R'R�RR�(RER�R�RHRoR�RRR R!tresourceR+RjR�R�tmsgt_groupsR�R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR��sN	
!$	c
C@s�|p	|std��ntd|d|d|d|�}i}t|||�}d|krd|S|d}	yt|	�}
|
d}Wn#tk
r�id	d
6|d<|SXy|j|�|d<Wn-tjjk
r�}t	d|�|d<nX|S(u�
    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']
    u5Either name or network_interface_id must be provided.RRR R!uerroruresultuidu(ID not found for this network interface.umessageuboto.get_error(
RR$R�R�tKeyErrortdelete_network_interfaceR&R'R�R(RERGRRR R!R+RjR�R�R�R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR��s(!

c	C@s�tjjj||f�s*td��ntjjj||f�sTtd��ntd|d|d|d|�}	i}
t|	||�}d|kr�|S|d}yt|�}
|
d	}Wn#tk
r�id
d6|
d<|
SX|rEy+t	d|d|d|d|d|�}WqEt
jjk
rA}t
j|�tSXny|	j|||�|
d<Wn-t
jjk
r�}td
|�|
d<nX|
S(u�
    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
    uPExactly one (but not both) of 'name' or 'network_interface_id' must be provided.uPExactly one (but not both) of 'instance_name' or 'instance_id' must be provided.RRR R!uerroruresultuidu(ID not found for this network interface.umessageREuboto.get_error(RRR@RARR$R�R�R�RJR&R'R(R)R*Rtattach_network_interfaceR�R(R�RERGRMRFRRR R!R+RjR�R�R�R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR��s>!


cC@s|p|p|s!td��ntd|d|d|d|�}i}	|s�t|||�}
d|
krp|
S|
d}t|�}y|dd	}Wq�tk
r�id
d6|	d<|	SXny|j||�|	d<Wn-tjjk
r
}
t	d|
�|	d<nX|	S(
u�
    Detach an Elastic Network Interface.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_ec2.detach_network_interface my_eni
    uFEither name or network_interface_id or attachment_id must be provided.RRR R!uerroruresultu
attachmentuidu%Attachment id not found for this ENI.umessageuboto.get_error(
RR$R�R�R�tdetach_network_interfaceR&R'R�R(RERGt
attachment_idtforceRRR R!R+RjR�R�R�R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR�3s*!

cC@s
|p	|std��n|dkrB|dkrBtd��ni}td|d|d|d|�}	t|	||�}
d|
kr�|
S|
d}t|�}|d	}|d
kr�d}
n0|dkr�d
}
n|dkr�d}
n|}
|}|jd�rf|
dkrftd|d|jd�d|d|d|d|�}|sfidd6|d<|Snd}|
dkr�y|dd	}Wq�tk
r�idd6|d<|SXny#|	j||
|d|�|d<Wn-t	j
jk
r}td|�|d<nX|S(u
    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'
    u5Either name or network_interface_id must be provided.u attr and value must be provided.RRR R!uerroruresultuidugroupsugroupSetusource_dest_checkusourceDestCheckudelete_on_terminationudeleteOnTerminationuvpc_idu"boto_secgroup.convert_to_group_idsR�u6Security groups do not map to valid security group idsumessageu
attachmentujNo attachment id found for this ENI. The ENI must be attached before delete_on_termination can be modifiedR�uboto.get_errorN(
RR1R$R�R�R�RR�t"modify_network_interface_attributeR&R'R�R(RERGR�R�RRR R!RjR+R�R�R�t_attrt_valuet_attachment_idR,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR�ZsX!

			!
c	C@s�td|d|d|d|�}y@|jd|d|�}|rF|Sg|D]}	|	j^qMSWn'tjjk
r�}
tj|
�gSXdS(u�
    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"}'

    RRR R!t
volume_idsReN(R$tget_all_volumesRaR&R'R(R)R*(RReRcRRR R!R+R<RjR,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR�s-!(
c@sitd6dd6id6}d.}i}	x�|D]�}
t|
jd
i��}t|
jdi���itd6|d
6|d6|d6|d6}i}
tjd|�d/}|
jd|�}y�x�|j�D]�\}}|dkr�||d<q�|dkrZtd|d|d|d|d|d|�}|sMdj|�}t	|��n||
d<q�||
|<q�WWn#t	k
r�}tj
|�q.nX|
|d
<t|�}tjd|�xT|D]L}|	j|j
jdd�i|d 6�j�d6�dj�j��q�Wq.Wtjd!|	�iid"6id#6}x�|	j�D]�}|d |d}�tjd$|j
tt|di���ttt|di��j��}tjd%|j
��t�j��}t||�}g||@D]#}|j|�|kr�|^q�}t||�}|s<|s<|rs|rstt|di��|d"|j
<�|d#|j
<ntjd&|j
�t|�r�t�fd'�|D��}tjd(|j
|�nt|�rt�fd)�|D��}tjd*|j
|�n|sAt|j
�d|d|d|d|�s_t|d<d+j|j
��|d<|S|r�t|�r�tjd,|j
|�t|j
|d|d|d|d|�s�t|d<d-j|j
|�|d<|Sq�q�qAqAW|d"s�|d#r|dj|�nd/|S(0u�
    .. 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.

    usuccessuucommentuchangesupendingu	rebootingurunningustoppingustoppedufiltersutagsureturn_objsuregionukeyukeyiduprofileugot filters: %su	in_statesu
volume_idsu
instance_nameRERdRRR R!u,Couldn't resolve instance Name {0} to an ID.uattachment.instance_idugot volume list: %su-u_uvolutag_sets after munging: %suoldunewucurrent tags on vol.id %s: %surequested tags on vol.id %s: %suNo changes needed for vol.id %sc3@s|]}|�|fVqdS(N((t.0tk(Rb(s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pys	<genexpr>BsuNew tags for vol.id %s: %sc3@s|]}|�|fVqdS(N((RR(Rb(s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pys	<genexpr>EsuUpdated tags for vol.id %s: %su%Failed to set tags on vol.id {0}: {1}uRemoved tags for vol.id %s: %su(Failed to remove tags on vol.id {0}: {1}(upendingu	rebootingurunningustoppingustoppedN(RR:R�R)R3R1titemsRJR\RR�Rt
setdefaultRatreplacetcopyR]tvaluesR;tsetR�R�RbRrtcreate_tagsRtdelete_tags(ttag_mapst
authoritativeRqRRR R!R<trunning_statesttag_setsttmRetargstnew_filtersRFRdRtvR�R,tvolumestvoltchangestvolumetcurrtreqtaddRjR]tremoveR�((Rbs9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pytset_volumes_tags�s�6
)




N($4#*
*
+c
	C@s�td|d|d|d|�}yd|j|�}i}xD|D]<}|j|krei||j<n|j||j|j<q@W|SWn'tjjk
r�}	tj	|	�iSXdS(u�
    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}'

    RRR R!N(
R$R�tres_idR�RER&R'R(R)R*(
ReRRR R!R+R<RbR�R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR�Ws!

c	C@s�t|t�s|g}ntd|d|d|d|�}y|j||�tSWn'tjjk
r}}tj	|�t
SXdS(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"}'

    RRR R!N(R�R�R$RRR&R'R(R)R*R(tresource_idsRbRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyRxs!
c	C@s�t|t�s|g}ntd|d|d|d|�}y|j||�tSWn'tjjk
r}}tj	|�t
SXdS(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"]'

    RRR R!N(R�R�R$R
RR&R'R(R)R*R(R RbRRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR
�s!
c	
	C@s�td|d|d|d|�}	yS|	j||||�}
|
ro|rot|	|�rod}tj|�tS|
SWn'tjjk
r�}tj|�tSXdS(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

    RRR R!u4Timed out waiting for the volume status "available".N(	R$t
detach_volumet_wait_for_volume_availableR)R*RR&R'R((
R�RFtdeviceR�twait_for_detachementRRR R!R+R<ttimeout_msgR,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR!�s !

c
	C@s�td|d|d|d|�}y|j|�SWn0tjjk
rd}	|setj|	�tSnXy$|j|d|�|j|�SWn'tjjk
r�}	tj|	�tSXdS(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

    RRR R!R�N(	R$t
delete_volumeR&R'R(R)R*RR!(
R�RFR#R�RRR R!R+R,((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR&�s!

icC@s�d}xytr�|d}tj|�|jd|g�}t|�dkrQtS|d}|jdkrntS||kr	tSq	WdS(NiiRu	available(RRwRxRRrRR�(R+R�R|tintervalRktvolsR((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR"s	


c		C@sftd|d|d|d|�}y|j|||�SWn'tjjk
ra}tj|�tSXdS(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

    RRR R!N(R$t
attach_volumeR&R'R(R)R*R(	R�RFR#RRR R!R+R*((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR)s!
cC@s|dkr'|dkr'td��ni}td|d|	d|
d|�}
y�|
jd|d|d|d	|d
|d|d|�}|r�t|
|j�r�d
}tj|�||d<n
|j|d<Wn-tj	j
k
r�}td|�|d<nX|S(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

    u3Size must be provided if not created from snapshot.RRR R!R�tzonetsnapshotR�R�R�t
kms_key_idu4Timed out waiting for the volume status "available".uerroruresultuboto.get_errorN(R1RR$t
create_volumeR"RaR)R*R&R'R(R(t	zone_nameR�R�R�R�R�R,twait_for_creationRRR R!R<R+RR%R*((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyR->s")!	

(St__doc__t
__future__RRRtloggingRwtsalt.utils.compatRtsalt.utils.datatsalt.utils.jsontsalt.utils.versionstsalt.extRtsalt.ext.six.movesRtsalt.exceptionsRRR&tboto.ec2tboto.ec2.blockdevicemappingRRtboto.ec2.networkinterfaceR	R
RRtImportErrorRt	getLoggerRR)RRR1R-R0R8R2R?RDRORRRVRWRZRnRsRR�RJR�R�R�R�R�R�R�R�R�R�R�RKR�R�R�R�R�R�R�R�RRR�RR
R!R&R"R)R-(((s9/usr/lib/python2.7/site-packages/salt/modules/boto_ec2.pyt<module>*s�


					.%("		R		927!0		5			�	 95			<#7	&	E	6~!!%	,	$	

Zerion Mini Shell 1.0