From nobody Wed Nov 27 21:41:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537536967160839.6072623438494; Fri, 21 Sep 2018 06:36:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 532EE80479; Fri, 21 Sep 2018 13:36:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1053B3091391; Fri, 21 Sep 2018 13:36:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9A1ED4A479; Fri, 21 Sep 2018 13:36:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LDZY8k022159 for ; Fri, 21 Sep 2018 09:35:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6273280F7B; Fri, 21 Sep 2018 13:35:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59A0E80F7A for ; Fri, 21 Sep 2018 13:35:31 +0000 (UTC) Received: from mail.univention.de (mail.univention.de [82.198.197.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F1D4307D982 for ; Fri, 21 Sep 2018 13:35:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by solig.knut.univention.de (Postfix) with ESMTP id 5689732A7C83 for ; Fri, 21 Sep 2018 15:35:28 +0200 (CEST) Received: from mail.univention.de ([127.0.0.1]) by localhost (solig.knut.univention.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s_7OCPIfU-9R; Fri, 21 Sep 2018 15:35:27 +0200 (CEST) Received: from fixa.knut.univention.de (mail.univention.de [82.198.197.8]) by solig.knut.univention.de (Postfix) with ESMTPSA id 7D1A732A7BC2; Fri, 21 Sep 2018 15:35:18 +0200 (CEST) Received: by fixa.knut.univention.de (Postfix, from userid 2260) id D1B07161E7D; Fri, 21 Sep 2018 15:35:17 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.10.1 (20141025) (Debian) at knut.univention.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: Philipp Hahn To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 15:35:17 +0200 Message-Id: <4bcd6734fa9a6ad3cc50af33236d4415cdcdf7f1.1537536402.git.hahn@univention.de> In-Reply-To: References: In-Reply-To: References: <1ce5060e-4249-0246-89d0-b7e01f8dd30a@redhat.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 214 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 21 Sep 2018 13:35:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 21 Sep 2018 13:35:30 +0000 (UTC) for IP:'82.198.197.8' DOMAIN:'mail.univention.de' HELO:'mail.univention.de' FROM:'hahn@univention.de' RCPT:'' X-RedHat-Spam-Score: -0.011 (RCVD_IN_DNSWL_NONE, SPF_PASS) 82.198.197.8 mail.univention.de 82.198.197.8 mail.univention.de X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH libvirt-python v2 22/22] event-test.py: Fix blanks X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 21 Sep 2018 13:36:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Closer to pep8 Signed-off-by: Philipp Hahn --- examples/event-test.py | 97 ++++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/examples/event-test.py b/examples/event-test.py index 1e94838..540bf9b 100755 --- a/examples/event-test.py +++ b/examples/event-test.py @@ -30,11 +30,14 @@ import threading event_impl =3D "poll" =20 do_debug =3D False + + def debug(msg): global do_debug if do_debug: print(msg) =20 + # # This general purpose event loop will support waiting for file handle # I/O and errors events, as well as scheduling repeatable timers with @@ -100,7 +103,6 @@ class virEventLoopPoll: self.cb(self.timer, self.opaque) =20 - def __init__(self): self.poll =3D select.poll() self.pipetrick =3D os.pipe() @@ -126,10 +128,9 @@ class virEventLoopPoll: # with the event loop for input events. When we need to force # the main thread out of a poll() sleep, we simple write a # single byte of data to the other end of the pipe. - debug("Self pipe watch %d write %d" %(self.pipetrick[0], self.pipe= trick[1])) + debug("Self pipe watch %d write %d" % (self.pipetrick[0], self.pip= etrick[1])) self.poll.register(self.pipetrick[0], select.POLLIN) =20 - # Calculate when the next timeout is due to occur, returning # the absolute timestamp for the next timeout, or 0 if there is # no timeout due @@ -159,7 +160,6 @@ class virEventLoopPoll: return h return None =20 - # This is the heart of the event loop, performing one single # iteration. It asks when the next timeout is due, and then # calculates the maximum amount of time it is able to sleep @@ -235,7 +235,6 @@ class virEventLoopPoll: finally: self.runningPoll =3D False =20 - # Actually run the event loop forever def run_loop(self): self.quit =3D False @@ -247,7 +246,6 @@ class virEventLoopPoll: self.pendingWakeup =3D True os.write(self.pipetrick[1], 'c'.encode("UTF-8")) =20 - # Registers a new file handle 'fd', monitoring for 'events' (libvirt # event constants), firing the callback cb() when an event occurs. # Returns a unique integer identier for this handle, that should be @@ -301,7 +299,7 @@ class virEventLoopPoll: h.set_interval(interval) self.interrupt() =20 - debug("Update timer %d interval %d" % (timerID, interval)) + debug("Update timer %d interval %d" % (timerID, interval)) break =20 # Stop monitoring for events on the file handle @@ -383,26 +381,32 @@ def virEventAddHandleImpl(fd, events, cb, opaque): global eventLoop return eventLoop.add_handle(fd, events, cb, opaque) =20 + def virEventUpdateHandleImpl(handleID, events): global eventLoop return eventLoop.update_handle(handleID, events) =20 + def virEventRemoveHandleImpl(handleID): global eventLoop return eventLoop.remove_handle(handleID) =20 + def virEventAddTimerImpl(interval, cb, opaque): global eventLoop return eventLoop.add_timer(interval, cb, opaque) =20 + def virEventUpdateTimerImpl(timerID, interval): global eventLoop return eventLoop.update_timer(timerID, interval) =20 + def virEventRemoveTimerImpl(timerID): global eventLoop return eventLoop.remove_timer(timerID) =20 + # This tells libvirt what event loop implementation it # should use def virEventLoopPollRegister(): @@ -413,20 +417,24 @@ def virEventLoopPollRegister(): virEventUpdateTimerImpl, virEventRemoveTimerImpl) =20 + # Directly run the event loop in the current thread def virEventLoopPollRun(): global eventLoop eventLoop.run_loop() =20 + def virEventLoopAIORun(loop): import asyncio asyncio.set_event_loop(loop) loop.run_forever() =20 + def virEventLoopNativeRun(): while True: libvirt.virEventRunDefaultImpl() =20 + # Spawn a background thread to run the event loop def virEventLoopPollStart(): global eventLoopThread @@ -435,6 +443,7 @@ def virEventLoopPollStart(): eventLoopThread.setDaemon(True) eventLoopThread.start() =20 + def virEventLoopAIOStart(): global eventLoopThread import libvirtaio @@ -445,6 +454,7 @@ def virEventLoopAIOStart(): eventLoopThread.setDaemon(True) eventLoopThread.start() =20 + def virEventLoopNativeStart(): global eventLoopThread libvirt.virEventRegisterDefaultImpl() @@ -509,10 +519,13 @@ def myDomainEventCallback(conn, dom, event, detail, o= paque): =20 =20 def myDomainEventRebootCallback(conn, dom, opaque): - print("myDomainEventRebootCallback: Domain %s(%s)" % (dom.name(), dom.= ID())) + print("myDomainEventRebootCallback: Domain %s(%s)" % ( + dom.name(), dom.ID())) + =20 def myDomainEventRTCChangeCallback(conn, dom, utcoffset, opaque): - print("myDomainEventRTCChangeCallback: Domain %s(%s) %d" % (dom.name()= , dom.ID(), utcoffset)) + print("myDomainEventRTCChangeCallback: Domain %s(%s) %d" % ( + dom.name(), dom.ID(), utcoffset)) =20 =20 def myDomainEventWatchdogCallback(conn, dom, action, opaque): @@ -521,7 +534,8 @@ def myDomainEventWatchdogCallback(conn, dom, action, op= aque): =20 =20 def myDomainEventIOErrorCallback(conn, dom, srcpath, devalias, action, opa= que): - print("myDomainEventIOErrorCallback: Domain %s(%s) %s %s %d" % (dom.na= me(), dom.ID(), srcpath, devalias, action)) + print("myDomainEventIOErrorCallback: Domain %s(%s) %s %s %d" % ( + dom.name(), dom.ID(), srcpath, devalias, action)) =20 =20 def myDomainEventIOErrorReasonCallback(conn, dom, srcpath, devalias, actio= n, reason, opaque): @@ -535,7 +549,8 @@ def myDomainEventGraphicsCallback(conn, dom, phase, loc= alAddr, remoteAddr, authS =20 =20 def myDomainEventControlErrorCallback(conn, dom, opaque): - print("myDomainEventControlErrorCallback: Domain %s(%s)" % (dom.name()= , dom.ID())) + print("myDomainEventControlErrorCallback: Domain %s(%s)" % ( + dom.name(), dom.ID())) =20 =20 def myDomainEventBlockJobCallback(conn, dom, disk, type, status, opaque): @@ -555,18 +570,27 @@ def myDomainEventTrayChangeCallback(conn, dom, devAli= as, reason, opaque): =20 def myDomainEventPMWakeupCallback(conn, dom, reason, opaque): print("myDomainEventPMWakeupCallback: Domain %s(%s) system pmwakeup" %= ( - dom.name(), dom.ID())) + dom.name(), dom.ID())) + + def myDomainEventPMSuspendCallback(conn, dom, reason, opaque): print("myDomainEventPMSuspendCallback: Domain %s(%s) system pmsuspend"= % ( - dom.name(), dom.ID())) + dom.name(), dom.ID())) + + def myDomainEventBalloonChangeCallback(conn, dom, actual, opaque): - print("myDomainEventBalloonChangeCallback: Domain %s(%s) %d" % (dom.na= me(), dom.ID(), actual)) + print("myDomainEventBalloonChangeCallback: Domain %s(%s) %d" % ( + dom.name(), dom.ID(), actual)) + + def myDomainEventPMSuspendDiskCallback(conn, dom, reason, opaque): print("myDomainEventPMSuspendDiskCallback: Domain %s(%s) system pmsusp= end_disk" % ( - dom.name(), dom.ID())) + dom.name(), dom.ID())) + + def myDomainEventDeviceRemovedCallback(conn, dom, dev, opaque): print("myDomainEventDeviceRemovedCallback: Domain %s(%s) device remove= d: %s" % ( - dom.name(), dom.ID(), dev)) + dom.name(), dom.ID(), dev)) =20 =20 def myDomainEventBlockJob2Callback(conn, dom, disk, type, status, opaque): @@ -575,7 +599,8 @@ def myDomainEventBlockJob2Callback(conn, dom, disk, typ= e, status, opaque): =20 =20 def myDomainEventTunableCallback(conn, dom, params, opaque): - print("myDomainEventTunableCallback: Domain %s(%s) %s" % (dom.name(), = dom.ID(), params)) + print("myDomainEventTunableCallback: Domain %s(%s) %s" % ( + dom.name(), dom.ID(), params)) =20 =20 def myDomainEventAgentLifecycleCallback(conn, dom, state, reason, opaque): @@ -585,21 +610,33 @@ def myDomainEventAgentLifecycleCallback(conn, dom, st= ate, reason, opaque): =20 def myDomainEventDeviceAddedCallback(conn, dom, dev, opaque): print("myDomainEventDeviceAddedCallback: Domain %s(%s) device added: %= s" % ( - dom.name(), dom.ID(), dev)) + dom.name(), dom.ID(), dev)) + + def myDomainEventMigrationIteration(conn, dom, iteration, opaque): print("myDomainEventMigrationIteration: Domain %s(%s) started migratio= n iteration %d" % ( - dom.name(), dom.ID(), iteration)) + dom.name(), dom.ID(), iteration)) + + def myDomainEventJobCompletedCallback(conn, dom, params, opaque): - print("myDomainEventJobCompletedCallback: Domain %s(%s) %s" % (dom.nam= e(), dom.ID(), params)) + print("myDomainEventJobCompletedCallback: Domain %s(%s) %s" % ( + dom.name(), dom.ID(), params)) + + def myDomainEventDeviceRemovalFailedCallback(conn, dom, dev, opaque): print("myDomainEventDeviceRemovalFailedCallback: Domain %s(%s) failed = to remove device: %s" % ( - dom.name(), dom.ID(), dev)) + dom.name(), dom.ID(), dev)) + + def myDomainEventMetadataChangeCallback(conn, dom, mtype, nsuri, opaque): print("myDomainEventMetadataChangeCallback: Domain %s(%s) changed meta= data mtype=3D%d nsuri=3D%s" % ( - dom.name(), dom.ID(), mtype, nsuri)) + dom.name(), dom.ID(), mtype, nsuri)) + + def myDomainEventBlockThresholdCallback(conn, dom, dev, path, threshold, e= xcess, opaque): print("myDomainEventBlockThresholdCallback: Domain %s(%s) block device= %s(%s) threshold %d exceeded by %d" % ( - dom.name(), dom.ID(), dev, path, threshold, excess)) + dom.name(), dom.ID(), dev, path, threshold, excess)) + =20 ########################################################################## # Network events @@ -638,6 +675,7 @@ def myStoragePoolEventLifecycleCallback(conn, pool, eve= nt, detail, opaque): def myStoragePoolEventRefreshCallback(conn, pool, opaque): print("myStoragePoolEventRefreshCallback: Storage pool %s" % pool.name= ()) =20 + ########################################################################## # Node device events ########################################################################## @@ -655,6 +693,7 @@ def myNodeDeviceEventLifecycleCallback(conn, dev, event= , detail, opaque): def myNodeDeviceEventUpdateCallback(conn, dev, opaque): print("myNodeDeviceEventUpdateCallback: Node device %s" % dev.name()) =20 + ########################################################################## # Secret events ########################################################################## @@ -672,6 +711,7 @@ def mySecretEventLifecycleCallback(conn, secret, event,= detail, opaque): def mySecretEventValueChanged(conn, secret, opaque): print("mySecretEventValueChanged: Secret %s" % secret.UUIDString()) =20 + ########################################################################## # Set up and run the program ########################################################################## @@ -695,12 +735,13 @@ def usage(): print(" --loop=3DTYPE, -l Choose event-loop-implementation (native= , poll, asyncio)") print(" --timeout=3DSECS Quit after SECS seconds running") =20 + def main(): try: opts, args =3D getopt.getopt(sys.argv[1:], "hdl:", ["help", "debug= ", "loop=3D", "timeout=3D"]) except getopt.GetoptError as err: # print help information and exit: - print(str(err)) # will print something like "option -a not recogni= zed" + print(str(err)) # will print something like "option -a not recogn= ized" usage() sys.exit(2) timeout =3D None @@ -736,16 +777,19 @@ def main(): =20 # Close connection on exit (to test cleanup paths) old_exitfunc =3D getattr(sys, 'exitfunc', None) + def exit(): print("Closing " + vc.getURI()) if run: vc.close() - if (old_exitfunc): old_exitfunc() + if (old_exitfunc): + old_exitfunc() + sys.exitfunc =3D exit =20 vc.registerCloseCallback(myConnectionCloseCallback, None) =20 - #Add 2 lifecycle callbacks to prove this works with more than just one + # Add 2 lifecycle callbacks to prove this works with more than just one vc.domainEventRegister(myDomainEventCallback, 1) domcallbacks =3D [ vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECY= CLE, myDomainEventCallback, 2), @@ -829,5 +873,6 @@ def main(): # Allow delayed event loop cleanup to run, just for sake of testing time.sleep(2) =20 + if __name__ =3D=3D "__main__": main() --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list