Fix get_core_storage_volumes()
This commit is contained in:
parent
e76ee88b01
commit
ef426c95b5
1 changed files with 24 additions and 16 deletions
|
|
@ -64,6 +64,7 @@ def get_apfs_volumes(device_path):
|
||||||
|
|
||||||
|
|
||||||
def get_core_storage_volumes(device_path):
|
def get_core_storage_volumes(device_path):
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
"""Get CoreStorage volumes contained in device_path, returns list."""
|
"""Get CoreStorage volumes contained in device_path, returns list."""
|
||||||
disks = []
|
disks = []
|
||||||
volumes = []
|
volumes = []
|
||||||
|
|
@ -85,12 +86,13 @@ def get_core_storage_volumes(device_path):
|
||||||
for p_v in l_vg['CoreStoragePhysicalVolumes']:
|
for p_v in l_vg['CoreStoragePhysicalVolumes']:
|
||||||
uuid = p_v['CoreStorageUUID']
|
uuid = p_v['CoreStorageUUID']
|
||||||
cmd = ['diskutil', 'coreStorage', 'info', '-plist', uuid]
|
cmd = ['diskutil', 'coreStorage', 'info', '-plist', uuid]
|
||||||
|
proc = run_program(cmd, check=False, encoding=None, errors=None)
|
||||||
try:
|
try:
|
||||||
uuid_data = plistlib.loads(proc.stdout)
|
plist_data = plistlib.loads(proc.stdout)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
LOG.error('failed to get diskutil corestorage info for %s', uuid)
|
LOG.error('failed to get diskutil corestorage info for %s', uuid)
|
||||||
continue
|
continue
|
||||||
if uuid_data['DeviceIdentifier'] == device_path:
|
if plist_data['DeviceIdentifier'] == device_path:
|
||||||
related = True
|
related = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -99,27 +101,33 @@ def get_core_storage_volumes(device_path):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Add logical disks to list
|
# Add logical disks to list
|
||||||
for l_v in l_vg['CoreStorageLogicalVolumes']:
|
for l_vf in l_vg['CoreStorageLogicalVolumeFamilies']:
|
||||||
uuid = l_v['CoreStorageUUID']
|
for l_v in l_vf['CoreStorageLogicalVolumes']:
|
||||||
cmd = ['diskutil', 'coreStorage', 'info', '-plist', uuid]
|
uuid = l_v['CoreStorageUUID']
|
||||||
try:
|
cmd = ['diskutil', 'coreStorage', 'info', '-plist', uuid]
|
||||||
uuid_data = plistlib.loads(proc.stdout)
|
proc = run_program(cmd, check=False, encoding=None, errors=None)
|
||||||
except (TypeError, ValueError):
|
try:
|
||||||
LOG.error('failed to get diskutil corestorage info for %s', uuid)
|
plist_data = plistlib.loads(proc.stdout)
|
||||||
continue
|
except (TypeError, ValueError):
|
||||||
disks.append(uuid_data['DeviceIdentifier'])
|
LOG.error('failed to get diskutil corestorage info for %s', uuid)
|
||||||
|
continue
|
||||||
|
disks.append(plist_data['DeviceIdentifier'])
|
||||||
|
|
||||||
# Get volumes from logical disks
|
# Get volumes from logical disks
|
||||||
for disk in disks:
|
for disk in disks:
|
||||||
cmd = ['diskutil', 'list', '-plist', f'/dev/{disk}']
|
cmd = ['diskutil', 'list', '-plist', f'/dev/{disk}']
|
||||||
proc = run_program(cmd, check=False, encoding=None, errors=None)
|
proc = run_program(cmd, check=False, encoding=None, errors=None)
|
||||||
try:
|
try:
|
||||||
disk_data = plistlib.loads(proc.stdout)
|
plist_data = plistlib.loads(proc.stdout)
|
||||||
|
disk_data = plist_data['AllDisksAndPartitions'][0]
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
LOG.error('Failed to get diskutil list for %s', disk)
|
LOG.error('Failed to get diskutil list for %s', disk)
|
||||||
continue
|
continue
|
||||||
for part in disk_data['AllDisksAndPartitions'][0]['Partitions']:
|
if 'Partitions' in disk_data:
|
||||||
volumes.append(Disk(f'/dev/{part["DeviceIdentifier"]}'))
|
for part in disk_data['Partitions']:
|
||||||
|
volumes.append(Disk(f'/dev/{part["DeviceIdentifier"]}'))
|
||||||
|
elif 'VolumeName' in disk_data:
|
||||||
|
volumes.append(Disk(f'/dev/{disk_data["DeviceIdentifier"]}'))
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
return volumes
|
return volumes
|
||||||
|
|
@ -186,13 +194,13 @@ def mount_volumes(device_path=None, read_write=False):
|
||||||
|
|
||||||
# Volumes
|
# Volumes
|
||||||
result += f'{"Mounted on "+vol.details.get("mountpoint", "?"):<40}'
|
result += f'{"Mounted on "+vol.details.get("mountpoint", "?"):<40}'
|
||||||
size = vol.details.get('VolumeSize', -1)
|
size = vol.details.get('TotalSize', -1)
|
||||||
free = vol.details.get('FreeSpace', -1)
|
free = vol.details.get('FreeSpace', -1)
|
||||||
used = size - free
|
used = size - free
|
||||||
result = (
|
result = (
|
||||||
f'{result} ({vol.details.get("fstype", "Unknown FS")+",":<5} '
|
f'{result} ({vol.details.get("fstype", "Unknown FS")+",":<5} '
|
||||||
f'{std.bytes_to_string(used, decimals=1):>9} used, '
|
f'{std.bytes_to_string(used, decimals=1):>9} used, '
|
||||||
f'{std.bytes_to_string(size, decimals=1):>9} size, '
|
f'{std.bytes_to_string(free, decimals=1):>9} free) '
|
||||||
)
|
)
|
||||||
report.append(result)
|
report.append(result)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue