orphan disk search update
This commit is contained in:
+6
-7
@@ -182,6 +182,8 @@ def render(rows, warnings, coverage):
|
||||
for entry in coverage:
|
||||
print(' ' + entry)
|
||||
for warning in warnings:
|
||||
if warning.endswith(': inactive or disabled; not scanned'):
|
||||
continue
|
||||
print('WARNING: ' + warning)
|
||||
group = None
|
||||
for row in sorted(rows, key=lambda r: (r['node'], r['storage'], r['volume'])):
|
||||
@@ -195,16 +197,13 @@ def render(rows, warnings, coverage):
|
||||
print('No unreferenced or unused volumes found in the successfully scanned storage.')
|
||||
|
||||
|
||||
def export_csv(path, rows, warnings):
|
||||
def export_csv(path, rows):
|
||||
# Exclusive creation avoids overwriting existing files, including symlink targets.
|
||||
with open(path, 'x', newline='') as handle:
|
||||
writer = csv.DictWriter(handle, fieldnames=FIELDS + ['disk_size', 'coverage_warnings'])
|
||||
writer = csv.DictWriter(handle, fieldnames=FIELDS + ['disk_size'])
|
||||
writer.writeheader()
|
||||
for row in rows:
|
||||
writer.writerow(dict(row, disk_size=format_size(row['size_bytes'], row.get('size_is_approximate', False)),
|
||||
coverage_warnings='; '.join(warnings)))
|
||||
if warnings and not rows:
|
||||
writer.writerow({'status': 'Incomplete scan', 'coverage_warnings': '; '.join(warnings)})
|
||||
writer.writerow(dict(row, disk_size=format_size(row['size_bytes'], row.get('size_is_approximate', False))))
|
||||
|
||||
|
||||
def main():
|
||||
@@ -220,7 +219,7 @@ def main():
|
||||
if args.interactive and sys.stdin.isatty() and not destination:
|
||||
destination = input('\nCSV export path (Enter to skip): ').strip()
|
||||
if destination:
|
||||
export_csv(destination, rows, warnings)
|
||||
export_csv(destination, rows)
|
||||
print('CSV saved: ' + destination)
|
||||
return 2 if warnings else 0
|
||||
except (OSError, RuntimeError, ValueError, subprocess.TimeoutExpired) as exc:
|
||||
|
||||
Reference in New Issue
Block a user