lost and found ( for me ? )

Ubuntu uvtool : how to use a template and use-data(cloud init)

Here are samples on how to use a template and user-data with uvt-kvm.

When you create a VM as below, the VM will belong to “default” network.
$ uvt-kvm create --password=hello test01

user name : ubuntu
credentials : hello

$ virsh dumpxml test01
   <interface type='network'>
     <mac address='52:54:00:fc:3c:56'/>
     <source network='default' bridge='virbr0'/>
     <target dev='vnet0'/>
     <model type='virtio'/>
     <alias name='net0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
   </interface>

When you create a VM without specifying a template, uvt-kvm will create a VM by using a “template.xml”
$ pwd
/usr/share/uvtool/libvirt

$ ls
remote-wait.sh  template.xml

If you want to customize a network which a VM belongs to, you can change that by using a template.

$ cat template02.xml
<domain type='kvm'>
 <os>
   <type>hvm</type>
   <boot dev='hd'/>
 </os>
 <features>
   <acpi/>
   <apic/>
   <pae/>
 </features>
 <devices>
   <interface type='network'>
     <source network='default'/>
     <model type='virtio'/>
   </interface>
   <interface type='network'>
     <source network='a-net'/>
     <model type='virtio'/>
   </interface>
   <interface type='network'>
     <source network='b-net'/>
     <model type='virtio'/>
   </interface>
   <serial type='pty'>
     <source path='/dev/pts/3'/>
     <target port='0'/>
   </serial>
   <graphics type='vnc' autoport='yes' listen='127.0.0.1'>
     <listen type='address' address='127.0.0.1'/>
   </graphics>
   <video/>
 </devices>
</domain>

$ uvt-kvm create --password=hello --template=./template02.xml --cpu 1 --disk 5 test02

[ user-data ]

Assign static IP addresses.
$ cat user-data
#cloud-config
ssh_pwauth: yes
chpasswd:
 list: |
   ubuntu:hello
 expire: False

write_files:
#  - path: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
#    owner: root:root
#    permissions: '0644'
#    content: |
#      network: {config: disabled}
 - path: /etc/network/interfaces.d/50-cloud-init.cfg
   owner: root:root
   permissions: '0644'
   content: |
     auto ens3
     iface ens3 inet dhcp

     auto ens4
     iface ens4 inet static
     address 192.168.130.120
     netmask 255.255.255.0

     auto ens5
     iface ens5 inet static
     address 192.168.131.120
     netmask 255.255.255.0

power_state:
 mode: reboot

$ uvt-kvm create --user-data=./user-data --template=./template02.xml --cpu 1 --disk 5 test05

$ uvt-kvm ip test05
192.168.122.34
$ ssh ubuntu@192.168.122.34

ubuntu@ubuntu:~$ ip a s | grep 192
   inet 192.168.122.34/24 brd 192.168.122.255 scope global ens3
   inet 192.168.130.120/24 brd 192.168.130.255 scope global ens4
   inet 192.168.131.120/24 brd 192.168.131.255 scope global ens5
ubuntu@ubuntu:~$