smarter way to write configs, provide structure and map to avail. resources (testboxe...
[tests.git] / system / config_1vservers.py
1 import utils
2 import os.path
3 from TestPool import TestPool
4
5 # the pool of IP addresses available - from 01 to 09
6 onelab_plcs_pool = [ 
7     ( 'vplc%02d.inria.fr'%i, '138.96.250.13%d'%i, 'ab:cd:ef:00:00:%02d'%i) for i in range(1,10) ]
8
9 # let's be flexible
10 def locate (user_provided):
11     global available
12     for (hostname,ip,mac) in available:
13         if hostname.find(user_provided) >=0 or ip.find(user_provided) >=0:
14             return (hostname,ip)
15
16 def config (plcs,options):
17     
18     utils.header ("Turning configuration into a vserver-based one for onelab")
19
20     test_pool = TestPool (onelab_plcs_pool,options)
21
22     if len(options.ips) != 0:
23         utils.header('Using user-provided IPS:\nips=%r'%options.ips)
24         options.ips.reverse()
25
26     plc_counter=0
27     for plc in plcs:
28         try:
29             if len (options.ips != 0):
30                 (hostname,ip,mac)=test_pool.locate(options.ips.pop())
31             else:
32                 (hostname,ip,mac)=test_pool.next_free()
33
34             ### rewrite fields in plc
35             # compute a helpful vserver name - remove domain in hostname
36             simplehostname=hostname.split('.')[0]
37             # myplc rpm basename, without .rpm
38             vservername = os.path.basename(options.myplc_url)
39             vservername = vservername.replace(".rpm","")
40             # vservername
41             vservername = vservername.replace("myplc","vtest")
42             if len(plcs) == 1 :
43                 vservername = "%s-%s" % (vservername,simplehostname)
44             else:
45                 plc_counter += 1
46                 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
47             # apply
48             plc['vservername']=vservername
49             plc['vserverip']=ip
50             plc['name'] = "%s_%s"%(plc['name'],simplehostname)
51             utils.header("Attaching plc %s to vserver %s (%s)"%(
52                     plc['name'],plc['vservername'],plc['vserverip']))
53             for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
54                 plc[key] = hostname
55                 
56         except:
57             raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
58
59     return plcs