%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlm	Z
ddlmZddl
mZddlmZmZmZmZmZddlZddljZddlm Z m!Z!m"Z"m#Z#dd	l$m%Z%ej&e'�Z(d
Z)d�Z*d�Z+dd
�Z-dd�Z.dd�Z/dd�Z0d�Z1d�Z2d�Z3dddddd�Z4d�Z5dd�Z6dd�Z7dd�Z8dd�Z9dd�Z:dd�Z;dS(u�
Parallels Cloud Module
======================

The Parallels cloud module is used to control access to cloud providers using
the Parallels VPS system.

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

.. code-block:: yaml

    my-parallels-config:
      # Parallels account information
      user: myuser
      password: mypassword
      url: https://api.cloud.xmission.com:4465/paci/v1.0/
      driver: parallels

i(tabsolute_importtprint_functiontunicode_literalsN(tElementTree(tURLError(t	urlencode(tHTTPBasicAuthHandlertRequestturlopentbuild_openertinstall_opener(tSaltCloudNotFoundtSaltCloudSystemExittSaltCloudExecutionFailuretSaltCloudExecutionTimeout(tsixu	parallelscC@st�tkrtStS(u,
    Check for PARALLELS configurations
    (tget_configured_providertFalset__virtualname__(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyt__virtual__?scC@stjttptd�S(u/
    Return the first configured instance.
    uuserupassworduurl(uuserupassworduurl(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyRIs	cC@sY|dkrtd��ntdd�}i}x"|D]}|j||jd<q7W|S(u>
    Return a list of the images that are on the provider
    uactionu`The avail_images function must be called with -f or --function, or with the --list-images optiontactionutemplateuname(Rtquerytattrib(tcalltitemstrettitem((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pytavail_imagesTs
cC@s�|dkrtd��ni}tdd�}x�|D]�}|jd}t|dd�}i|dd6|dd	dd
6|dd6||<d|d
kr�|d
dg||d<nd|d
kr7|d
dg||d<q7q7W|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.RuveunameRuiduplatformu
template-infouimageustateu
private-ipunetworkuprivate_ipsu	public-ipu
public_ips(RRRt
show_instance(RRRRtnametnode((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyt
list_nodesfs"

 cC@s�|dkrtd��ni}tdd�}x�|D]�}|jd}t|dd�}|||<|ddd||d	<d
|dkr�|dd
dg||d
<nd|dkr7|dddg||d<q7q7W|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.RuveunameRuplatformu
template-infouimageu
private-ipunetworkuaddressuprivate_ipsu	public-ipu
public_ips(RRRR (RRRRR!R"((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pytlist_nodes_full�s


 $cC@s tjjjt�td|�S(uO
    Return a list of the VMs that are on the provider, with select fields
    uquery.selection(tsalttutilstcloudtlist_nodes_selectR$R(R((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR(�scC@s|t�}tjd|tdt�}xE|D]=}tj|�||d||dfkr+||dSq+Wtd��dS(u(
    Return the image object to use
    uimaget
search_globalunameuidu'The specified image could not be found.N(RRtget_cloud_config_valueRRRt	text_typeR(tvm_timagestvm_imagetimage((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyt	get_image�s	
+cC@s6tjd�}tj|d�}|d|_tj|d�}tjd|td|ddt�|_tj|d�}tjd|tdd	dt�|jd
<tjd|tdddt�|jd
<tj|d�}tjd|tdddt�|_tj|d�}tjd|tdddt�|_tj|d�}tjd|tdd	dt�|_tj|d�}d|jd<tjd|tdddt�|jd<tjd|tdt�}	t	i|	d6dd�}
tj|d�}tj|d�}|	|jd<tj|d �}
|
|	d!|
jd!<|
|	d"|
jd#<tj|d$�}tjd%|tdd&�|jd'<tjd(|tdt�|jd(<tj
|d)d*�}td+d,d-d.j|d�d/itd0d1|t
|��d26d3td4d5td6�td7dd8d9d:|�}|S(;u3
    Build and submit the XML to create a node
    uveunameudescriptionudesctdefaultR)ucpuu
cpu_numberu1unumberu	cpu_poweru1000upoweruram-sizeuramu256u	bandwidthu100uno-of-public-ipuip_numuve-diskutrueulocalu	disk_sizeu10usizeuimageRufunctionuplatformu
template-infouos-infou
technologyuosTypeutypeuadminussh_usernameurootuloginupasswordtencodinguUTF-8ucloud.fire_eventueventurequesting instanceusalt/cloud/{0}/requestingtargsucloud.filter_eventu
requestingukwargstsock_dirusock_dirt	transportu	transportRtmethoduPOSTtdata(tETtElementt
SubElementttextRR*RRRt
show_imagettostringt	__utils__tformattlistR(R,tcontentR!tdesctcputramt	bandwidthtip_numtdiskR.R/tplatformttemplatetos_infotadminR7R"((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pytcreate_node�sb
"""
"
 
cC@s�y=|dr<tjttpd|dd|�tkr<tSWntk
rPnXtddddj|d�d	td
d|dddd
g�dtddtd�tj	d|d�yt
|�}Wn4tk
r}tjd|d|dt
j�tSX|d}t|d�s0idj|�d6St|ddd�t|d�sgidj|�d6Sd�}y\tjjj|d|dfdtjd|tdd1�d"tjd#|tdd ��}Wn\ttfk
r*}z*yt|d�Wntk
rnXWd$ttj|���XnX|d%d&d'jd(�}|d)}||d*<td+|t�}tj	d,|d�tjd-|dtj|��tddd.d/j|d�d	td
d0|dddd
g�dtddtd�|S(2u-
    Create a single VM from a data dict
    uprofileu	parallelsR,ucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunameR3ucloud.filter_eventucreatinguproviderudriverR4usock_dirR5u	transportuCreating Cloud VM %suqError creating %s on PARALLELS

The following exception was thrown when trying to run the initial deployment: 
%stexc_info_on_logleveluCREATEDu&Unable to start {0}, command timed outuErrorRuactionuSTARTEDcS@s*t|dd�}d|dkr&dS|S(NRuactionu	public-ipunetwork(R (tvm_nameR7((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyt__query_node_data?stupdate_argsttimeoutuwait_for_ip_timeoutR1ii<tintervaluwait_for_ip_intervalNunetworku	public-ipuaddressu/iussh_hostucloud.bootstrapuCreated Cloud VM '%s'u'%s' VM creation details:
%sucreated instanceusalt/cloud/{0}/createducreatedi,( Rtis_profile_configuredRRRtAttributeErrorR>R?tlogtinfoRLt	ExceptionterrortloggingtDEBUGt
wait_untiltstartR%R&R'twait_for_ipR*RR
tdestroyRRR+tsplittdebugtpprinttpformat(R,R7texcR!ROtcompst	public_ipR((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pytcreates|	

"



	



"
uGETc@sZtjdt�tdt�}t�}|jddd|dtjdt�tdt�dtjd	t�tdt��t|�}t|�|r�||7}n|r�|d
j	|�7}nt
|t�s�i}ni|d6}t|t
j�rd|krid
d6|d<n|rHt|�}	tddj	||	�|�}
ntd||�}
�fd�|
_tjd�|
j��|r�tj|�nybt|
�}tjd|j��d|jkr�|j�}|j�tj|�}
|
SiSWnVtk
rU}tjd|j|j�tj|j��}tj|�i|d6SXdS(u1
    Make a web call to a Parallels provider
    uurlR)trealmuParallels Instance Managerturituseruusertpasswdupasswordu/{0}udatau<?xmluapplication/xmluContent-typeuheadersturlu{0}?{1}c@s�S(N(((R6(s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyt<lambda>�su%s %su"PARALLELS Response Status Code: %sucontent-lengthu%PARALLELS Response Status Code: %s %suerrorN( RR*RRRt_HTTPBasicAuthHandlertadd_passwordt
_build_openert_install_openerR?ttypetdictt
isinstanceRtstring_typest
_urlencodet_Requestt
get_methodRUR`tget_full_urlt_urlopentgetcodetheaderstreadtcloseR8t
fromstringRRXtcodetmsg(RtcommandR3R6R7tpathtauth_handlertopenertkwargstparamstreqtresultRARRctroot((R6s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyRpsZ		


	
!

cC@sLtjjjtjd|t�|ttjjjtjjjt|���S(u-
    Return the script deployment object
    uscript(	R%R&R't	os_scriptRR*Rtsalt_config_to_yamlt
minion_config(R,((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pytscript�scC@s�|dkrtd��ntddd|d�}d|krH|dSi}x,|D]$}|ji|j|jd6�qUW|S(	u=
    Show the details from Parallels concerning an image
    ufunctionu=The show_image function must be called with -f or --function.RutemplateR�uimageuerroruname(RRtupdateR(R�RRRR((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR<�s
"cC@s�|dkrtd��ntddd|�}i}x�|D]�}d|jkre|j||j<n|j||j<|jr=i||j<|j}x(|D]}|j||j|j<q�Wq=q=Wtd|tt	�|S(u@
    Show the details from Parallels concerning an instance
    uactionu<The show_instance action must be called with -a or --action.RuveR�utextucloud.cache_node(
RRt__dict__R;ttagRt	_childrenR>RR(R!RRRRtchildrentchild((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR �s 
	
	
"i,cC@s|tj�}t|dd�}xWtrw|d|kr;tStjd�tj�||krbtSt|dd�}q!WdS(uA
    Wait until a specific state has been reached on  a node
    RuactionustateiN(ttimeR tTruetsleepR(R!tstateRQt
start_timeR"((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR[�s	
cC@sn|dkrtd��ntddddj|�di|d6d	td
dtd�t|d
d�}|ddkr�t|d
d�t|d�s�idj|�d6Sntddd|dd�}d|kr�|dStddddj|�di|d6d	td
dtd�tjdt	�t
krZtd|tjd�dt�nid j|�d!6S("um
    Destroy a node.

    CLI Example:

    .. code-block:: bash

        salt-cloud --destroy mymachine
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingR3unameR4usock_dirR5u	transportRuactionustateuSTARTEDuSTOPPEDu(Unable to destroy {0}, command timed outuErrorRuveR�R6uDELETEuerrorudestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:iu{0} was destroyed.u	Destroyed(
RR>R?RR tstopR[RtgetRR�RR_(R!RR"R7((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR^s<




$cC@sg|dkrtd��ntddddj|�dd�}d	|krS|d	Sid
j|�d6S(uj
    Start a node.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a start mymachine
    uactionu<The show_instance action must be called with -a or --action.RuveR�u	{0}/startR6uPUTuerroru{0} was started.uStarted(RRR?(R!RR7((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR\7s
$cC@sg|dkrtd��ntddddj|�dd�}d	|krS|d	Sid
j|�d6S(uh
    Stop a node.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop mymachine
    uactionu<The show_instance action must be called with -a or --action.RuveR�u{0}/stopR6uPUTuerroru{0} was stopped.uStopped(RRR?(R!RR7((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyR�Ns
$(<t__doc__t
__future__RRRR�RaRYtsalt._compatRR8tsalt.ext.six.moves.urllib.errorRtsalt.ext.six.moves.urllib.parseRRut!salt.ext.six.moves.urllib.requestRRmRRvRRyR	RoR
Rptsalt.utils.cloudR%tsalt.configRtsalt.exceptionsRRR
Rtsalt.extRt	getLoggert__name__RURRRtNoneRR#R$R(R0RLRfRR�R<R R[R^R\R�(((s?/usr/lib/python2.7/site-packages/salt/cloud/clouds/parallels.pyt<module>s>(
"	
				Y	_C	7

Zerion Mini Shell 1.0