~ubuntu-branches/ubuntu/natty/libvirt/natty

« back to all changes in this revision

Viewing changes to examples/domain-events/events-python/event-test.py

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-02-23 09:05:46 UTC
  • mfrom: (1.2.8 upstream) (3.4.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110223090546-4pwmrrt7h51hr3l3
Tags: 0.8.8-1ubuntu1
* Resynchronize and merge from Debian unstable. Remaining changes:
  - debian/patches:
    * 9000-delayed_iff_up_bridge.patch
    * 9001-dont_clobber_existing_bridges.patch
    * 9002-better_default_uri_virsh.patch
    * 9003-better-default-arch.patch
    * 9004-libvirtd-group-name.patch
    * 9005-increase-unix-socket-timeout.patch
    * 9006-default-config-test-case.patch
    * 9007-fix-daemon-conf-ftbfs.patch
    * 9011-move-ebtables-script.patch
    * 9014-skip-nodeinfotest.patch
    * 9020-lp545795.patch
    * 9021-fix-uint64_t.patch
  - debian/patches/series:
    * Disable qemu-disable-network.diff.patch
  - debian/control:
    * set ubuntu maintainer
    * Build-Depends:
      - swap libxen to libxen3, qemu to qemu-kvm, and open-iscsi to
        open-iscsi-utils in Build-Depends
      - remove virtualbox Build-Depends
      - add libxml2 and libapparmor-dev Build-Depends
    * convert Vcs-Git to Xs-Debian-Vcs-Git
    * libvirt-bin Depends: move netcat-openbsd, bridge-utils, dnsmasq-base
      (>= 2.46-1), and iptables from Recommends to Depends
    * libvirt-bin Recommends: move qemu to Suggests
    * libvirt-bin Suggests: add apparmor
    * libvirt0 Recommands: move lvm2 to Suggests
  - keep debian/libvirt-bin.apport
  - keep debian/libvirt-bin.cron.daily
  - debian/libvirt-bin.dirs:
    * add apparmor, cron.daily, and apport dirs
  - debian/libvirt-bin.examples:
    * add debian/libvirt-suspendonreboot
  - debian/libvirt-bin.install:
    * add /etc/apparmor.d files
    * add apport hook
  - debian/libvirt-bin.manpages:
    * add debian/libvirt-migrate-qemu-disks.1
  - debian/libvirt-bin.postinst:
    * replace libvirt groupname with libvirtd
    * add each admin user to libvirtd group
    * call apparmor_parser on usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
    * call 'libvirt-migrate-qemu-disks -a' after
      libvirt-bin has started if migrating from
      older than 0.8.3-1ubuntu1
  - debian/libvirt-bin.postrm:
    * replace libvirt groupname with libvirtd
    * remove usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
  - keep added files under debian/:
    * libvirt-bin.upstart
    * libvirt-migrate-qemu-disks
    * libvirt-migrate-qemu-disks.1
    * libvirt-suspendonreboot
    * apparmor profiles
  - debian/README.Debian:
    * add 'Apparmor Profile' section
    * add 'Disk migration' section
  - debian/rules:
    * don't build with vbox since virtualbox-ose is in universe
    * add --with-apparmor to DEB_CONFIGURE_EXTRA_FLAGS
    * set DEB_DH_INSTALLINIT_ARGS to '--upstart-only'
    * set DEB_MAKE_CHECK_TARGET to 'check'
    * remove unneeded binary-install/libvirt-bin:: and clean::
      sections (they only deal with sysvinit stuff)
    * add build/libvirt-bin:: section to install
      - apparmor files
      - apport hooks
      - libvirt-migrate-qemu-disks
* The following Ubuntu packaging changes occurred during the divergence
  between Debian and Ubuntu. These changes are not new, but included here
  for completeness: (0.8.5-0ubuntu1 - 0.8.5-0ubuntu5):
  - Have upstart job source /etc/default/libvirt-bin.  This is only a
    temporary fix until upstart provides proper default override support
    through /etc/init/libvirt-bin.override (or any other mechanism).
    (LP: 708172)
  - debian/apparmor/usr.sbin.libvirtd: use PUx instead of Ux for executables
    (LP: 573315)
  - Rebuild with python 2.7 as the python default.
  - debian/libvirt-bin.cron.daily: use shell globbing to enumerate xml files.
    Based on patch thanks to Henryk Plötz (LP: 655176)
* Dropped the following patches included/fixed upstream:
  - 9010-dont-disable-ipv6.patch
  - 9022-build-cleanup-declaration-of-xen-tests.patch
  - 9023-vah-require-uuid.patch
  - 9009-autodetect-nc-params.patch
    * rolled into Debian's
      Autodetect-if-the-remote-nc-command-supports-the-q-o.patch
* Updated the following patches:
  - 9011-move-ebtables-script.patch:
    * LOCALSTATEDIR is defined in configmake.h
  - 9000-9006: added DEP-3 tags
  - 9002-better_default_uri_virsh.patch: updated (context changed)
* New patches:
  - 9022-drop-booton-when-kernel-specified.patch (LP: #720426)
  - 9023-fix-lxc-console-hangup.patch (LP: #668369)
  - 9024-skip-broken-commandtest.patch
* debian/patches/series:
  - don't apply Disable-CHECKSUM-rule.patch: our iptables can do this
  - don't apply Debian-specific Debianize-libvirt-guests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
import time
16
16
import threading
17
17
 
 
18
do_debug = False
 
19
def debug(msg):
 
20
    global do_debug
 
21
    if do_debug:
 
22
        print msg
 
23
 
18
24
#
19
25
# This general purpose event loop will support waiting for file handle
20
26
# I/O and errors events, as well as scheduling repeatable timers with
83
89
                    self.opaque[1])
84
90
 
85
91
 
86
 
    def __init__(self, debug=False):
87
 
        self.debugOn = debug
 
92
    def __init__(self):
88
93
        self.poll = select.poll()
89
94
        self.pipetrick = os.pipe()
 
95
        self.pendingWakeup = False
 
96
        self.runningPoll = False
90
97
        self.nextHandleID = 1
91
98
        self.nextTimerID = 1
92
99
        self.handles = []
106
113
        # with the event loop for input events. When we need to force
107
114
        # the main thread out of a poll() sleep, we simple write a
108
115
        # single byte of data to the other end of the pipe.
109
 
        self.debug("Self pipe watch %d write %d" %(self.pipetrick[0], self.pipetrick[1]))
 
116
        debug("Self pipe watch %d write %d" %(self.pipetrick[0], self.pipetrick[1]))
110
117
        self.poll.register(self.pipetrick[0], select.POLLIN)
111
118
 
112
 
    def debug(self, msg):
113
 
        if self.debugOn:
114
 
            print msg
115
 
 
116
119
 
117
120
    # Calculate when the next timeout is due to occurr, returning
118
121
    # the absolute timestamp for the next timeout, or 0 if there is
165
168
    # these pointless repeated tiny sleeps.
166
169
    def run_once(self):
167
170
        sleep = -1
 
171
        self.runningPoll = True
168
172
        next = self.next_timeout()
169
 
        self.debug("Next timeout due at %d" % next)
 
173
        debug("Next timeout due at %d" % next)
170
174
        if next > 0:
171
175
            now = int(time.time() * 1000)
172
176
            if now >= next:
174
178
            else:
175
179
                sleep = (next - now) / 1000.0
176
180
 
177
 
        self.debug("Poll with a sleep of %d" % sleep)
 
181
        debug("Poll with a sleep of %d" % sleep)
178
182
        events = self.poll.poll(sleep)
179
183
 
180
184
        # Dispatch any file handle events that occurred
183
187
            # telling us to wakup. if so, then discard
184
188
            # the data just continue
185
189
            if fd == self.pipetrick[0]:
 
190
                self.pendingWakeup = False
186
191
                data = os.read(fd, 1)
187
192
                continue
188
193
 
189
194
            h = self.get_handle_by_fd(fd)
190
195
            if h:
191
 
                self.debug("Dispatch fd %d handle %d events %d" % (fd, h.get_id(), revents))
 
196
                debug("Dispatch fd %d handle %d events %d" % (fd, h.get_id(), revents))
192
197
                h.dispatch(self.events_from_poll(revents))
193
198
 
194
199
        now = int(time.time() * 1000)
201
206
            # Deduct 20ms, since schedular timeslice
202
207
            # means we could be ever so slightly early
203
208
            if now >= (want-20):
204
 
                self.debug("Dispatch timer %d now %s want %s" % (t.get_id(), str(now), str(want)))
 
209
                debug("Dispatch timer %d now %s want %s" % (t.get_id(), str(now), str(want)))
205
210
                t.set_last_fired(now)
206
211
                t.dispatch()
207
212
 
 
213
        self.runningPoll = False
 
214
 
208
215
 
209
216
    # Actually the event loop forever
210
217
    def run_loop(self):
213
220
            self.run_once()
214
221
 
215
222
    def interrupt(self):
216
 
        os.write(self.pipetrick[1], 'c')
 
223
        if self.runningPoll and not self.pendingWakeup:
 
224
            self.pendingWakeup = True
 
225
            os.write(self.pipetrick[1], 'c')
217
226
 
218
227
 
219
228
    # Registers a new file handle 'fd', monitoring  for 'events' (libvirt
230
239
        self.poll.register(fd, self.events_to_poll(events))
231
240
        self.interrupt()
232
241
 
233
 
        self.debug("Add handle %d fd %d events %d" % (handleID, fd, events))
 
242
        debug("Add handle %d fd %d events %d" % (handleID, fd, events))
234
243
 
235
244
        return handleID
236
245
 
247
256
        self.timers.append(h)
248
257
        self.interrupt()
249
258
 
250
 
        self.debug("Add timer %d interval %d" % (timerID, interval))
 
259
        debug("Add timer %d interval %d" % (timerID, interval))
251
260
 
252
261
        return timerID
253
262
 
260
269
            self.poll.register(h.get_fd(), self.events_to_poll(events))
261
270
            self.interrupt()
262
271
 
263
 
            self.debug("Update handle %d fd %d events %d" % (handleID, h.get_fd(), events))
 
272
            debug("Update handle %d fd %d events %d" % (handleID, h.get_fd(), events))
264
273
 
265
274
    # Change the periodic frequency of the timer
266
275
    def update_timer(self, timerID, interval):
269
278
                h.set_interval(interval);
270
279
                self.interrupt()
271
280
 
272
 
                self.debug("Update timer %d interval %d"  % (timerID, interval))
 
281
                debug("Update timer %d interval %d"  % (timerID, interval))
273
282
                break
274
283
 
275
284
    # Stop monitoring for events on the file handle
278
287
        for h in self.handles:
279
288
            if h.get_id() == handleID:
280
289
                self.poll.unregister(h.get_fd())
281
 
                self.debug("Remove handle %d fd %d" % (handleID, h.get_fd()))
 
290
                debug("Remove handle %d fd %d" % (handleID, h.get_fd()))
282
291
            else:
283
292
                handles.append(h)
284
293
        self.handles = handles
290
299
        for h in self.timers:
291
300
            if h.get_id() != timerID:
292
301
                timers.append(h)
293
 
                self.debug("Remove timer %d" % timerID)
 
302
                debug("Remove timer %d" % timerID)
294
303
        self.timers = timers
295
304
        self.interrupt()
296
305
 
329
338
 
330
339
# This single global instance of the event loop wil be used for
331
340
# monitoring libvirt events
332
 
eventLoop = virEventLoopPure(debug=False)
 
341
eventLoop = virEventLoopPure()
333
342
 
334
343
# This keeps track of what thread is running the event loop,
335
344
# (if it is run in a background thread)