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'/>

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

$ 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'>
   <boot dev='hd'/>
   <interface type='network'>
     <source network='default'/>
     <model type='virtio'/>
   <interface type='network'>
     <source network='a-net'/>
     <model type='virtio'/>
   <interface type='network'>
     <source network='b-net'/>
     <model type='virtio'/>
   <serial type='pty'>
     <source path='/dev/pts/3'/>
     <target port='0'/>
   <graphics type='vnc' autoport='yes' listen=''>
     <listen type='address' address=''/>

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

[ user-data ]

Assign static IP addresses.
$ cat user-data
ssh_pwauth: yes
 list: |
 expire: False

#  - 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

     auto ens5
     iface ens5 inet static

 mode: reboot

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

$ uvt-kvm ip test05
$ ssh ubuntu@

ubuntu@ubuntu:~$ ip a s | grep 192
   inet brd scope global ens3
   inet brd scope global ens4
   inet brd scope global ens5

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.