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,mapper,options):
23 key=key.replace("*",".*")
24 return re.compile(key).match(name)
32 return node['node_fields']['hostname']
34 def apply_first_map (self, type, name, obj, maplist):
35 for (map_pattern,rename_dict) in maplist:
36 if TestMapper.match (name,map_pattern):
37 utils.header("TestMapper/%s : applying match key %s on plc %s"%(type,map_pattern,name))
38 for (k,v) in rename_dict.iteritems():
41 # step down but last step in path
43 for step in path[:-1]:
44 if not o.has_key(step):
45 utils.header ("WARNING : cannot apply step %s in path %s on %s %s"%(
49 # last step is the one for side-effect
51 if not o.has_key(step):
52 utils.header ("WARNING : cannot apply step %s in path %s on %s %s"%(
55 # apply formatting if found
58 if self.options.verbose:
59 utils.header("mapping %s->%s towards %s"%(name,k,v))
61 # only apply first rule
66 plc_maps = self.mapper['plc']
69 name=TestMapper.plc_name(plc)
70 self.apply_first_map ('plc',name,plc,plc_maps)
72 node_maps = self.mapper['node']
74 for site in plc['sites']:
75 for node in site['nodes']:
76 nodename = TestMapper.node_name(node)
77 self.apply_first_map('node',nodename,node,node_maps)