Statistics
| Branch: | Tag: | Revision:

root / db / DBController.py @ fcbc5bb3

History | View | Annotate | Download (1 kB)

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

    
5
import zmq
6

    
7
from db.models import *
8

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