def _get_guest_cpu_model_config(self):
    mode = CONF.libvirt.cpu_mode
    model = CONF.libvirt.cpu_model
    if ((CONF.libvirt.virt_type == 'kvm') or (CONF.libvirt.virt_type == 'qemu')):
        if (mode is None):
            mode = 'host-model'
        if (mode == 'none'):
            return vconfig.LibvirtConfigGuestCPU()
    elif ((mode is None) or (mode == 'none')):
        return None
    if ((CONF.libvirt.virt_type != 'kvm') and (CONF.libvirt.virt_type != 'qemu')):
        msg = (_("Config requested an explicit CPU model, but the current libvirt hypervisor '%s' does not support selecting CPU models") % CONF.libvirt.virt_type)
        raise exception.Invalid(msg)
    if ((mode == 'custom') and (model is None)):
        msg = _('Config requested a custom CPU model, but no model name was provided')
        raise exception.Invalid(msg)
    elif ((mode != 'custom') and (model is not None)):
        msg = _('A CPU model name should not be set when a host CPU model is requested')
        raise exception.Invalid(msg)
    LOG.debug("CPU mode '%(mode)s' model '%(model)s' was chosen", {'mode': mode, 'model': (model or '')})
    cpu = vconfig.LibvirtConfigGuestCPU()
    cpu.mode = mode
    cpu.model = model
    return cpu
def _get_guest_cpu_model_config(self):
    mode = CONF.libvirt.cpu_mode
    model = CONF.libvirt.cpu_model
    if ((CONF.libvirt.virt_type == 'kvm') or (CONF.libvirt.virt_type == 'qemu')):
        if (mode is None):
            mode = 'host-model'
        if (mode == 'none'):
            return vconfig.LibvirtConfigGuestCPU()
    elif ((mode is None) or (mode == 'none')):
        return None
    if ((CONF.libvirt.virt_type != 'kvm') and (CONF.libvirt.virt_type != 'qemu')):
        msg = (_("Config requested an explicit CPU model, but the current libvirt hypervisor '%s' does not support selecting CPU models") % CONF.libvirt.virt_type)
        raise exception.Invalid(msg)
    if ((mode == 'custom') and (model is None)):
        msg = _('Config requested a custom CPU model, but no model name was provided')
        raise exception.Invalid(msg)
    elif ((mode != 'custom') and (model is not None)):
        msg = _('A CPU model name should not be set when a host CPU model is requested')
        raise exception.Invalid(msg)
    LOG.debug("CPU mode '%(mode)s' model '%(model)s' was chosen", {'mode': mode, 'model': (model or )})
    cpu = vconfig.LibvirtConfigGuestCPU()
    cpu.mode = mode
    cpu.model = model
    return cpu