Using cloud-init in oVirt
What is cloud-init? #
cloud-init provides the capability of early initialization of a virtual machine.
This usually happens during the startup of the guest operating system on the virtual machine.
What can I do with it in oVirt? #
oVirt allows you to configure: #
- an initial user account including password and your SSH key
- a hostname
- the timezone of the virtual machine
- DNS settings and networks on the virtual machine
Additionally it allows you to pass a custom cloud-init script, which should give you the full flexibility cloud-init provides.
Virtual machine requirements #
In order to use cloud-init with a virtual machine the cloud-init package has to be installed on the VM in question. For most distributions packages for cloud-init should be available in their respective package repositories.
So the VM, you would like to use cloud-init with, needs to have preinstalled the cloud-init package and should be configured to start automatically on boot.
cloud-init configuration within oVirt #
There are two ways to configure the cloud-init parameters:
- Permanent: Allows to save a configuration, which is useful in case of stateless virtual machines that discard all changes after the VM gets shutdown.
- Temporary: Allows to pass configuration via the run once dialog that will be only used for the current run of the virtual machine.
How to permanently setup cloud-init parameters for a VM in oVirt #
- Log in to the user portal or the administration portal of your oVirt instance
- In case of the user portal, click on the ‘Extended’ link in the left upper corner to get the list of your VMs. (This step is not required for the Administration portal)
- Select the VM you’d like to configure in the list by left clicking it
- The ‘Edit’ link in the list header should now become active – Click it
- The ‘Edit Virtual Machine’ dialog opens up.
- Now choose the ‘Initial Run’ section on the left hand side of the dialog (Usually the 3rd entry from the top) If the ‘Initial Run’ section is not present, press the ‘Show Advanced Options’ in the left bottom area of the dialog, to reveal hidden options.
- You’re presented with a check box ‘Use Cloud-Init/Sysprep’ – mark it as checked – This will reveal the available options.
Now you can configure the options as you wish and after pressing OK, with the next start of the VM the configuration should be applied automatically.
How to temporarily setup cloud-init parameters for a VM in oVirt via Run-Once #
- Log in to the user portal or the administration portal of your oVirt instance
- In case of the user portal click on the ‘Extended’ link, in the left upper corner to get the list of your VMs. (This step is not required for the Administration portal)
- Select the VM you’d like to configure in the list by left clicking it
- Click the ‘Run-Once’ link in the list header – This will open the ‘Run Virtual Machine(s) dialog
- Now choose the 'Initial Run’ section
- You’re presented with a check box ‘Use Cloud-Init’ – mark it as checked – This will reveal the available options.
Now you can configure the options as you wish and after pressing OK the VM will be started with these options configured and being applied to the within the VM.
The information entered will not be persisted and is discarded on shutdown of the VM, applied changes inside of the VM of course stay as they are, as long as it is not a stateless VM.
Using the cloud-init with the oVirt SDK #
One can also utilize cloud-init with the oVirt SDK
An example for this can be found here
Screenshots #
Here are now some screenshots from the Run Once dialog
The configuration, looks and behavior in the Edit VM dialog are equivalent.
Run Once Dialog – Unchecked cloud-init checkbox #
Run Once Dialog – Checked cloud-init checkbox default #
Run Once Dialog – Hostname, timezone and authentication information #
Run Once Dialog – Network configuration DHCP #
Run Once Dialog – Network configuration static #
Run Once Dialog – Custom cloud-init script #
A video presentation #
This is an old presentation from 2013 made by my colleague Omer Frenkel
It’s not completely up to date but at least gives an idea :-)