HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/__pycache__/virt.cpython-310.pyc
o

�N�g!E�@s�dZddlZddlZddlZddlZddlZddlZddl	Zddl
mZe�e
�Zd*dd�Zd+dd	�Zd,d
d�Zd-dd
�Zdd�Zd.dd�Z												d/dd�Zd+dd�Zdd�Zdd�Zd d!�Zd0d"d#�Zd$d%�Zd&d'�Zd*d(d)�ZdS)1z#
Control virtual machines via Salt
�N)�SaltClientError�cCsPd}d}|��D]\}}||krqt|t�sq|�dd�|kr%|d}|}q|S)zO
    Determine what the most resource free host is based on the given data
    rrZfreemem)�items�
isinstance�dict�get)�dataZomit�hostZbestmem�hv_�comps�r�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/virt.py�_determine_hosts
�rFcCsh|D]/}t||t�sq|||�di�vr1||||d|ii}|s-t�|dd�d�|SqiS)z.
    Scan the query data for the named VM
    �vm_info�nested�rZ	outputter�progress)rrr�
__jid_event__�
fire_event)�namer�quietr
�retrrr
�_find_vm%s
��rcCs(|rt�d�i}tj�td��y}zX|jdddd�D]M}|s qt|t�s&qi}t	t
|����}|r7||kr7qt||t�s?qd||vrFqt||dt�sPq||d||<|�|�|sht
�|dd	�d
�qWnty�}z
t|�WYd}~nd}~ww|Wd�S1s�wYdS)z�
    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.
    �0'quiet' is deprecated. Please migrate to --quiet�	conf_file�virtual:physicalzvirt.full_info�grain�Ztgt_typerZ
virt_queryrrN)�log�warning�salt�client�get_local_client�__opts__�cmd_iterrr�next�iter�keys�updaterrr�print)r	rrr!�info�chunk�id_�client_errorrrr
�query7sJ

�


�����$�r.cCs:|rt�d�i}tj�td���}|jdddd�D]o}|sqt|t�s%qi}t	t
|����}|r6||kr6qt||t�s>qd||vrEqt||dt�sOqi}||d��D]\}	}
|
d|vrm||
d�
|	�qY|	g||
d<qY|||<|�|�|s�t�|d	d
�d�q|Wd�S1s�wYdS)
z�
    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.
    rrrzvirt.vm_inforrr�staterrrN)rrr r!r"r#r$rrr%r&r'r�appendr(rr)r	rZhyperrr!r*r+r,r�key�valrrr
�list_sH

�


��$�r3cCsttdd��}t|�|S)z�
    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.
    T�r)rr.r))r	rrr
�	next_host�sr5cCsFt|dd�}|D]}d||vr||�d�qt�|dd�d�|S)zD
    Return information about the host connected to this master
    Tr4rrrr)r.�poprr)r	rr,rrr
�	host_info�s�r7�kvmT�default�base�
seed.apply�NonecCstt�ddid�t|dd�}|D]}d||vr/|||dvr/t�dd|�d�id�d	Sq|d
ur8t|�}||vs>|sLt�dd|�d�id�d	Sd
}d
}|r�t�dd
id�tjj��\}}tj	�
tdd|�}tjj�
|d��}|�tjj�|��Wd
�n1s�wYtj�td���}t�dd|�d|��id�z|j|d|||gd||||	|
||||||
|||d�d�}Wnty�}z
t|�WYd
}~nd
}~wwt|�}|s�t�dd|�d�id�	Wd
�d	S|D] }||ddu�rtd�|||d��Wd
�d	Sq�t�dd|�d|��id�	Wd
�dS1�s3wYd
S)aX
    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.

    serial_type
        Enable serial console. Set to 'pty' for serial console or 'tcp' for
        telnet.
        Default is 'None'
    �messagezSearching for hostsrTr4r�Virtual machine z is already deployed�failNzHost z was not foundzMinion will be preseededZpki_dirZminions�wrzCreating VM z	 on host z	virt.init�X)�image�nic�
hypervisor�start�disk�saltenv�seed�install�pub_key�priv_key�seed_cmd�
enable_vnc�enable_qcow�serial_type)�timeout�kwarg�VM z was not initialized.rFz/VM {} initialization failed. Returned error: {}z initialized on host �good)rrr.rr �utilsZcloudZgen_keys�os�path�joinr#�filesZfopen�writeZstringutilsZto_strr!r"r$rr)r%�format)rZcpuZmemrBrDr	rHrCrIrErFrGrMrLrNrOr�noderJrKZaccepted_keyZfp_r!�cmd_retr-rZ	minion_idrrr
�init�s�O�����
�����&���'�&�r]cCstdd�}t|||�S)z0
    Return the information on the named VM
    Tr4)r.r)rrrrrr
rCs
rcCs�i}tj�td��g}t|dd�}|s(t�dd|�d�id�	Wd�d	Stt|�	���}z!|j
|d
|gdd�}|D]}|�|�q=t�dd
|��id�Wntyg}z
t
|�WYd}~nd}~ww|Wd�S1stwYdS)z5
    Force power down and restart an existing VM
    rTr4r=�Failed to find VM z	 to resetrNr?z
virt.resetrA�rPz	Reset VM )r r!r"r#rrrr%r&r'r$r(rr))rrr!rr	r\�compr-rrr
�resetKs*����$�racCsBi}tj�td���}t|dd�}|s(t�dd|�d�id�	Wd�d	Stt|�	���}|||d
dkrKt
d|�d
��	Wd�dSz|j|d|gdd�}Wn!tyx}zd|�d|��WYd}~Wd�Sd}~ww|D]}|�
|�q{t�dd|��id�	Wd�dS1s�wYdS)z'
    Start a named virtual machine
    rTr4r=r^z	 to startrNr?r/ZrunningrRz is already running�	bad statez
virt.startrAr_r>z not started: zStarted VM rS)r r!r"r#rrrr%r&r'r)r$rr(�rrr!rr	r\r-r`rrr
rEbs4�����
$�rEcCs6i}tj�td���}t|dd�}|s$td|�d��	Wd�dStt|����}|||dd	krGtd
|�d��	Wd�dSz|j	|d
|gdd�}Wnt
yr}zd�||�WYd}~Wd�Sd}~ww|D]}|�|�qut
�dd|��id�	Wd�dS1s�wYdS)z4
    Force power down the named virtual machine
    rTr4r^z to destroyNr?r/�shutdownrRz is already shutdownrbz	virt.stoprAr_z.Virtual machine {} could not be forced off: {}r=zPowered off VM rrS)r r!r"r#rr)r%r&r'r$rrZr(rrrcrrr
�	force_off|s4��	���$�rec
CsPi}tj�td���}t|dd�}|s(t�dd|�d�id�	Wd�d	Stt|�	���}z
|j
|d
|dgdd�}Wnty\}zd
�||�WYd}~Wd�Sd}~ww|D]}|�
|�q_|r�t�d|�tj�t��
}	|	�|�Wd�n1s�wYt�dd|��id�	Wd�dS1s�wYdS)z
    Destroy the named VM
    rTr4�errorr^z	 to purgerNr?z
virt.purgerAr_z*Virtual machine {} could not be purged: {}zDeleting key %sr=z
Purged VM rS)r r!r"r#rrrr%r&r'r$rrZr(r�debugr1ZKey�
delete_key)
rrhrr!rr	r\r-r`Zskeyrrr
�purge�s:�����
�$�ricCsFi}tj�td���}t|dd�}|s(t�dd|�d�id�	Wd�d	Stt|�	���}|||d
dkrOt�dd|�d
�id�	Wd�dSz|j
|d|gdd�}Wntyz}zd�||�WYd}~Wd�Sd}~ww|D]}|�
|�q}t�dd|��id�	Wd�dS1s�wYdS)z
    Pause the named VM
    rTr4rfr^�	 to pauserNr?r/�pausedrRz is already pausedrbz
virt.pauserAr_z*Virtual machine {} could not be pasued: {}r=z
Paused VM rS�r r!r"r#rrrr%r&r'r$rrZr(rcrrr
�pause�s<�������$�rmcCsFi}tj�td���}t|dd�}|s(t�dd|�d�id�	Wd�d	Stt|�	���}|||d
dkrOt�dd|�d
�id�	Wd�dSz|j
|d|gdd�}Wntyz}zd�||�WYd}~Wd�Sd}~ww|D]}|�
|�q}t�dd|��id�	Wd�dS1s�wYdS)z
    Resume a paused VM
    rTr4rfr^rjrNz	not foundr/rkrRz is not pausedrbzvirt.resumerAr_z+Virtual machine {} could not be resumed: {}r=zResumed VM rSrlrcrrr
�resume�s8������
$�rnc
Cs�tj�td���}tdd�}t||dd�}ztt|��}Wnty9t	�
dd|�d�id�YWd�d	Sw|||d
}|sYt	�
dd|�d�id�	Wd�d	S|s`t||�}||vryt	�
dd|�d�id�	Wd�d	Sz|�|d
|dg�|j
|d||gtd�}Wnty�}zd�||�WYd}~Wd�Sd}~wwd�|||�}	t	�
d|	id�Wd�dS1s�wYdS)z�
    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.
    rTr4rfz	Named VM z was not found to migraterNr�diskszTarget host z
 not foundzvirt.seed_non_shared_migratezvirt.migrate)Zcopy_storagez,Virtual machine {} could not be migrated: {}z�The migration of virtual machine {} to host {} has begun, and can be tracked via jid {}. The ``salt-run virt.query`` runner can also be used, the target VM will be shown as paused until the migration is complete.r=)r r!r"r#r.rr%r&�
StopIterationrrr�cmdZ	cmd_async�allrrZ)
r�targetr!rZorigin_dataZorigin_hostroZjidr-�msgrrr
�migrate�s\
����
��
����
�"�ru)r)F)NF)NFN)N)r8NTr9TTr9r:Fr;Fr<)T)�__doc__�loggingZos.pathrUZsalt.clientr Zsalt.keyZsalt.utils.cloudZsalt.utils.filesZsalt.utils.stringutilsZsalt.exceptionsr�	getLogger�__name__rrrr.r3r5r7r]rrarErerirmrnrurrrr
�<module>sL




(-

�
!