From 519d06c84b145017580f1b14875f8915537e440f Mon Sep 17 00:00:00 2001 From: yehaiyang Date: Thu, 12 Aug 2021 11:11:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=B7=BB=E5=8A=A0=E4=B8=BB?= =?UTF-8?q?=E6=9C=BA=E6=97=B6fdisk=E6=8A=A5=E9=94=99=20=E6=97=A0=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98=20(link=20#I413UN)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/host/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spug_api/apps/host/utils.py b/spug_api/apps/host/utils.py index b4c1eff..bfd815c 100644 --- a/spug_api/apps/host/utils.py +++ b/spug_api/apps/host/utils.py @@ -207,7 +207,16 @@ def fetch_host_extend(ssh): elif index == 3: response['os_name'] = line else: - response['disk'].append(round(int(line) / 1024 / 1024 / 1024, 0)) + # If user does not has sudo privilege, + # when executes 'fdisk' command, + # will return 'fdisk: command not found' + # and raise an exception. + if 'command not found' in line: + response['disk'].append('Permission denied') + elif line.isdigit(): + response['disk'].append(round(int(line) / 1024 / 1024 / 1024, 0)) + else: + response['disk'].append(line) return response -- Gitee