6e63fe38e754461a232bb7eb315bb78aa4d3ac27
[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, '02:34:56:00:ee:%02d'%i) for i in range(1,10) ]
8 # vplc09 is reserved for a fixed myplc - from 01 to 08
9 onelab_plcs_pool = [ 
10     ( 'vplc%02d.inria.fr'%i, '138.96.255.%d'%(200+i), '02:34:56:00:ee:%02d'%i) for i in range(1,21) ]
11
12 def config (plcs,options):
13     
14     utils.header ("Turning configuration into a vserver-based one for onelab")
15
16     test_pool = TestPool (onelab_plcs_pool,options)
17
18     if len(options.ips_plc) != 0:
19         utils.header('Using user-provided IPS:\nips_plc=%r'%options.ips_plc)
20         options.ips_plc.reverse()
21
22     plc_counter=0
23     for plc in plcs:
24         try:
25             if len(options.ips_plc) != 0:
26                 ip=options.ips_plc[0]
27                 options.ips_plc=options.ips_plc[1:]
28                 (hostname,ip,mac)=test_pool.locate(ip)
29                 utils.header("Using user-provided %s %s for plc %s"%(
30                         hostname,ip,plc['name']))
31             else:
32                 (hostname,ip,mac)=test_pool.next_free()
33                 utils.header("Using auto-allocated %s %s for plc %s"%(
34                         hostname,ip,plc['name']))
35
36             ### rewrite fields in plc
37             # compute a helpful vserver name - remove domain in hostname
38             simplehostname=hostname.split('.')[0]
39             vservername = options.buildname
40             if len(plcs) == 1 :
41                 vservername = "%s-%s" % (vservername,simplehostname)
42             else:
43                 plc_counter += 1
44                 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
45             # apply
46             plc['vservername']=vservername
47             plc['vserverip']=ip
48             plc['name'] = "%s_%s"%(plc['name'],simplehostname)
49             utils.header("Attaching plc %s to vserver %s (%s)"%(
50                     plc['name'],plc['vservername'],plc['vserverip']))
51             for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
52                 plc[key] = hostname
53                 
54         except:
55             raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
56
57     return plcs