def virtEvent(uri):
    # Run a background thread with the event loop
    virEventLoopNativeStart()

    # Connect libbert - If be disconnected, reprocess.
    while True:
        vc = libvirt.openReadOnly(uri)

        # Event callback settings
        callback_ids = []
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
                                        myDomainEventCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_REBOOT,
                                        myDomainEventRebootCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
                                        myDomainEventRTCChangeCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR,
                                        myDomainEventIOErrorCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG,
                                        myDomainEventWatchdogCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS,
                                        myDomainEventGraphicsCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE,
                                        myDomainEventDiskChangeCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON,
                                        myDomainEventIOErrorReasonCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_CONTROL_ERROR,
                                        myDomainEventGenericCallback, None)
        callback_ids.append(cid)

        # Connection monitoring.
        vc.setKeepAlive(5, 3)
        while vc.isAlive() == 1:
            time.sleep(1)

        # If connection between libvirtd was lost, clear callback connection.
        evf.warn_log('Libvirt Connection Closed Unexpectedly.')
        for cid in callback_ids:
            try:
                vc.domainEventDeregisterAny(cid)
            except:
                pass
        vc.close()
        del vc
        time.sleep(3)
Ejemplo n.º 2
0
def virtEvent(uri):
    # Run a background thread with the event loop
    virEventLoopNativeStart()

    # Connect libbert - If be disconnected, reprocess.
    while True:
        vc = libvirt.openReadOnly(uri)

        # Event callback settings
        callback_ids = []
        cid = vc.domainEventRegisterAny(None,
                                        libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
                                        myDomainEventCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None,
                                        libvirt.VIR_DOMAIN_EVENT_ID_REBOOT,
                                        myDomainEventRebootCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None,
                                        libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
                                        myDomainEventRTCChangeCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None,
                                        libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR,
                                        myDomainEventIOErrorCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None,
                                        libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG,
                                        myDomainEventWatchdogCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(None,
                                        libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS,
                                        myDomainEventGraphicsCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(
            None, libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE,
            myDomainEventDiskChangeCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(
            None, libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON,
            myDomainEventIOErrorReasonCallback, None)
        callback_ids.append(cid)
        cid = vc.domainEventRegisterAny(
            None, libvirt.VIR_DOMAIN_EVENT_ID_CONTROL_ERROR,
            myDomainEventGenericCallback, None)
        callback_ids.append(cid)

        # Connection monitoring.
        vc.setKeepAlive(5, 3)
        while vc.isAlive() == 1:
            time.sleep(1)

        # If connection between libvirtd was lost, clear callback connection.
        evf.warn_log('Libvirt Connection Closed Unexpectedly.')
        for cid in callback_ids:
            try:
                vc.domainEventDeregisterAny(cid)
            except:
                pass
        vc.close()
        del vc
        time.sleep(3)
Ejemplo n.º 3
0
def errHandler(ctxt, err):
    global errno
    #print "libvirt Error(%s)" % (err[2])
    evf.warn_log(err[2])
    errno = err
def errHandler(ctxt, err):
    global errno
    # print "libvirt Error(%s)" % (err[2])
    evf.warn_log(err[2])
    errno = err