%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/cloud/clouds/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyc

�
���^c@@s�dZddlmZmZmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddl!j"j#Z#ddl$j"j%Z%ddl&j'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1m2Z2m3Z3dd	l4m5Z6m7Z8ydd
l9m:Z:e;Z<Wne=k
re>Z<nXy6ddl?Z?ddl@mAZAddlBmCZCe;ZDWne=k
rje>ZDnXyddlEZEe;ZFWne=k
r�e>ZFnXe
jGeH�ZIid
d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6ZJdZKd#ZLd$d%d&d'd(d)gZMejNd*ejO�ZPd+ZQd,�ZRd-�ZSd.�ZTd/�ZUd0�ZVd1�ZWeXeXeXeXe>e>d2�ZYeXeXd3d4d5d6d3d7�ZZeXd8�Z[eXeXd9�Z\d:�Z]d;�Z^d<�Z_d=�Z`d>�Zad?�ZbeXd@�ZceXdA�ZddB�ZedC�ZfdD�ZgdE�ZhdF�ZidG�ZjdH�ZkdI�ZldJ�ZmeXdK�ZneXdL�ZodM�ZpdN�ZqdO�ZrdP�ZsdQ�ZtdR�ZueXeXdS�ZveXeXdT�ZweXdU�ZxdV�ZyeXeXdW�ZzeXeXdX�Z{eXeXeXe;eXdY�Z|dZ�Z}eXeXd[�Z~d\�ZeXe;d]�Z�eXd^�Z�eXd_�Z�eXeXeXeXeXeXeXd`�Z�eXeXeXeXeXeXda�Z�eXeXeXeXeXdb�Z�eXdc�Z�eXdd�Z�eXde�Z�eXdf�Z�eXeXeXeXdg�Z�eXeXeXdh�Z�eXeXdi�Z�dj�Z�dk�Z�eXdl�Z�eXeXdm�Z�eXdn�Z�eXdo�Z�eXeXeXe>dp�Z�eXeXeXe>dq�Z�dr�Z�eXds�Z�eXdt�Z�eXdu�Z�eXdv�Z�eXeXdw�Z�eXeXdx�Z�eXeXdy�Z�eXeXeXeXeXeXdz�Z�eXeXd{�Z�d|�Z�eXeXe>d}�Z�d~�Z�eXeXeXeXd�Z�eXeXd��Z�eXeXeXeXd��Z�eXeXeXeXd��Z�d��Z�eXeXd��Z�eXeXd��Z�eXeXd��Z�eXeXd��Z�eXeXd��Z�eXeXe>d��Z�eXeXd��Z�eXeXd��Z�eXeXd��Z�eXeXeXeXeXd��Z�eXeXeXeXd��Z�eXeXd��Z�d��Z�eXeXd��Z�eXeXeXeXd��Z�eXeXeXeXd��Z�dS(�uT	
The EC2 Cloud Module
====================

The EC2 cloud module is used to interact with the Amazon Elastic Compute Cloud.

To use the EC2 cloud module, set up the cloud configuration at
 ``/etc/salt/cloud.providers`` or ``/etc/salt/cloud.providers.d/ec2.conf``:

.. code-block:: yaml

    my-ec2-config:
      # EC2 API credentials: Access Key ID and Secret Access Key.
      # Alternatively, to use IAM Instance Role credentials available via
      # EC2 metadata set both id and key to 'use-instance-role-credentials'
      id: GKTADJGHEIQSXMKKRBJ08H
      key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

      # If 'role_arn' is specified the above credentials are used to
      # to assume to the role. By default, role_arn is set to None.
      role_arn: arn:aws:iam::012345678910:role/SomeRoleName

      # The ssh keyname to use
      keyname: default
      # The amazon security group
      securitygroup: ssh_open
      # The location of the private key which corresponds to the keyname
      private_key: /root/default.pem

      # Be default, service_url is set to amazonaws.com. If you are using this
      # driver for something other than Amazon EC2, change it here:
      service_url: amazonaws.com

      # The endpoint that is ultimately used is usually formed using the region
      # and the service_url. If you would like to override that entirely, you
      # can explicitly define the endpoint:
      endpoint: myendpoint.example.com:1138/services/Cloud

      # SSH Gateways can be used with this provider. Gateways can be used
      # when a salt-master is not on the same private network as the instance
      # that is being deployed.

      # Defaults to None
      # Required
      ssh_gateway: gateway.example.com

      # Defaults to port 22
      # Optional
      ssh_gateway_port: 22

      # Defaults to root
      # Optional
      ssh_gateway_username: root

      # Default to nc -q0 %h %p
      # Optional
      ssh_gateway_command: "-W %h:%p"

      # One authentication method is required. If both
      # are specified, Private key wins.

      # Private key defaults to None
      ssh_gateway_private_key: /path/to/key.pem

      # Password defaults to None
      ssh_gateway_password: ExamplePasswordHere

      driver: ec2

      # Pass userdata to the instance to be created
      userdata_file: /etc/salt/my-userdata-file

:depends: requests
i(tabsolute_importtprint_functiontunicode_literals(t
cmp_to_keyN(tElementTree(tSaltCloudExceptiontSaltCloudSystemExittSaltCloudConfigErrortSaltCloudExecutionTimeouttSaltCloudExecutionFailure(tsix(tmaptrangetzip(turlparset	urlencode(tRSA(t
PKCS1_v1_5(tSHAuec2_ap_northeastuap-northeast-1uec2_ap_northeast_2uap-northeast-2uec2_ap_southeastuap-southeast-1uec2_ap_southeast_2uap-southeast-2uec2_eu_westu	eu-west-1uec2_eu_centralueu-central-1uec2_sa_eastu	sa-east-1uec2_us_eastu	us-east-1uec2_us_gov_west_1u
us-gov-west-1uec2_us_westu	us-west-1uec2_us_west_oregonu	us-west-2u
2014-10-01uRequestLimitExceededuInsufficientInstanceCapacityu
InternalErroruUnavailableuInsufficientAddressCapacityu$InsufficientReservedInstanceCapacityu	/\*.*?\*/uec2cC@s*t�tkrtSt�tkr&tStS(uH
    Set up the libcloud functions and check for EC2 configurations
    (tget_configured_providertFalsetget_dependenciest__virtualname__(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt__virtual__�s
cC@stjttptd�S(u/
    Return the first configured instance.
    uidukey(uidukey(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�s	cC@s*itd6tptd6}tjt|�S(u*
    Warn if dependencies aren't met.
    urequestsupycrypto or m2crypto(tHAS_REQUESTStHAS_M2tHAS_PYCRYPTORtcheck_driver_dependenciesR(tdeps((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�scC@s�tjdkr$t|j��}nt|�}|dkr{|j}d|krm|jd�}|d}ni|j|6Si}x�|D]�}|j}d|kr�|jd�}|d}n||kr*tjdkr�t|j��}nt|�}|dkrt|�||<q||j||<q�t||t	�se||}g||<||j
|�n||j
t|��q�W|S(u)
    Convert an XML tree into a dict
    iiiu}i(ii(ii(tsystversion_infotlentgetchildrenttagtsplitttextt_xml_to_dictt
isinstancetlisttappend(txmltreetchildren_lentnametcompstxmldicttitemttempvar((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR(�s8	

	


cC@s.i}i}x�tj|�D]�\}}d|krAt|d<n|d|krbi||d<n|d|df}|||dkri|d6|d6||d|<qqWxvtj|�D]e\}}xVtj|�D]E\}}|\}}	|d}
|d}|
|kr�|||
<q�q�Wq�W|S(u4
    Return an optimized list of providers.

    We want to reduce the duplication of querying
    the same region.

    If a provider is using the same credentials for the same region
    the same data will be returned for each provider, thus causing
    un-wanted duplicate data and API calls to EC2.

    ulocationuidukeyunameudata(R
t	iteritemstDEFAULT_LOCATION(t	providerst
tmp_providerstoptimized_providersR.tdatatcredstlocationttmp_datat_idt_keyt_namet_data((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytoptimize_providerss&



cC@s%tj||jd�tj�j�S(Nuutf-8(thmactnewtencodethashlibtsha256tdigest(tkeytmsg((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytsign.sc6C@s;t�}|jdd�}tj|�\}}	}
d}x�|tjkr�|j�}tjj�jd�}
|s�t	�}n|s�|jddj
||��}dj
|�}t|�j}t|�j
}nnt|�j}t|�j
}|dkrCd	j
|�}tj|�|tkr8i|d
6|fSi|d
6Stjd|�d}|}d
}t|�j
}|j�}tjj�}|jd�}|jd�}d|dd|d}d}tjjjd�}|jdt�}||d<tt|��}t|j|�}ttt||���}|jdd�}|d|d|d|d|d|} d}!|d|d|dd}"|!d|d|"dtjjj| �}#td|djd�|�}$t|$|�}%t|%|�}&t|&d�}'t j!|'|#jd�t"j#�j$�}(|!dd|d d|"d!d"|d!d#|(})i|d$6|)d%6}*tjd&|�tj%d'|�yPt&j|d(|*d)|�}+tjd*|+j'�tj%d+|+j(�|+j)�PWq<t&j*j+k
r�},t,j-|,j.j/�}-t0|-�}.|.jd,i�jd-i�jd.d�}/|/r�|/t1kr�|d/7}tjd0|,j.j'|,|.|�tj2|�q<ntjd1|,j.j'|,|.�|tkr�i|.d
6|fSi|.d
6SXq<Wtjd1|,j.j'|,|.�|tkr/i|.d
6|fSi|.d
6S|+j(}0t,j-|0�}-|-d/}1|tkrq|-}1n|r�t3j4d5kr�t5|-j6��}2nt5|-�}2xMt7d|2�D]9}3|-|3j8j9d4�}4|4d/|kr�|-|3}1q�q�Wng}5x!|1D]}3|5j:t0|3��qW|tkr7|5|fS|5S(6Nuservice_urlu
amazonaws.comiu%Y-%m-%dT%H:%M:%SZuendpointuec2.{0}.{1}uhttps://{0}/uurCould not find a valid endpoint in the requesturl: {0}. Looking for something like https://some.ec2.endpoint/?argsuerroruUsing EC2 endpoint: %suGETuec2u%Y%m%dT%H%M%SZu%Y%m%duhost:u
ux-amz-date:uhost;x-amz-dateuec2_api_versionuVersionu+u%20uAWS4-HMAC-SHA256u/uaws4_requestuAWS4ukeyuutf-8u uCredential=uidu, uSignedHeaders=u
Signature=u
x-amz-dateu
AuthorizationuEC2 Request: %suEC2 Request Parameters: %stheaderstparamsuEC2 Response Status Code: %suEC2 Response Text: %suErrorsuErroruCodeiuFEC2 Response Status Code and Error: [%s %s] %s; Attempts remaining: %su.EC2 Response Status Code and Error: [%s %s] %siiu}(ii(;RtgettawsR9tAWS_MAX_RETRIEStcopytdatetimetutcnowtstrftimetget_locationtformatt	_urlparsetnetloctpathtlogterrortTruetdebugtstriptsalttutilst	hashutilst
sha256_digesttDEFAULT_EC2_API_VERSIONtsortedR*Rt
_urlencodeR
treplaceRIRCRARBRDREt	hexdigestttracetrequestststatus_codeR'traise_for_statust
exceptionst	HTTPErrortETt
fromstringtresponsetcontentR(tEC2_RETRY_CODEStsleep_exponential_backoffR!R"R#R$RR%R&R+(6RKtsetnamet
requesturlR:t
return_urltreturn_roottprovidertservice_urlt
access_key_idtsecret_access_keyttokentattemptstparams_with_headerst	timestamptendpointt
endpoint_pathtendpoint_errtmethodtregiontservicet
canonical_urithosttttamz_datet	datestamptcanonical_headerstsigned_headerstpayload_hashtec2_api_versiontkeystvaluestquerystringtcanonical_requestt	algorithmtcredential_scopetstring_to_signtkDatetkRegiontkServicetsigning_keyt	signaturetauthorization_headerRJtresulttexctrootR8terr_codeRntitemsR-R1R/tret((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytquery2s�		
	
. 6

*

	
	

i
i<iic	C@s_|d	krd
}n|d	kr*i}n|}x(trZtjdt|d�t|d��|||�}|tkr�tjd|�|d8}|dkr�td��q�n|d	k	r�|S|dkr�tdjt|d�t|d����nt	j
|�||8}|dkr3||9}||krD|d}ntjd|�q3q3Wd	S(u�
    Helper function that waits for a spot instance request to become active
    for a specific maximum amount of time.

    :param update_callback: callback function which queries the cloud provider
                            for spot instance request. It must return None if
                            the required data, running instance included, is
                            not available yet.
    :param update_args: Arguments to pass to update_callback
    :param update_kwargs: Keyword arguments to pass to update_callback
    :param timeout: The maximum amount of time(in seconds) to wait for the IP
                    address.
    :param interval: The looping interval, i.e., the amount of time to sleep
                     before the next iteration.
    :param interval_multiplier: Increase the interval by this multiplier after
                                each request; helps with throttling
    :param max_failures: If update_callback returns ``False`` it's considered
                         query failure. This value is the amount of failures
                         accepted before giving up.
    :returns: The update_callback returned data
    :raises: SaltCloudExecutionTimeout

    u@Waiting for spot instance reservation. Giving up in 00:%02d:%02di<uXupdate_callback has returned False which is considered a failure. Remaining Failures: %siiu\Too many failures occurred while waiting for the spot instance reservation to become active.uDUnable to get an active spot instance request for 00:{0:02d}:{1:02d}u2Interval multiplier in effect; interval is now %ssN((tNoneRZRXR[tintRR	RRTttimetsleeptinfo(	tupdate_callbacktupdate_argst
update_kwargsttimeouttintervaltinterval_multipliertmax_failurestdurationR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_wait_for_spot_instance�sB			





	cC@s`|dkrtd��niiidd6dd6dd6d	d
6d6idd6dd6d
d6dd
6d6d6iidd6dd6dd6dd
6d6d6i
idd6dd6dd6dd
6d6idd6dd6dd6dd
6d6idd6dd6dd6dd
6d6id d6d!d6d"d6d#d
6d 6id$d6d%d6d&d6d'd
6d$6id(d6dd6d)d6dd
6d(6id*d6dd6d+d6dd
6d*6id,d6dd6d-d6dd
6d,6id.d6d!d6d/d6d#d
6d.6id0d6d1d6d2d6d'd
6d06d36iid4d6dd6d5d6d6d
6d46id7d6dd6d8d6d9d
6d76id:d6d!d6d;d6d<d
6d:6id=d6d%d6d>d6d?d
6d=6d@6iidAd6dd6dBd6dd
6dA6idCd6d1d6dDd6d'd
6dC6dE6iidFd6dd6dGd6d9d
6dF6idHd6d1d6dGd6dId
6dH6idJd6dKd6dGd6dLd
6dJ6dM6iidNd6dd6dOd6d6d
6dN6idPd6dd6dQd6d9d
6dP6idRd6d!d6dSd6d<d
6dR6idTd6d1d6dUd6d?d
6dT6dV6i
idWd6dXd6dYd6dZd
6dW6id[d6d\d6d]d6d^d
6d[6id_d6d`d6dGd6dad
6d_6idbd6dcd6dGd6d6d
6db6iddd6ded6dGd6d9d
6dd6idfd6dgd6dGd6d<d
6df6idhd6did6dGd6d?d
6dh6idjd6dkd6dGd6dId
6dj6idld6dmd6dnd6dd
6dl6idod6dpd6dqd6d6d
6do6idrd6dsd6dtd6d9d
6dr6idud6dvd6dwd6d<d
6du6idxd6dyd6d2d6d?d
6dx6dz6iid{d6d|d6dDd6d?d
6d{6d}6iid~d6dd6d�d6d�d
6d~6d�6iid�d6d�d6dGd6d�d
6d�6id�d6d�d6dGd6d�d
6d�6id�d6d�d6dGd6d�d
6d�6id�d6dd6dGd6d�d
6d�6id�d6dd6dGd6d�d
6d�6id�d6dd6dGd6d�d
6d�6id�d6dd6dGd6d�d
6d�6id�d6dd6d�d6d�d
6d�6id�d6dd6dd6d�d
6d�6id�d6dd6dd6d�d
6d�6id�d6d!d6d"d6d�d
6d�6id�d6d�d6d&d6d�d
6d�6id�d6dKd6d�d6d�d
6d�6id�d6d�d6d�d6dd
6d�6id�d6dd6d�d6dd
6d�6id�d6dd6d�d6dd
6d�6id�d6dd6d�d6d#d
6d�6d�6}|S(�u�
    Return a dict of all available VM sizes on the cloud provider with
    relevant data. Latest version can be found at:

    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
    uactionu^The avail_sizes function must be called with -f or --function, or with the --list-sizes optionucc2.8xlargeuidu816 (2 x Intel Xeon E5-2670, eight-core with hyperthread)ucoresu3360 GiB (4 x 840 GiB)udisku60.5 GiBuramucc1.4xlargeu48 (2 x Intel Xeon X5570, quad-core with hyperthread)u1690 GiB (2 x 840 GiB)u22.5 GiBuCluster Computeucg1.4xlargeuT8 (2 x Intel Xeon X5570, quad-core with hyperthread), plus 2 NVIDIA Tesla M2050 GPUsu1680 GiB (2 x 840 GiB)uCluster CPUuc4.largeu2uEBS - 500 Mbpsu3.75 GiBu	c4.xlargeu4uEBS - 750 Mbpsu7.5 GiBu
c4.2xlargeu8uEBS - 1000 Mbpsu15 GiBu
c4.4xlargeu16uEBS - 2000 Mbpsu30 GiBu
c4.8xlargeu36uEBS - 4000 Mbpsu60 GiBuc3.largeu32 GiB (2 x 16 GiB SSD)u	c3.xlargeu80 GiB (2 x 40 GiB SSD)u
c3.2xlargeu160 GiB (2 x 80 GiB SSD)u
c3.4xlargeu320 GiB (2 x 160 GiB SSD)u
c3.8xlargeu32u640 GiB (2 x 320 GiB SSD)uCompute Optimizedu	d2.xlargeu"6 TiB (3 x 2 TiB hard disk drives)u30.5 GiBu
d2.2xlargeu#12 TiB (6 x 2 TiB hard disk drives)u61 GiBu
d2.4xlargeu$24 TiB (12 x 2 TiB hard disk drives)u122 GiBu
d2.8xlargeu$24 TiB (24 x 2 TiB hard disk drives)u244 GiBu
Dense Storageu
g2.2xlargeu60 GiB (1 x 60 GiB SSD)u
g2.8xlargeu240 GiB (2 x 120 GiB SSD)uGPUu	p2.xlargeuEBSu
p2.8xlargeu488 GiBup2.16xlargeu64u732 GiBuGPU Computeu	i2.xlargeuSSD (1 x 800 GiB)u
i2.2xlargeuSSD (2 x 800 GiB)u
i2.4xlargeuSSD (4 x 800 GiB)u
i2.8xlargeuSSD (8 x 800 GiB)uHigh I/Oux1.16xlargeu64 (with 5.45 ECUs each)u1920 GiB (1 x 1920 GiB)u976 GiBux1.32xlargeu128 (with 2.73 ECUs each)u3840 GiB (2 x 1920 GiB)u1952 GiBur4.largeu2 (with 3.45 ECUs each)u	15.25 GiBu	r4.xlargeu4 (with 3.35 ECUs each)u
r4.2xlargeu8 (with 3.35 ECUs each)u
r4.4xlargeu16 (with 3.3 ECUs each)u
r4.8xlargeu32 (with 3.1 ECUs each)ur4.16xlargeu64 (with 3.05 ECUs each)ur3.largeu2 (with 3.25 ECUs each)u32 GiB (1 x 32 GiB SSD)u	r3.xlargeu4 (with 3.25 ECUs each)u80 GiB (1 x 80 GiB SSD)u
r3.2xlargeu8 (with 3.25 ECUs each)u160 GiB (1 x 160 GiB SSD)u
r3.4xlargeu16 (with 3.25 ECUs each)u320 GiB (1 x 320 GiB SSD)u
r3.8xlargeu32 (with 3.25 ECUs each)uHigh Memoryucr1.8xlargeu'16 (2 x Intel Xeon E5-2670, eight-core)uHigh-Memory Clusteruhs1.8xlargeu16 (8 cores + 8 hyperthreads)u$48 TiB (24 x 2 TiB hard disk drives)u117 GiBuHigh Storageut2.nanou1u512 MiBut2.microu1 GiBut2.smallu2 GiBu	t2.mediumu4 GiBut2.largeu8 GiBu	t2.xlargeu16 GiBu
t2.2xlargeu32 GiBum4.largeuEBS - 450 Mbpsu	m4.xlargeu
m4.2xlargeu
m4.4xlargeu64 GiBum4.10xlargeu40u160 GiBum4.16xlargeuEBS - 10000 Mbpsu256 GiBu	m3.mediumuSSD (1 x 4)um3.largeuSSD (1 x 32)u	m3.xlargeuSSD (2 x 40)u
m3.2xlargeuSSD (2 x 80)uGeneral Purpose(R(tcalltsizes((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytavail_sizes$sdc
C@s�|dkrtd��nt|t�s3i}nd|krL|d}n$t�}tjd|tdd�}i}idd6|d6}tj|d	t	�d
t
�dtdd
�}x|D]}|||d<q�W|S(uI
    Return a dict of all available VM images on the cloud provider.
    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optionuownertdefaultuamazonuDescribeImagesuActionuOwnerR:Rvtoptstsigveru4uimageId(RR)tdictRRtget_cloud_config_valueRRMR�RStget_provider(tkwargsR�townerRvR�RKtimagestimage((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytavail_images�s*	
	

			
cC@sLtjjjtjd|t�|ttjjjtjjjt|���S(u-
    Return the script deployment object
    uscript(	R]R^tcloudt	os_scriptRR�Rtsalt_config_to_yamlt
minion_config(tvm_((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytscript�scC@stjd|tdt�S(u
    Return the keyname
    ukeynamet
search_global(RR�RR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytkeyname�scC@stjd|tdt�S(u#
    Return the security group
    u
securitygroupR�(RR�RR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
securitygroup�scC@stjd|tdt�S(uX
    Return the IAM profile.

    The IAM instance profile to associate with the instances.
    This is either the Amazon Resource Name (ARN) of the instance profile
    or the name of the role.

    Type: String

    Default: None

    Required: No

    Example: arn:aws:iam::111111111111:instance-profile/s3access

    Example: s3access

    uiam_profileR�(RR�RR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytiam_profile�scC@sJtjd|tdddt�}|dkrFtjd|�d}n|S(uj
    Return the ssh_interface type to connect to. Either 'public_ips' (default)
    or 'private_ips'.
    u
ssh_interfaceR�u
public_ipsR�uprivate_ipsuiInvalid ssh_interface: %s. Allowed options are ("public_ips", "private_ips"). Defaulting to "public_ips".(u
public_ipsuprivate_ips(RR�RRRXtwarning(R�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
ssh_interfaces		cC@shtjd|tdd
dt�}t|tj�s7d
Si|d6}tjd|tdd
dt�|d<tjd|tdd
dt�|d<tjd|tdd
dt�|d<tjd	|tdd
dt�|d	<tjd
|tdd
dt�|d
<|d}|d
k	r>tj	j
|�r>tdj|���n&|d
krd|d	rdtd��n|S(u/
    Return the ssh_gateway configuration.
    ussh_gatewayR�R�ussh_gateway_portussh_gateway_usernameussh_gateway_userussh_gateway_private_keyussh_gateway_keyussh_gateway_passwordussh_gateway_commandu8The defined ssh_gateway_private_key '{0}' does not existuYNo authentication method. Please define:  ssh_gateway_password or ssh_gateway_private_keyN(
RR�RR�RR)R
tstring_typestosRWtisfileRRT(R�tssh_gatewaytssh_gateway_configtkey_filename((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytget_ssh_gateway_configs>	






cC@s4tjdtjd|pt�tdtdt��S(u�
    Return the EC2 region to use, in this order:
        - CLI parameter
        - VM parameter
        - Cloud profile setting
    ulocationR�R�(RRLRR�RR4R(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyRS]sc
C@s�|dkrtd��ni}idd6}tj|dt�dt�dtdd	�}x2|D]*}i|d
d6|dd
6||d
<qbW|S(u&
    List all available locations
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optionuDescribeRegionsuActionR:RvR�R�u4u
regionNameunameuregionEndpointuendpoint(RRMR�RSR�R(R�R�RKR�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytavail_locationsps
			
cC@s�tjd|tdt�}|dkr+dSt|�}||kr[tdj|���n(||dkr�tdj|���n|S(u-
    Return the availability zone to use
    uavailability_zoneR�u@The specified availability zone isn't valid in this region: {0}
u	availableu?The specified availability zone isn't currently available: {0}
N(RR�RRR�t_list_availability_zonesRRT(R�tavztzones((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytget_availability_zone�scC@stjd|tdt�S(uq
    Returns the Tenancy to use.

    Can be "dedicated" or "default". Cannot be present for spot instances.
    utenancyR�(RR�RR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytget_tenancy�sc@s�tjd|tdt�}|jd�r.|Sttd�sIit_n|tjkrctj|Sidd6dd6|d	6}d
��tt	j
|dt�dt�d
tdd�dt
�fd���dd}|tj|<|S(u$
    Returns the ImageId to use
    uimageR�uami-uimagesuDescribeImagesuActionunameu
Filter.0.NameuFilter.0.Value.0cS@stjj|dd�S(NucreationDateu%Y-%m-%dT%H:%M:%S.%fZ(RPtstrptime(tx((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt<lambda>�sR:RvR�R�u4RGc@s"tjjj�|��|��S(N(R]R^tcompattcmp(titj(t_t(s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��si����uimageId(RR�RRt
startswiththasattrtget_imageidR�RbRMR�RSR�R(R�R�RKtimage_id((R�s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��s$

	
c
C@s�idd6}x�tj|dt�dt�dtdd�D]�}|jdi�jd	i�}t|t�sz|g}nxM|D]E}|d
dkr�|d|kr�tj	d
||d�|dSq�Wq;WdS(u5
    Returns the SubnetId of a SubnetName to use
    uDescribeSubnetsuActionR:RvR�R�u4utagSetuitemukeyuNameuvalueuAWS Subnet ID of %s is %susubnetIdN(RMR�RSR�RRLR)R*RXR[R�(t
subnetnameRKtsubnetttagsR%((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_get_subnetname_id�s

 cC@sTtjd|tdt�}|r%|Stjd|tdt�}|rPt|�SdS(u%
    Returns the SubnetId to use
    usubnetidR�u
subnetnameN(RR�RRR�R�(R�tsubnetidR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytget_subnetid�s
c
C@s�t�}t|t�s$|g}nidd6}xttj|dt�dt�dtdd�D]E}|d|kr_tj	d	|d|d
�|j
|d
�q_q_Wt|�S(uC
    Returns the SecurityGroupId of a SecurityGroupName to use
    uDescribeSecurityGroupsuActionR:RvR�R�u4u	groupNameu AWS SecurityGroup ID of %s is %sugroupId(tsetR)R*RMR�RSR�RRXR[tadd(tsecuritygroupname_listtsecuritygroupid_setRKtsg((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_get_securitygroupname_id�s	
c
C@st�}tjd|tdt�}|rB|jt|��}ntjd|tdt�}|rt|t�s~|g}nidd6}xwtj	|dt
�dt�dtd	d
�D]E}|d|kr�tj
d|d|d
�|j|d
�q�q�Wnt|�S(u%
    Returns the SecurityGroupId
    usecuritygroupidR�usecuritygroupnameuDescribeSecurityGroupsuActionR:RvR�R�u4u	groupNameu AWS SecurityGroup ID of %s is %sugroupId(R�RR�RRtunionR)R*RMR�RSR�RXR[R�(R�R�tsecuritygroupid_listR�RKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytsecuritygroupid
s,		
cC@stjd|tdt�S(u+
    Returns the PlacementGroup to use
    uplacementgroupR�(RR�RR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytget_placementgroup1scC@stjd|tdt�S(uE
    Returns the spot instance configuration for the provided vm
    uspot_configR�(RR�RR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytget_spot_config:scC@sY|dkrtpd}n|jdd�}d|krU|jd�}|d}n|S(u+
    Extract the provider name from vm
    uec2uprovideru:iN(R�RRLR&(R�Rvt
prov_comps((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�Cs
c
C@s~i}idd6dd6t|�d6}tj|dt|�dt�dtd	d
�}x |D]}|d||d<q^W|S(
u;
    List all availability zones in the current region
    uDescribeAvailabilityZonesuActionuregion-nameu
Filter.0.NameuFilter.0.Value.0R:RvR�R�u4u	zoneStateuzoneName(RSRMR�R�R(R�R�RKR�tzone((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�Rs
		
cC@stjd|tdt�S(u�
    Return the block device mapping:

    .. code-block:: python

        [{'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'},
          {'DeviceName': '/dev/sdc', 'VirtualName': 'ephemeral1'}]
    ublock_device_mappingsR�(RR�RRZ(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytblock_device_mappingsgs	cC@s�idd6}|jdd�|d<tj|dtdt|�dt�d	td
d�}x"|D]}d|kr`|dSq`Wd
S(u'
    Request and return Elastic IP
    uAllocateAddressuActionudomainuvpcuDomainRuR:RvR�R�u4uallocationIdN(t
setdefaultRMR�RZRSR�RR�(t	interfaceR�RKteipsteip((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_request_eipus
		
cC@s<d|kr6|dd'k	r6i|dd6|dd6Sidd6}tj|dtdt|�dt�dtd	d
�}d|kr�d|kr�t|d�|d<nd
|kr�d|kr�t|d�|d
<nt	||�}|s
t
dj|jd
����ni|d
6}x+d(D]#}||kr!||||<q!q!Wx7d)D]/}||krO|j
t|||��qOqOWd|kr�x+d*D]#}||kr�||||<q�q�W|jdt�|d<|Sd|d<tj|dtdt|�dt�dtd	d
�}|d}|s7|jd�rOtdj|���n|jd�}tjd||d�|jdt�}	t|	tj�r�t||	d|�n|jd�r�t||jd�d|�n�|jd�rt||�}
t||
d|�n�|jd�r�t|�}g}x0t|�D]"\}
}|jt||��q?Wx7t|�D]&\}
}t|||
|d|�qrWnd |kr&id!d6|d"6d d#6|d d$6}tj|dtdt|�dt�dtd	d
�}d%|kr&tjd&�q&ni|dd6|d6S(+u_
    Create an Elastic Interface if necessary and return a Network Interface Specification
    uNetworkInterfaceIduDeviceIndexuDescribeSubnetsuActionRuR:RvR�R�u4uSecurityGroupIdusecuritygroupnameuSubnetIdu
subnetnameuNo such subnet <{0}>uDescriptionuPrivateIpAddressuSecondaryPrivateIpAddressCountuPrivateIpAddressesuAssociatePublicIpAddressudelete_interface_on_terminateuDeleteOnTerminationuCreateNetworkInterfaceiunetworkInterfaceIduFailed to create interface: {0}u$Created network interface %s inst %sR�u
associate_eipuallocate_new_eipuallocate_new_eipsuNameu
CreateTagsuResourceId.0u	Tag.0.KeyuTag.0.Valueuerroru#Failed to set name of interface {0}N(uDescriptionuPrivateIpAddressuSecondaryPrivateIpAddressCount(uPrivateIpAddressesuSecurityGroupId(uDeviceIndexuAssociatePublicIpAddressuNetworkInterfaceId(R�RMR�RZRSR�RR�R�t_get_subnet_id_for_interfaceRRTRLtupdatet_param_from_configRRXR[RR)R
R�t_associate_eip_with_interfaceR�t_list_interface_private_addrst	enumerateR+RY(R�R�RKtsubnet_queryt	subnet_idtkR�teni_descteni_idtassociate_public_ipt_new_eipt	addr_listteip_listtidxtaddrt
tag_paramsttag_response((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_create_eni_if_necessary�s�
		


!

		
!
		cC@s�x�|D]�}d|krt|dt�rRt|d|�}|dk	r�|Sq�x4|dD]%}t||�}|dk	r]|Sq]WqqWdS(Nuitem(R)R�t_get_subnet_from_subnet_queryR�(RR�tsubnet_query_resultRR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��s

	cC@sId|krE|jd�r:|d|dkrB|dSqE|dSndS(NusubnetIduSubnetId(RL(RR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�s
cC@s�|jd�}|sdS|g}|jdi�jdg�}t|t�sS|SxQ|D]I}|jd�dkr{qZn|jd�rZ|j|jd��qZqZW|S(u�
    Returns a list of all of the private IP addresses attached to a
    network interface. The 'primary' address will be listed first.
    uprivateIpAddressuprivateIpAddressesSetuitemuprimaryutrueN(RLR�R)R*R+(Rtprimaryt	addressestlsttentry((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�s	
cC@s�t|t�std��nidd6|d6}x'tj|�D]\}}|||<qBWtj|dtdt|�dt	�dt
d	d
�}t|t�r�|jd�r�tdj||���n|Sd
S(u`
    Change properties of the interface
    with id eni_id to the values in properties dict
    u#ENI properties must be a dictionaryuModifyNetworkInterfaceAttributeuActionuNetworkInterfaceIdRuR:RvR�R�u4uerroru3Could not change interface <{0}> attributes <'{1}'>N(
R)R�RR
R3RMR�RZRSR�RRLRT(Rt
propertiesR�RKRtvR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_modify_eni_propertiess$

		cC@s�idd6|d6|d6}|r.||d<ntj|dtdt|�dt�d	td
d�}|djd
�s�tdj||���nt	j
d||�|djd
�S(u�
    Accept the id of a network interface, and the id of an elastic ip
    address, and associate the two of them, such that traffic sent to the
    elastic ip address will be forwarded (NATted) to this network interface.

    Optionally specify the private (10.x.x.x) IP address that traffic should
    be NATted to - useful if you have multiple IP addresses assigned to an
    interface.
    uAssociateAddressuActionuNetworkInterfaceIduAllocationIduPrivateIpAddressRuR:RvR�R�u4iu
associationIduICould not associate elastic ip address <{0}> with network interface <{1}>u1Associated ElasticIP address %s with interface %s(RMR�RZRSR�RRLRRTRXR[(Rteip_idt
private_ipR�RKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�<s&



		
cC@s�i}g}xU|D]M}d|kr|d|krFtjd�dS||tj|d�<qqW|ddddd}t|t�r�xG|D]!}|j|d|df�q�Wn|j|d|df�x�|D]�\}}	t}
d	||	d
kr||	d
d	}
n)d||	d
krB||	d
d}
ni|	dd
6|
d6}t	||d|�}d||	d
kr�i||	d
dd6}
t	||
d|�}q�q�WdS(NuDeviceIndexu5Duplicate DeviceIndex in profile. Cannot update ENIs.iuinstancesSetuitemunetworkInterfaceSetunetworkInterfaceIdu
attachmentuDeleteOnTerminationudeviceIndexudelete_interface_on_terminateuattachmentIduAttachment.AttachmentIduAttachment.DeleteOnTerminationR�uSourceDestCheckuSourceDestCheck.Value(
RXRYR�R
t	text_typeR)R*R+RZR(t
interfacestinstanceR�tconfig_enist
instance_enisR�t
query_enist	query_eniRteni_datatdelete_on_terminatetparams_attachmenttset_eni_attachment_attributestparams_sourcedesttset_eni_sourcedest_property((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_update_enisds6

"
cC@s
i}t|t�rZx�tj|�D].\}}|jtdj||�|��q%Wn�t|t�sxt|t�r�x�t	|�D]4\}}dj||�}|jt||��q�WnIt|t
�r�|jitj|�j�|6�n|ji||6�|S(uW
    Return EC2 API parameters based on the given config data.

    Examples:
    1. List of dictionaries
    >>> data = [
    ...     {'DeviceIndex': 0, 'SubnetId': 'subid0',
    ...      'AssociatePublicIpAddress': True},
    ...     {'DeviceIndex': 1,
    ...      'SubnetId': 'subid1',
    ...      'PrivateIpAddress': '192.168.1.128'}
    ... ]
    >>> _param_from_config('NetworkInterface', data)
    ... {'NetworkInterface.0.SubnetId': 'subid0',
    ...  'NetworkInterface.0.DeviceIndex': 0,
    ...  'NetworkInterface.1.SubnetId': 'subid1',
    ...  'NetworkInterface.1.PrivateIpAddress': '192.168.1.128',
    ...  'NetworkInterface.0.AssociatePublicIpAddress': 'true',
    ...  'NetworkInterface.1.DeviceIndex': 1}

    2. List of nested dictionaries
    >>> data = [
    ...     {'DeviceName': '/dev/sdf',
    ...      'Ebs': {
    ...      'SnapshotId': 'dummy0',
    ...      'VolumeSize': 200,
    ...      'VolumeType': 'standard'}},
    ...     {'DeviceName': '/dev/sdg',
    ...      'Ebs': {
    ...          'SnapshotId': 'dummy1',
    ...          'VolumeSize': 100,
    ...          'VolumeType': 'standard'}}
    ... ]
    >>> _param_from_config('BlockDeviceMapping', data)
    ... {'BlockDeviceMapping.0.Ebs.VolumeType': 'standard',
    ...  'BlockDeviceMapping.1.Ebs.SnapshotId': 'dummy1',
    ...  'BlockDeviceMapping.0.Ebs.VolumeSize': 200,
    ...  'BlockDeviceMapping.0.Ebs.SnapshotId': 'dummy0',
    ...  'BlockDeviceMapping.1.Ebs.VolumeType': 'standard',
    ...  'BlockDeviceMapping.1.DeviceName': '/dev/sdg',
    ...  'BlockDeviceMapping.1.Ebs.VolumeSize': 100,
    ...  'BlockDeviceMapping.0.DeviceName': '/dev/sdf'}

    3. Dictionary of dictionaries
    >>> data = { 'Arn': 'dummyarn', 'Name': 'Tester' }
    >>> _param_from_config('IamInstanceProfile', data)
    {'IamInstanceProfile.Arn': 'dummyarn', 'IamInstanceProfile.Name': 'Tester'}

    u{0}.{1}(
R)R�R
R3R�R�RTR*ttupleRtboolRtlower(RGR8tparamRRR
t	conf_itemtprefix((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��s3)&c0@s|dkrtd��n|jdt|��}t|�}|dk	r�d|krstdj|d���nidd6d	d
6d|kr�|dndd
6|dd6}d}nctjd|tdt	dd�}tjd|tdt	dd�}idd6|d6|d6}d}t
|�}|||d<d}	tjd|tdt	dd�}
|
dkr�tjd|tdt	dd�}	natjd|
�t
jj|
�r�tjjj|
d��"}tjjj|j��}	WdQXntjjjt||	�}	|	dk	rgy*tjtjjj|	��||d<Wqgtk
rc}tjd |�qgXntjd!|tdt	�}
|
||d"<t|�}|r�|||d#<nt|�}|rt |t!�s�|||d$<qx4t"|�D]#\}}|||d%j|�<q�Wnt#|�}|r�y2|j$d&�rQ|||d'<n|||d(<Wq�t%k
rt&d)��q�Xnt'|�}|dk	r�|||d*<nt(|�}|dk	r�|dk	r�t&d+j|d���n||d,<nt)|�}|dk	r"|||d-<nt*|�}|r�t |t!�sT|||d.<q�x4t"|�D]#\}}|||d/j|�<qaWnt+|�}|dk	r�|||d0<nt,|�}|r�x-|D]"}d1|kr�|j-d1�q�q�Wn|}|r|j.t/|d2|��ntjd3|tdt	�}|r�g}x:|D]2}tj0d4|�t1||�}|j2|�qMW|j.t/|d5|��ntjd6|tdt	�}|dk	r�t |t3�s�t&d7��n|||d8<ntjd9|tdt	�} | r6t | t3�r6t&d:��n| |d;<| r�tj4d<||d�id=d6|d>6}!yXt5j6|!d?t|�d@t7�dAtdBdC�}"dD|"kr�|"dDStj0dE|"�Wn9tk
r}tj8dF||d|dGt9j:��nX|"s)dHj|�}#t|#��nd}$d}%dI|"dJkr�|"dJdIdk	r�|"dJdIdK}&t |&t!�r�|&dJ}&n|&dL}$|&dMjdNd�}%ntj4dO|$�n|$dk	r�|r�g|D]}'|'dP^q�}(ng}(|$|(kr|(j;|$�})n"t<|(�})|$|dQj||)�<dRj||)�}*t=j>| �j?�||*<|r�|)t<|�kr�dS||)kr�dTj||)�}+|%||+<q�q�ntjdU|tdt	dt	�},|,r�t |,t3�r�t&dV��nt@dWdXdYdZj|d�d[it@d\d]|t!|��d^6|d6d_td`datdb�t7|��yBt5j6|dcd?|d@�dAtdBdC�}-dD|-kr�	|-dDSWn6tk
r�	}tj8dd|d|dGt9j:��nX|ru|-dJde}.|.|df<�fdg�}/t@dWdXdhdij|d�d_td`datdb�y�tA|/dj|.|fdktjdl|tddz�dotjdp|tddq�drtjds|tdd�dttjdu|tddm��}-tj0dv|-�WqutBtCfk
rq}zjyRidwd6|.dx6}t5j6|d?|d@�dAtdBdC�}-tj0dy|.|-�Wntk
rSnXWdtt=j>|���XquXn|-|fS({u�
    Put together all of the information necessary to request an instance on EC2,
    and then fire off the request the instance.

    Returns data about the instance
    ufunctionu?The request_instance action must be called with -a or --action.ulocationu
spot_priceu=Spot instance config for {0} requires a spot_price attribute.unameuRequestSpotInstancesuActionu1u
InstanceCountutypeuone-timeuTypeu	SpotPriceuLaunchSpecification.umin_instanceR�R�iumax_instanceuRunInstancesuMinCountuMaxCountuuImageIdu
userdata_fileuuserdatauuserdata_file: %surNuUserDatauFailed to encode userdata: %susizeuInstanceTypeuKeyNameuSecurityGroup.1uSecurityGroup.{0}uarn:aws:iam:uIamInstanceProfile.ArnuIamInstanceProfile.Nameu''iam_profile' should be a string value.uPlacement.AvailabilityZoneuASpot instance config for {0} does not support specifying tenancy.uPlacement.TenancyuSubnetIduSecurityGroupId.1uSecurityGroupId.{0}uPlacement.GroupNameutaguBlockDeviceMappingunetwork_interfacesuCreate network interface: %suNetworkInterfaceu
ebs_optimizedu*'ebs_optimized' should be a boolean value.uEbsOptimizedudel_root_vol_on_destroyu4'del_root_vol_on_destroy' should be a boolean value.uset_del_root_vol_on_destroyu?Attempting to look up root device name for image id %s on VM %suDescribeImagesu	ImageId.1R:RvR�R�u4uerroruEC2 Response: '%s'u=Error getting root device name for image id %s for VM %s: 
%stexc_info_on_logleveluTThere was an error querying EC2 for the root device of image id {0}. Empty response.ublockDeviceMappingiuitemu
deviceNameuebsu
volumeTypeuFound root device name: %su
DeviceNameu${0}BlockDeviceMapping.{1}.DeviceNameu1{0}BlockDeviceMapping.{1}.Ebs.DeleteOnTerminationuEbs.VolumeTypeu({0}BlockDeviceMapping.{1}.Ebs.VolumeTypeudel_all_vols_on_destroyu4'del_all_vols_on_destroy' should be a boolean value.ucloud.fire_eventueventurequesting instanceusalt/cloud/{0}/requestingtargsucloud.filter_eventu
requestingukwargstsock_dirusock_dirt	transportu	transportuinstancesSetuGError creating %s on EC2 when trying to run the initial deployment: 
%suspotInstanceRequestIdu
spotRequestIdc
@sidd6|d6}tj|d|d�dtdd�}|sRtjd	�tSt|t�r�d
|kr�tjd|d
�tStj	d|�|d
j
d�}|dkr�|S|dkr�tjd|d
dd�dS|dkrtjd�tSdS(NuDescribeSpotInstanceRequestsuActionuSpotInstanceRequestId.1R:RvR�R�u4u5There was an error while querying EC2. Empty responseuerroru#There was an error in the query. %suReturned query data: %siustateuactiveuopenuSpot instance status: %sustatusumessageu	cancelledufaileducloseduKSpot instance request resulted in state '{0}'. Nothing else we can do here.(u	cancelledufaileduclosed(
RMR�RRXRYRR)R�R�R[RLR�R�(tsir_idR:RKR8tstate(Rv(s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt__query_spot_instance_requests0

	
uwaiting for spot instanceusalt/cloud/{0}/waiting_for_spotR�R�uwait_for_spot_timeouti
i<R�uwait_for_spot_intervaliR�u!wait_for_spot_interval_multiplierR�uwait_for_spot_max_failuresuwait_for_spot_instance data %suCancelSpotInstanceRequestsuSpotInstanceRequestId.1u4Canceled spot instance request %s. Data returned: %siX(DRRLRSR�R�RTRR�RRR�RXRfR�RWtexistsR]R^tfilestfopentstringutilst
to_unicodetreadR�tuserdata_templatetbase64t	b64encodetto_bytest	Exceptiont	exceptionR�R�R)R*RR�R�tAttributeErrorRR�R�R�R�R�R�tpopR�R�R[RR+R)R�RMR�R�RYtloggingtDEBUGtindexR#R
RR*t	__utils__R�RR	(0R�R�R:tspot_configRKtspot_prefixtmin_instancetmax_instanceR�tuserdatat
userdata_filetfh_R�tvm_sizet
ex_keynametex_securitygrouptcountertsg_tex_iam_profiletaz_ttenancy_t	subnetid_tex_securitygroupidtplacementgroup_tblockdevicemappings_holdert_bdtex_blockdevicemappingstnetwork_interfacesteni_devicesR�t_new_enitset_ebs_optimizedtset_del_root_vol_on_destroyt	rd_paramstrd_dataterr_msgtrd_nametrd_typeR1tdevtdev_listt	dev_indexttermination_keyttype_keytset_del_all_vols_on_destroyR8R2R4((Rvs9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytrequest_instance�s�
	


$$



	


	
		
	

 

		


&
	

		
c	@s�|dkrtd��n�d}�jdt����tddddj�d	�d
i|d6dtdd
td�tjd|�idd6|d6}t���d}x�|t	j
kr�t	j|d�d�dtdtdd�\}}tjd|�t
|t�r?d|kr?tjd||d�n*t
|t�rh|rhtjd|�nPt	j|�|d7}q�q�Wtdj|d������fd �}yvtjjj|d!||fd"tjd#�td$d0�d'tjd(�td$d%�d)tjd*�td$d��}Wn\ttfk
r�}z*yt�d	�Wntk
rknXWd+ttj|���XnXd,�kr��d,tkr�tddd-d.j�d	�d
i|d/6dtdd
td�n|S(1u:
    Query an instance upon creation from the EC2 API
    ufunctionu=The query_instance action must be called with -a or --action.uinstance_idulocationucloud.fire_eventueventuquerying instanceusalt/cloud/{0}/queryingunameR/R0usock_dirR1u	transportuThe new VM instance_id is %suDescribeInstancesuActionuInstanceId.1iR:RvR�RtR�u4uThe query returned: %suerroru:There was an error in the query. %s attempts remaining: %su4Query returned an empty list. %s attempts remaining.iu(An error occurred while creating VM: {0}c
@stj|d�d�dtdd�}|s>tjd�tSt|t�rqd|krqtjd|d�tStj	d	|�t
��d
kr�d|dd
dkr�|Stjd�nt
��dkr�d|dd
dkr�|Stjd�ndS(NR:RvR�R�u4u5There was an error while querying EC2. Empty responseuerroru#There was an error in the query. %suReturned query data: %su
public_ipsu	ipAddressiuinstancesSetuitemuPublic IP not detected.uprivate_ipsuprivateIpAddressuPrivate IP not detected.(RMR�RRXRYRR)R�R�R[R�(RKturlR8(R:RvR�(s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt__query_ip_address�s.	
R�R�uwait_for_ip_timeoutR�i
i<R�uwait_for_ip_intervalR�uwait_for_ip_interval_multiplierNureactoruinstance queriedusalt/cloud/{0}/query_reactorudataiX(RRLRSRFRTRRXR[R�RMRNR�RZR)R�R�R*RqR]R^R�twait_for_ipRR�RR	tdestroyR
R(	R�R�tinstance_idRKR{R8RsRnR�((R:RvR�s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytquery_instancess�







$


cC@s|dkrtd��n|dFkr0i}n|dFkrEi}n|jdt|��}tddddj|d�d	i|d
6dtdd
td�tjd|td�}tjd|td�}tjd|t�r\tjd|tdd�}tjd|tdd�}	tjd|tdd�}
tjd|tdd�}tjd|tdt	�}tjd|tdt
�}
|	rL|	dkrLtjd �x�t
rHt
d!|dd"i|d#d$6d%d&�}|jd'dF�}	|	dFkrtj|�tjd(�q�|}d)|d'<d)|d*<tj|�|	|d<Pq�Wntjjj|d+d,d-|�s|td.��n|s�tjd/�tjjj|||	d0|
d1|�sYtd2��qYq�tjd3|tdd4�}tjjj|d+|d-|�std5��ntjd6�tjjj||||	d-|d7|
�s�td8��q�nQtjjj|d+|d-|d9|�r�tjd:|tddF�}|r�i}xOd;|kr�td<|d=d%d&d>t|��}tj|�tjd?�q�Wtjjj|d;�}|jd@�}t|�dAkr:t	S|djdB�}d}x:|dCj�D](}|svqdn|dDj||�7}qdWtjjj|dE��#}|j tjjj!|��WdFQX|j"�nx�|dGD]�}tjjj#dH|d+|dI|dJtjdK|tddZ�dL|dMdN|d9|dOtjdP|tddQ�dRtjd:|tddS��	r�|tdT<||dT<Pq�q�WtdU��ntdV��dW|kr|dWt
krtdddXdYj|d�d	i|d
6dtdd
td�n|S([uR
    Wait for an instance upon creation from the EC2 API, to become available
    ufunctionu@The wait_for_instance action must be called with -a or --action.ugatewayucloud.fire_eventueventuwaiting for sshusalt/cloud/{0}/waiting_for_sshunameR/u
ip_addressR0usock_dirR1u	transportussh_connect_timeouti�ussh_portiu
win_installeruwin_usernameR�u
Administratoruwin_passworduuwin_deploy_auth_retriesi
uwin_deploy_auth_retry_delayiu	use_winrmuwinrm_verify_ssluautou/Waiting for auto-generated Windows EC2 passwordR.R�uprivate_keyukey_fileR�uactionupasswordi<uXXX-REDACTED-XXXupasswordDatatporti�R�u(Failed to connect to remote windows hostu+Trying to authenticate via SMB using psexectretriestretry_delayu8Failed to authenticate against remote windows host (smb)u
winrm_portibu0Failed to connect to remote windows host (winrm)u.Trying to authenticate via Winrm using pywinrmtverifyu2Failed to authenticate against remote windows hosttgatewayuknown_hosts_fileuoutput_decodedRquinstance_idR:iu!-----BEGIN SSH HOST KEY KEYS-----iu-----END SSH HOST KEY KEYS-----iu
{0} {1}uaNu	usernamesR�tusernametssh_timeoutuwait_for_passwd_timeoutR�ukey_filenametdisplay_ssh_outputtmaxtriesuwait_for_passwd_maxtriesitknown_hosts_fileu	/dev/nullussh_usernameu)Failed to authenticate against remote sshuFailed to connect to remote sshureactorussh is availableu salt/cloud/{0}/ssh_ready_reactori<($RR�RLR�RFRTRRR�RRZRXR[tget_password_dataR�R�R]R^R�t
wait_for_porttvalidate_windows_credtwait_for_winrmtget_console_outputRStpprintR8R9R&R#t
splitlinesR6R7twritetto_strtclosetwait_for_passwd(R�R8t
ip_addressRzR�R�tssh_connect_timeouttssh_portRxt
win_passwdtwin_deploy_auth_retriestwin_deploy_auth_retry_delayt	use_winrmtwinrm_verify_sslt
password_datatlogging_datat
winrm_portR|tconsoletoutputR/R�tlinetfp_tuser((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytwait_for_instance�s
		


	
	




	
		
		

"



	

cC@s�|dkrtd��ntjj|�sEtdj|���ntjtj|�j�}|dkr�tdj|���nt	S(NuRThe required 'private_key' configuration setting is missing from the 'ec2' driver.u'The EC2 key file '{0}' does not exist.
ii�u=The EC2 key file '{0}' needs to be set to mode 0400 or 0600.
(ii�(
R�RR�RWR5RTtstattS_IMODEtst_modeRZ(R�tkey_mode((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_validate_key_path_and_mode�	sc$C@s\|rtd��ny=|drQtjttp4d|dd|�tkrQtSWntk
renXtjd|tdt�}tjd|tdd�}tjd	|td
tddl�}|r�t
|�ntddd
dj|d�dtdd|ddddg�dtddtd�td|d|dd|d�||d<||d	<t
|�|d<t|�}||d<tjd|d|�tjjj|tddm�|d%<d&|kr0d'|kr�d(|kr�tjd)|d�tjjjtjjd*|t��\|d(<|d'<q�n�t|�dlkrQtd+��nt||�\}}t|tj�r�tjd,|�iSg|d-<x#|D]}|d-j|d.�q�W|d-j�|d&<|d-r�t|d-�nt |�}tjd/|tid
t�}t|t!�s3t"d0��nx8tj#|�D]'}	t|	tj�sCt"d1��qCqCW|d|d2<tddd3d4j|d�di|d56dtddtd�tjjj$t%d6d7d8|dd9|d:|d&d;d<d=|�d>|krfd/|d>krft|d>d/t!�s?t"d0��nx=tj#|d>d/�D]$}	t|	t&�sWt"d1��qWqWWi}
d?|kr�t"d@��n|d?}|d|
d2<x/tj'|d>d/�D]\}}
|
|
|<q�Wtddd3dAj|�di|
d56dtddtd�tjjj$t%d6d7d8|dd9|
d:|d;d<d=|�ntjdB|td
t�}|r�t(|||�ntjdC|d�|dDdEdF}t)|�dGkr�|dH}tjdI|�n|dJ}tjdK|�||dL<tjjj*|t�dGkrN|dH}tjdM|�n|dJ}tjdM|�||dN<|r�tjdO|tdt�}t+||||�}n|j,�}tjdP|td
t�}|r�tdddQdRj|d�di|dP6dtddtd�tjdS|d�t-|di|dP6|dTdUdV6|d.d&6|j.dWt�dW6d;d<�}||dX<ntjdY|tdld
t�}|r%tjdZ|�t/|di|dY6d:|d&d;d<�}t|t!�r%|j.d[dl�r%tjd\|d&|�iSnx:tj'td]|t��D]\}}	|j0||	�qBWtjd^|d�tjd_|dt1j2|��i|dd6|dd6|dd6|d&d&6}|r�||dP<n|r�||dY<ntddd`daj|d�dtddb|t3|��dtddtd�t4d:|d&�}tdc|tt�|j5|�i}t6|�}|r�	x2|D]'}d/|kr�	|d/||dd<q�	q�	Wni}|r�
x�tj'|de�D]�\}}g} t|t!�r
| j|�nx|D]}!| j|!�q
Wx|| D]t}"|"df|kry
d2||"dfkry
|d||"dfd2<n|"df|kr6
||"df||"|dgdh<q6
q6
Wq�	Wn|rXx�tj'|�D]�\}#}tddd3dijt&|#��di|d56dtddtd�tdjt%d6d7d8|dd9|dk|#d;d<d=|�q�
Wn|S(nu-
    Create a single VM from a data dict
    u,You cannot create an instance with -a or -f.uprofileuec2R�udeployR�uwin_passworduuprivate_keyR�ucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunameR/ucloud.filter_eventucreatinguproviderudriverR0usock_dirR1u	transportucloud.cachedir_index_addukey_filenameugatewayulocationuCreating Cloud VM %s in %st
default_usersuec2-userucentosuubuntuuadminubitnamiurootu	usernamesuinstance_idupub_keyupriv_keyuGenerating minion keys for '%s'ukeysizeuNThe required 'keyname' configuration setting is missing from the 'ec2' driver.uError requesting instance: %suinstance_id_listu
instanceIdutagu'tag' should be a dict.uR'tag' values must be strings. Try quoting the values. e.g. "2013-09-19T20:09:46Z".uNameusetting tagsusalt/cloud/{0}/taggingutagsR�iR.R�RqR�uactionR:uspot_configu
spotRequestIduFailed to find spotRequestIdu#salt/cloud/spot_request_{0}/taggingunetwork_interfacesuCreated node %siuinstancesSetuitemuprivate_ipsuprivateIpAddressuSalt node data. Private_ip: %su	ipAddressuSalt node data. Public_ip: %sussh_hostuSalt interface set to: %su	salt_hostudisplay_ssh_outputuvolumesuattaching volumesu salt/cloud/{0}/attaching_volumesu$Create and attach volumes to node %su	placementuavailabilityZoneuzoneudel_all_vols_on_destroyuAttached Volumesussm_documentu!Associating with ssm document: %suerroru4Failed to associate instance %s with ssm document %sucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreateducloud.cache_nodeu
DeviceNameublockDeviceMappingu
deviceNameurootDeviceTypeuvolumeIdu#salt/cloud/block_volume_{0}/taggingucloud.wait_for_funtresource_idN(uec2-userucentosuubuntuuadminubitnamiuroot(7RRtis_profile_configuredRRRRAR�RZR�R�RFRTR�RSRXR�R]R^R�t
ssh_usernamesR[tgen_keysR�RlR)R
R�RYR+RBtqueue_instancesRrR�Rt
itervaluestwait_for_funtset_tagststrR3R'R�tget_salt_interfaceR�ROtcreate_attach_volumesRLtssm_create_associationR�R�tpformatR*t	_get_nodeR�R�($R�R�tdeploytwin_passwordR�R:R8RR�tvaluetspot_request_tagsR2RRR\R�tsalt_ip_addressRzR�tvolumestcreatedtssm_documenttassocRGt
event_datatnodetex_blockdevicetagsRYRZtblock_device_volume_id_mapt_devicet_maptbd_itemstmapitemt	blockitemtvolid((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytcreate�	s�	


"




	 


		




$



	







	


	!)




 

$,


cC@s8x1|D])}td|�}td|tt�qWdS(u�
    Queue a set of instances to be provisioned later. Expects a list.

    Currently this only queries node data, and then places it in the cloud
    cache (if configured). If the salt-cloud-reactor is being used, these
    instances will be automatically provisioned using that.

    For more information about the salt-cloud-reactor, see:

    https://github.com/saltstack-formulas/salt-cloud-reactor
    Rqucloud.cache_nodeN(R�RFRR(t	instancesRqR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�gs
c
C@s�|dkrtd��nd|kr>t|�d|d<nt|dtj�rptjjj|d�}n
|d}g}xJ|D]B}t	}dj
|d|�}i|d6|d	d	6}	d
|kr�|d
|	d
<nFd|kr�|d|	d<n)d|kr|d|	d<ntd
��d|krA|d|	d<nd|kr^|d|	d<nd|kr{|d|	d<nd|kr�|d|	d<nd|kr�|d|	d<nd
|	kr�t|	ddd|�}
t
}d|
kr�|
d|	d
<q�nt|i|	d
d
6|dd6d|ddd�}|jdd�}|r�|r�|dk	r�td|dd|dd|�n|r�dj
|	d
|d||d�}
tj|
�|j|
�q�q�W|S(u3
    Create and attach volumes to created node
    uactionuDThe create_attach_volumes action must be called with -a or --action.uinstance_idu
instanceIduvolumesu
{0} on {1}udeviceuvolume_nameuzoneu	volume_idusnapshotusizeuNCannot create volume.  Please define one of 'volume_id', 'snapshot', or 'size'utagsutypeuiopsu	encryptedukmskeyidR�ufunctiontwait_to_finishuvolumeIdRqudel_all_vols_on_destroytdeviceR�u+{0} attached to {1} (aka {2}) as device {3}N(RR�R)R
R�R]R^tyamlt	safe_loadRRTRt
create_volumeRZt
attach_volumeRLR�t_toggle_delvolRXR�R+(R.R�R�R�R�R�tvolumeR�tvolume_nametvolume_dicttcreated_volumetattachtdelvols_on_destroyRH((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�xst

	
	



cC@s�|dkrtd��ntjd|�t|�d}tddddj|�d	i|d
6|d6dtd
dtd�idd6|d6}tj|dt	�dt
�dtdd�}|S(u
    Stop a node
    uactionu3The stop action must be called with -a or --action.uStopping node %su
instanceIducloud.fire_eventueventustopping instanceusalt/cloud/{0}/stoppingR/unameuinstance_idR0usock_dirR1u	transportu
StopInstancesuActionuInstanceId.1R:RvR�R�u4(RRXR�R�RFRTRRMR�RSR�(R.R�RqRKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytstop�s(


			cC@s�|dkrtd��ntjd|�t|�d}tddddj|�d	i|d
6|d6dtd
dtd�idd6|d6}tj|dt	�dt
�dtdd�}|S(u
    Start a node
    uactionu4The start action must be called with -a or --action.uStarting node %su
instanceIducloud.fire_eventueventustarting instanceusalt/cloud/{0}/startingR/unameuinstance_idR0usock_dirR1u	transportuStartInstancesuActionuInstanceId.1R:RvR�R�u4(RRXR�R�RFRTRRMR�RSR�(R.R�RqRKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytstart�s(


			c
C@s�|d kri}n|d kr-t�}n|d kr�d|krY|d}|d=nd|kry|d}|d=n|d kr�|d kr�td|dd d|�d}q�q�|}n|d kr�idd6Sid	d
6|d6}tjd||�|r|r|}nxOttj|��D]8\}\}	}
|	|d
j|�<|
|dj|�<q)Wd}xe|t	j
kr�t	j|ddd|dt�dt
dd�td|ddd|�}tjd|�t}
x�|D]�}|d|kr�q�n|jd�d kr3|j|d�dkr3q�ntj|j|d��tj|d�kr�tjd|d|j|d�|d�t}
Pq�q�W|
r�tjd|�|d7}t	j|�qnn|SWtdj|���d S(!uw
    Set tags for a resource. Normally a VM name or instance_id is passed in,
    but a resource_id may be passed instead. If both are passed in, the
    instance_id will be used.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a set_tags mymachine tag1=somestuff tag2='Other stuff'
        salt-cloud -a set_tags resource_id=vol-3267ab32 tag=somestuff
    uresource_iduinstance_idR.RqR:u
instanceIdu5A valid instance_id or resource_id was not specified.uErroru
CreateTagsuActionuResourceId.1uTags to set for %s: %suTag.{0}.Keyu
Tag.{0}.ValueiRrutagSetRvR�R�u4R�uactionuSetting the tags returned: %sukeyuvalueuu,Setting the tag %s returned %s instead of %su)Failed to set tags. Remaining attempts %siuFailed to set tags on {0}!N(R�RSR�RXR[RR
R3RTRMRNR�R�Rtget_tagsRRLRRZR�RqR(R.R�R�R:RqR�R�RKR
ttag_kttag_vR{tsettagstfailed_to_set_tagsR%((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�sr	



%	


	(	
./"

cC@s�|dkrt�}n|dkr�|dkr~|rIt|�d}q�d|krb|d}q�d|kr�|d}q�q�|}nidd6dd6|d6}tj|d	d
d|dt�d
tdd�S(uL
    Retrieve tags for a resource. Normally a VM name or instance_id is passed
    in, but a resource_id may be passed instead. If both are passed in, the
    instance_id will be used.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a get_tags mymachine
        salt-cloud -a get_tags resource_id=vol-3267ab32
    u
instanceIduinstance_iduresource_iduDescribeTagsuActionuresource-idu
Filter.1.NameuFilter.1.ValueRrutagSetR:RvR�R�u4N(R�RSR�RMR�R�R(R.RqR�R:R�R�RK((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�zs(
	

	c
C@s|dkri}nd|kr0td��n|rWd|krW|d}|d=n|spt|�d}nidd6|d6}x:t|djd��D]\}}||d	j|�<q�Wtj|d
ddt�d
t	�dt
dd�|rtd|�Std|�SdS(u�
    Delete tags for a resource. Normally a VM name or instance_id is passed in,
    but a resource_id may be passed instead. If both are passed in, the
    instance_id will be used.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a del_tags mymachine tags=mytag,
        salt-cloud -a del_tags mymachine tags=tag1,tag2,tag3
        salt-cloud -a del_tags resource_id=vol-3267ab32 tags=tag1,tag2,tag3
    utagsu7A tag or tags must be specified using tags=list,of,tagsuresource_idu
instanceIdu
DeleteTagsuActionuResourceId.1u,uTag.{0}.KeyRrutagSetR:RvR�R�u4R�RqN(R�RR�RR&RTRMR�RSR�RR�(R.R�R�RqR�RKR
R%((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytdel_tags�s.	



&		
cC@su|dkrtd��ntjd||d�t|i|dd6dd�tjjjtd||d�dS(	u�
    Properly rename a node. Pass in the new name as "new name".

    CLI Example:

    .. code-block:: bash

        salt-cloud -a rename mymachine newname=yourmachine
    uactionu5The rename action must be called with -a or --action.uRenaming %s to %sunewnameuNameR�upki_dirN(	RRXR�R�R]R^R�t
rename_keyR(R.R�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytrename�s
c
C@s�|dkrtd��nt|�}|d}|jd�}td|d|ddd	t�}td
ddd
j|�di|d6|d6dtddtd�|dkr�tdj|���ni}tj	dt
�tdt�}|tk	rOdj|tj
�j�}t|di|d6dd�tjd|�||d<nidd6|d6}	t�}
t�}tj|	d |
d!|d"td#d$�}tj|�|j|d%�|d/k	rid&d6|d'6}	tj|	d |
d!|d"td#d$�}|d%|d(<ntd
dd)d*j|�di|d6|d6dtddtd�td+|�tjd,t�tkr�td-|tjd.�d%t�n|S(0u�
    Destroy a node. Will check termination protection and warn if enabled.

    CLI Example:

    .. code-block:: bash

        salt-cloud --destroy mymachine
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.u
instanceIduspotInstanceRequestIdR.RqR�uactiontquietucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingR/unameuinstance_idR0usock_dirR1u	transportutrueu�This instance has been protected from being destroyed. Use the following command to disable protection:

salt-cloud -a disable_term_protect {0}urename_on_destroyR�u
{0}-DEL{1}R�unewnameu>Machine will be identified as %s until it has been cleaned up.uTerminateInstancesuActionuInstanceId.1R:RvR�R�u4iuCancelSpotInstanceRequestsuSpotInstanceRequestId.1uspotInstanceudestroyed instanceusalt/cloud/{0}/destroyeducloud.cachedir_index_deluupdate_cachedirucloud.delete_minion_cachediru:N(RR�RLtshow_term_protectRZRFRTRRR�RRtuuidtuuid4thexR�RXR�RSR�RMR�R�R�RR&(
R.R�t
node_metadataRqR2t	protectedR�trename_on_destroytnewnameRKR:RvR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyRp�s�

	
		


			


	
$cC@s~t|�d}idd6|d6}tj|dddt�dt�d	td
d�}|gkrstjd�nidd
6S(ul
    Reboot a node.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a reboot mymachine
    u
instanceIduRebootInstancesuActionuInstanceId.1RrutagSetR:RvR�R�u4uCompleteuReboot(R�RMR�RSR�RRXR�(R.R�RqRKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytrebootZ
s


			cC@sw|dkrtd��ni|dd6dd6}tj|ddd	t�d
t�dtdd
�}tj|�|S(u5
    Show the details from EC2 concerning an AMI
    ufunctionu;The show_image action must be called with -f or --function.uimageu	ImageId.1uDescribeImagesuActionRrutagSetR:RvR�R�u4(RRMR�RSR�RRXR�(R�R�RKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
show_imageu
s
			
cC@s�|r"|dkr"td��n|dkrU|jdd
�}|jdd
�}n|rr|rrtd��ntd|d|�}td	|tt�|S(u�
    Show the details from EC2 concerning an AMI.

    Can be called as an action (which requires a name):

    .. code-block:: bash

        salt-cloud -a show_instance myinstance

    ...or as a function (which requires either a name or instance_id):

    .. code-block:: bash

        salt-cloud -f show_instance my-ec2 name=myinstance
        salt-cloud -f show_instance my-ec2 instance_id=i-d34db33f
    uactionu)The show_instance action requires a name.ufunctionunameuinstance_iduCThe show_instance function requires either a name or an instance_idR.Rqucloud.cache_nodeN(RRLR�R�RFRR(R.RqR�R�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
show_instance�
scC@sX|dkrt�}nidd6}tj|�jd�rjt|�dksat|�dkrj|}n|r}||d<nd|d<||d	<tj|�t�}d
}x�|t	j
krSyMt	j|d|d|d
tdd�}t
|�j�}tt|��SWq�tk
rO|d7}tjd|p8||�t	j|�q�Xq�WiS(NuDescribeInstancesuActionui-i
iuInstanceId.1utag:Nameu
Filter.1.NameuFilter.1.Value.1iR:RvR�R�u4iu<Failed to get the data for node '%s'. Remaining attempts: %s(R�RSR
RR�R#RXRfR�RMRNR�Rt_extract_instance_infoR�tnexttitert
IndexErrorR[Rq(R.RqR:RKRvR{R�t
instance_info((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��
s8
<	



		

cC@s.|dkrtd��nt|p*t��S(u;
    Return a list of the VMs that are on the provider
    uactionuBThe list_nodes_full function must be called with -f or --function.(Rt_list_nodes_fullRS(R:R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytlist_nodes_full�
scC@s�d|kr~|ddk	r~|d}t|dt�rnx*|dD]}|ddkrD|dSqDW|dS|dddS|dS(NutagSetuitemukeyuNameuvalueu
instanceId(R�R)R*(R1ttagsetR%((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_extract_name_tag�
s
cC@sli}x_|D]W}t|ddt�r�x7|ddD]�}t|�}|||<|||d<||jtd|dd|dd|d	d
|ddd|jd
g�d|jdg���q9Wq
|dd}t|�}|||<|||d<||jtd|dd|dd|d	d
|ddd|jd
g�d|jdg���q
W|S(uE
    Given an instance query, return a dict of all instance data
    uinstancesSetuitemunametidu
instanceIdR�uimageIdtsizeuinstanceTypeR3u
instanceStatetprivate_ipsuprivateIpAddresst
public_ipsu	ipAddress(R)R*R�R�R�RL(R�R�RR1R.((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��
s8










cC@s�tp	d}d|kr4|jd�}|d}nidd6}tj|d|d|dtd	d
�}d|kr�tdj|dd
dd���nt|�}td||t�|S(u8
    Return a list of the VMs that in this location
    uec2u:iuDescribeInstancesuActionR:RvR�R�u4uerroru*An error occurred while listing nodes: {0}uErrorsuErroruMessageucloud.cache_node_list(	RR&RMR�RRRTR�RF(R:RvR/RKR�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�s"

	c
C@s*|dkrtd��ni}idd6}tj|dt�dt�dtdd	�}d
|kr�tdj|d
dd
d���nx�|D]�}t|ddt�r�|dd}n|ddg}xJ|D]B}|dd}t	|�}	|d}
i|d6|
d6||	<q�Wq�W|S(u�
    Return a list of the VMs that are on the provider. Only a list of VM names,
    and their state, is returned. This is the minimum amount of information
    needed to check for existing VMs.
    uactionuAThe list_nodes_min function must be called with -f or --function.uDescribeInstancesuActionR:RvR�R�u4uerroru*An error occurred while listing nodes: {0}uErrorsuErroruMessageuinstancesSetuitemu
instanceStateunameu
instanceIdustateuid(
RRMR�RSR�RRTR)R*R�(R:R�R�RKR�RR�R1R3R.R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytlist_nodes_min5s0
			


 cC@s�|dkrtd��ni}tt��}d|krdtdj|dddd���nx�|D]y}i||dd6||d	d	6||d
d
6||dd6||dd6||d
d
6||dd6||<qkW|S(u;
    Return a list of the VMs that are on the provider
    uactionu=The list_nodes function must be called with -f or --function.uerroru*An error occurred while listing nodes: {0}uErrorsuErroruMessageuiduimageunameusizeustateuprivate_ipsu
public_ips(RR�RSRT(R�R�tnodesR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
list_nodes\s&
cC@s&tjjjtt��td|�S(uO
    Return a list of the VMs that are on the provider, with select fields
    uquery.selection(R]R^R�tlist_nodes_selectR�RSR(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�zscC@s�|dkrtd��n|s4t|�d}nidd6|d6dd6}tj|d	t�d
t�dtdtd
d�}t}x(|D] }d|kr�|d}Pq�q�Wt	j	|tkr�t
jnt
jd|dkr�dp�d|�|S(uZ
    Show the details from EC2 concerning an instance's termination protection state

    uactionu@The show_term_protect action must be called with -a or --action.u
instanceIduDescribeInstanceAttributeuActionu
InstanceIdudisableApiTerminationu	AttributeR:RvRuR�R�u4uvalueu#Termination Protection is %s for %sutrueuenabledudisabled(
RR�RMR�RSR�RZRRRXRCRDtINFO(R.RqR�R�RKR�tdisable_protectR1((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��s0

			

c
C@s�|dkrtd��nt�}tj|�jd�rit|�dks`t|�dkri|}n|r�|r�td��ntd|d|d	|�}tj|tkr�t	j
nt	jd
|d|�|dS(uM
    Show the details from EC2 regarding cloudwatch detailed monitoring.
    uactionuGThe show_detailed_monitoring action must be called with -a or --action.ui-i
iuOThe show_detailed_monitoring action must be provided with a name or instance IDR.RqR:u Detailed Monitoring is %s for %su
monitoring(RRSR
RR�R#R�RXRZRCRDR�(R.RqR�R�R:tmatched((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytshow_detailed_monitoring�s	<	cC@swt|�d}idd6|d6|d6}tj|dt�dt�dtd	td
d�}td|d
|dd�S(u=
    Enable or Disable termination protection on a node

    u
instanceIduModifyInstanceAttributeuActionu
InstanceIduDisableApiTermination.ValueR:RvRuR�R�u4R.RqR�uaction(R�RMR�RSR�RZRR�(R.R�RqRKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt_toggle_term_protect�s

			cC@s(|dkrtd��nt|d�S(u�
    Enable termination protection on a node

    CLI Example:

    .. code-block:: bash

        salt-cloud -a enable_term_protect mymachine
    uactionuBThe enable_term_protect action must be called with -a or --action.utrue(RR�(R.R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytenable_term_protect�s
cC@s(|dkrtd��nt|d�S(u�
    Disable termination protection on a node

    CLI Example:

    .. code-block:: bash

        salt-cloud -a disable_term_protect mymachine
    uactionuBThe enable_term_protect action must be called with -a or --action.ufalse(RR�(R.R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytdisable_term_protect�s
cC@s�|dkrtd��nt|�d}idd6|d6}tj|dt�dt�d	td
tdd�}td
|d|dd�S(uH
    Enable/disable detailed monitoring on a node

    CLI Example:
    uactionuBThe enable_term_protect action must be called with -a or --action.u
instanceIduUnmonitorInstancesuActionuInstanceId.1R:RvRuR�R�u4R.RqR�(	RR�RMR�RSR�RZRR�(R.R�RqRKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytdisable_detailed_monitoring�s

			cC@s�|dkrtd��nt|�d}idd6|d6}tj|dt�dt�d	td
tdd�}td
|d|dd�S(uI
    Enable/disable detailed monitoring on a node

    CLI Example:

    uactionuBThe enable_term_protect action must be called with -a or --action.u
instanceIduMonitorInstancesuActionuInstanceId.1R:RvRuR�R�u4R.RqR�(	RR�RMR�RSR�RZRR�(R.R�RqRKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytenable_detailed_monitorings

			c
C@s�|dkrtd��n|s*i}n|jdd�}|jdd�}|jdd�}|dkrt|�d}nidd6|d	6}tj|d
t�dt�dtd
d�}|dddd}t	|dt
�s�|dg|d<ng}	x�t|d�D]�\}
}|d}|dk	rH||krHqn|dk	rn||ddkrnqni|d6|ddd6|ddd6}
|	j|
�qW|	S(u�
    Do not delete all/specified EBS volumes upon instance termination

    CLI Example:

    .. code-block:: bash

        salt-cloud -a show_delvol_on_destroy mymachine
    uactionuEThe show_delvol_on_destroy action must be called with -a or --action.uinstance_idudeviceu	volume_idu
instanceIduDescribeInstancesuActionuInstanceId.1R:RvR�R�u4iuinstancesSetuitemublockDeviceMappingu
deviceNameuebsuvolumeIdudevice_nameudeleteOnTerminationN(
RRLR�R�RMR�RSR�RR)R*RR+(R.R�R�RqR�t	volume_idRKR8tblockmapR�R
R1tdevice_nameR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytshow_delvol_on_destroy0sB	

			
 c	C@sm|dkrtd��n|s*i}n|jdd
�}|jdd
�}td|d|d|dd	�S(u�
    Do not delete all/specified EBS volumes upon instance termination

    CLI Example:

    .. code-block:: bash

        salt-cloud -a keepvol_on_destroy mymachine
    uactionuAThe keepvol_on_destroy action must be called with -a or --action.udeviceu	volume_idR.R�R�R�ufalseN(RRLR�R�(R.R�R�R�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytkeepvol_on_destroyos
	c	C@sm|dkrtd��n|s*i}n|jdd
�}|jdd
�}td|d|d|dd	�S(u�
    Delete all/specified EBS volumes upon instance termination

    CLI Example:

    .. code-block:: bash

        salt-cloud -a delvol_on_destroy mymachine
    uactionu@The delvol_on_destroy action must be called with -a or --action.udeviceu	volume_idR.R�R�R�utrueN(RRLR�R�(R.R�R�R�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytdelvol_on_destroy�s
	c
C@s�|st|�d}n|rRtjd|dt�dt�dtdd�}nMidd	6|d
6}tj|dtdt�dt�dtdd�\}}|dd
dd}idd	6|d6}t|dt�s�|dg|d<nx�t	|d�D]�\}	}
|
d}|dk	r5||kr5qn|dk	r[||
ddkr[qn||dj|	�<||dj|	�<qWtj|dtdt�dt�dtdd�i|d6|d6|d6}t||dd�S(Nu
instanceIdRsR:RvR�R�u4uDescribeInstancesuActionuInstanceId.1RtiuinstancesSetuitemublockDeviceMappinguModifyInstanceAttributeu
InstanceIdu
deviceNameuebsuvolumeIdu!BlockDeviceMapping.{0}.DeviceNameu.BlockDeviceMapping.{0}.Ebs.DeleteOnTerminationRuuinstance_idudeviceu	volume_idR�uaction(
R�RMR�RSR�RRZR)R*RR�RTR(
R.RqR�R�R�RsR8RKRR
R1RR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��sN		

		


 		

c	C@s|dkrtjd�tSd|kr:tjd�tS|jdd#�}|s�d|krotjd�tSd|kr�tjd	�tSi|dd
6i|jdd�d
6|dd6d6g}nt|t�s�|g}nidd6|dd6}|jtd|��d|kr.|d|d<nd|krK|d|d<nd|krh|d|d<nd|kr�|d|d<ntj	|�t
j|dtdtdt
�dt�dtd d!�}i}x9|d"D]-}x$|j�D]\}}|||<q�Wq�W|S($u�
    Create an ami from a snapshot

    CLI Example:

    .. code-block:: bash

        salt-cloud -f register_image my-ec2-config ami_name=my_ami description="my description"
                root_device_name=/dev/xvda snapshot_id=snap-xxxxxxxx
    ufunctionu@The create_volume function must be called with -f or --function.uami_nameu0ami_name must be specified to register an image.ublock_device_mappingusnapshot_iduKsnapshot_id or block_device_mapping must be specified to register an image.uroot_device_nameuProot_device_name or block_device_mapping must be specified to register an image.u
DeviceNameuvolume_typeugp2u
VolumeTypeu
SnapshotIduEbsu
RegisterImageuActionuNameuBlockDeviceMappinguRootDeviceNameudescriptionuDescriptionuvirtualization_typeuVirtualizationTypeuarchitectureuArchitectureRtRuR:RvR�R�u4iN(RXRYRRLR�R)R*R�R�R[RMR�RZRSR�RR�(	R�R�tblock_device_mappingRKR8tr_datatdRR((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytregister_image�s\




			cK@s
t|d�S(uh
    Wrapper around create_volume.
    Here just to ensure the compatibility with the cloud module.
    ufunction(R�(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
volume_create#scC@s�|dkrtjd�tSd|kr:tjd�tSd|kr_d|kr_d|d<nidd	6|dd
6}d|kr�|d|d<nd|kr�|d|d<nd
|kr�|d
|d<nd|kr|jd
d�dkr|d|d<nd|krId|krI|d|d<d|krI|d|d<qInd|krrd|krrtjd�tStj|�tj|dtdtdt�dt	�dt
dd�}i}x<|dD]0}x'tj|�D]\}}|||<q�Wq�W|d }	d!|kr�t
|d!tj�rEtjjj|d!�}
n
|d!}
t
|
t�r�td"|
d#|	d$d%dt��}||d!<q�n|r�tjjjd&td'i|	d(6d)|d*d+d,d-�n|S(.u&
    Create a volume.

    zone
        The availability zone used to create the volume. Required. String.

    size
        The size of the volume, in GiBs. Defaults to ``10``. Integer.

    snapshot
        The snapshot-id from which to create the volume. Integer.

    type
        The 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. String.

    iops
        The number of I/O operations per second (IOPS) to provision for the volume,
        with a maximum ratio of 50 IOPS/GiB. Only valid for Provisioned IOPS SSD
        volumes. Integer.

        This option will only be set if ``type`` is also specified as ``io1``.

    encrypted
        Specifies whether the volume will be encrypted. Boolean.

        If ``snapshot`` is also given in the list of kwargs, then this value is ignored
        since volumes that are created from encrypted snapshots are also automatically
        encrypted.

    tags
        The tags to apply to the volume during creation. Dictionary.

    call
        The ``create_volume`` function must be called with ``-f`` or ``--function``.
        String.

    wait_to_finish
        Whether or not to wait for the volume to be available. Boolean. Defaults to
        ``False``.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f create_volume my-ec2-config zone=us-east-1b
        salt-cloud -f create_volume my-ec2-config zone=us-east-1b tags='{"tag1": "val1", "tag2", "val2"}'
    ufunctionu@The create_volume function must be called with -f or --function.uzoneu:An availability zone must be specified to create a volume.usizeusnapshotu10uCreateVolumeuActionuAvailabilityZoneuSizeu
SnapshotIdutypeu
VolumeTypeuiopsustandarduio1uIopsu	encryptedu	EncryptedukmskeyiduKmsKeyIdu8If a KMS Key ID is specified, encryption must be enabledRtRuR:RvR�R�u4iuvolumeIdutagsR�R�R�uactiontfunR�u	volume_idtfun_calltargument_being_watchedustatustrequired_argument_responseu	available(RXRYRRLR[RMR�RZRSR�RR
R3R)R�R]R^R�R�R�R�R�trun_func_until_ret_argtdescribe_volumes(R�R�R�RKR8RRRRR�R�tnew_tags((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR�+sr2


$
			



cC@s\tj|dtdt�dt�dtdd�}|drXtjd|d	|�tS|S(
NRtR:RvR�R�u4iu3Error attaching volume %s to instance %s. Retrying!u	volume_id(	RMR�RZRSR�RRXR�R(RKtkwsRqR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt__attach_vol_to_instance�s			
cC@su|dkrtd��n|s*i}nd|krC|d}n|rc|rct|�d}n|r�|r�tjd�tSd|kr�tjd�tSd|kr�tjd	�tSid
d6|dd6|d
6|dd6}tj|�t�}tjj	j
td|||fdtj
d|tdd�dtj
d|tdd�dtj
d|tdd��}|S(u(
    Attach a volume to an instance
    uactionu<The attach_volume action must be called with -a or --action.uinstance_idu
instanceIdu,Either a name or an instance_id is required.u	volume_iduA volume_id is required.udeviceu%A device is required (ex. /dev/sdb1).uAttachVolumeuActionuVolumeIdu
InstanceIduDeviceR�R�uwait_for_ip_timeoutR�i
i<R�uwait_for_ip_intervalR�uwait_for_ip_interval_multiplieriiX(RR�RXRYRR[RR]R^R�RoRRR�R(R.R�RqR�RKR�R8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��sD	






	cC@s|si}nt||�S(uo
    Wrapper around describe_volumes.
    Here just to keep functionality.
    Might be depreciated later.
    (R(R�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytshow_volume�s	cC@s�|dkrtd��n|s*i}nd|krGtjd�tSidd6|dd6}tj|dtd	t�d
t�dt	dd
�}|S(u*
    Detach a volume from an instance
    uactionu<The detach_volume action must be called with -a or --action.u	volume_iduA volume_id is required.uDetachVolumeuActionuVolumeIdRtR:RvR�R�u4(
RRXRYRRMR�RZRSR�R(R.R�RqR�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
detach_volumes"	

			cC@s{|si}nd|kr,tjd�tSidd6|dd6}tj|dtdt�dt�d	td
d�}|S(u
    Delete a volume
    u	volume_iduA volume_id is required.uDeleteVolumeuActionuVolumeIdRtR:RvR�R�u4(	RXRYRRMR�RZRSR�R(R.R�RqR�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
delete_volumes	

			cK@s
t|d�S(uk
    Wrapper around describe_volumes.
    Here just to ensure the compatibility with the cloud module.
    ufunction(R(R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytvolume_list3scC@s�|dkrtjd�tS|s,i}nidd6}d|kr�|djd�}x0t|�D]\}}||dj|�<qeWntj|�tj|dt	d	t
�d
t�dtdd
�}|S(u�
    Describe a volume (or volumes)

    volume_id
        One or more volume IDs. Multiple IDs must be separated by ",".

    TODO: Add all of the filters.
    ufunctionuCThe describe_volumes function must be called with -f or --function.uDescribeVolumesuActionu	volume_idu,uVolumeId.{0}RtR:RvR�R�u4(
RXRYRR&RRTR[RMR�RZRSR�R(R�R�RKR�tvolume_indexR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR;s&		

			cC@s�|dkrtjd�tS|s,i}nd|krItjd�tSidd6|dd6}tj|dtd	t�d
t�dtdd
�}|S(u
    Create an SSH keypair
    ufunctionuAThe create_keypair function must be called with -f or --function.ukeynameuA keyname is required.u
CreateKeyPairuActionuKeyNameRtR:RvR�R�u4(	RXRYRRMR�RZRSR�R(R�R�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytcreate_keypair`s$	

			c
C@s2|dkrtjd�tS|s,i}nd|krItjd�tSd|krftjd�tSidd6|dd	6}|d}tjj|�r�tjjj	|d
��"}tjj
j|j��}WdQXn|dk	r�tj|�|d<ntj|d
tdt�dt�dtdd�}|S(uC
    Import an SSH public key.

    .. versionadded:: 2015.8.3
    ufunctionuAThe import_keypair function must be called with -f or --function.ukeynameuA keyname is required.ufileuA public key file is required.u
ImportKeyPairuActionuKeyNameurNuPublicKeyMaterialRtR:RvR�R�u4(RXRYRR�RWR5R]R^R6R7R8R9R:R�R<R=RMR�RZRSR�R(R�R�RKtpublic_key_fileRMt
public_keyR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytimport_keypair}s6	



$			cC@s�|dkrtjd�tS|s,i}nd|krItjd�tSidd6|dd6}tj|dtd	t�d
t�dtdd
�}|S(u,
    Show the details of an SSH keypair
    ufunctionu?The show_keypair function must be called with -f or --function.ukeynameuA keyname is required.uDescribeKeyPairsuActionu	KeyName.1RtR:RvR�R�u4(	RXRYRRMR�RZRSR�R(R�R�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytshow_keypair�s$	

			cC@s�|dkrtjd�tS|s,i}nd|krItjd�tSidd6|dd6}tj|dtd	t�d
t�dtdd
�}|S(u
    Delete an SSH keypair
    ufunctionuAThe delete_keypair function must be called with -f or --function.ukeynameuA keyname is required.u
DeleteKeyPairuActionuKeyNameRtR:RvR�R�u4(	RXRYRRMR�RZRSR�R(R�R�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytdelete_keypair�s$	

			cC@sp|dkrtd��n|dkr0i}n|jdd�}|jdd�}|dkrotd��nidd6|d	6|d
6}tj|�tj|dtdtd
t�dt	�dt
dd�d}i}x8|D]0}x'tj|�D]\}	}
|
||	<q�Wq�Wd|krl|d}|rlt
jjjdtdi|d6d|dddd�qln|S(u�
    Create a snapshot.

    volume_id
        The ID of the Volume from which to create a snapshot.

    description
        The optional description of the snapshot.

    CLI Exampe:

    .. code-block:: bash

        salt-cloud -f create_snapshot my-ec2-config volume_id=vol-351d8826
        salt-cloud -f create_snapshot my-ec2-config volume_id=vol-351d8826 \
            description="My Snapshot Description"
    ufunctionuBThe create_snapshot function must be called with -f or --function.u	volume_idudescriptionuu3A volume_id must be specified to create a snapshot.uCreateSnapshotuActionuVolumeIduDescriptionRtRuR:RvR�R�u4iu
snapshotIdR
R�usnapshot_idRRustatusR
u	completedN(RR�RLRXR[RMR�RZRSR�RR
R3R]R^R�Rtdescribe_snapshots(R�R�R�R�tdescriptionRKR8RRRRtsnapshot_id((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytcreate_snapshot�sD	


		




cC@s�|dkrtjd�tSd|kr:tjd�tSidd6}d|krd|d|d<ntj|�tj|dtd	t�d
t�dt	dd
�}|S(u
    Delete a snapshot
    ufunctionuBThe delete_snapshot function must be called with -f or --function.usnapshot_idu5A snapshot_id must be specified to delete a snapshot.uDeleteSnapshotuActionu
SnapshotIdRtR:RvR�R�u4(
RXRYRR[RMR�RZRSR�R(R�R�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytdelete_snapshot's$


			cC@s|dkrtjd�tSd|kr:tjd�tSd|krWtjd�tSd|krpd|d<nid	d
6}d|kr�|d|d<nd|kr�|d|d<nd|kr�|d|d
<ntj|�tj|dtdt�dt�dt	dd�}|S(u
    Copy a snapshot
    ufunctionu@The copy_snapshot function must be called with -f or --function.u
source_regionu5A source_region must be specified to copy a snapshot.usource_snapshot_idu:A source_snapshot_id must be specified to copy a snapshot.udescriptionuuCopySnapshotuActionuSourceRegionuSourceSnapshotIduDescriptionRtR:RvR�R�u4(
RXRYRR[RMR�RZRSR�R(R�R�RKR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt
copy_snapshotFs6




			c
C@s�|dkrtjd�tSidd6}d|krG|d|d<nd|kr�|djd�}x0t|�D]\}}||dj|�<qsWnd	|kr�|d	jd�}x0t|�D]\}}||d
j|�<q�Wnd|kr=|djd�}	x0t|	�D]\}
}||dj|
�<qWntj|�tj|d
t	dt
�dt�dtdd�}|S(u�
    Describe a snapshot (or snapshots)

    snapshot_id
        One or more snapshot IDs. Multiple IDs must be separated by ",".

    owner
        Return the snapshots owned by the specified owner. Valid values
        include: self, amazon, <AWS Account ID>. Multiple values must be
        separated by ",".

    restorable_by
        One or more AWS accounts IDs that can create volumes from the snapshot.
        Multiple aws account IDs must be separated by ",".

    TODO: Add all of the filters.
    ufunctionuDThe describe_snapshot function must be called with -f or --function.uDescribeSnapshotsuActionusnapshot_idsusnapshot_idu,uSnapshotId.{0}uowneru	Owner.{0}u
restorable_byuRestorableBy.{0}RtR:RvR�R�u4(
RXRYRR&RRTR[RMR�RZRSR�R(
R�R�RKtsnapshot_idstsnapshot_indexR townerstowner_indexR�trestorable_bystrestorable_by_indext
restorable_byR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyRqs6

			c	C@sW|dkrtd��n|dkr3t�}n|sLt|�d}n|dkrai}n|dkr�d|kr�|d}|d=q�nidd6|d6}i}tj|dtd	|d
t�dtdd
�}xv|D]n}t	t
j|��dkr'tj
t	t
j|���|d<q�t	t
j|��|t	t
j|��<q�W|S(u�
    Show the console output from the instance.

    By default, returns decoded data, not the Base64-encoded data that is
    actually returned from the EC2 API.
    uactionuAThe get_console_output action must be called with -a or --action.u
instanceIduinstance_iduGetConsoleOutputuActionu
InstanceIdRuR:RvR�R�u4uoutputuoutput_decodedN(RR�RSR�RMR�RZR�RR�R
titerkeystbinasciit
a2b_base64R�(	R.R:RqR�R�RKR�R8R1((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��s6
	



		
%,cC@s�|dkrtd��n|s4t|�d}n|dkrIi}n|dkrxd|krx|d}|d=qxnidd6|d6}i}tj|dtd	t�d
t�dtdd
�}x6|D].}t	t
j|��|t	t
j|��<q�Wt
r8tr8d|ks$d|kr4tjd�n|Sd|kr�d|kr�tjjj|dd��&}tjjj|j��|d<WdQXq�nd|kr�|jdd�}	|	dk	r�|d}
tj|	�}	t
rtj|
jd��}|j|	tj�}nat j!j"j#}
t j$j%�jd|
�}t j&jj'|
�}t(j%|�}|j)|	|�}tjjj|�|d<q�n|S(u�
    Return password data for a Windows instance.

    By default only the encrypted password data will be returned. However, if a
    key_file is passed in, then a decrypted password will also be returned.

    Note that the key_file references the private key that was used to generate
    the keypair associated with this instance. This private key will _not_ be
    transmitted to Amazon; it is only used internally inside of Salt Cloud to
    decrypt data _after_ it has been received from Amazon.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a get_password_data mymachine
        salt-cloud -a get_password_data mymachine key_file=/root/ec2key.pem

    Note: PKCS1_v1_5 was added in PyCrypto 2.5
    uactionu@The get_password_data action must be called with -a or --action.u
instanceIduinstance_iduGetPasswordDatauActionu
InstanceIdRuR:RvR�R�u4ukeyukey_fileu8No crypto library is installed, can not decrypt passwordurNupasswordDatauasciiiupassword(*RR�R�RMR�RZRSR�RR�R
R�R+RRRXtwarnR]R^R6R7R8R9R:RLR<t	b64decodeRtload_key_stringRCtprivate_decryptt
pkcs1_paddingtCryptotHashRtdigest_sizetRandomRBt	PublicKeyt	importKeyRtdecrypt(R.R�RqR�RKR�R8R1tkf_tpwdatatrsa_keyRGtpasswordtdsizetsentineltkey_obj((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR}�sZ	



			
,+
cC@s�idd6dd6dd6dd6d	d
6dd6}|dkrEi}nd
|krvx;|D]}t|||�qXWnt||d
|d
�dS(u 
    Download most recent pricing information from AWS and convert to a local
    JSON file.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f update_pricing my-ec2-config
        salt-cloud -f update_pricing my-ec2-config type=linux

    .. versionadded:: 2015.8.0
    u6https://a0.awsstatic.com/pricing/1/ec2/linux-od.min.jsulinuxu5https://a0.awsstatic.com/pricing/1/ec2/rhel-od.min.jsurhelu5https://a0.awsstatic.com/pricing/1/ec2/sles-od.min.jsuslesu6https://a0.awsstatic.com/pricing/1/ec2/mswin-od.min.jsumswinu9https://a0.awsstatic.com/pricing/1/ec2/mswinSQL-od.min.jsumswinsqlu<https://a0.awsstatic.com/pricing/1/ec2/mswinSQLWeb-od.min.jsumswinsqlwebutypeN(R�t_parse_pricing(R�R�tsourcestsource((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytupdate_pricing7s
	
cC@s�tj|dt�}g}d}tjtd|d�}|j�jd�jd�}x)d"D]!}|j	|dj
|��}q_WxMd#D]E}|j	|dj
|��}|j	dj
|�dj
|��}q�W|j	dd�}i}tjj
j|�}xb|ddD]R}i}	x5|dD])}
x |
dD]}||	|d<q8Wq'W|	||d<qWtjjtddj
|��}tjjj|d ��}
tj||
�Wd!QXtS($u`
    Download and parse an individual pricing file from AWS

    .. versionadded:: 2015.8.0
    R'uutextu);u	callback(uversuconfigurateuvalueColumnsu
currenciesu
instanceTypesutypeuECUu	storageGBunameuvCPUu	memoryGiBu
storageGiBuUSDu"{0}"uregionupriceusizeu"{0}"su"{0}s"u""u"uregionsusizesucachediruec2-pricing-{0}.puwN(uversuconfigurateuvalueColumnsu
currenciesu
instanceTypesutypeuECUu	storageGBunameuvCPUu	memoryGiBu
storageGiBuUSD(uregionupriceusize(thttpR�RZtretsubt
JS_COMMENT_RER\trstriptlstripRdRTR]R^tjsontloadsR�RWtjoinRR6R7tmsgpacktdump(RmR.tprice_jsR�tcurrent_itemtkeywordtregionst
price_jsonR�R�titypeR�toutfiletfho((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyRAXsL

(	c
C@sbtdj|di�}|s+idd6S|jdd�}|jd�}t|�dksn|d	d
kryidd6S|jdd%�}ti|d6d
�}|d}|jdd�dkr_|jdd�dkr,|jdd�}d|j�kr#d|j�krd}	q)d}	q\d}	q�|jdd�j�jd�rVd}	q�d}	n'|jdd�dkr�d }	nd}	t	j
jtd!d"j|	��}
t	j
j
|
�s�ti|	d#6d
�ntjjj|
d$��%}tjjjtj|��}Wd%QXt|�}
|jd&d%�}|d%krEid'd6Sy||
|}Wn%tk
r~id(j||
�d6SXi}|jd)t�r�||d*<nd|d+<xC|jd,g�D]/}|d+ctj|d-jd.d��7<q�Wtj|d+�|d+<|d+d/|d0<|d0d1|d2<|d0d3|d4<|d2d5|d6<i||d6S(7u
    Show pricing for a particular profile. This is only an estimate, based on
    unofficial pricing sources.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f show_pricing my-ec2-config profile=my-profile

    If pricing sources have not been cached, they will be downloaded. Once they
    have been cached, they will not be updated automatically. To manually update
    all prices, use the following command:

    .. code-block:: bash

        salt-cloud -f update_pricing <provider>

    .. versionadded:: 2015.8.0
    uprofilesuprofileu#The requested profile was not founduErroruprovideru0:0u:iiuec2u,The requested profile does not belong to EC2uimageufunctioniuimageOwnerAliasuuamazonuplatformuwindowsudescriptionusqluwebumswinsqlwebumswinsqlumswinu
imageLocationuamazon/suseuslesulinuxuimageOwnerIdu309956199498urhelucachediruec2-pricing-{0}.putypeurNusizeu-The requested profile does not contain a sizeucThe size ({0}) in the requested profile does not have a price associated with it for the {1} regionurawu_rawuper_houruvalueColumnsupricesuUSDiuper_dayiuper_weekiu	per_monthi4uper_year(RRLR&R#R�R�R*R\R�R�RWRMRTR�RDR]R^R6R7R8R9RNtloadRStKeyErrorRtdecimaltDecimal(R�R�tprofileRvR/R�t
image_dictt
image_infotimage_descriptionR.t	pricefiletfhit	ec2_priceR�R�trawR�tcol((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytshow_pricing�sf"
			!				$
	

-cC@s|dkrtd��n|s*i}nd|krC|d}n|rc|rct|�d}n|r�|r�tjd�tSd|kr�tjd�tSidd	6|d
6|dd6}tj|dtd
t�dt	�dddt
dd�}tj|�|S(u*
    Associates the specified SSM document with the specified instance

    http://docs.aws.amazon.com/ssm/latest/APIReference/API_CreateAssociation.html

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a ssm_create_association ec2-instance-name ssm_document=ssm-document-name
    uactionuEThe ssm_create_association action must be called with -a or --action.uinstance_idu
instanceIdu,Either a name or an instance_id is required.ussm_documentuA ssm_document is required.uCreateAssociationuActionu
InstanceIduNameRuR:RvtproductussmR�R�u4(RR�RXRYRRMR�RZRSR�RR�(R.R�RqR�RKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyR��s6
	




			
cC@s|dkrtd��n|s*i}nd|krC|d}n|rc|rct|�d}n|r�|r�tjd�tSd|kr�tjd�tSidd	6|d
6|dd6}tj|dtd
t�dt	�dddt
dd�}tj|�|S(u3
    Describes the associations for the specified SSM document or instance.

    http://docs.aws.amazon.com/ssm/latest/APIReference/API_DescribeAssociation.html

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a ssm_describe_association ec2-instance-name ssm_document=ssm-document-name
    uactionuGThe ssm_describe_association action must be called with -a or --action.uinstance_idu
instanceIdu,Either a name or an instance_id is required.ussm_documentuA ssm_document is required.uDescribeAssociationuActionu
InstanceIduNameRuR:RvRfussmR�R�u4(RR�RXRYRRMR�RZRSR�RR�(R.R�RqR�RKR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pytssm_describe_association s6	




			
(�t__doc__t
__future__RRRt	functoolsRR�R!R�R�R�R�RCRARDR,RPR<RNRFRZtsalt.utils.cloudR]tsalt.utils.compattsalt.utils.filestsalt.utils.hashutilstsalt.utils.jsontsalt.utils.stringutilstsalt.utils.yamltsalt._compatRRltsalt.utils.httpR^REtsalt.utils.awsRMtsalt.configRtsalt.exceptionsRRRRR	tsalt.extR
tsalt.ext.six.movesRRR
tsalt.ext.six.moves.urllib.parseRRURRctM2CryptoRRZRtImportErrorRR3t
Crypto.CipherRtCrypto.HashRRRgRt	getLoggert__name__RXt
EC2_LOCATIONSR4RaRptcompiletSRHRRRRR(R@RIR�R�R�R�R�R�R�R�R�R�R�RSR�R�R�R�R�R�R�R�R�R�R�R�R�R�RR�RR�RR�R'R�RlRrR�R�R�R�R�R�R�R�R�R�R�RpR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RRRR�RR	R�RR�RRRRRRRRRR!R"R#RR�R}RDRAReR�Rg(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.pyt<module>Ks�(	









		
			)	'	�E��$								C	"						$							d				 ($	H����	�|	V!!d'0h%'
		)'	%	?5L	�	5	%,D+<1R!	8]3

Zerion Mini Shell 1.0