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