def process(output, dependencies): """Return the correct value for cpu_socket_count output.""" # process the internal dmi cpu socket count result dmi_cpu_socket_count = \ dependencies.get('internal_cpu_socket_count_dmi') if dmi_cpu_socket_count and dmi_cpu_socket_count.get('rc') == 0: dmi_status = dmi_cpu_socket_count.get('stdout_lines') dmi_count = 0 for status in dmi_status: if 'status: populated' in status.lower(): dmi_count += 1 if dmi_count > 0: return dmi_count # process the cpuinfo socket count as a fallback cpuinfo_cpu_socket_count = \ dependencies.get('internal_cpu_socket_count_cpuinfo') if cpuinfo_cpu_socket_count and \ cpuinfo_cpu_socket_count.get('rc') == 0 and \ cpuinfo_cpu_socket_count.get('stdout_lines'): cpuinfo_count = cpuinfo_cpu_socket_count.get('stdout_lines', [0])[0] if is_int(cpuinfo_count): if convert_to_int(cpuinfo_count) != 0 and \ convert_to_int(cpuinfo_count) <= 8: return convert_to_int(cpuinfo_count) # assign the socket_count to the cpu_count as a last resort cpu_count = dependencies.get('cpu_count') if is_int(cpu_count): return convert_to_int(cpu_count) return None
def to_internal_value(self, data): """Create internal value.""" if not is_int(data): raise ValidationError(_(messages.SJ_SCAN_IDS_INV)) int_data = convert_to_int(data) actual_scan = Scan.objects.filter(id=int_data).first() if actual_scan is None: raise ValidationError(_(messages.SJ_SCAN_DO_NOT_EXIST % int_data)) return actual_scan
def process(output, dependencies): """Process internal_xen_guest output.""" result = output.get('stdout_lines') if isinstance(result, list): result = [line for line in result if line] return bool(result) and\ is_int(result[0]) and \ convert_to_int(result[0]) > 0 return False
def process(output, dependencies): """Return the correct value for cpu core count output.""" cpu_socket_count = dependencies.get('cpu_socket_count') cpu_core_per_socket = dependencies.get('cpu_core_per_socket') cpu_count = dependencies.get('cpu_count') cpu_hyperthreading = dependencies.get('cpu_hyperthreading') virt_type = dependencies.get('virt_type') # if the virt_type is vmware and cpu_count exists # then return cpu_count if virt_type and virt_type == 'vmware' and is_int(cpu_count): return convert_to_int(cpu_count) # if the cpu_core_per_socket & the cpu_socket_count are present # return the product of the two if is_int(cpu_core_per_socket) and is_int(cpu_socket_count): return convert_to_int(cpu_core_per_socket) * \ convert_to_int(cpu_socket_count) if is_int(cpu_count): if cpu_hyperthreading: return convert_to_int(cpu_count) / 2 # if there is no threading, return the cpu count return convert_to_int(cpu_count) return None