HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/vmctl.cpython-310.pyc
o

�N�g&�@s�dZddlZddlZddlZddlmZmZe�e	�Z
dd�Zdd�Zdd	�Z
d
d�Zdd
�Zddd�Z									ddd�Zddd�Zddd�ZdS)a
Manage vms running on the OpenBSD VMM hypervisor using vmctl(8).

.. versionadded:: 2019.2.0

:codeauthor: ``Jasper Lievisse Adriaanse <jasper@openbsd.org>``

.. note::

    This module requires the `vmd` service to be running on the OpenBSD
    target machine.
�N)�CommandExecutionError�SaltInvocationErrorcCs"tddkrtjj�d�rdSdS)z6
    Only works on OpenBSD with vmctl(8) present.
    �osZOpenBSD�vmctlT)FzmThe vmm execution module cannot be loaded: either the system is not OpenBSD or the vmctl binary was not found)Z
__grains__�salt�utils�path�which�r
r
�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/vmctl.py�__virtual__srcCst|d�}|ikrdS|dS)z2
    Lookup the name associated with a VM id.
    )�idN�name)�status)r
�vmr
r
r�_id_to_name%s
rcCsRd}d|�d|��}td|ddd�}|ddkrd	}|Std
|dg|d�d
��)z�
    Create a VMM disk with the specified `name` and `size`.

    size:
        Size in megabytes, or use a specifier such as M, G, T.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.create_disk /path/to/disk.img size=10G
    Fz
vmctl create z -s �cmd.run_all�trace�Zoutput_loglevelZpython_shell�retcoderTz'Problem encountered creating disk image�stderr��errors�changes��info��__salt__r)r�size�ret�cmd�resultr
r
r�create_disk0s
��r"cCsLd}d|��}td|ddd�}|ddkrd}|Std	|d
g|d�d��)
z�
    Load additional configuration from the specified file.

    path
        Path to the configuration file.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.load path=/etc/vm.switches.conf
    Fzvmctl load rrrrrT�!Problem encountered running vmctlrrrr)rrr r!r
r
r�loadMs
��r$cCsFd}d}td|ddd�}|ddkrd}|Std	|d
g|d�d��)
z�
    Remove all stopped VMs and reload configuration from the default configuration file.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.reload
    Fzvmctl reloadrrrrrTr#rrrr)rr r!r
r
r�reloadhs
��r%FcCsxd}ddg}|r|�d�n|r|�d�n|r|�d�td|ddd	�}|d
dkr0d}|Std
|dg|d�d��)a
    Reset the running state of VMM or a subsystem.

    all:
        Reset the running state.

    switches:
        Reset the configured switches.

    vms:
        Reset and terminate all VMs.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.reset all=True
    Fr�reset�all�vms�switchesrrrrrTr#rrr)�appendrr)r'r(r)rr r!r
r
rr&�s 
��r&c	Cs�ddd�}	ddg}
|s|std��|r|
�|�n	|
�|�t|�}|dkr.|
�d|���|r7|
�d	|g�|rA|
�d
|���|rK|
�d|���|rR|
�d�|rZ|rZtd
��|rc|
�d|g�|ro|
�dd�|D��t|
�dkr�t|�}|r�d|	d<|	Std|
ddd�}|ddkr�d|	d<t�d|d�}
|
r�|
�	�d|	d<|	St�d|d�}
|
r�d|	d<|	St
d|dg|	d�d ��)!ai
    Starts a VM defined by the specified parameters.
    When both a name and id are provided, the id is ignored.

    name:
        Name of the defined VM.

    id:
        VM id.

    bootpath:
        Path to a kernel or BIOS image to load.

    disk:
        Path to a single disk to use.

    disks:
        List of multiple disks to use.

    local_iface:
        Whether to add a local network interface. See "LOCAL INTERFACES"
        in the vmctl(8) manual page for more information.

    memory:
        Memory size of the VM specified in megabytes.

    switch:
        Add a network interface that is attached to the specified
        virtual switch on the host.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.start 2   # start VM with id 2
        salt '*' vmctl.start name=web1 bootpath='/bsd.rd' nics=2 memory=512M disk='/disk.img'
    FN)r�consoler�start�"Must provide either "name" or "id"rz-i z-bz-m z-n z-Lz%Must provide either "disks" or "disk"�-dcss�|]}d|gVqdS)r.Nr
��.0�xr
r
r�	<genexpr>�s�zstart.<locals>.<genexpr>�z)VM already exists and cannot be redefinedZcommentrrrrTrz.*successfully, tty (\/dev.*)rr+z .*Operation already in progress$r#rr)rr*r�extend�lenrr�re�match�groupsr)rr
ZbootpathZdiskZdisksZlocal_ifaceZmemoryZnicsZswitchrr Zvmstater!�mr
r
rr,�sX
0

���r,c
Cs.i}ddg}td|ddd�}|ddkr!td	|d
g|d�d��|d
��d��}dd�|D�}|d
��dd�D]R}|��}ttt||���}|�d�}	|ddkr[d|d<n|	rj|ddkrj|d|d<nd|d<|r~t|d�|kr~|	|iS|r�|	|kr�|	|iS|||	<q<|s�|r�iS|S)ap
    List VMs running on the host, or only the VM specified by ``id``.  When
    both a name and id are provided, the id is ignored.

    name:
        Name of the defined VM.

    id:
        VM id.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.status           # to list all VMs
        salt '*' vmctl.status name=web1 # to get a single VM
    rrrrFrrrr#r)�errorrr�stdoutcSsg|]}|���qSr
)�lowerr/r
r
r�
<listcomp>9szstatus.<locals>.<listcomp>�Nr�pid�-�stopped�state������Zrunningr
)	rr�
splitlines�split�dict�list�zip�pop�int)
rr
rr r!�header�line�datarZvmnamer
r
rrs6�	


rcCs�i}ddg}|s|std��|r|�|�n|�|�td|ddd�}|dd	kr>t�d
|d�r8d|d
<|Sd|d
<|Std|dg|d�d��)a
    Stop (terminate) the VM identified by the given id or name.
    When both a name and id are provided, the id is ignored.

    name:
        Name of the defined VM.

    id:
        VM id.

    CLI Example:

    .. code-block:: bash

        salt '*' vmctl.stop name=alpine
    r�stopr-rrFrrrz&^vmctl: sent request to terminate vm.*rTrr#rr)rr*rr6r7r)rr
rr r!r
r
rrOcs$
	���rO)FFF)	NNNNNFNrN)NN)�__doc__�loggingr6Zsalt.utils.pathrZsalt.exceptionsrr�	getLogger�__name__�logrrr"r$r%r&r,rrOr
r
r
r�<module>s0


*
�
qI