def find_match(self, hw_items): '''Finds an hardware profile matching the hardware items in the state If a profiles matches, its count is decremented. Returns the name of the matching profile. ''' idx = 0 times = '*' name = None valid_roles = [] for name, times in self._data: LOG.info('testing %s' % name) if times == '*' or int(times) > 0: valid_roles.append(name) specs = self._load_specs(name) var = {} var2 = {} if matcher.match_all(hw_items, specs, var, var2): LOG.info('Specs %s matches' % name) forced = (var2 != {}) if var2 == {}: var2 = var if times != '*': self._data[idx] = (name, int(times) - 1) LOG.info('Decrementing %s to %d' % (name, int(times) - 1)) dbase = cmdb.load_cmdb(self._cfg_dir, name) if dbase: if cmdb.update_cmdb(dbase, var, var2, forced): cmdb.save_cmdb(self._cfg_dir, name, dbase) else: idx += 1 continue return name, var idx += 1 else: if not valid_roles: raise StateError('No more role available in %s' % (self._state_filename,)) else: raise StateError( 'Unable to match requirements on the following available ' 'roles in %s: %s' % (self._cfg_dir, ', '.join(valid_roles)))