1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pymongo
from bson.son import SON
import sys
import inspect
import kpov_random_helpers
import settings
import guestfs
import glob
if __name__ == '__main__':
if len(sys.argv) != 3:
print "Usage: {0} task_name task_source.py"
print "The task_source should contain two functions - task(param1, param2, ...) and task_check(res, params)"
task_id = sys.argv[1]
fname = sys.argv[2]
db = pymongo.Connection(settings.DB_HOST).kpov
try:
db.authenticate(settings.USERNAME, settings.PASSWORD)
except Exception, e:
print "Not authenticated:"+str(e)
#no auth or auth config?
source = open(fname).read()
code = compile(source, fname, 'exec')
# the following line creates:
# task, task_check, gen_params, prepare_disks, computers, params_meta.
exec(code)
task_source = inspect.getsource(task)
task_check_source = inspect.getsource(task_check)
gen_params_source = inspect.getsource(gen_params)
prepare_disks_source = inspect.getsource(prepare_disks)
x = params_meta.keys() # check for existence
db.computers_meta.remove({'task_id': task_id})
auto_networks = set([None])
for k, v in computers.iteritems():
for n in v.get('networks_interfaces', []):
auto_networks.add(n.get('network', None))
db.computers_meta.update({'task_id': task_id, 'name': k}, {'$set': v}, upsert=True)
auto_networks.remove(None)
db.networks.remove({'task_id': task_id})
try:
net_list = networks.iteritems()
except:
net_list = [(k, {'public': False}) for k in auto_networks]
for k, v in net_list:
db.networks.update({'task_id': task_id, 'name': k}, {'$set': v}, upsert=True)
db.task_checkers.update({'task_id': task_id}, {'$set': {'source': task_check_source}}, upsert=True)
db.tasks.update({'task_id': task_id},{'$set': {'source': task_source}}, upsert=True)
db.prepare_disks.update({'task_id': task_id}, {'$set': {'source': prepare_disks_source}}, upsert=True)
db.gen_params.update({'task_id': task_id}, {'$set': {'source': gen_params_source}}, upsert=True)
db.task_params_meta.update({'task_id': task_id}, {'$set': {'params': params_meta}}, upsert=True)
|