File: monitor.py

package info (click to toggle)
python-pyxs 0.4.2~git20190115.97f14313-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: python: 1,196; makefile: 93
file content (24 lines) | stat: -rw-r--r-- 687 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-
"""
    monitor
    ~~~~~~~

    A simple monitor, which fires a callback each time a new domains
    is introduced or released from XenStore.

    :copyright: (c) 2011 by Selectel, see AUTHORS for more details.
"""

import pyxs

with pyxs.monitor() as m:
    m.watch(b"@introduceDomain", b"unused")
    m.watch(b"@releaseDomain", b"unused")

    for wpath, _token in m.wait():
        # Funny thing is -- XenStored doesn't send us domid of the
        # event target, so we have to get it manually, via ``xc``.
        if wpath == b"@introduceDomain":
            print("Hey, we got a new domain here!")
        else:
            print("Ooops, we lost him ...")