summaryrefslogtreecommitdiff
path: root/src/completion
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-05-23 10:07:46 +0200
committerChristian Poessinger <christian@poessinger.com>2021-05-23 10:42:08 +0200
commit5f9d07f4d1aff0d1b23ebf5cceefc32ee16dde74 (patch)
tree0acb2dcb77b8363c55d1ce1b2e28634050e2a67a /src/completion
parent22e0e5201610aae7df0983ee62bb0eeb7ceb5017 (diff)
downloadvyos-1x-5f9d07f4d1aff0d1b23ebf5cceefc32ee16dde74.tar.gz
vyos-1x-5f9d07f4d1aff0d1b23ebf5cceefc32ee16dde74.zip
op-mode: disks: T1621: bugfix no disk output
(cherry picked from commit 51899c362f2eba1dd067414f2dfa8e78f30ca408)
Diffstat (limited to 'src/completion')
-rwxr-xr-xsrc/completion/list_disks.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/completion/list_disks.py b/src/completion/list_disks.py
index ff1135e23..0aa872abb 100755
--- a/src/completion/list_disks.py
+++ b/src/completion/list_disks.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2019 VyOS maintainers and contributors
+# Copyright (C) 2019-2021 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -23,11 +23,20 @@ parser.add_argument("-e", "--exclude", type=str, help="Exclude specified device
args = parser.parse_args()
disks = set()
-with open('/proc/partitions') as partitions_file:
- for line in partitions_file:
- fields = line.strip().split()
- if len(fields) == 4 and fields[3].isalpha() and fields[3] != 'name':
- disks.add(fields[3])
+with open('/proc/partitions') as f:
+ table = f.read()
+
+for line in table.splitlines()[1:]:
+ fields = line.strip().split()
+ # probably an empty line at the top
+ if len(fields) == 0:
+ continue
+ disks.add(fields[3])
+
+if 'loop0' in disks:
+ disks.remove('loop0')
+if 'sr0' in disks:
+ disks.remove('sr0')
if args.exclude:
disks.remove(args.exclude)