%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s_dZddlmZmZmZddlmZddlZddlZddlj	Z	ddl
mZddlZ
ddlmZmZeje�ZyddlZeZWnek
r�eZnXdZdad�Zd	�Zd
�Zd�Zd�Z dddd
�Z!dddddd�Z"dd�Z#dd�Z$ddd�Z%ddd�Z&ddd�Z'dd�Z(ddd�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/ddd�Z0dddd�Z1ddddd�Z2ddd�Z3ddd �Z4ddd!�Z5ddd"�Z6ddd#�Z7ddd$�Z8ddd%�Z9ddd&�Z:ddd'�Z;ddd(�Z<ddd)�Z=ddd*�Z>ddd+�Z?dd,�Z@dd-�ZAdd.�ZBdd/�ZCddd0�ZDddd1�ZEdd2�ZFdddd3�ZGdddd4�ZHddd5�ZIdddd6�ZJdS(7u�
XenServer Cloud Driver
======================

The XenServer driver is designed to work with a Citrix XenServer.

Requires XenServer SDK
(can be downloaded from https://www.citrix.com/downloads/xenserver/product-software/ )

Place a copy of the XenAPI.py in the Python site-packages folder.

:depends: XenAPI

Example provider configuration:

    .. code-block:: yaml

        # /etc/salt/cloud.providers.d/myxen.conf
        myxen:
          driver: xen
          url: http://10.0.0.120
          user: root
          password: p@ssw0rd

Example profile configuration:

    .. code-block:: yaml

        # /etc/salt/cloud.profiles.d/myxen.conf
        suse:
          provider: myxen
          user: root
          password: p@ssw0rd
          image: opensuseleap42_2-template
          storage_repo: 'Local storage'
          resource_pool: default_pool
          clone: True
          minion:
            master: 10.0.0.18
        sles:
          provider: myxen
          user: root
          clone: False
          image: sles12sp2-template
          deploy: False
        w2k12:
          provider: myxen
          image: w2k12svr-template
          clone: True
          userdata_file: /srv/salt/win/files/windows-firewall.ps1
          win_installer: /srv/salt/win/files/Salt-Minion-2016.11.3-AMD64-Setup.exe
          win_username: Administrator
          win_password: p@ssw0rd
          use_winrm: False
          ipv4_cidr: 10.0.0.215/24
          ipv4_gw: 10.0.0.1

i(tabsolute_importtprint_functiontunicode_literals(tdatetimeN(tsix(tSaltCloudSystemExittSaltCloudExceptionuxencC@s<t�tkrtSt�tkr&tStjjt�atS(u>
    Only load if Xen configuration and XEN SDK is found.
    (tget_configured_providertFalset_get_dependenciestsalttcachetCachet__opts__t__virtualname__(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt__virtual__]scC@stjtitd6�S(uO
    Warn if dependencies aren't met.

    Checks for the XenAPI.py module
    uXenAPI(tconfigtcheck_driver_dependenciesRtHAS_XEN_API(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR	lscC@stjttptd�S(u/
    Return the first configured instance.
    uurl(uurl(Rtis_provider_configuredR
t__active_provider_name__R(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyRxs	cC@s�d}djt�}tjdt�tdt�}tjdt�tdt�}tjdt�tdt�}tjdt�tdtdt�}yKtj|d	|�}t	j
d
||d|�|jj||||�Wn�tj
k
r{}tj|jdd
�}|jd�}	dj|	d �d|}
tj|
�}t	j
d|
|d|�|jj||||�nX|S(u0
    Get a connection to the XenServer host
    u1.0usalt_cloud_{}_driveruurlt
search_globaluuserupasswordu
ignore_ssltdefaultt
ignore_sslu-url: %s user: %s password: %s, originator: %suXXX-pw-redacted-XXXudetailsiu/iu:session is -> url: %s user: %s password: %s, originator:%s(tformatRRtget_cloud_config_valueRR
RtXenAPItSessiontlogtdebugtxenapitlogin_with_passwordtFailureRt	text_typet__dict__tsplittjoin(tapi_versiont
originatorturltusertpasswordRtsessiontextpool_master_addrtslash_partstnew_url((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt_get_session�sR						cC@st�}|jjj�}i}x�|D]�}|jjj|�}|dr(|dr(y|dd}Wn+tk
r�d}tjd|d�nXi|dd6|d	6|dd
6|dd6|d
d6t	|d|�d6dd6||d<q(q(W|S(uU
    List virtual machines

      .. code-block:: bash

          salt-cloud -Q

    u
is_a_templateuis_control_domainuother_configubase_template_nameu/VM %s, doesnt have base_template_name attributeu
name_labeluuuiduiduimageunameumemory_dynamic_maxusizeupower_stateustateuprivate_ipsu
public_ipsN(
R/RtVMtget_all_recordst
get_recordt	ExceptiontNoneRRt	get_vm_ip(R*tvmstrettvmtrecordtbase_template_name((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt
list_nodes�s*		

cC@su|dkrtd��n|d
kr@tjd�t�}nt|d|�}d
}|jjj|�}|d
k	r�xm|D]b}|jj	j
|�r�|jj	j
|�j�}|jd�\}}tjd||�|Sq�Wn|jjj
|�}	yO|jjj|	�}
d|
j�krLtjd||
d�|
d}nWn!tjk
rptjd	�nX|S(u�
    Get the IP address of the VM

    .. code-block:: bash

        salt-cloud -a get_vm_ip xenvm01

    .. note:: Requires xen guest tools to be installed in VM

    ufunctionu1This function must be called with -a or --action.uNew session being createdR*u/u'VM vif returned for instance: %s ip: %su0/ipu3VM guest metrics returned for instance: %s 0/ip: %su%Could not get vm metrics at this timeN(RR4RRR/t_get_vmRR0tget_VIFstVIFtget_ipv4_addressestpopR#tget_guest_metricstVM_guest_metricstget_networkstkeysRR tinfo(tnameR*tcallR8R7tvifstviftcidrtsubnettvgmtnet((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR5�s8


c
C@s#d}|dkr!td��ntjd||||�|dkr_tjd�t�}nt||�}|jjj|�}|dk	rtjdt	|��xw|D]l}|jj
j|�}	tj|	�y |jj
j||||�Wq�t
jk
rtjd�q�Xq�WntS(	u:
    Set the IP address on a virtual interface (vif)

    ustaticufunctionu0The function must be called with -a or --action.u3Setting name: %s ipv4_cidr: %s ipv4_gw: %s mode: %suNew session being createduThere are %s vifs.u,Static IP assignment could not be performed.N(RRRR4R/R<RR0R=tlenR>R2tconfigure_ipv4RR REtTrue(
RFt	ipv4_cidrtipv4_gwR*RGtmodeR8RHRIR9((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt	set_vm_ips.	


c	C@s�|dkrt�}ni}|jjj�}x|D]}|jjj|�}|dr7|dr7y|dd}Wn+tk
r�d}tjd|d�nX|jjj|�}|d|d<|d|d	<||d
<d|d<|d|d
<t	|d|�|d<d|d<d|j
�kr8|d=n|||d<q7q7WtpVd}d|kr�|jd�}|d}ntjd|�tjd|�tjdt
�td||t
�|S(uZ
    List full virtual machines

      .. code-block:: bash

          salt-cloud -F

    u
is_a_templateuis_control_domainuother_configubase_template_nameu/VM %s, doesnt have base_template_name attributeu
name_labeluuuiduidunameuimageusizeupower_stateustateuprivate_ipsu
public_ipsu
snapshot_timeuxenu:iuret: %suprovider: %su__opts__: %sucloud.cache_node_listN(R4R/RR0tget_allR2R3RRR5RDRR#R
t	__utils__(	R*R7R6R8R9R:tvm_cfgtprovidertcomps((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytlist_nodes_full1sD	






cC@s tjjjt�td|�S(uf
    Perform a select query on Xen VM instances

    .. code-block:: bash

        salt-cloud -S

    uquery.selection(R
tutilstcloudtlist_nodes_selectRZR
(RG((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR]bs	cC@s8|dkrtd��ntjd|�|d
k	rnd|kre|ddkr\t}qkt}qzt}ni}t}t�}|jjj	�}i}x�|D]�}|jjj
|�}tjt|��|tkr	i|jd�d6|d6||jd�<q�|j
i|d	6�|||jd�<q�W|S(u
    Return available Xen VDI images

    If this function is called with the ``-f`` or ``--function`` then
    it can return a list with minimal deatil using the ``terse=True`` keyword
    argument.

    .. code-block:: bash

        salt-cloud -f vdi_list myxen terse=True

    uactionu3This function must be called with -f or --function.ukwargs is %suterseuTrueuuuiduOpqueRefu
name_labelu	OpaqueRefN(RRRR4RPRR/RtVDIRUR2ttypetgettupdate(RGtkwargstterseR*tvdisR7tvditdata((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytvdi_listrs2
				
cC@s"|dkrtd��nt�S(u�
    Return available Xen locations (not implemented)

    .. code-block:: bash

        salt-cloud --list-locations myxen

    uactionuBThe avail_locations function must be called with -f or --function.(Rt	pool_list(R*RG((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytavail_locations�s
cC@s&|dkrtd��nidd6S(uu
    Return a list of Xen template definitions

    .. code-block:: bash

        salt-cloud --list-sizes myxen

    uactionu>The avail_sizes function must be called with -f or --function.uKSizes are build into templates. Consider running --list-images to see sizesuSTATUS(R(R*RG((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytavail_sizes�s
	cC@sfi}t�}|jjj�}x>|D]6}|jjj|�}|dr(|||d<q(q(W|S(u�
    Return available Xen template information.

    This returns the details of
    each template to show number cores, memory sizes, etc..

    .. code-block:: bash

       salt-cloud -f template_list myxen

    u
is_a_templateu
name_label(R/RR0RUR2(RGt	templatesR*R6R8R9((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt
template_list�s	

cC@s.|dkrtd��ntjd||�|dkrFt�}nt|d|�}|jjj|�}|dr*|dr*y|dd}Wn+t	k
r�d}tjd	|d
�nXi|dd6|d
6|d
d6|dd6|dd6t
||�d6dd6}td|tt
�n|S(u�
    Show information about a specific VM or template

        .. code-block:: bash

            salt-cloud -a show_instance xenvm01

    .. note:: memory is memory_dynamic_max

    ufunctionu=The show_instnce function must be called with -a or --action.u$show_instance-> name: %s session: %sR*u
is_a_templateuis_control_domainuother_configubase_template_nameu/VM %s, doesnt have base_template_name attributeu
name_labeluuuiduiduimageunameumemory_dynamic_maxusizeupower_stateustateuprivate_ipsu
public_ipsucloud.cache_nodeN(RRRR4R/R<RR0R2R3R5RVRR
(RFR*RGR8R9R:R7((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt
show_instance�s8


cC@s�d}d|j�kr.t|d|�}n=|jjj�}|sOd}n|jjj�d}|}|jjj|�}tjd|d�|S(u<
    Called by create() used to determine resource pool
    uu
resource_pooliuresource pool: %su
name_labelN(	RDt	_get_poolRtpoolRUR4R2RR(R*tvm_t
resource_poolRot
first_pooltpool_record((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt_determine_resource_pools	cC@s�d}d|j�kr.t|d|�}nYd}|r�|jjj|�}|jjj|�}tj	d|d�|}nd}tj	d|�|S(uF
    Called by create() used to determine storage repo for create
    uustorage_repoustorage repository: %su
name_labelN(
RDt_get_srR4RRotget_default_SRtSRR2RR(R*RqRptstorage_repot
default_srt	sr_record((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt_determine_storage_repos	cC@s�|d}i}i}tddddj|�di|d6|dd6|dd	6d
tddtd
�tjd|�td|d|dd|d�t�}t||�}t|||�}|jd�}|jd�}|dkr�t
}ntjd|�tddddj|�d
tddtd
�|rTt|||�nt||||�t
||�t||�}	t|d|�t||�}	t||�t|||�|jdt
�}
tjd|
�|
r|jjj|	�}|dk	r2t|||�q2ntjd|d�|jjj|	�}t|�}|ji|d6�tddddj|�di|d6|dd6|dd	6d
tddtd
�|S(u�
    Create a VM in Xen

    The configuration for this function is read from the profile settings.

    .. code-block:: bash

        salt-cloud -p some_profile xenvm01

    unameucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingtargsuprofileudriveruprovidertsock_dirusock_dirt	transportu	transportuAdding %s to cloud cache.ucloud.cachedir_index_adduxenuimageucloneu
Clone: %s urequesting instanceusalt/cloud/{0}/requestingudeployudelopy is set to %su1The Salt minion will not be installed, deploy: %suextraucreated instanceusalt/cloud/{0}/createdN(RVRR
RRR/RtR{R`R4RPt	_clone_vmt_copy_vmt
_provision_vmR<tstartt_wait_for_ipt_set_static_ipRR0R2t_deploy_salt_minionRmRa(RpRFR9R7R*RqRxtimagetcloneR8tdeploy((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytcreate)s|

		



cC@s�t||�|d<|jdd�|d<|jdd�|d<|jdd�|d<tjd||d�|ddk	r�tjd	|�td
|t�}tjd|�ndS(
u,
    Deploy salt minion during create()
    ussh_hostuuserurootupasswordu	p@ssw0rd!uprovideruxenu%s has IP of %suInstalling Salt minion on %sucloud.bootstrapuboot return: %sN(R5R`RRR4RERVR
(RFR*Rptboot_ret((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��scC@s�d}d}d|j�kr8tjd�|d}nd|j�kr�tjd�|d}tjd�t||||d�ndS(u2
    Set static IP during create() if defined
    uuipv4_gwuipv4_gw is found in keysu	ipv4_cidruipv4_cidr is found in keysu attempting to set IP in instanceN(RDRRRTR4(RFR*RpRQRR((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��s




cC@s�tj�}d}x�|dkr�t||�}|dk	rW|jd�rWd}qWntj�}||}tjd|j|�|jdkr�tjd�Pnt	j
d�qWdS(u6
    Wait for IP  to be available during create()
    u169u0Waited %s seconds for %s to report ip address...i�uTimeout getting IP addressiN(RtnowR4R5t
startswithRRtsecondstwarningttimetsleep(RFR*t
start_timetstatust
check_timetdelta((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��s 


cC@s�|dks|dkrdS|jjj|�}tjd|�x^|jjj|�dkr�t|jjj|�d�d}tjd|�t	j
d�qDWtjd|�|jjj|�dS(	uC
    Run  XenAPI task in asynchronous mode to prevent timeouts
    u
Running %supendingiiduTask progress %.2f%%iuCleaning up task %sN(R4Rttasktget_name_labelRRt
get_statustroundtget_progressR�R�tdestroy(R�R*t	task_nametprogress((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt_run_async_task�s"cC@sf|dkrt�}ntjd||�t||�}|jjjj||�}t	||�dS(u�
    Create VM by cloning

    This is faster and should be used if source and target are
    in the same storage repository

    uCreating VM %s by cloning %sN(
R4R/RRR<RtAsyncR0R�R�(R�RFR*tsourceR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�scC@si|dkrt�}ntjd||�t||�}|jjjj|||�}t	||�dS(u�
    Create VM by copy

    This is slower and should be used if source and target are
    NOT in the same storage repository

    template = object reference
    name = string name of new VM
    session = object reference
    sr = object reference
    uCreating VM %s by copying %sN(
R4R/RRR<RR�R0tcopyR�(ttemplateRFR*tsrR�R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��scC@s`|dkrt�}ntjd|�t||�}|jjjj|�}t	||�dS(u-
    Provision vm right after clone/copy
    uProvisioning VM %sN(
R4R/RRER<RR�R0t	provisionR�(RFR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�scC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjjj	|t
t�}t||�t
|�S(uU
    Start  a vm

    .. code-block:: bash

        salt-cloud -a start xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.uStarting VM %sN(RR4R/RRER<RR�R0R�RRPR�Rm(RFRGR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�s	
cC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjjj	|�}t
||�t|�S(uT
    Pause a vm

    .. code-block:: bash

        salt-cloud -a pause xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.u
Pausing VM %sN(RR4R/RRER<RR�R0tpauseR�Rm(RFRGR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�'s	
cC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjjj	|�}t
||�t|�S(uX
    UnPause a vm

    .. code-block:: bash

        salt-cloud -a unpause xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.uUnpausing VM %sN(RR4R/RRER<RR�R0tunpauseR�Rm(RFRGR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�=s	
cC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjjj	|�}t
||�t|�S(u`
    Suspend a vm to disk

    .. code-block:: bash

        salt-cloud -a suspend xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.uSuspending VM %sN(RR4R/RRER<RR�R0tsuspendR�Rm(RFRGR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�Ss	
cC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjjj	|t
t�}t||�t
|�S(u`
    Resume a vm from disk

    .. code-block:: bash

        salt-cloud -a resume xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.uResuming VM %sN(RR4R/RRER<RR�R0tresumeRRPR�Rm(RFRGR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR�is	
cC@s+|dkrtd��nt|||�S(uS
    Stop a vm

    .. code-block:: bash

        salt-cloud -a stop xenvm01


    ufunctionu=The show_instnce function must be called with -a or --action.(Rtshutdown(RFRGR*((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytstops
cC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjjj	|�}t
||�t|�S(u[
    Shutdown  a vm

    .. code-block:: bash

        salt-cloud -a shutdown xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.uStarting VM %sN(RR4R/RRER<RR�R0R�R�Rm(RFRGR*R8R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��s	
cC@s�|dkrtd��n|dkr3t�}ntjd|�t||�}|jjj|�}|dkr�|jj	jj
|�}t||�t|�Sdj
|�SdS(uV
    Reboot a vm

    .. code-block:: bash

        salt-cloud -a reboot xenvm01

    ufunctionu=The show_instnce function must be called with -a or --action.uStarting VM %suRunningu {} is not running to be rebootedN(RR4R/RRER<RR0tget_power_stateR�tclean_rebootR�RmR(RFRGR*R8tpower_stateR�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytreboot�s	

cC@sK|dkrt�}n|jjj|�}t|�dkrG|dSdS(u.
    Get XEN vm instance object reference
    iiN(R4R/RR0tget_by_name_labelRN(RFR*R6((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR<�scC@sK|dkrt�}n|jjj|�}t|�dkrG|dSdS(u4
    Get XEN sr (storage repo) object reference
    iiN(R4R/RRwR�RN(RFR*tsrs((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyRu�scC@sm|dkrt�}n|jjj�}x<|D]4}|jjj|�}||jd�kr1|Sq1WdS(u0
    Get XEN resource pool object reference
    u
name_labelN(R4R/RRoRUR2R`(RFR*tpoolsRoRs((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyRn�s
cC@s�|dkrtd��ni}tddddj|�di|d6d	td
dtd�t�}t|�}|r�|jjj|�}t	j
d
|d�|ddkr�|jjjj|�}t
||�nt||�|d<|jjjj|�}t
||�t|d<tddddj|�di|d6d	td
dtd�tjdt�tkr�td|tjd�dt�ntd|�|SdS(ug
    Destroy Xen VM or template instance

    .. code-block:: bash

        salt-cloud -d xenvm01

    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingR|unameR}usock_dirR~u	transportupower_state: %supower_stateuHalteduvbdu	destroyedudestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:iucloud.cachedir_index_delN(RRVRR
R/R<RR0R2RRR�t
hard_shutdownR�tdestroy_vm_vdisR�RPR`RRR#(RFRGR7R*R8R9R�((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��sJ	

	




cC@st|dkrtd��ni}t�}|jjj�}x1|D])}|jjj|�}|||d<qCW|S(uk
    Geta list of storage repositories

    .. code-block:: bash

        salt-cloud -f sr_list myxen

    ufunctionu:This function must be called with -f, --function argument.u
name_label(RR/RRwRUR2(RGR7R*R�R�Rz((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytsr_list s		
cC@st|dkrtd��ni}t�}|jjj�}x1|D])}|jjj|�}|||d<qCW|S(ud
    Get a list of Xen Servers

    .. code-block:: bash

        salt-cloud -f host_list myxen
    uactionu:This function must be called with -f, --function argument.u
name_label(RR/RthostRUR2(RGR7R*thostsR�thost_record((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt	host_list6s	
cC@st|dkrtd��ni}t�}|jjj�}x1|D])}|jjj|�}|||d<qCW|S(uh
    Get a list of Resource Pools

    .. code-block:: bash

        salt-cloud -f pool_list myxen

    uactionu:This function must be called with -f, --function argument.u
name_label(RR/RRoRUR2(RGR7R*R�RoRs((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyRhKs		
cC@st|dkrtd��ni}t�}|jjj�}x1|D])}|jjj|�}|||d<qCW|S(ug
    Get a list of Resource Pools

    .. code-block:: bash

        salt-cloud -f pool_list myxen
    ufunctionu:This function must be called with -f, --function argument.uuuid(RR/RtPIFRUR2(RGR7R*tpifstpifR9((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytpif_listas	
cC@s�|dkrtd��n|dkr+dSi}i}t�}t|�}|jjj|�}|dk	r�d}xC|D]8}	|jjj|	�}
|
|dj	|�<|d7}qzWn|||<|S(u�
    Get a list of virtual network interfaces  on a VM

    **requires**: the name of the vm with the vbd definition

    .. code-block:: bash

        salt-cloud -a vif_list xenvm01

    ufunctionu8This function must be called with -a, --action argument.uA name kwarg is rquirediuvif-{}iN(
RR4R/R<RR0R=R>R2R(RFRGRbR7RfR*R8RHtxRIt
vif_record((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytvif_listvs$	

cC@s�|dkrtd��n|dkr+dSi}i}t�}|jjj|�}t|�dkr�|d}|jjj|�}|dk	r�d}xC|D]8}	|jjj	|	�}
|
|dj
|�<|d7}q�Wq�n|}|S(u�
    Get a list of VBDs on a VM

    **requires**: the name of the vm with the vbd definition

    .. code-block:: bash

        salt-cloud -a vbd_list xenvm01

    ufunctionu8This function must be called with -a, --action argument.uA name kwarg is rquirediiuvbd-{}N(RR4R/RR0R�RNtget_VBDstVBDR2R(RFRGR7RfR*R6R8tvbdsR�tvbdt
vbd_record((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytvbd_list�s(	

cC@s"|dkrtd��nt�S(u�
    Get a list of images from Xen

    If called with the `--list-images` then it returns
    images with all details.

    .. code-block:: bash

        salt-cloud --list-images myxen

    uactionu:This function must be called with -f, --function argument.(RRl(RG((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytavail_images�sc
C@s|dkrt�}ni}|jjj|�}t|�dkr|jjj|d�}|dk	rd}x�|D]�}|jjj|�}|ddkr�|jj	j|d�}	d|	dkr�|jj	j
|d�|	d|dj|�<q�n|d7}qwWqn|S(	ut
    Get virtual block devices on VM

    .. code-block:: bash

        salt-cloud -a destroy_vm_vdis  xenvm01

    iiuVDIuOpaqueRef:NULLuisou
name_labeluvdi-{}N(R4R/RR0R�RNR�R�R2R^R�R(
RFR*RGR7R6R�R�R�R�t
vdi_record((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyR��s$	

c	C@s�|dkrtd��n|d	kr0i}n|jdd	�}t�}|jjj�}i}t}xm|D]e}|jjj|�}|drp|d|kr�t	}|jjj
|�idd6||<q�qpqpW|s�idd6||<n|S(
u�
    Destroy Xen VM or template instance

        .. code-block:: bash

            salt-cloud -f destroy_template myxen name=testvm2

    uactionu6The destroy_template function must be called with  -f.unameu
is_a_templateu
name_labelu	destroyedustatusu	not foundN(RR4R`R/RR0R1RR2RPR�(	RFRGRbR*R6R7tfoundR8R9((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytdestroy_template�s(			

cC@su|dkrtd��n|dkr@tjd�t�}nt|d|�}|jjj|�}|rq|SdS(ui
    Get PV arguments for a VM

    .. code-block:: bash

        salt-cloud -a get_pv_args xenvm01

    ufunctionu1This function must be called with -a or --action.uNew session being createdR*N(	RR4RRR/R<RR0tget_PV_args(RFR*RGR8tpv_args((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytget_pv_argss	
cC@s�|dkrtd��n|d	kr@tjd�t�}nt|d|�}y8tjd|d�|jjj|t	|d��Wn@t
k
r�tjd�tSt
jk
r�tjd�tSXtS(
u�
    Set PV arguments for a VM

    .. code-block:: bash

        salt-cloud -a set_pv_args xenvm01 pv_args="utf-8 graphical"

    ufunctionu1This function must be called with -a or --action.uNew session being createdR*uSetting PV Args: %supv_argsuNo pv_args parameter found.uSetting PV Args failed.N(RR4RRR/R<RR0tset_PV_argststrtKeyErrorterrorRRR RERP(RFRbR*RGR8((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pytset_pv_args#s"	
$


(Kt__doc__t
__future__RRRRtloggingR�tsalt.configRtsalt.extRtsalt.utils.cloudR
tsalt.exceptionsRRt	getLoggert__name__RRRPRtImportErrorRRR4RRR	RR/R;R5RTRZR]RgRiRjRlRmRtR{R�R�R�R�R�RR�R�R�R�R�R�R�R�R�R�R<RuRnR�R�R�RhR�R�R�R�R�R�R�R�(((s9/usr/lib/python2.7/site-packages/salt/cloud/clouds/xen.pyt<module><s�


				5	!.&1,-			o			: " !

Zerion Mini Shell 1.0