Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Not possible set type for domain interface #27

Open
arykalin opened this issue Dec 29, 2021 · 1 comment
Open

Not possible set type for domain interface #27

arykalin opened this issue Dec 29, 2021 · 1 comment

Comments

@arykalin
Copy link

Hi, I need following configuration for domain interface:

    <interface type="ethernet">
      <target dev="eth1"></target>
      <model type="virtio"></model>
    </interface>

But there is no type field in libvirtGoXML.DomainInterface struct, and when I'm trying to validate domain with interface without type validation fails:

vagrant@node1:/vagrant/tests/go/e2e/hypervisor$ cat domain.xml
<domain type="kvm">
  <name>f45ca900-3415-45b1-8cfc-d81651fc7e9a</name>
  <memory unit="b">2000</memory>
  <currentMemory unit="b">2000</currentMemory>
  <vcpu>4</vcpu>
  <cputune>
    <shares>2</shares>
  </cputune>
  <os>
    <type arch="x86_64">hvm</type>
    <boot dev="hd"></boot>
  </os>
  <features>
    <acpi></acpi>
  </features>
  <clock offset="utc"></clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm-spice</emulator>
    <disk type="block" device="disk">
      <driver name="qemu" type="raw" cache="none"></driver>
      <source dev="/dev/vg1/aad102ed-fc2d-4459-bad4-4e414f88b629"></source>
      <target dev="vda" bus="virtio"></target>
    </disk>
    <interface>
      <target dev="6201d5ad4153466"></target>
      <model type="virtio"></model>
    </interface>
    <serial type="pty">
      <target port="0"></target>
    </serial>
    <console type="pty">
      <target type="serial" port="0"></target>
    </console>
    <channel type="unix">
      <target type="virtio" name="org.qemu.guest_agent.0"></target>
      <address type="virtio-serial" controller="0" bus="0" port="1"></address>
    </channel>
    <graphics type="vnc"></graphics>
  </devices>
</domain>

vagrant@node1:/vagrant/tests/go/e2e/hypervisor$ virt-xml-validate domain.xml
Relax-NG validity error : Extra element devices in interleave
domain.xml:20: element devices: Relax-NG validity error : Element domain failed to validate content
domain.xml fails to validate
vagrant@node1:/vagrant/tests/go/e2e/hypervisor$ 


@berrange
Copy link
Contributor

berrange commented Jan 4, 2022

The 'type' attributes in libvirt XML schemas are almost always used as a discriminator to select between different schemas for the element contents. In C code this would be considered a 'union' but Golang doesn't support unions, so we use a set of optional struct fields only one of which should be set.

In the case of the <interface> XML this is selected via the DomainInterfaceSource struct.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants