import json


def parse_ironic(ironic_file):
    """Extracts relevant data from each ironic input file
    """
    with open(ironic_file, 'r') as f:
        try:
            ironic = json.load(f)
        except Exception:
            raise RuntimeError(
                'Invalid JSON file: {ironic_data_file}'.format(
                ironic_data_file=ironic_file))
        try:
            uuid = ironic['extra']['system']['product']['uuid']
        except Exception:
            raise RuntimeError(
                'The Machine Unique UUID is not defined in '
                'data file: {ironic_data_file}'.format(
                ironic_data_file=ironic_file))
        try:
            disks = ironic['inventory']['disks']
        except Exception:
            raise RuntimeError(
                'No disks were found in '
                'data file: {ironic_data_file}'.format(
                ironic_data_file=ironic_file))
        try:
            root_disk = ironic['root_disk']
        except Exception:
            raise RuntimeError(
                'No root disk was found in '
                'data file: {ironic_data_file}'.format(
                ironic_data_file=ironic_file))
    return uuid.lower(), root_disk, disks