orphan disk search update

This commit is contained in:
David Schroeder
2026-09-22 22:28:41 -05:00
parent 3ecc338466
commit e34f9d832e
4 changed files with 19 additions and 17 deletions
+6 -7
View File
@@ -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: