Loading

OpenStack+kvm虚拟机xml格式解析

配置说明

首先介绍一下配置结构:
xml配置遵循<keyword> xxxxxx </keyword>的格式,即一个配置段以<keyword>开头,以</keyword>结尾;
那么可知整个虚拟机的xml格式,为包在<domain></domain>配置段之间的一段配置,即:

domain配置段

<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>QEMU-fedora-i686</name>
  <memory>219200</memory>
  <os>
    <type arch='i686' machine='pc'>hvm</type>
  </os>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-newarg'/>
    <qemu:env name='QEMU_ENV' value='VAL'/>
  </qemu:commandline>
</domain>

domain配置段为所有kvm虚拟机的根配置,有两项属性:
type:定义了使用什么管理程序进行管理实例运行,合法参数是驱动配置的,包含"xen","kvm","qemu","lxc"等等
id:定义了一个运行中的客户机的唯一标识符,未运行的虚拟机无id值。
在domain配置之内,还可以进行其他配置的定义:

  <name>instance-0000d165</name>
  <uuid>156917bc-debf-4515-97f7-8b7cfd9e16bd</uuid>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+0:+0</label>
    <imagelabel>+0:+0</imagelabel>
  </seclabel>

name:定义了虚拟机的名称,仅包含字母数字字符,在单宿主机上唯一不可重复,通常作为虚拟机的xml配置的文件名
uuid:定义了一个全局的虚拟机唯一id,必须遵循RFC 4122规范,如在创建中未指定,则会生成一个随机UUDID,

metadata配置段

  <metadata>
    <nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.0">
      <nova:package version="4.6.1-1.bc.el7"/>
      <nova:name>ec-wb-test</nova:name>
      <nova:creationTime>2021-02-05 09:50:44</nova:creationTime>
      <nova:flavor name="ecloud-normalNetImprove-2vcpu-4G-20G-6248-2.0G">
        <nova:memory>4096</nova:memory>
        <nova:disk>0</nova:disk>
        <nova:swap>0</nova:swap>
        <nova:ephemeral>0</nova:ephemeral>
        <nova:vcpus>2</nova:vcpus>
      </nova:flavor>
      <nova:owner>
        <nova:user uuid="4d3ba0aa7c334e1ab8fc20f319f0ec2b">sre_isre_laishijie-EC</nova:user>
        <nova:project uuid="5a107930ea384a03b1fbc5f16c4f6e44">sre_isre_laishijie</nova:project>
      </nova:owner>
      <nova:root type="image" uuid="952b0f1c-fd94-4a02-8881-799f7eac6888"/>
    </nova:instance>
  </metadata>

metadata配置段存储了(libvirt之外的)自定义的配置信息,通常由其他对接组件指定,如nova
如上述配置中,指定了再nova层面的一些信息,如nova版本,nova侧的云主机名称,创建时间,flavor名称,租户信息,image信息等等。

memory配置段

  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <memoryBacking>
    <hugepages>
      <page size='1048576' unit='KiB' nodeset='0'/>
    </hugepages>
  </memoryBacking>

cpu配置段

  <vcpu placement='static'>2</vcpu>
  <cputune>
    <shares>2048</shares>
    <vcpupin vcpu='0' cpuset='0,5-19,40,45-59'/>
    <vcpupin vcpu='1' cpuset='0,5-19,40,45-59'/>
    <emulatorpin cpuset='0,5-19,40,45-59'/>
  </cputune>
  <numatune>
    <memory mode='strict' nodeset='0'/>
    <memnode cellid='0' mode='strict' nodeset='0'/>
  </numatune>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>Skylake-Server-IBRS</model>
    <vendor>Intel</vendor>
    <topology sockets='2' cores='1' threads='1'/>
    <feature policy='require' name='ss'/>
    <feature policy='require' name='hypervisor'/>
    <feature policy='require' name='tsc_adjust'/>
    <feature policy='require' name='clflushopt'/>
    <feature policy='require' name='pku'/>
    <feature policy='require' name='stibp'/>
    <feature policy='require' name='ssbd'/>
    <numa>
      <cell id='0' cpus='0-1' memory='4194304' unit='KiB' memAccess='shared'/>
    </numa>
  </cpu>

resource配置段

  <resource>
    <partition>/machine</partition>
  </resource>

smbios配置段

  <sysinfo type='smbios'>
    <system>
      <entry name='manufacturer'>RDO</entry>
      <entry name='product'>OpenStack Compute</entry>
      <entry name='version'>4.6.1-1.bc.el7</entry>
      <entry name='serial'>c883a8db-1dfe-438d-9a07-3e251f73c5cc</entry>
      <entry name='uuid'>156917bc-debf-4515-97f7-8b7cfd9e16bd</entry>
      <entry name='family'>Virtual Machine</entry>
    </system>
  </sysinfo>

os配置段

  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
    <smbios mode='sysinfo'/>
  </os>

clock配置段

  <clock offset='utc'>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='hpet' present='no'/>
  </clock>

device配置段

<devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='cdrom'>
...
    </disk>
    <controller type='scsi' index='0' model='virtio-scsi'>
...
    </controller>
    <interface type='vhostuser'>
...
    </interface>
    <serial type='pty'>
...
    </serial>
    <console type='pty' tty='/dev/pts/0'>
...
    </console>
    <channel type='unix'>
...
    </channel>
    <input type='mouse' bus='ps2'>
...
    </input>
    <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0' keymap='en-us'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <watchdog model='i6300esb' action='none'>
      <alias name='watchdog0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </watchdog>
    <memballoon model='virtio'>
      <stats period='10'/>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
</devices>

一个完整的OpenStack+kvm虚拟机xml文件形同如下内容,仅供参考:

<domain type='kvm' id='30'>
  <name>instance-0000d165</name>
  <uuid>156917bc-debf-4515-97f7-8b7cfd9e16bd</uuid>
  <metadata>
    <nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.0">
      <nova:package version="4.6.1-1.bc.el7"/>
      <nova:name>ec-wb-test</nova:name>
      <nova:creationTime>2021-02-05 09:50:44</nova:creationTime>
      <nova:flavor name="ecloud-normalNetImprove-2vcpu-4G-20G-6248-2.0G">
        <nova:memory>4096</nova:memory>
        <nova:disk>0</nova:disk>
        <nova:swap>0</nova:swap>
        <nova:ephemeral>0</nova:ephemeral>
        <nova:vcpus>2</nova:vcpus>
      </nova:flavor>
      <nova:owner>
        <nova:user uuid="4d3ba0aa7c334e1ab8fc20f319f0ec2b">sre_isre_laishijie-EC</nova:user>
        <nova:project uuid="5a107930ea384a03b1fbc5f16c4f6e44">sre_isre_laishijie</nova:project>
      </nova:owner>
      <nova:root type="image" uuid="952b0f1c-fd94-4a02-8881-799f7eac6888"/>
    </nova:instance>
  </metadata>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <memoryBacking>
    <hugepages>
      <page size='1048576' unit='KiB' nodeset='0'/>
    </hugepages>
  </memoryBacking>
  <vcpu placement='static'>2</vcpu>
  <cputune>
    <shares>2048</shares>
    <vcpupin vcpu='0' cpuset='0,5-19,40,45-59'/>
    <vcpupin vcpu='1' cpuset='0,5-19,40,45-59'/>
    <emulatorpin cpuset='0,5-19,40,45-59'/>
  </cputune>
  <numatune>
    <memory mode='strict' nodeset='0'/>
    <memnode cellid='0' mode='strict' nodeset='0'/>
  </numatune>
  <resource>
    <partition>/machine</partition>
  </resource>
  <sysinfo type='smbios'>
    <system>
      <entry name='manufacturer'>RDO</entry>
      <entry name='product'>OpenStack Compute</entry>
      <entry name='version'>4.6.1-1.bc.el7</entry>
      <entry name='serial'>c883a8db-1dfe-438d-9a07-3e251f73c5cc</entry>
      <entry name='uuid'>156917bc-debf-4515-97f7-8b7cfd9e16bd</entry>
      <entry name='family'>Virtual Machine</entry>
    </system>
  </sysinfo>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
    <smbios mode='sysinfo'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>Skylake-Server-IBRS</model>
    <vendor>Intel</vendor>
    <topology sockets='2' cores='1' threads='1'/>
    <feature policy='require' name='ss'/>
    <feature policy='require' name='hypervisor'/>
    <feature policy='require' name='tsc_adjust'/>
    <feature policy='require' name='clflushopt'/>
    <feature policy='require' name='pku'/>
    <feature policy='require' name='stibp'/>
    <feature policy='require' name='ssbd'/>
    <numa>
      <cell id='0' cpus='0-1' memory='4194304' unit='KiB' memAccess='shared'/>
    </numa>
  </cpu>
  <clock offset='utc'>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/var/lib/nova/instances/156917bc-debf-4515-97f7-8b7cfd9e16bd/disk.config'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='network' device='disk'>
      <driver name='qemu' type='raw' cache='none' discard='unmap'/>
      <source protocol='rbd' name='ebs_ceph_ssd_sys/volume-6347f0d3-b2b1-41b2-a2b4-e75c19a9cba9'>
        <host name='10.203.135.1' port='6789'/>
        <host name='10.203.135.8' port='6789'/>
        <host name='10.203.135.15' port='6789'/>
      </source>
      <target dev='sda' bus='scsi'/>
      <iotune>
        <total_bytes_sec>146800640</total_bytes_sec>
        <total_iops_sec>2800</total_iops_sec>
      </iotune>
      <serial>6347f0d3-b2b1-41b2-a2b4-e75c19a9cba9</serial>
      <wwn>004439433801266d</wwn>
      <alias name='scsi0-0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='scsi' index='0' model='virtio-scsi'>
      <alias name='scsi0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <alias name='virtio-serial0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <controller type='usb' index='0' model='piix3-uhci'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <interface type='vhostuser'>
      <mac address='fa:16:3e:95:e2:9a'/>
      <source type='unix' path='/usr/local/var/run/openvswitch/vhub2f8a3fa-ff' mode='server'/>
      <target dev='vhub2f8a3fa-ff'/>
      <model type='virtio'/>
      <driver name='vhost' queues='2' rx_queue_size='1024' tx_queue_size='1024'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/0'/>
      <log file='/var/lib/nova/instances/156917bc-debf-4515-97f7-8b7cfd9e16bd/console.log' append='off'/>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/0'>
      <source path='/dev/pts/0'/>
      <log file='/var/lib/nova/instances/156917bc-debf-4515-97f7-8b7cfd9e16bd/console.log' append='off'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/org.qemu.guest_agent.0.instance-0000d165.sock'/>
      <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'>
      <alias name='input1'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input2'/>
    </input>
    <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0' keymap='en-us'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <watchdog model='i6300esb' action='none'>
      <alias name='watchdog0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </watchdog>
    <memballoon model='virtio'>
      <stats period='10'/>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+0:+0</label>
    <imagelabel>+0:+0</imagelabel>
  </seclabel>
</domain>


posted @ 2021-02-18 09:44  motorao  阅读(879)  评论(0编辑  收藏  举报