Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open vSwitch のブリッジを扱いやすくする #1

Open
sobadon opened this issue Nov 20, 2022 · 2 comments
Open

Open vSwitch のブリッジを扱いやすくする #1

sobadon opened this issue Nov 20, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@sobadon
Copy link

sobadon commented Nov 20, 2022

概要

libvrit の domain(libvirt_domain)作成時に、Open vSwitch のブリッジとそのブリッジからどの VLAN を VM に渡すかを直接指定できるようにする。

fork 元の実装では、ブリッジとして直接指定できる(.tf ファイルに記述できる)のは Linux Kernel のブリッジ?(ip コマンドで作成できるブリッジ)のみである。fork 元の Terraform Provider を利用して Open vSwitch のブリッジを指定するには xmlxslt で XML をいじくる必要がある。
参考:Terraform + libvirt + Open vSwitch - Qiita

しかし、こんないじくりを毎度やるのは面倒である。だから、この issue では .tf ファイルにシンプルに記述するだけで Open vSwitch のブリッジから特定の VLAN を VM に渡すなどができるようにする。具体的には以下の項目を直接 .tf ファイルで指定できるようにする。

  • Open vSwitch の Interface ID
    • これは誤解していた。不要だと思われる。
  • VLAN Trunk かどうか
  • Trunk である or Trunk でない場合に、Untagged なパケットはどの VLAN とするか(native VLAN 的な)

なお、fork 元は、libvirt のすべての機能を網羅することを予定していないようなので fork 元に PR は送らない。

その他

@sobadon sobadon added the enhancement New feature or request label Nov 20, 2022
@sobadon sobadon self-assigned this Nov 20, 2022
@sobadon
Copy link
Author

sobadon commented Nov 20, 2022

Open vSwitch で 1 つの Tagged VLAN を Untag して VM に渡す XML の例。virsh edit のときに virtualportparameters は書かなくても良かった。interfaceid は、Open vSwitch の何らかの指定値ではない様子。

test_vm1.xml
<domain type='kvm'>
  <name>test-vm1</name>
  <uuid>0e7e4d57-6f38-4fff-adf0-06a3a9f25fc6</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-focal'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu mode='custom' match='exact' check='none'>
    <model fallback='forbid'>qemu64</model>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='volume' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source pool='vol1' volume='test_vm1_vol1.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <wwn>05abcd9e6062ec99</wwn>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/opt/libvirt/vol1/cloud_init.iso'/>
      <target dev='hdd' bus='ide'/>
      <readonly/>
      <serial>cloudinit</serial>
      <address type='drive' controller='0' bus='1' target='0' unit='1'/>
    </disk>
    <controller type='scsi' index='0' model='virtio-scsi'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </controller>
    <controller type='usb' index='0' model='piix3-uhci'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:0a:a9:00'/>
      <source bridge='br_vlan2'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='52:54:00:93:98:32'/>
      <source bridge='br_ovs_dev1'/>
      <vlan>
        <tag id='2'/>
      </vlan>
      <virtualport type='openvswitch'>
        <parameters interfaceid='c0a6364a-a5e4-4d9d-99a4-be76392cc29e'/>
      </virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <channel type='unix'>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' autoport='yes'>
      <listen type='address'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/urandom</backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </rng>
  </devices>
</domain>

VM 起動中の ovs-vsctl show

vxlan_dev1 が VLAN Trunk している。

$ sudo ovs-vsctl show
1588e296-68b1-41ac-9551-e7eaf22943fc
    Bridge br_ovs_dev1
        Port br_ovs_dev1
            Interface br_ovs_dev1
                type: internal
        Port vxlan_dev1
            Interface vxlan_dev1
        Port vnet2
            tag: 2
            Interface vnet2
    ovs_version: "2.13.8"

@sobadon
Copy link
Author

sobadon commented Nov 20, 2022

Open vSwitch で 1 つの Tagged VLAN を Untag して VM に渡し、もう 1 つの Tagged VLAN をそのまま Tagged のまま VM に渡す XML の例。

<vlan><tag> を複数指定していると、<vlan>trunk='yes' は自動で設定される。virsh edit で編集するとき trunk=yes なしで保存したら自動でそれが追加されていた。

test_vm1.xml
    <interface type='bridge'>
      <mac address='52:54:00:ce:16:de'/>
      <source bridge='br_ovs_dev1'/>
      <vlan trunk='yes'>
        <tag id='2' nativeMode='untagged'/>
        <tag id='3'/>
      </vlan>
      <virtualport type='openvswitch'>
        <parameters interfaceid='a6d60ecc-e074-4cee-9736-85d14f0505de'/>
      </virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </interface>
VM 起動中の ovs-vsctl show

vxlan_dev1 が VLAN Trunk している。

$ sudo ovs-vsctl show
1588e296-68b1-41ac-9551-e7eaf22943fc
    Bridge br_ovs_dev1
        Port br_ovs_dev1
            Interface br_ovs_dev1
                type: internal
        Port vxlan_dev1
            Interface vxlan_dev1
        Port vnet2
            tag: 2
            trunks: [2, 3]
            Interface vnet2
    ovs_version: "2.13.8"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant