File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/engines/__pycache__/libvirt_events.cpython-310.pyc
Back
o ;j�T � @ s� d Z ddlZddlZddlZe�e�Zzddl Z W n e y$ dZ Y nw dd� Zddddd d �Ze e d�r9dZndZd ddddddddddddddefddddd d!d"d#fd$d%d&d'd �Zd(d)� Zd*d+� Zd,d-� Zd.d/� Zd0d1� Zd2d3� Zd4d5� Zd6d7� Zd8d9� Zd:d;� Zd<d=� Zd>d?� Zd@dA� ZdBdC� ZdDdE� ZdFdG� ZdHdI� Z dJdK� Z!dLdM� Z"dNdO� Z#dPdQ� Z$dRdS� Z%dTdU� Z&dVdW� Z'dXdY� Z(dZd[� Z)d\d]� Z*d^d_� Z+d`da� Z,dbdc� Z-ddde� Z.dfdg� Z/dhdi� Z0djdk� Z1dldm� Z2dndo� Z3dpdq� Z4drds� Z5dtdu� Z6dydwdx�Z7dS )za� An engine that listens for libvirt events and resends them to the salt event bus. The minimal configuration is the following and will listen to all events on the local hypervisor and send them with a tag starting with ``salt/engines/libvirt_events``: .. code-block:: yaml engines: - libvirt_events Note that the automatically-picked libvirt connection will depend on the value of ``uri_default`` in ``/etc/libvirt/libvirt.conf``. To force using another connection like the local LXC libvirt driver, set the ``uri`` property as in the following example configuration. .. code-block:: yaml engines: - libvirt_events: uri: lxc:/// tag_prefix: libvirt filters: - domain/lifecycle - domain/reboot - pool Filters is a list of event types to relay to the event bus. Items in this list can be either one of the main types (``domain``, ``network``, ``pool``, ``nodedev``, ``secret``), ``all`` or a more precise filter. These can be done with values like <main_type>/<subtype>. The possible values are in the CALLBACK_DEFS constant. If the filters list contains ``all``, all events will be relayed. Be aware that the list of events increases with libvirt versions, for example network events have been added in libvirt 1.2.1 and storage events in 2.0.0. Running the engine on non-root ------------------------------ Running this engine as non-root requires a special attention, which is surely the case for the master running as user `salt`. The engine is likely to fail to connect to libvirt with an error like this one: [ERROR ] authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.monitor' To fix this, the user running the engine, for example the salt-master, needs to have the rights to connect to libvirt in the machine polkit config. A polkit rule like the following one will allow `salt` user to connect to libvirt: .. code-block:: javascript polkit.addRule(function(action, subject) { if (action.id.indexOf("org.libvirt") == 0 && subject.user == "salt") { return polkit.Result.YES; } }); :depends: libvirt 1.0.0+ python binding .. versionadded:: 2019.2.0 � Nc C s2 t du rd} nt �� dk rd} nd} t| � | fS )z8 Only load if libvirt python binding is present Nzlibvirt module not foundi@B zlibvirt >= 1.0.0 required� )�libvirtZ getVersion�bool)�msg� r �O/opt/saltstack/salt/lib/python3.10/site-packages/salt/engines/libvirt_events.py�__virtual__P s r ZdomainEventRegisterAnyZnetworkEventRegisterAnyZstoragePoolEventRegisterAnyZnodeDeviceEventRegisterAnyZsecretEventRegisterAny)�domain�network�pool�nodedev�secretZVIR_DOMAIN_EVENT_ID_BLOCK_JOB_2ZVIR_DOMAIN_EVENT_ID_BLOCK_JOB�� lifecycleN)ZrebootN)Z rtc_changeN)ZwatchdogN)ZgraphicsN)Zio_errorZ#VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON)Z control_errorN)Zdisk_changeN)Ztray_changeN)ZpmwakeupN)Z pmsuspendN)Zballoon_changeN)Zpmsuspend_diskN)Zdevice_removedNZ block_job)ZtunableN)Zagent_lifecycleN)Zdevice_addedN)Zmigration_iterationN)Z job_completedN)Zdevice_removal_failedN)Zmetadata_changeN)Zblock_thresholdN)r ))r Z#VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE)ZrefreshZ!VIR_STORAGE_POOL_EVENT_ID_REFRESH))r Z"VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE)�updateZVIR_NODE_DEVICE_EVENT_ID_UPDATE)r )Z value_changedNc C s2 d� | �d�d t| �d��dkrdf�S df�S )z^ Get the part before the first '_' or the end of attr including the potential '_' r �_r � )�join�split�len)�attrr r r �_compute_subprefix� s 2r c s� � fdd�t jD �}dd� |D ���fdd��D �}�fdd�|�� D ���fdd�|D �}|D ]}|tt d�� |f��krJ|�� �d d �}| S q0dS )z� Convert the libvirt enum integer value into a human readable string. :param prefix: start of the libvirt attribute to look for. :param value: integer to convert to string c s&