search for orphan disks
This commit is contained in:
+15
-1
@@ -30,6 +30,8 @@ def enabled(value):
|
||||
def references(root, nodes, guests):
|
||||
"""Read pmxcfs on this host, including offline guests and all config sections."""
|
||||
refs, errors, seen, contents = {}, [], set(), {}
|
||||
guest_names = {(guest['type'], str(guest['vmid'])): guest.get('name')
|
||||
for guest in guests}
|
||||
for node in nodes:
|
||||
for kind, directory in [('qemu', 'qemu-server'), ('lxc', 'lxc')]:
|
||||
folder = root / node['node'] / directory
|
||||
@@ -48,6 +50,18 @@ def references(root, nodes, guests):
|
||||
continue
|
||||
contents[str(path)] = content
|
||||
seen.add((node['node'], kind, path.stem))
|
||||
name = guest_names.get((kind, path.stem))
|
||||
name_key = 'name' if kind == 'qemu' else 'hostname'
|
||||
for line in content.splitlines():
|
||||
line = line.strip()
|
||||
if line.startswith('['):
|
||||
break
|
||||
key, sep, value = line.partition(':')
|
||||
if sep and key == name_key and value.strip():
|
||||
name = value.strip()
|
||||
break
|
||||
guest_id = f"{'VM' if kind == 'qemu' else 'LXC'} {path.stem}"
|
||||
guest_label = f'{name} ({guest_id})' if name else f'{guest_id} (name unavailable)'
|
||||
section = 'current'
|
||||
for line in content.splitlines():
|
||||
line = line.strip()
|
||||
@@ -61,7 +75,7 @@ def references(root, nodes, guests):
|
||||
continue
|
||||
for volume in VOLUME.findall(value):
|
||||
refs.setdefault(volume, []).append({
|
||||
'node': node['node'], 'guest': f'{kind} {path.stem}',
|
||||
'node': node['node'], 'guest': guest_label,
|
||||
'unused': bool(re.fullmatch(r'unused\d+', key)) and section == 'current',
|
||||
'section': section,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user