def test_multiple(self): spec = ('disk', '$disk', 'size', '8') lines = [ ('disk', 'vda', 'size', '8'), ('disk', 'vdb', 'size', '8'), ] arr = {} self.assertTrue(matcher.match_multiple(lines, spec, arr)) self.assertEqual(arr['disk'], ['vda', 'vdb'])
def generate_filename_and_macs(items): '''Generate a file name for a hardware using DMI information (product name and version) then if the DMI serial number is available we use it unless we lookup the first mac address. As a result, we do have a filename like : <dmi_product_name>-<dmi_product_version>-{dmi_serial_num|mac_address}''' # Duplicate items as it will be modified by match_* functions hw_items = list(items) sysvars = {} sysvars['sysname'] = '' matcher.match_spec(('system', 'product', 'name', '$sysprodname'), hw_items, sysvars) if 'sysprodname' in sysvars: sysvars['sysname'] = re.sub(r'\W+', '', sysvars['sysprodname']) + '-' matcher.match_spec(('system', 'product', 'vendor', '$sysprodvendor'), hw_items, sysvars) if 'sysprodvendor' in sysvars: sysvars['sysname'] += re.sub(r'\W+', '', sysvars['sysprodvendor']) + \ '-' matcher.match_spec(('system', 'product', 'serial', '$sysserial'), hw_items, sysvars) # Let's use any existing DMI serial number or take the first mac address if 'sysserial' in sysvars: sysvars['sysname'] += re.sub(r'\W+', '', sysvars['sysserial']) + '-' # we always need to have the mac addresses for pxemngr if matcher.match_multiple(hw_items, ('network', '$eth', 'serial', '$serial'), sysvars): if 'sysserial' not in sysvars: sysvars['sysname'] += sysvars['serial'][0].replace(':', '-') else: log('unable to detect network macs') return sysvars