Statistics
| Branch: | Tag: | Revision:

root / aquarium / bigeye.py @ 87ace70f

History | View | Annotate | Download (841 Bytes)

1
#
2
# Run all the time, and wait for messages from ganeti, then update the database
3
#
4

    
5
import zmq
6
from aquarium.models import *
7

    
8
def main():
9
        context = zmq.Context()
10
        
11
        sock = context.socket(zmq.SUB)
12
        sock.connect('tcp://127.0.0.1:6666')
13
        
14
        # accept all messages
15
        sock.setsockopt(zmq.SUBSCRIBE, '')
16
        
17
        while True:
18
                message = sock.recv()
19
                
20
                # do something
21
                if message == 'start':
22
                        all_machines = VirtualMachine.objects.all()
23
                        for vm in all_machines:
24
                                vm.state = 1
25
                                vm.save()
26
                                print "Changed stated of vm with name %s to RUNNING" % ( vm.name, )
27
                elif message == 'stop':
28
                        all_machines = VirtualMachine.objects.all()
29
                        for vm in all_machines:
30
                                vm.state = 0
31
                                vm.save()
32
                                print "Changed stated of vm with name %s to STOPPED" % ( vm.name, )
33
                elif message == 'quit':
34
                        print "Killing the bigeye"
35
                        break
36
        
37
        sock.close()