Specify CPU Mode for libvirt Guests

Problem:
I need to specify “host model” in the KVM Guest XML file for VM Guests running Centos Stream 8 and up. When Provisioning via Foreman - the CPU Mode is not specified in the XML file that is being generated. I looked at the libvirt.rb file on the foreman that generates the XML file and noticed that there is a stanza that looks like you can configure this but I am unsure how to modify the .rb file to build the new VM’s with this function.

What can/should I add to this file to specify “host model” as the VM CPU mode so I can ensure seamless installation of Centos Stream 8/9 guests via the Foreman and Katello?

Expected outcome:

libvirt guest XML Configuration:

  <cpu mode='host-model' check='partial'>
    <model fallback='allow'/>
  </cpu>

Foreman and Proxy versions:
Foreman Version 3.3.1

Distribution and version:
Centos 7.9.2009

type or paste code here

I wanted to point you at Foreman Provisioning non-KVM Guests on Libvirt? for similar shenanigans, but that was you already :smiley:

What part are you looking to modify exactly? the mode=host-model?

Yes. Currently the Foreman Generated XML Files do not specify the CPU Mode - consequently this results in a kernel panic when I try to provision anything newer than CentOS 7.

I am needing the Guest KVM XML files to specify

  <cpu mode='host-model' check='partial'>
    <model fallback='allow'/>
  </cpu>

Example:

Foreman Provisioned Guest

<domain type='kvm'>
  <name>tigercms1.tiger.local</name>
  <uuid>841151a0-8ac1-4e67-ae8d-edc97d5f4039</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>

Manually provisioned Guest

<domain type='kvm'>
  <name>red.tiger.local</name>
  <uuid>0d6dbc18-549a-4fd5-a981-3f1a1a8e455c</uuid>
  <memory unit='KiB'>8388608</memory>
  <currentMemory unit='KiB'>8388608</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
>   <cpu mode='host-model' check='partial'>
>     <model fallback='allow'/>
>   </cpu>
  <clock offset='utc'>

Notice the Lines I have block-quoted in the Manually provisioned XML. This is what I need to have added to the libvirt guests that are provisioned via Katello.

I noticed there is a function in the libvirt.rb file that appears to be just what I need, however, I am unsure how to leverage this :smile:

   # 'custom' is not implemented. This needs extra UI.
    CPU_MODES = %w(default host-model host-passthrough)

Also - I just noticed that on the new version (Foreman 3.5 Katello 4.7) that a UI has been added to specify this.

Solution: Upgrade to Latest Supported version haha

1 Like