Contextualization Overview 4.2
OpenNebula comes a method to pass information to a newly created Virtual Machine. This is very handy to configure parameters as soon as the VM is running. The most common thing configured with this system is networking.
Following are the instructions to contextualize your images to configure the network. For more in depth information and information on how to use this information for other duties head to the Contextualizing Virtual Machines guide.
To enable the Virtual Machine images to use the contextualization information written by OpenNebula we need to add to it a series of scripts that will trigger the contextualization.
You can use the images available in the Marketplace, that are already prepared, or prepare your own images. To make your life easier you can use a couple of Linux packages that do the work for you.
The contextualization package will also mount any partition labeled
swap as swap. OpenNebula sets this label for volatile swap disks.
We will also need to add the gateway information to the Virtual Networks that need it. This is an example of a Virtual Network with gateway information:
NAME=public NETWORK_ADDRESS=188.8.131.52 NETWORK_MASK=255.255.255.0 GATEWAY=184.108.40.206 DNS="220.127.116.11 18.104.22.168"
And then in the VM template contextualization we set NETWORK to “yes”:
CONTEXT=[ NETWORK=YES ]
When the template is instantiated, those parameters for `eth0` are automatically set in the VM as:
CONTEXT=[ DISK_ID="0", ETH0_DNS="22.214.171.124 126.96.36.199", ETH0_GATEWAY="188.8.131.52", ETH0_IP="184.108.40.206", ETH0_MASK="255.255.255.0", ETH0_NETWORK="220.127.116.11", NETWORK="YES", TARGET="hda" ]
If you add more that one interface to a Virtual Machine you will end with same parameters changing ETH0 to ETH1, ETH2, etc.
You can also add `SSH_PUBLIC_KEY` parameter to the context to add a SSH public key to the `authorized_keys` file of root.
CONTEXT=[ SSH_PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+vPFFwem49zcepQxsyO51YMSpuywwt6GazgpJe9vQzw3BA97tFrU5zABDLV6GHnI0/ARqsXRX1mWGwOlZkVBl4yhGSK9xSnzBPXqmKdb4TluVgV5u7R5ZjmVGjCYyYVaK7BtIEx3ZQGMbLQ6Av3IFND+EEzf04NeSJYcg9LA3lKIueLHNED1x/6e7uoNW2/VvNhKK5Ajt56yupRS9mnWTjZUM9cTvlhp/Ss1T10iQ51XEVTQfS2VM2y0ZLdfY5nivIIvj5ooGLaYfv8L4VY57zTKBafyWyRZk1PugMdGHxycEh8ek8VZ3wUgltnK+US3rYUTkX9jj+Km/VGhDRehp user@host" ]
You can get more information about these parameters in the contextualization guide.