'Create the VM record in Xen, making sure that we do not create
a duplicate name-label.  Also do a rough sanity check on memory
to try to short-circuit a potential failure later.  (The memory
check only accounts for running VMs, so it can miss other builds
that are in progress.)'

def _create_vm_record(self, context, instance, name_label, disk_image_type, kernel_file, ramdisk_file, image_meta, rescue=False):

    mode = vm_utils.determine_vm_mode(instance, disk_image_type)
    if rescue:
        rescue_vm_mode = image_meta.properties.get('hw_vm_mode', None)
        if (rescue_vm_mode is None):
            LOG.debug('vm_mode    not    found    in    rescue    image    properties.Setting    vm_mode    to    %s', mode, instance=instance)
        else:
            mode = obj_fields.VMMode.canonicalize(rescue_vm_mode)
    if (instance.vm_mode != mode):
        instance.vm_mode = mode
        instance.save()
    device_id = vm_utils.get_vm_device_id(self._session, image_meta)
    use_pv_kernel = (mode == obj_fields.VMMode.XEN)
    LOG.debug('Using    PV    kernel:    %s', use_pv_kernel, instance=instance)
    vm_ref = vm_utils.create_vm(self._session, instance, name_label, kernel_file, ramdisk_file, use_pv_kernel, device_id)
    return vm_ref
