%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/engines/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/engines/libvirt_events.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlm	Z	ej
e�Zyddl
Z
Wnek
r�dZ
nXd�Zidd6dd	6d
d6dd
6dd6Zee
d�r�dZndZidVdWdXdYdZd[d\d]d^d_d`dadbdcd!efdddedfdgdhdidjdkfd6dmd	6dndofd6dpdqfd
6drdsfd6Zd-�Zd.�Zd/�Zd0�Zd1�Zd2�Zd3�Zd4�Zd5�Zd6�Zd7�Zd8�Z d9�Z!d:�Z"d;�Z#d<�Z$d=�Z%d>�Z&d?�Z'd@�Z(dA�Z)dB�Z*dC�Z+dD�Z,dE�Z-dF�Z.dG�Z/dH�Z0dI�Z1dJ�Z2dK�Z3dL�Z4dM�Z5dN�Z6dO�Z7dP�Z8dQ�Z9dR�Z:dS�Z;ddTddU�Z<dS(tu�
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.

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
i(tabsolute_importtunicode_literalstprint_functionN(turlparsecC@sGtdkrd}n!tj�dkr0d}nd}t|�|fS(u8
    Only load if libvirt python binding is present
    ulibvirt module not foundi@Bulibvirt >= 1.0.0 requireduN(tlibvirttNonet
getVersiontbool(tmsg((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt__virtual__Ws		udomainEventRegisterAnyudomainunetworkEventRegisterAnyunetworkustoragePoolEventRegisterAnyupoolunodeDeviceEventRegisterAnyunodedevusecretEventRegisterAnyusecretuVIR_DOMAIN_EVENT_ID_BLOCK_JOB_2uVIR_DOMAIN_EVENT_ID_BLOCK_JOBu	lifecycleurebootu
rtc_changeuwatchdogugraphicsuio_erroru#VIR_DOMAIN_EVENT_ID_IO_ERROR_REASONu
control_errorudisk_changeutray_changeupmwakeupu	pmsuspenduballoon_changeupmsuspend_diskudevice_removedu	block_jobutunableuagent_lifecycleudevice_addedumigration_iterationu
job_completedudevice_removal_failedumetadata_changeublock_thresholdurefreshuupdateu
value_changedcC@sAdj|jd�dt|jd��dkr7dndf�S(u^
    Get the part before the first '_' or the end of attr including
    the potential '_'
    uu_ii(tjointsplittlen(tattr((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_compute_subprefix�sc@s:gtjD]%}|j|�r
|t|�^q
}g|D]}t|�^q<��fd��D�}g|j�D]=\}}|dks�|jd�rw|d �krw|^qw}g|D]}t|�|kr�|^q�}xN|D]F}	|ttdj||	f��kr�|	j	�j
dd�}
|
Sq�WdS(u�
    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"i|]}�j|�|�qS((tcount(t.0tp(tprefixes(s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pys
<dictcomp>�s	iu_i����uu uunknown(Rt__dict__t
startswithRRtitemstendswithtgetattrR
tlowertreplace(tprefixtvalueR
t
attributesRtcountsRtsub_prefixestfilteredt	candidatetname((Rs?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_get_libvirt_enum_string�s5P+
$cC@sStd|�}|dkr%|dfSdj|j��}t||�}||fS(uX
    Convert event and detail numeric values into a tuple of human readable strings
    uVIR_DOMAIN_EVENT_uunknownuVIR_DOMAIN_EVENT_{0}_(R"tformattupper(teventtdetailt
event_nameRtdetail_name((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_get_domain_event_detail�s
cC@s|d}|d}|d}t|j��}|jg}|jrX|j|j�n|jjd�}|r�|j|�ndj|�}	i|j�d6}
|
j|�dj||	||f�}t	j
d�dkrtjj
jt	t	d�j|
|�ntd	||
�d
S(uP
    Convenience function adding common data to the event and sending it
    on the salt event bus.

    :param opaque: the opaque data that is passed to the callback.
                   This is a dict with 'prefix', 'object' and 'event' keys.
    :param conn: libvirt connection
    :param data: additional event data dict to send
    uprefixuobjectueventu/uuriu__roleumasterusock_diru
event.sendN(RtgetURItschemetnetloctappendtpathtstripR
tupdatet__opts__tgettsalttutilsR%tget_master_eventt
fire_eventt__salt__(topaquetconntdatat
tag_prefixtobject_typet
event_typeturituri_tagR.turi_strtall_datattag((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_salt_send_event�s(



	
cC@s\ii|j�d6|j�d6|j�d6d6|d6}|j|�t|||�dS(u�
    Helper function send a salt event for a libvirt domain.

    :param opaque: the opaque data that is passed to the callback.
                   This is a dict with 'prefix', 'object' and 'event' keys.
    :param conn: libvirt connection
    :param domain: name of the domain related to the event
    :param event: name of the event
    :param event_data: additional event data dict to send
    unameuiduuuidudomainueventN(R!tIDt
UUIDStringR0RC(R8R9tdomainR%t
event_dataR:((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_salt_send_domain_event�s



cC@sAt||�\}}t||||di|d6|d6�dS(u)
    Domain lifecycle events handler
    ueventudetailN(R)RH(R9RFR%R&R8t	event_strt
detail_str((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_lifecycle_cbscC@st||||di�dS(u&
    Domain reboot events handler
    ueventN(RH(R9RFR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_reboot_cb
scC@s%t||||di|d6�dS(u*
    Domain RTC change events handler
    ueventu	utcoffsetN(RH(R9RFt	utcoffsetR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_rtc_change_cbsc	C@s.t||||ditd|�d6�dS(u(
    Domain watchdog events handler
    ueventuVIR_DOMAIN_EVENT_WATCHDOG_uactionN(RHR"(R9RFtactionR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_watchdog_cbsc	C@sCt||||di|d6|d6td|�d6|d6�dS(u)
    Domain I/O Error events handler
    ueventusrcPathudevuVIR_DOMAIN_EVENT_IO_ERROR_uactionureasonN(RHR"(R9RFtsrcpathtdevaliasROtreasonR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_io_error_cb&s
c
@s�d��fd�}t||||dit�|�d6||�d6||�d6|d6g|D]"}	i|	dd	6|	d
d6^qcd6�d
S(u(
    Domain graphics events handler
    uVIR_DOMAIN_EVENT_GRAPHICS_c@s7itdj��|d�d6|dd6|dd6S(uC
        transform address structure into event data piece
        u{0}_ADDRESS_ufamilyunodeuservice(R"R#(taddr(R(s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pytget_address8s ueventuphaseulocaluremoteu
authSchemeiutypeiunameusubjectN(RHR"(
R9RFtphasetlocaltremotetauthtsubjectR8RVtitem((Rs?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_graphics_cb2s

cC@st||||di�dS(u-
    Domain control error events handler
    ueventN(RH(R9RFR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_control_error_cbIsc	C@sCt||||di|d6|d6|d6td|�d6�dS(u+
    Domain disk change events handler
    ueventu
oldSrcPathu
newSrcPathudevuVIR_DOMAIN_EVENT_DISK_ureasonN(RHR"(R9RFtold_srctnew_srctdevRSR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_disk_change_cbPs
c	C@s5t||||di|d6td|�d6�dS(u+
    Domain tray change events handler
    ueventudevuVIR_DOMAIN_EVENT_TRAY_CHANGE_ureasonN(RHR"(R9RFRaRSR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_tray_change_cb\scC@s%t||||didd6�dS(u&
    Domain wakeup events handler
    ueventuunknownureasonN(RH(R9RFRSR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_pmwakeup_cbfscC@s%t||||didd6�dS(u'
    Domain suspend events handler
    ueventuunknownureasonN(RH(R9RFRSR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_pmsuspend_cboscC@s%t||||di|d6�dS(u.
    Domain balloon change events handler
    ueventuactualN(RH(R9RFtactualR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_balloon_change_cbxscC@s%t||||didd6�dS(u,
    Domain disk suspend events handler
    ueventuunknownureasonN(RH(R9RFRSR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_pmsuspend_disk_cb�sc	C@sEt||||di|d6td|�d6td|�d6�dS(u)
    Domain block job events handler
    ueventudiskuVIR_DOMAIN_BLOCK_JOB_TYPE_utypeuVIR_DOMAIN_BLOCK_JOB_ustatusN(RHR"(R9RFtdisktjob_typetstatusR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_block_job_cb�scC@s%t||||di|d6�dS(u.
    Domain device removal events handler
    ueventudevN(RH(R9RFRaR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_device_removed_cb�scC@s%t||||di|d6�dS(u'
    Domain tunable events handler
    ueventuparamsN(RH(R9RFtparamsR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_tunable_cb�sc	C@s>t||||ditd|�d6td|�d6�dS(u/
    Domain agent lifecycle events handler
    ueventu/VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_ustateu0VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_ureasonN(RHR"(R9RFtstateRSR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt _domain_event_agent_lifecycle_cb�scC@s%t||||di|d6�dS(u/
    Domain device addition events handler
    ueventudevN(RH(R9RFRaR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_device_added_cb�scC@s%t||||di|d6�dS(u3
    Domain migration iteration events handler
    ueventu	iterationN(RH(R9RFt	iterationR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt$_domain_event_migration_iteration_cb�scC@s%t||||di|d6�dS(u.
    Domain job completion events handler
    ueventuparamsN(RH(R9RFRnR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_domain_event_job_completed_cb�scC@s%t||||di|d6�dS(u6
    Domain device removal failure events handler
    ueventudevN(RH(R9RFRaR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt&_domain_event_device_removal_failed_cb�sc	C@s5t||||ditd|�d6|d6�dS(u/
    Domain metadata change events handler
    ueventuVIR_DOMAIN_METADATA_utypeunsuriN(RHR"(R9RFtmtypetnsuriR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt _domain_event_metadata_change_cb�scC@s:t||||di|d6|d6|d6|d6�dS(u/
    Domain block threshold events handler
    ueventudevupathu	thresholduexcessN(RH(R9RFRaR.t	thresholdtexcessR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt _domain_event_block_threshold_cb�s
cC@sLt||ii|j�d6|j�d6d6td|�d6dd6�dS(	u*
    Network lifecycle events handler
    unameuuuidunetworkuVIR_NETWORK_EVENT_ueventuunknownudetailN(RCR!RER"(R9tnetR%R&R8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_network_event_lifecycle_cb�s
cC@sLt||ii|j�d6|j�d6d6td|�d6dd6�dS(	u/
    Storage pool lifecycle events handler
    unameuuuidupooluVIR_STORAGE_POOL_EVENT_ueventuunknownudetailN(RCR!RER"(R9tpoolR%R&R8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_pool_event_lifecycle_cb�s
cC@s@t||ii|j�d6|j�d6d6|dd6�dS(u-
    Storage pool refresh events handler
    unameuuuidupoolueventN(RCR!RE(R9RR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_pool_event_refresh_cb
s

cC@s?t||ii|j�d6d6td|�d6dd6�dS(u.
    Node device lifecycle events handler
    unameunodedevuVIR_NODE_DEVICE_EVENT_ueventuunknownudetailN(RCR!R"(R9RaR%R&R8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_nodedev_event_lifecycle_cbs
cC@s3t||ii|j�d6d6|dd6�dS(u+
    Node device update events handler
    unameunodedevueventN(RCR!(R9RaR8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_nodedev_event_update_cb$scC@s?t||ii|j�d6d6td|�d6dd6�dS(u)
    Secret lifecycle events handler
    uuuidusecretuVIR_SECRET_EVENT_ueventuunknownudetailN(RCRER"(R9tsecretR%R&R8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_secret_event_lifecycle_cb0s
cC@s3t||ii|j�d6d6|dd6�dS(u,
    Secret value change events handler
    uuuidusecretueventN(RCRE(R9R�R8((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_secret_event_value_changed_cb=scC@s$tjd|j��|j�dS(uJ
    Close the libvirt connection

    :param cnx: libvirt connection
    uClosing libvirt connection: %sN(tlogtdebugR*tclose(tcnx((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_cleanupIscC@sgx`|j�D]R\}}t|}|jdd�}t||�}x|D]}||�qKWq
WdS(u�
    Unregister all the registered callbacks

    :param cnx: libvirt connection
    :param callback_ids: dictionary mapping a libvirt object type to an ID list
                         of callbacks to deregister
    uReguDeregN(RtREGISTER_FUNCTIONSRR(R�tcallback_idstobjtidst
register_nametderegister_namet
deregistertcallback_id((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_callbacks_cleanupSs

c
C@s�|}|dkr-dj||�j�}ntt|�sStjd||�dStt|�}dj||�}t�j	|d�}|dkr�tj
d|�dSt|t|�}	|	d||i|d6|d6|d6�S(	u�
    Helper function registering a callback

    :param cnx: libvirt connection
    :param tag_prefix: salt event tag prefix to use
    :param obj: the libvirt object name for the event. Needs to
                be one of the REGISTER_FUNCTIONS keys.
    :param event: the event type name.
    :param real_id: the libvirt name of an alternative event id to use or None

    :rtype integer value needed to deregister the callback
    uVIR_{0}_EVENT_ID_{1}u(Skipping "%s/%s" events: libvirt too oldu_{0}_event_{1}_cbuMissing function %s in engineuprefixuobjectueventN(RR#R$thasattrRR�twarningRtglobalsR2terrorR�(
R�R;R�R%treal_idtlibvirt_namet
libvirt_idt
callback_nametcallbacktregister((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_register_callbackcs"

cC@s.||krg||<n||j|�dS(u
    Helper function adding a callback ID to the IDs dict.
    The callback ids dict maps an object to event callback ids.

    :param ids: dict of callback IDs to update
    :param obj: one of the keys of REGISTER_FUNCTIONS
    :param callback_id: the result of _register_callback
    N(R-(R�R�R�((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt_append_callback_id�s	
usalt/engines/libvirt_eventsc
C@sw|dkrdg}nz@ytj�tj|�}tjd|j��i}d|k}x�tj�D]�\}}x|D]w\}}	dj	||f�}
|
|kr�||kr�|r�qnt
|||||	�}|rt|||�qqWqlWt}x,|s2tj
�dk}tjd|�qWWn tk
rV}
tj|
�nXWdt||�t|�XdS(u~
    Listen to libvirt events and forward them to salt.

    :param uri: libvirt URI to listen on.
                Defaults to None to pick the first available local hypervisor
    :param tag_prefix: the begining of the salt event tag to use.
                       Defaults to 'salt/engines/libvirt_events'
    :param filters: the list of event of listen on. Defaults to 'all'
    ualluOpened libvirt uri: %su/iu === in the loop exit_loop %s ===N(RRtvirEventRegisterDefaultImpltopenReadOnlyR�R�R*t
CALLBACK_DEFSRR
R�R�tFalsetvirEventRunDefaultImplt	Exceptiont	exceptionR�R�(R>R;tfiltersR�R�tall_filtersR�t
event_defsR%R�tevent_filtert
registered_idt	exit_loopterr((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pytstart�s4
		
(u	lifecycleN(urebootN(u
rtc_changeN(uwatchdogN(ugraphicsN(uio_erroru#VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON(u
control_errorN(udisk_changeN(utray_changeN(upmwakeupN(u	pmsuspendN(uballoon_changeN(upmsuspend_diskN(udevice_removedN(utunableN(uagent_lifecycleN(udevice_addedN(umigration_iterationN(u
job_completedN(udevice_removal_failedN(umetadata_changeN(ublock_thresholdN(u	lifecycleN((u	lifecycleN(u	lifecycleN(urefreshN(u	lifecycleN(uupdateN(u	lifecycleN(u
value_changedN(=t__doc__t
__future__RRRtloggingtsalt.utils.eventR3tsalt.ext.six.moves.urllib.parseRt	getLoggert__name__R�RtImportErrorRR	R�R�tBLOCK_JOB_IDR�RR"R)RCRHRKRLRNRPRTR]R^RbRcRdReRgRhRlRmRoRqRrRtRuRvRyR|R~R�R�R�R�R�R�R�R�R�R�R�(((s?/usr/lib/python2.7/site-packages/salt/engines/libvirt_events.pyt<module>Bs�

	

		



				*												
												
	
	
							
				
	
		
		
		#	

Zerion Mini Shell 1.0