diff --git a/apps/assets/automations/gather_facts/format_asset_info.py b/apps/assets/automations/gather_facts/format_asset_info.py index d3184bf59..29b9b7cf4 100644 --- a/apps/assets/automations/gather_facts/format_asset_info.py +++ b/apps/assets/automations/gather_facts/format_asset_info.py @@ -1,3 +1,5 @@ +from collections import Counter + __all__ = ['FormatAssetInfo'] @@ -7,13 +9,28 @@ class FormatAssetInfo: self.tp = tp @staticmethod - def posix_format(info): - for cpu_model in info.get('cpu_model', []): - if cpu_model.endswith('GHz') or cpu_model.startswith("Intel"): - break - else: - cpu_model = '' - info['cpu_model'] = cpu_model[:48] + def get_cpu_model_count(cpus): + try: + if len(cpus) % 3 == 0: + step = 3 + models = [cpus[i + 2] for i in range(0, len(cpus), step)] + elif len(cpus) % 2 == 0: + step = 2 + models = [cpus[i + 1] for i in range(0, len(cpus), step)] + else: + raise ValueError("CPU list format not recognized") + + model_counts = Counter(models) + result = ', '.join([f"{model} x{count}" for model, count in model_counts.items()]) + except Exception as e: + print(f"Error processing CPU model list: {e}") + result = '' + return result + + def posix_format(self, info): + cpus = self.get_cpu_model_count(info.get('cpu_model', [])) + + info['cpu_model'] = cpus info['cpu_count'] = info.get('cpu_count', 0) return info