mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
Model changes for instance last_seen field to replace modified (#10870)
* Model changes for instance last_seen field to replace modified * Break up refresh_capacity into smaller units * Rename execution node methods, fix last_seen clustering * Use update_fields to make it clear save only affects capacity * Restructing to pass unit tests * Fix bug where a PATCH did not update capacity value
This commit is contained in:
@@ -18,8 +18,6 @@ import tempfile
|
||||
import psutil
|
||||
from functools import reduce, wraps
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
# Django
|
||||
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
|
||||
from django.utils.dateparse import parse_datetime
|
||||
@@ -72,9 +70,6 @@ __all__ = [
|
||||
'set_current_apps',
|
||||
'extract_ansible_vars',
|
||||
'get_search_fields',
|
||||
'get_system_task_capacity',
|
||||
'get_cpu_capacity',
|
||||
'get_mem_capacity',
|
||||
'model_to_dict',
|
||||
'NullablePromptPseudoField',
|
||||
'model_instance_diff',
|
||||
@@ -715,7 +710,14 @@ def get_cpu_effective_capacity(cpu_count):
|
||||
return cpu_count * forkcpu
|
||||
|
||||
|
||||
def get_cpu_capacity():
|
||||
def measure_cpu(): # TODO: replace with import from ansible-runner
|
||||
return psutil.cpu_count()
|
||||
|
||||
|
||||
def get_corrected_cpu(cpu_count): # formerlly get_cpu_capacity
|
||||
"""Some environments will do a correction to the reported CPU number
|
||||
because the given OpenShift value is a lie
|
||||
"""
|
||||
from django.conf import settings
|
||||
|
||||
settings_abscpu = getattr(settings, 'SYSTEM_TASK_ABS_CPU', None)
|
||||
@@ -726,9 +728,7 @@ def get_cpu_capacity():
|
||||
elif settings_abscpu is not None:
|
||||
return 0, int(settings_abscpu)
|
||||
|
||||
cpu = psutil.cpu_count()
|
||||
|
||||
return (cpu, get_cpu_effective_capacity(cpu))
|
||||
return cpu_count # no correction
|
||||
|
||||
|
||||
def get_mem_effective_capacity(mem_mb):
|
||||
@@ -747,7 +747,11 @@ def get_mem_effective_capacity(mem_mb):
|
||||
return max(1, ((mem_mb // 1024 // 1024) - 2048) // forkmem)
|
||||
|
||||
|
||||
def get_mem_capacity():
|
||||
def measure_memory(): # TODO: replace with import from ansible-runner
|
||||
return psutil.virtual_memory().total
|
||||
|
||||
|
||||
def get_corrected_memory(memory):
|
||||
from django.conf import settings
|
||||
|
||||
settings_absmem = getattr(settings, 'SYSTEM_TASK_ABS_MEM', None)
|
||||
@@ -758,33 +762,7 @@ def get_mem_capacity():
|
||||
elif settings_absmem is not None:
|
||||
return 0, int(settings_absmem)
|
||||
|
||||
mem = psutil.virtual_memory().total
|
||||
return (mem, get_mem_effective_capacity(mem))
|
||||
|
||||
|
||||
def get_system_task_capacity(scale=Decimal(1.0), cpu_capacity=None, mem_capacity=None):
|
||||
"""
|
||||
Measure system memory and use it as a baseline for determining the system's capacity
|
||||
"""
|
||||
from django.conf import settings
|
||||
|
||||
settings_forks = getattr(settings, 'SYSTEM_TASK_FORKS_CAPACITY', None)
|
||||
env_forks = os.getenv('SYSTEM_TASK_FORKS_CAPACITY', None)
|
||||
|
||||
if env_forks:
|
||||
return int(env_forks)
|
||||
elif settings_forks:
|
||||
return int(settings_forks)
|
||||
|
||||
if cpu_capacity is None:
|
||||
_, cpu_cap = get_cpu_capacity()
|
||||
else:
|
||||
cpu_cap = cpu_capacity
|
||||
if mem_capacity is None:
|
||||
_, mem_cap = get_mem_capacity()
|
||||
else:
|
||||
mem_cap = mem_capacity
|
||||
return min(mem_cap, cpu_cap) + ((max(mem_cap, cpu_cap) - min(mem_cap, cpu_cap)) * scale)
|
||||
return memory
|
||||
|
||||
|
||||
_inventory_updates = threading.local()
|
||||
|
||||
Reference in New Issue
Block a user