root / db / DBController.py @ 7bd50624
History | View | Annotate | Download (1.1 kB)
1 |
#
|
---|---|
2 |
# Bill Allocator - Administration script
|
3 |
#
|
4 |
# Run all the time, and wait for messages from ganeti, then update the database
|
5 |
#
|
6 |
# Copyright © 2010 Greek Research and Technology Network
|
7 |
#
|
8 |
|
9 |
import zmq |
10 |
|
11 |
from db.models import * |
12 |
|
13 |
def main(): |
14 |
context = zmq.Context() |
15 |
|
16 |
sock = context.socket(zmq.SUB) |
17 |
sock.connect('tcp://127.0.0.1:6666')
|
18 |
|
19 |
# accept all messages
|
20 |
sock.setsockopt(zmq.SUBSCRIBE, '')
|
21 |
|
22 |
while True: |
23 |
message = sock.recv() |
24 |
|
25 |
# do something
|
26 |
if message == 'start': |
27 |
all_machines = VirtualMachine.objects.all() |
28 |
for vm in all_machines: |
29 |
vm.state = 1
|
30 |
vm.save() |
31 |
print "Changed stated of vm with name %s to RUNNING" % ( vm.name, ) |
32 |
elif message == 'stop': |
33 |
all_machines = VirtualMachine.objects.all() |
34 |
for vm in all_machines: |
35 |
vm.state = 0
|
36 |
vm.save() |
37 |
print "Changed stated of vm with name %s to STOPPED" % ( vm.name, ) |
38 |
elif message == 'quit': |
39 |
print "Killing the bigeye" |
40 |
break
|
41 |
|
42 |
sock.close() |