Hey folks,

Just wanting to share the knowledge in case I get hit by a bus (and provide an opportunity for those of you who know more than me to point out my howling errors) :-)

With the new MAAS (1.8) devices API, to allocate an IP address for a container we need to know the MAC address of the container. To setup routing for the container we need to know the IP address before we create the container. So we need to know (i.e. generate) the MAC address before container creation.

In order to specify a MAC address for a KVM image we need to create a libvirt domain xml template to pass as the template argument to uvt-kvm.

References:

http://manpages.ubuntu.com/manpages/trusty/man1/uvt-kvm.1.html
https://libvirt.org/formatdomain.html#elementsNICS
https://help.ubuntu.com/lts/serverguide/cloud-images-and-uvtool.html

Ideally we'd like to specify as *little as possible* in the template and have the generated libvirt xml (i.e. the created image) be identical to what uvt-kvm would have created for us without the template. The only change being that the image will have a network interface with the MAC address we specify.

Attached are two xml files. "juju-bare-metal.xml" is the *generated* xml (using master) for a kvm image on MAAS bare metal (functionally the same as the xml we generate for a kvm image in a kvm image - I checked). "template.xml" is the minimal template I found that would cause uvt-kvm to generate the same image.

We already have code support (need to check it works) for specifying a NIC with MAC address for lxc.

All the best,

Michael Foord

<domain type='kvm'>
  <name>juju-machine-0-kvm-0</name>
  <uuid>2fec39e2-30ad-4bbf-b8be-1b6b678fc957</uuid>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm-spice</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/uvtool/libvirt/images/juju-machine-0-kvm-0.qcow'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/uvtool/libvirt/images/juju-machine-0-kvm-0-ds.qcow'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <interface type='bridge'>
      <mac address='52:54:00:91:16:bd'/>
      <source bridge='juju-br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='stdio'>
      <target port='0'/>
    </serial>
    <console type='stdio'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <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>
  </devices>
</domain>


<domain type='kvm'>
  <name>new-machine</name>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type>hvm</type>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <devices>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <serial type='stdio'>
      <target port='0'/>
    </serial>
    <console type='stdio'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <interface type='network'>
      <mac address='52:54:00:7a:ef:cf'/>
      <model type='virtio'/>
      <source network='maas'/>
    </interface>
  </devices>
</domain>

-- 
Juju-dev mailing list
Juju-dev@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju-dev

Reply via email to