Use python-native api to get disk size
In before, we shellout a command to retrieve the total disk size of the host. A better approach is to leverage the python-native library psutil to do that. Using python api would have less overhead than spawning a shell command. Change-Id: I02e2babac9bc36f5d738cff0b17ebd9416bd1757
This commit is contained in:
parent
a1bb8fe016
commit
24b212e987
@ -98,6 +98,7 @@ pep8==1.5.7
|
||||
pika==0.10.0
|
||||
pika-pool==0.1.3
|
||||
prettytable==0.7.2
|
||||
psutil==3.2.2
|
||||
pyasn1==0.4.2
|
||||
pycadf==2.7.0
|
||||
pycparser==2.18
|
||||
|
@ -6,6 +6,7 @@ PyYAML>=3.12 # MIT
|
||||
eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT
|
||||
keystonemiddleware>=4.17.0 # Apache-2.0
|
||||
pecan!=1.0.2,!=1.0.3,!=1.0.4,!=1.2,>=1.0.0 # BSD
|
||||
psutil>=3.2.2 # BSD
|
||||
python-etcd>=0.4.3 # MIT License
|
||||
python-glanceclient>=2.8.0 # Apache-2.0
|
||||
python-neutronclient>=6.7.0 # Apache-2.0
|
||||
|
@ -21,6 +21,7 @@ from neutronclient.common import exceptions as n_exc
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import psutil
|
||||
import six
|
||||
|
||||
from zun.common import consts
|
||||
@ -1117,17 +1118,8 @@ class DockerDriver(driver.ContainerDriver):
|
||||
runtimes)
|
||||
|
||||
def get_total_disk_for_container(self):
|
||||
try:
|
||||
(output, err) = utils.execute('df', '-B', '1G',
|
||||
CONF.docker.docker_data_root,
|
||||
run_as_root=True)
|
||||
except exception.CommandError as e:
|
||||
LOG.info('There was a problem while executing df -B 1G %s',
|
||||
CONF.docker.docker_data_root)
|
||||
raise exception.CommandError(cmd='df',
|
||||
error=six.text_type(e))
|
||||
|
||||
total_disk = int(output.split('\n')[1].split()[1])
|
||||
disk_usage = psutil.disk_usage(CONF.docker.docker_data_root)
|
||||
total_disk = disk_usage.total / 1024 ** 3
|
||||
return int(total_disk * (1 - CONF.compute.reserve_disk_for_image))
|
||||
|
||||
def get_cpu_used(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user