root / ganeti / events.py @ b80d0a1e
History | View | Annotate | Download (815 Bytes)
1 |
#!/usr/bin/env python
|
---|---|
2 |
#
|
3 |
# Copyright (c) 2010 Greek Research and Technology Network
|
4 |
#
|
5 |
""" Receive Ganeti events over 0mq """
|
6 |
|
7 |
import sys |
8 |
import zmq |
9 |
import time |
10 |
import json |
11 |
import logging |
12 |
|
13 |
GANETI_ZMQ_PUBLISHER = "tcp://ganeti-master:5801" # FIXME: move to settings.py |
14 |
|
15 |
def main(): |
16 |
# Connect to ganeti-0mqd
|
17 |
zmqc = zmq.Context() |
18 |
subscriber = zmqc.socket(zmq.SUB) |
19 |
subscriber.setsockopt(zmq.IDENTITY, "DBController")
|
20 |
subscriber.setsockopt(zmq.SUBSCRIBE, "")
|
21 |
subscriber.connect(GANETI_ZMQ_PUBLISHER) |
22 |
|
23 |
print "Connected to %s." % GANETI_ZMQ_PUBLISHER |
24 |
|
25 |
# Get updates, expect random Ctrl-C death
|
26 |
while True: |
27 |
data = subscriber.recv() |
28 |
print data
|
29 |
|
30 |
if __name__ == "__main__": |
31 |
logging.basicConfig(level=logging.DEBUG) |
32 |
sys.exit(main()) |
33 |
|
34 |
# vim: set ts=4 sts=4 sw=4 et ai :
|