2 # Thierry Parmentelat - INRIA Sophia Antipolis
6 # this works on a spec as defined in a config file
7 # and allows to remap various fields, typically to another testbox
8 # see an example in config_onelab_testbox32.py
16 def __init__ (self,plcs,options):
22 key=key.replace("*",".*")
23 return re.compile(key).match(name)
31 return node['node_fields']['hostname']
33 def apply_first_map (self, type, name, obj, maplist):
34 for (map_pattern,rename_dict) in maplist:
35 if TestMapper.match (name,map_pattern):
36 utils.header("TestMapper/%s : applying match key %s on plc %s"%(type,map_pattern,name))
37 for (k,v) in rename_dict.iteritems():
40 # step down but last step in path
42 for step in path[:-1]:
43 if not o.has_key(step):
45 utils.header ("WARNING : created step %s in path %s on %s %s"%(
48 # last step is the one for side-effect
50 if not o.has_key(step):
51 utils.header ("WARNING : inserting key %s for path %s on %s %s"%(
53 # apply formatting if '%s' found in the value
56 if self.options.verbose:
57 utils.header("mapping %s->%s towards %s"%(name,k,v))
59 # only apply first rule
62 def node_names (self):
65 for site in plc['sites']:
66 for node in site['nodes']:
67 result.append(node['node_fields']['hostname'])
70 def map (self,mapper):
73 plc_maps = mapper['plc']
77 node_maps = mapper['node']
82 name=TestMapper.plc_name(plc)
83 self.apply_first_map ('plc',name,plc,plc_maps)
85 for site in plc['sites']:
86 for node in site['nodes']:
87 nodename = TestMapper.node_name(node)
88 self.apply_first_map('node',nodename,node,node_maps)