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