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
15 def __init__ (self,plcs,options):
25 return node['node_fields']['hostname']
27 def apply_first_map (self, type, name, obj, maplist):
28 for (map_pattern,rename_dict) in maplist:
29 if self.options.verbose:
30 print 'dbg: TestMapper/',type,'name=',name,'& pattern=',map_pattern
31 if utils.match (name,map_pattern):
32 utils.header("TestMapper/%s : applying rules '%s' on %s"%(type,map_pattern,name))
33 for (k,v) in rename_dict.iteritems():
36 # step down but last step in path
38 for step in path[:-1]:
39 if not o.has_key(step):
41 utils.header ("WARNING : created step %s in path %s on %s %s"%(
44 # last step is the one for side-effect
46 if not o.has_key(step):
47 utils.header ("WARNING : inserting key %s for path %s on %s %s"%(
49 # apply formatting if '%s' found in the value
52 print("TestMapper, rewriting %s: %s into %s"%(name,k,v))
54 # only apply first rule
57 def node_names (self):
60 for site in plc['sites']:
61 for node in site['nodes']:
62 result.append(node['node_fields']['hostname'])
65 def map (self,mapper):
67 plc_maps = mapper.get('plc',[])
68 node_maps = mapper.get('node',[])
71 name=TestMapper.plc_name(plc)
72 self.apply_first_map ('plc',name,plc,plc_maps)
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)