moving to multi-plcs daily tests
[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     plc_counter=0
19     for plc in plcs:
20         try:
21             if options.ips_plc :
22                 ip=options.ips_plc.pop()
23                 (hostname,ip,mac)=test_pool.locate(ip,True)
24                 if not options.quiet:
25                     utils.header("Using user-provided %s %s for plc %s"%(
26                             hostname,ip,plc['name']))
27             else:
28                 (hostname,ip,mac)=test_pool.next_free()
29                 if not options.quiet:
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