ed99c3e40defa139a6c86ceebc7e0f79c379eec1
[tests.git] / system / config_1vservers.py
1 import utils
2 import os.path
3 from TestPool import TestPoolIP
4
5 onelab_plcs_ip_pool = [ 
6     ( 'vplc%02d.inria.fr'%i, 
7       '138.96.255.%d'%(200+i), 
8       '02:34:56:00:ee:%02d'%i) for i in range(1,21) ]
9
10 def config (plcs,options):
11     
12     utils.header ("Turning configuration into a vserver-based one for onelab")
13
14     ip_pool = TestPoolIP (onelab_plcs_ip_pool,options)
15
16     plc_counter=0
17     for plc in plcs:
18         try:
19             if options.ips_plc :
20                 ip_or_hostname=options.ips_plc.pop()
21                 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
22                 if not options.quiet:
23                     utils.header("Using user-provided %s %s for plc %s"%(
24                             hostname,ip_or_hostname,plc['name']))
25             else:
26                 (hostname,ip,mac)=ip_pool.next_free()
27                 if not options.quiet:
28                     utils.header("Using auto-allocated %s %s for plc %s"%(
29                             hostname,ip,plc['name']))
30
31             ### rewrite fields in plc
32             # compute a helpful vserver name - remove domain in hostname
33             simplehostname=hostname.split('.')[0]
34             vservername = options.buildname
35             if len(plcs) == 1 :
36                 vservername = "%s-%s" % (vservername,simplehostname)
37             else:
38                 plc_counter += 1
39                 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
40             # apply
41             plc['vservername']=vservername
42             plc['vserverip']=ip
43             plc['name'] = "%s_%s"%(plc['name'],simplehostname)
44             utils.header("Attaching plc %s to vserver %s (%s)"%(
45                     plc['name'],plc['vservername'],plc['vserverip']))
46             for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
47                 plc[key] = hostname
48                 
49         except:
50             raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
51
52     return plcs