%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/runners/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/runners/virt.pyc

�
���^c@@srdZddlmZmZmZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
Z	ddlmZddlmZeje�Zdd�Zed�Zded	�Zdedd
�Zd�Zdd�Zd
dedeeddeded�Zed�Zd�Z d�Z!d�Z"ed�Z#d�Z$d�Z%dd�Z&dS(u#
Control virtual machines via Salt
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltClientError(tsixucC@s�d}d}xotj|�D]^\}}||kr:qnt|t�sOqn|jdd�|kr|d}|}qqW|S(uO
    Determine what the most resource free host is based on the given data
    uiufreemem(Rt	iteritemst
isinstancetdicttget(tdatatomitthosttbestmemthv_tcomps((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyt_determine_hosts

cC@s�x�|D]�}t||t�s&qn|||jdi�krii||d||6|6}|s�tji|d6dd6d�n|SqWiS(u.
    Scan the query data for the named VM
    uvm_infoudataunestedu	outputteruprogress(RRRt
__jid_event__t
fire_event(tnameR	tquietR
tret((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyt_find_vm,s
 !cC@sf|rtjd�ni}tjjtd�}yx	|jdddd�D]�}|s`qNnt|t�suqNni}t	t
j|��}|r�||kr�qNq�nt||t�s�qNnd||kr�qNnt||dt�s�qNn||d||<|j|�|sNt
ji|d6d	d
6d�qNqNWWntk
ra}t|�nX|S(u�
    Query the virtual machines. When called without options all hosts
    are detected and a full query is returned. A single host can be
    passed in to specify an individual host to query.
    u0'quiet' is deprecated. Please migrate to --quietu	conf_fileuvirtual:physicaluvirt.full_infottgt_typeugrainuretudatau
virt_queryu	outputteruprogress(tlogtwarningtsalttclienttget_local_clientt__opts__tcmd_iterRRtnextRtiterkeystupdateRRRtprint(RRRRtinfotchunktid_tclient_error((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytquery<s:	
)cC@s�|rtjd�ni}tjjtd�}xh|jdddd�D]N}|s]qKnt|t�srqKni}t	t
j|��}|r�||kr�qKq�nt||t�s�qKnd||kr�qKnt||dt�s�qKni}x^t
j||d�D]E\}	}
|
d|krF||
dj
|	�q|	g||
d<qW|||<|j|�|sKtji|d	6d
d6d�qKqKW|S(
u�
    List the virtual machines on each host, this is a simplified query,
    showing only the virtual machine names belonging to each host.
    A single host can be passed in to specify an individual host
    to list.
    u0'quiet' is deprecated. Please migrate to --quietu	conf_fileuvirtual:physicaluvirt.vm_infoRugrainuretustateudataunestedu	outputteruprogress(RRRRRRRRRRRRRtappendR RR(RRthyperRRR"R#R$R	tkeytval((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytlistas>	$

%cC@s#ttdt��}t|�|S(u�
    Return the host to use for the next autodeployed VM. This queries
    the available host and executes some math the determine the most
    "available" next host.
    R(RR&tTrueR!(R((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyt	next_host�s
cC@sit|dt�}x2|D]*}d||kr||jd�qqWtji|d6dd6d�|S(uD
    Return information about the host connected to this master
    Ruvm_infoudataunestedu	outputteruprogress(R&R,tpopRR(RR	R$((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyt	host_info�s
ukvmudefaultubaseu
seed.applycC@s�tjidd6d�t|dt�}xY|D]Q}d||kr0|||dkr�tjidj|�d6d�dSq0q0W|d
kr�t|�}n||ks�|r�tjidj|�d6d�dSd
}d
}|rttjid	d6d�tjj	j
�\}}tjj
td
d|�}tjjj|d��#}|jtjjj|��Wd
QXntjjtd�}tjidj||�d6d�y�|j|d|||gdddi
|d6|d6|d6|	d6|
d6|d6|d6|d6|d6|d6|
d6|d6|d 6�}Wntk
rU}t|�nXt|�}|s�tjid!j|�d6d�dSxD|D]<}||d"tkr�td#j|||d"��dSq�Wtjid$j||�d6d�d%S(&u�
    This routine is used to create a new virtual machine. This routines takes
    a number of options to determine what the newly created virtual machine
    will look like.

    name
        The mandatory name of the new virtual machine. The name option is
        also the minion id, all minions must have an id.

    cpu
        The number of cpus to allocate to this new virtual machine.

    mem
        The amount of memory to allocate to this virtual machine. The number
        is interpreted in megabytes.

    image
        The network location of the virtual machine image, commonly a location
        on the salt fileserver, but http, https and ftp can also be used.

    hypervisor
        The hypervisor to use for the new virtual machine. Default is `kvm`.

    host
        The host to use for the new virtual machine, if this is omitted
        Salt will automatically detect what host to use.

    seed
        Set to `False` to prevent Salt from seeding the new virtual machine.

    nic
        The nic profile to use, defaults to the "default" nic profile which
        assumes a single network interface per VM associated with the "br0"
        bridge on the master.

    install
        Set to False to prevent Salt from installing a minion on the new VM
        before it spins up.

    disk
        The disk profile to use

    saltenv
        The Salt environment to use

    enable_vnc
        Whether a VNC screen is attached to resulting VM. Default is `False`.

    seed_cmd
        If seed is `True`, use this execution module function to seed new VM.
        Default is `seed.apply`.

    enable_qcow
        Clone disk image as a copy-on-write qcow2 image, using downloaded
        `image` as backing file.
    uSearching for hostsumessageuprogressRuvm_infou'Virtual machine {0} is already deployedufailuHost {0} was not founduMinion will be preseededupki_diruminionsuwNu	conf_fileuCreating VM {0} on host {1}u	virt.initttimeoutiXtkwarguimageunicu
hypervisorustartudiskusaltenvuseeduinstallupub_keyupriv_keyuseed_cmdu
enable_vncuenable_qcowuVM {0} was not initialized.uretu1VM {0} initialization failed. Returned error: {1}uVM {0} initialized on host {1}ugood(RRR&R,tformattNoneRRtutilstcloudtgen_keystostpathtjoinRtfilestfopentwritetstringutilstto_strRRRRR!RtFalse(Rtcputmemtimaget
hypervisorRtseedtnictinstalltstarttdisktsaltenvt
enable_vnctseed_cmdtenable_qcowR	tnodetpub_keytpriv_keytaccepted_keytfp_Rtcmd_retR%Rt	minion_id((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytinit�s|H
%	 
#cC@stdt�}t|||�S(u0
    Return the information on the named VM
    R(R&R,R(RRR	((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytvm_info9scC@s�i}tjjtd�}t|dt�}|sXtjidj|�d6d�dSt	t
j|��}y`|j|d|gdd	�}x|D]}|j
|�q�Wtjid
j|�d6d�Wntk
r�}t|�nX|S(u5
    Force power down and restart an existing VM
    u	conf_fileRuFailed to find VM {0} to resetumessageuprogressufailu
virt.resetR0iXuReset VM {0}(RRRRRUR,RRR2RRRRR RR!(RRRR	RRRtcompR%((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytresetAs& 		
$cC@s#i}tjjtd�}t|dt�}|sXtjidj|�d6d�dSt	t
j|��}|||ddkr�td	j|��d
Sy"|j
|d|gdd
�}Wn tk
r�}dj||�SXx|D]}|j|�q�Wtjidj|�d6d�dS(u'
    Start a named virtual machine
    u	conf_fileRuFailed to find VM {0} to startumessageuprogressufailustateurunninguVM {0} is already runningu	bad stateu
virt.startR0iXu$Virtual machine {0} not started: {1}uStarted VM {0}ugood(RRRRRUR,RRR2RRRR!RRR (RRRR	RRRR%RV((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyRGZs, 	

 cC@si}tjjtd�}t|dt�}|sKtdj|��dStt	j
|��}|||ddkr�tdj|��dSy"|j|d	|gd
d�}Wn tk
r�}dj||�SXx|D]}|j
|�q�Wtjid
j|�d6d�dS(u4
    Force power down the named virtual machine
    u	conf_fileRu Failed to find VM {0} to destroyufailustateushutdownuVM {0} is already shutdownu	bad stateu	virt.stopR0iXu0Virtual machine {0} could not be forced off: {1}uPowered off VM {0}umessageuprogressugood(RRRRRUR,R!R2RRRRRR RR(RRRR	RRRR%RV((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyt	force_offvs,	

 c
C@s/i}tjjtd�}t|dt�}|sXtjidj|�d6d�dSt	t
j|��}y%|j|d|tgdd	�}Wn t
k
r�}d
j||�SXx|D]}|j|�q�W|rtjd|�tjjt�}	|	j|�ntjidj|�d
6d�dS(u
    Destroy the named VM
    u	conf_fileRuFailed to find VM {0} to purgeuerroruprogressufailu
virt.purgeR0iXu,Virtual machine {0} could not be purged: {1}uDeleting key %su
Purged VM {0}umessageugood(RRRRRUR,RRR2RRRRRR RtdebugR)tKeyt
delete_key(
RR[RRR	RRRR%RVtskey((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytpurge�s. 

 cC@s0i}tjjtd�}t|dt�}|sXtjidj|�d6d�dSt	t
j|��}|||ddkr�tjid	j|�d6d�d
Sy"|j|d|gdd
�}Wn t
k
r�}dj||�SXx|D]}|j|�q�Wtjidj|�d6d�dS(u
    Pause the named VM
    u	conf_fileRuFailed to find VM {0} to pauseuerroruprogressufailustateupauseduVM {0} is already pausedu	bad stateu
virt.pauseR0iXu,Virtual machine {0} could not be pasued: {1}u
Paused VM {0}umessageugood(RRRRRUR,RRR2RRRRRR (RRRR	RRRR%RV((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytpause�s,  	

 cC@s0i}tjjtd�}t|dt�}|sXtjidj|�d6d�dSt	t
j|��}|||ddkr�tjid	j|�d6d�d
Sy"|j|d|gdd
�}Wn t
k
r�}dj||�SXx|D]}|j|�q�Wtjidj|�d6d�dS(u
    Resume a paused VM
    u	conf_fileRuFailed to find VM {0} to pauseuerroruprogressu	not foundustateupauseduVM {0} is not pausedu	bad stateuvirt.resumeR0iXu-Virtual machine {0} could not be resumed: {1}uResumed VM {0}umessageugood(RRRRRUR,RRR2RRRRRR (RRRR	RRRR%RV((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytresume�s,  	

 c
C@s�tjjtd�}tdt�}t||dt�}yt|j��d}Wn2t	k
r�t
jidj|�d6d�dSX|||d}|s�t
jidj|�d6d�dS|s�t
||�}n||kr
t
jid	j|�d6d�dSy8|j|d
|tg�|j|d||g�}Wn tk
rg}dj||�SXd
j|||�}	t
ji|	d6d�dS(u�
    Migrate a VM from one host to another. This routine will just start
    the migration and display information on how to look up the progress.
    u	conf_fileRiu%Named VM {0} was not found to migrateuerroruprogressuudisksuTarget host {0} not founduvirt.seed_non_shared_migrateuvirt.migrate_non_sharedu.Virtual machine {0} could not be migrated: {1}u�The migration of virtual machine {0} to host {1} has begun, and can be tracked via jid {2}. The ``salt-run virt.query`` runner can also be used, the target VM will be shown as paused until the migration is complete.umessageN(RRRRR&R,RR+tkeyst
IndexErrorRRR2Rtcmdt	cmd_asyncR(
RttargetRR	torigin_datatorigin_hosttdiskstjidR%tmsg((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pytmigrate�s6
   	('t__doc__t
__future__RRRtos.pathR7tloggingtsalt.clientRtsalt.keytsalt.utils.cloudtsalt.utils.filestsalt.utils.stringutilstsalt.exceptionsRtsalt.extRt	getLoggert__name__RRR?RR3R&R+R-R/R,RTRURWRGRXR]R^R_Rj(((s5/usr/lib/python2.7/site-packages/salt/runners/virt.pyt<module>sH%*	�					

Zerion Mini Shell 1.0