mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 21:35:01 -02:30
Change use of subprocess lib for calculating system capacity
Suggested by Ryan Petrello as a part of the PR feedback for the isolated instance setup work.
This commit is contained in:
@@ -25,8 +25,11 @@ def main():
|
|||||||
argument_spec = dict()
|
argument_spec = dict()
|
||||||
)
|
)
|
||||||
# Duplicated with awx.main.utils.common.get_system_task_capacity
|
# Duplicated with awx.main.utils.common.get_system_task_capacity
|
||||||
proc = subprocess.Popen(['free', '-m'], stdout=subprocess.PIPE)
|
try:
|
||||||
out,err = proc.communicate()
|
out = subprocess.check_output(['free', '-m'])
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
module.fail_json(msg=str(e))
|
||||||
|
return
|
||||||
total_mem_value = out.split()[7]
|
total_mem_value = out.split()[7]
|
||||||
if int(total_mem_value) <= 2048:
|
if int(total_mem_value) <= 2048:
|
||||||
cap = 50
|
cap = 50
|
||||||
|
|||||||
@@ -543,8 +543,11 @@ def get_system_task_capacity():
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
if hasattr(settings, 'SYSTEM_TASK_CAPACITY'):
|
if hasattr(settings, 'SYSTEM_TASK_CAPACITY'):
|
||||||
return settings.SYSTEM_TASK_CAPACITY
|
return settings.SYSTEM_TASK_CAPACITY
|
||||||
proc = subprocess.Popen(['free', '-m'], stdout=subprocess.PIPE)
|
try:
|
||||||
out,err = proc.communicate()
|
out = subprocess.check_output(['free', '-m'])
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logger.error('Problem obtaining capacity from system, error:\n{}'.format(str(e)))
|
||||||
|
return 0
|
||||||
total_mem_value = out.split()[7]
|
total_mem_value = out.split()[7]
|
||||||
if int(total_mem_value) <= 2048:
|
if int(total_mem_value) <= 2048:
|
||||||
return 50
|
return 50
|
||||||
|
|||||||
Reference in New Issue
Block a user