Commit 9712a805 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #49394 from wwwtyro/rye/rbd-stats-improvement

Automatic merge from submit-queue (batch tested with PRs 49326, 49394, 49346, 49379, 49399) more robust stat handling from ceph df output in the kubernetes-master charm create-rbd-pv action **What this PR does / why we need it**: more robust stat handling from ceph df output in the kubernetes-master charm create-rbd-pv action **Release note**: ```release-note more robust stat handling from ceph df output in the kubernetes-master charm create-rbd-pv action ```
parents 1dbe09b1 1c21e8ab
...@@ -23,6 +23,7 @@ from subprocess import check_call ...@@ -23,6 +23,7 @@ from subprocess import check_call
from subprocess import check_output from subprocess import check_output
from subprocess import CalledProcessError from subprocess import CalledProcessError
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
import json
import re import re
import os import os
import sys import sys
...@@ -179,14 +180,13 @@ def get_monitors(): ...@@ -179,14 +180,13 @@ def get_monitors():
def get_available_space(): def get_available_space():
''' Determine the space available in the RBD pool. Throw an exception if ''' Determine the space available in the RBD pool. Throw an exception if
the RBD pool ('rbd') isn't found. ''' the RBD pool ('rbd') isn't found. '''
command = ['ceph', 'df'] command = 'ceph df -f json'.split()
debug_command(command) debug_command(command)
out = check_output(command).decode('utf-8') out = check_output(command).decode('utf-8')
for line in out.splitlines(): data = json.loads(out)
stripped = line.strip() for pool in data['pools']:
if stripped.startswith('rbd'): if pool['name'] == 'rbd':
M = stripped.split()[-2].replace('M', '') return int(pool['stats']['max_avail'] / (1024 * 1024))
return int(M)
raise UnknownAvailableSpaceException('Unable to determine available space.') # noqa raise UnknownAvailableSpaceException('Unable to determine available space.') # noqa
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment