Update mount_volumes to match build_volume_report

This commit is contained in:
2Shirt 2022-05-21 14:35:25 -07:00
parent 29d4e80f7e
commit 1616379398
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -183,6 +183,12 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False):
NOTE: If device_path is specified then only volumes
under that path will be mounted.
"""
def _get_volumes(dev) -> list:
"""Convert lsblk JSON tree to a flat list of items, returns list."""
volumes = [dev]
for child in dev.get('children', []):
volumes.extend(_get_volumes(child))
return volumes
json_data = {}
volumes = []
containers = []
@ -199,12 +205,10 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False):
json_data = get_json_from_command(cmd)
# Build list of volumes
for dev in json_data.get('blockdevices', []):
for dev in _get_volumes(json_data.get('blockdevices', [])):
volumes.append(dev)
for child in dev.get('children', []):
volumes.append(child)
if child['parttype'] == UUID_CORESTORAGE:
containers.append(child['name'])
if dev.get('parttype', '') == UUID_CORESTORAGE:
containers.append(dev['name'])
# Scan CoreStorage containers
if scan_corestorage: