'Transform the API format of data to the internally used one.
Only validate if the source_type field makes sense.'

@classmethod
def from_api(cls, api_dict, image_uuid_specified):

    if (not api_dict.get('no_device')):
        source_type = api_dict.get('source_type')
        device_uuid = api_dict.get('uuid')
        destination_type = api_dict.get('destination_type')
        if ((source_type == 'blank') and device_uuid):
            raise exception.InvalidBDMFormat(details=_('Invalid    device    UUID.'))
        elif (source_type != 'blank'):
            if (not device_uuid):
                raise exception.InvalidBDMFormat(details=_('Missing    device    UUID.'))
            api_dict[(source_type + '_id')] = device_uuid
        if ((source_type == 'image') and (destination_type == 'local')):
            boot_index = api_dict.get('boot_index', (-1))
            if (boot_index is None):
                boot_index = (-1)
            boot_index = int(boot_index)
            if (not (image_uuid_specified and (boot_index == 0))):
                raise exception.InvalidBDMFormat(details=_('Mapping    image    to    local    is    not    supported.'))
    api_dict.pop('uuid', None)
    return cls(api_dict)
