%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/lib/python2.7/site-packages/salt/cloud/clouds/
Upload File :
Create Path :
Current File : //proc/self/root/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyo

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZddlZddlZddlZddljZddlmZmZmZmZyddlZeZ Wne!k
r"e"Z nXej#e$�Z%d	Z&d
Z'd
Z(d�Z)d�Z*d
�Z+d�Z,dd�Z.dd�Z/dd�Z0ddd�Z1ddd�Z2d�Z3dd�Z4ii	id
d6dd6d6id
d6dd6d6id
d6dd6d6idd6dd6d6idd6dd6d 6idd6d!d6d"6id#d6dd6d$6id#d6d!d6d%6id#d6d&d6d'6d(6iid
d6dd6d)6id
d6dd6d*6idd6dd6d+6idd6dd6d,6idd6d!d6d-6id#d6dd6d.6id#d6d!d6d/6id#d6d&d6d06d16Z5e5d(e5d2<e5d(e5d3<ddd4�Z6d5�Z7d6�Z8dd7�Z9dd8�Z:dd9�Z;dd:�Z<ddd;�Z=d<�Z>d=�Z?d>�Z@dd?�ZAe"dd@�ZBddA�ZCddB�ZDdS(Cu�
QingCloud Cloud Module
======================

.. versionadded:: 2015.8.0

The QingCloud cloud module is used to control access to the QingCloud.
http://www.qingcloud.com/

Use of this module requires the ``access_key_id``, ``secret_access_key``,
``zone`` and ``key_filename`` parameter to be set.

Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
``/etc/salt/cloud.providers.d/qingcloud.conf``:

.. code-block:: yaml

    my-qingcloud:
      driver: qingcloud
      access_key_id: AKIDMRTGYONNLTFFRBQJ
      secret_access_key: clYwH21U5UOmcov4aNV2V2XocaHCG3JZGcxEczFu
      zone: pek2
      key_filename: /path/to/your.pem

:depends: requests
i(tabsolute_importtprint_functiontunicode_literalsN(tsha256(tsix(tquote(trange(tSaltCloudNotFoundtSaltCloudSystemExittSaltCloudExecutionFailuretSaltCloudExecutionTimeoutu	qingcloudicC@s*t�tkrtSt�tkr&tStS(u-
    Check for QingCloud configurations.
    (tget_configured_providertFalsetget_dependenciest__virtualname__(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt__virtual__Gs
cC@stjttptd�S(u/
    Return the first configured instance.
    u
access_key_idusecret_access_keyuzoneukey_filename(u
access_key_idusecret_access_keyuzoneukey_filename(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyRTs	cC@stjtitd6�S(u*
    Warn if dependencies aren't met.
    urequests(Rtcheck_driver_dependenciesRtHAS_REQUESTS(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyR
_scC@s�d|d<dj|j�|�}t|j��}g}xW|D]O}tj||�jd�}|jt|dd�dt|dd��qAWd	j	|�}	||	7}t
j|d
t�}
|
j
|�tj|
j��j�}|S(u�
    Generate an API request signature. Detailed document can be found at:

    https://docs.qingcloud.com/api/common/signature.html
    u
HmacSHA256usignature_methodu{0}
{1}
uutf-8tsafeuu=u-_~u&t	digestmod(tformattuppertsortedtkeysRt	text_typetencodetappendt_quotetjointhmactnewRtupdatetbase64t	b64encodetdigesttstrip(t
parameterstaccess_key_secrettmethodtpathtstring_to_signRtpairstkeytvaltqstht	signature((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt_compute_signatureis

1

c
C@s^d}tjdt�tdt�}tjdt�tdt�}i|d6td6tjdtj��d6t	d6}|r�x|j
�D]�\}}t|t�r}x�t
d	t|�d	�D]�}t||d	t�rXx�||d	j
�D]a\}}	t|	t�st|	t�r8tjjj|	d
d�}	n|	|d
j|||�<q�Wq�||d	|dj||�<q�Wq�|||<q�Wnt||dd�}
|
|d<tj|d|dt�}|jdkr�tdj|j|j���ntj|j�|j}tjjj|�}
|
ddkrZttj |
jdi����n|
S(u0
    Make a web call to QingCloud IaaS API.
    uhttps://api.qingcloud.com/iaas/u
access_key_idt
search_globalusecret_access_keyusignature_versionu%Y-%m-%dT%H:%M:%SZu
time_stampuversionit
separatorsu,u:u{0}.{1}.{2}u{0}.{1}uGETu/iaas/u	signaturetparamstverifyi�uHAn error occurred while querying QingCloud. HTTP Code: {0}  Error: '{1}'uret_codeiumessage(u,u:(!Rtget_cloud_config_valueRRRt#DEFAULT_QINGCLOUD_SIGNATURE_VERSIONttimetstrftimetgmtimetDEFAULT_QINGCLOUD_API_VERSIONtitemst
isinstancetlistRtlentdicttsalttutilstjsontdumpsRR3trequeststgettstatus_codeRttexttlogtdebugturltloadstpprinttpformat(R6R+t
access_key_idR)treal_parametersR.tvaluetitsktsvR2trequesttcontenttresult((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytquery�sH
 ! %
	!cC@s�|dkrtd��nidd6}td|�}i}xP|dD]D}i||d<x-|D]%}tj||�||d|<qcWqHW|S(u�
    Return a dict of all available locations on the provider with
    relevant data.

    CLI Examples:

    .. code-block:: bash

        salt-cloud --list-locations my-qingcloud
    uactionufThe avail_locations function must be called with -f or --function, or with the --list-locations optionu
DescribeZonesR6uzone_setuzone_id(RRZRR(tcallR6R>RYtregionR.((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytavail_locations�s

'cC@skt�}tjtjd|tdt��}|sBtd��n||krR|Stdj|���dS(u5
    Return the VM's location. Used by create().
    uzoneR4u"No location specified for this VM.u2The specified location, '{0}', could not be found.N(	R]RRRR8RRRR(tvm_t	locationstvm_location((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt
_get_location�s	cC@sZ|dkrt�}nt|t�rL|jdd�}|dk	rL|Sn|d}|S(Nuzone(tNoneRR?RBRH(tkwargstprovidertzone((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt_get_specified_zones
cC@s�|dkrtd��nt|t�s3i}nidd6dd6t|t��d6}td|�}i}xG|dD];}i||d	<x$|D]}||||d	|<q�WqzW|S(
u�
    Return a list of the images that are on the provider.

    CLI Examples:

    .. code-block:: bash

        salt-cloud --list-images my-qingcloud
        salt-cloud -f avail_images my-qingcloud zone=gd1
    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optionuDescribeImagesusystemuprovideruzoneR6u	image_setuimage_id(RR?RBRfRRZ(RcR[R6R>RYtimageR.((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytavail_imagess 	
cC@skt�}tjtjd|tdt��}|sBtd��n||krR|Stdj|���dS(u2
    Return the VM's image. Used by create().
    uimageR4uNo image specified for this VM.u/The specified image, '{0}', could not be found.N(	RhRRRR8RRRR(R^timagestvm_image((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt
_get_image3s	cC@s�|dkrtd��nt|t�s3i}n|d}|jd�}idd6|d6t|t��d6}td	|�}|d
s�td��ni}xG|d
D];}i||d<x$|D]}||||d|<q�Wq�W|S(
uC
    Show the details from QingCloud concerning an image.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f show_image my-qingcloud image=trustysrvx64c
        salt-cloud -f show_image my-qingcloud image=trustysrvx64c,coreos4
        salt-cloud -f show_image my-qingcloud image=trustysrvx64c zone=ap1
    ufunctionu=The show_images function must be called with -f or --functionuimageu,uDescribeImagesuactionuimagesuzoneR6u	image_setu'The specified image could not be found.uimage_id(RR?RBtsplitRfRRZR(RcR[RiR6R>RYRgR.((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt
show_imageGs(	


ucpuu1Gumemoryuc1m1u2Guc1m2u4Guc1m4iuc2m2uc2m4u8Guc2m8iuc4m4uc4m8u16Guc4m16upek2usmall_busmall_cumedium_aumedium_bumedium_cularge_aularge_bularge_cupek1uap1ugd1cC@s�|dkrtd��nt|t��}i}xOt|D]C}i||<x0t||D] }t||||||<q]Wq>W|S(u�
    Return a list of the instance sizes that are on the provider.

    CLI Examples:

    .. code-block:: bash

        salt-cloud --list-sizes my-qingcloud
        salt-cloud -f avail_sizes my-qingcloud zone=pek2
    uactionu^The avail_sizes function must be called with -f or --function, or with the --list-sizes option(RRfRtQINGCLOUD_SIZES(RcR[ReRYtsize_keyt
attribute_key((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytavail_sizes�s
"cC@sqt�}tjtjd|tdt��}|sBtd��n||j�krX|Stdj	|���dS(u1
    Return the VM's size. Used by create().
    usizeR4u$No size specified for this instance.u.The specified size, '{0}', could not be found.N(
RqRRRR8RRRRR(R^tsizestvm_size((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt	_get_size�s	cC@s�|jdg�}|r.|d}|g}ng}xB|jdg�D].}|jdd�}|rG|j|�qGqGWi|dd6|ddd6|d	d
6|dd6|d
6|d6}|S(u\
    Normalize the QingCloud instance data. Used by list_nodes()-related
    functions.
    ueipueip_addruvxnetsu
private_ipuinstance_iduiduimageuimage_idu
instance_typeusizeustatusustateuprivate_ipsu
public_ipsN(RHRbR(t	full_nodet
public_ipst	public_iptprivate_ipstvxnett
private_iptnormalized_node((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt_show_normalized_node�s"

c	C@s|dkrtd��nt�}idd6|d6ddddgd	6}td
|�}tjd|d|�i}|dd
kr�|Sx9|dD]-}t|�}|j|�|||d<q�Wtp�d}d|kr�|jd�}|d
}nt	t
d<td||t
�|S(u�
    Return a list of the instances that are on the provider.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -F my-qingcloud
    uactionuBThe list_nodes_full function must be called with -f or --function.uDescribeInstancesuzoneupendingurunningustoppedu	suspendedustatusR6u#Total %s instances found in zone %sutotal_countiuinstance_setuinstance_idu	qingcloudu:uupdate_cachedirucloud.cache_node_list(RRfRZRKRLR|R#RRltTrueRt	__utils__(	R[ReR6R>RYtnodeR{Rdtcomps((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytlist_nodes_full�s0
	


cC@s�|dkrtd��nt�}i}xf|j�D]X\}}i|dd6|dd6|dd6|dd6|dd6|dd6||<q7W|S(	u�
    Return a list of the instances that are on the provider.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -Q my-qingcloud
    uactionu=The list_nodes function must be called with -f or --function.uiduimageusizeustateu
public_ipsuprivate_ips(RR�R>(R[tnodestrettinstance_idRu((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt
list_nodess
	cC@sk|dkrtd��nt�}i}x:|j�D],\}}i|dd6|dd6||<q7W|S(u�
    Return a list of the instances that are on the provider. Only a list of
    instances names, and their state, is returned.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f list_nodes_min my-qingcloud
    ufunctionuAThe list_nodes_min function must be called with -f or --function.u
instance_nameunameustatus(RR�R>(R[R�RYR�Ru((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytlist_nodes_min+s	cC@s#tjjjtd�td|�S(u�
    Return a list of the instances that are on the provider, with selected
    fields.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -S my-qingcloud
    ufunctionuquery.selection(RCRDtcloudtlist_nodes_selectR�R(R[((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyR�Gs	cC@s�|dkrtd��nidd6|d6tdd
dt��d6}td|�}|d	d
krtdj|���n|dd
}t|�}|j|�|}|S(u�
    Show the details from QingCloud concerning an instance.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a show_instance i-2f733r5n
    uactionu<The show_instance action must be called with -a or --action.uDescribeInstancesuinstances.1RcRduzoneR6utotal_countiu2The specified instance, '{0}', could not be found.uinstance_setN(	RRfRbRRZRRR|R#(R�R[RcR6R>RuR{RY((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt
show_instanceYs 

cC@s6t|dd�}|stS|jdg�r2|SdS(NR[uactionuprivate_ips(R�RRH(R�tdata((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt_query_node_data}s
cC@s
y=|dr<tjttpd|dd|�tkr<tSWntk
rPnXtddddj|d�d	td
d|dddd
g�dtddtd�tj	d|d�idd6|dd6t
|�d6t|�d6t|�d6|dd6|dd6|dd6}tddddj|d�d	itd
d|t
|��d 6dtddtd�t|�}|d!d"}yXtjjjtd#|fd$tjd%|td&d5�d)tjd*|td&d'��}Wn\ttfk
rD}z*yt|d�Wntk
r&nXWd+ttj|���XnX|d,d"}tjd-|�||d.<td/|t�tj	d0|d�tjd1|dtj|��tddd2d3j|d�d	td
d4|dddd
g�dtddtd�|S(6u�
    Create a single instance from a data dict.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -p qingcloud-ubuntu-c1m1 hostname1
        salt-cloud -m /path/to/mymap.sls -P
    uprofileu	qingcloudR^ucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunametargsucloud.filter_eventucreatinguproviderudrivertsock_dirusock_dirt	transportu	transportuCreating Cloud VM %suRunInstancesuactionu
instance_nameuzoneu
instance_typeuimage_iduvxnetsuvxnets.1u
login_modeu
login_keypairurequesting instanceusalt/cloud/{0}/requestingu
requestingukwargsu	instancesitupdate_argsttimeoutuwait_for_ip_timeouttdefaulti
i<tintervaluwait_for_ip_intervalNuprivate_ipsuVM %s is now runningussh_hostucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreatediX(Rtis_profile_configuredRRRtAttributeErrorR~RRKtinfoRaRtRkR@RZRCRDR�twait_for_ipR�R8R
R	tdestroyRRRRLRORP(R^R6RYtnew_instance_idR�texcRz((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytcreate�s�	

"



 
	

 "
cC@sRtjjjtjd|t�|ttjjjtjjjt|���}|S(u.
    Return the script deployment object.
    uscript(	RCRDR�t	os_scriptRR8Rtsalt_config_to_yamlt
minion_config(R^t
deploy_script((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytscript�scC@sb|dkrtd��ntjd|�idd6tdt��d6|d6}t|�}|S(uq
    Start an instance.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a start i-2f733r5n
    uactionu3The stop action must be called with -a or --action.uStarting instance %suStartInstancesRduzoneuinstances.1(RRKR�RfRRZ(R�R[R6RY((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytstart�s

cC@so|dkrtd��ntjd|�idd6tdt��d6|d6t|�d6}t|�}|S(	u�
    Stop an instance.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a stop i-2f733r5n
        salt-cloud -a stop i-2f733r5n force=True
    uactionu3The stop action must be called with -a or --action.uStopping instance %su
StopInstancesRduzoneuinstances.1uforce(RRKR�RfRtintRZ(R�tforceR[R6RY((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytstopscC@sb|dkrtd��ntjd|�idd6tdt��d6|d6}t|�}|S(us
    Reboot an instance.

    CLI Examples:

    .. code-block:: bash

        salt-cloud -a reboot i-2f733r5n
    uactionu3The stop action must be called with -a or --action.uRebooting instance %suRestartInstancesRduzoneuinstances.1(RRKR�RfRRZ(R�R[R6RY((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pytreboot6s

cC@s�|dkrtd��nt|dd�}|d}tdddd	j|�d
i|d6dtd
dtd�idd6tdt��d6|d6}t|�}tddddj|�d
i|d6dtd
dtd�|S(u�
    Destroy an instance.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a destroy i-2f733r5n
        salt-cloud -d i-2f733r5n
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.R[uactionu
instance_nameucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingR�unameR�usock_dirR�u	transportuTerminateInstancesRduzoneuinstances.1udestroyed instanceusalt/cloud/{0}/destroyed(RR�R~RRRfRRZ(R�R[t
instance_datatnameR6RY((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyR�Qs2





(Et__doc__t
__future__RRRR:ROtloggingR!R$thashlibRtsalt.extRtsalt.ext.six.moves.urllib.parseRRtsalt.ext.six.movesRtsalt.utils.cloudRCtsalt.utils.datatsalt.utils.jsontsalt.configRtsalt.exceptionsRRR	R
RGR}RtImportErrorRt	getLoggert__name__RKRR=R9RRR
R3RbRZR]RaRfRhRkRmRnRqRtR|R�R�R�R�R�R�R�R�R�R�R�R�(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/qingcloud.pyt<module>s�"


	
		
	I
$	-		0$	
	g	

Zerion Mini Shell 1.0