File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/guestfs.cpython-310.pyc
o
�N�g` � @ sj d Z ddlZddlZddlZddlZddlZddlZddlm Z e�
e�Zdd� Z
ddd�Zdd d
�ZdS )
zO
Interact with virtual machine images via libguestfs
:depends: - libguestfs
� N)�DEFAULT_HASH_TYPEc C s t jj�d�r dS dS )z?
Only load if libguestfs python bindings are installed
Z
guestmountZguestfs)FzMThe guestfs execution module cannot be loaded: guestmount binary not in path.)�salt�utils�path�which� r r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/guestfs.py�__virtual__ s r �rwc C s4 |du rt j�t�� d| �t j��dd��}t� d|� t j�
|�s3zt �|� W n ty2 Y nw t �
|�r�ttt�dt��}|t �d���� }t j�t�� d| �t j��dd�| �}t� d |� t j�
|�s�zt �|� W n ty� t�d
|� Y nw nnq4d| � d|� d
|� �}td |dd� |S )zz
Mount an image
CLI Example:
.. code-block:: bash
salt '*' guest.mount /srv/images/fedora.qcow
NZguest�/�.z
Using root %sT� hash_type� zEstablishing new root as %szPath already existing: %szguestmount -i -a z --� �cmd.runF)Zpython_shell)�osr �join�tempfileZ
gettempdir�lstrip�sep�replace�log�debug�isdir�makedirs�OSError�listdir�getattr�hashlibZ__opts__�getr �urandom� hexdigest�info�__salt__)�location�access�rootr
Zrand�cmdr r r �mount sB
��
����r( c C s� d| � �}t d |� d}|durF|dk rJtt d d|� ���� �dkrL|d }t�d� |durH|dk rNtt d d|� ���� �dks$dS dS dS dS dS dS )z�
Unmount an image
CLI Example:
.. code-block:: bash
salt '*' guestfs.umount /mountpoint disk=/srv/images/fedora.qcow
zguestunmount -q r r N� zlsof � )r# �len�
splitlines�time�sleep)�nameZdiskr'