Contextualization Overview 4.0

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.

inlinetoc

Preparing the Virtual Machine Image

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.

  • Start a image (or finish its installation)
  • Download the package for your distribution:
    • DEB: Compatible with Ubuntu 11.10/12.04 and Debian Squeeze
    • RPM: Compatible with CentOS and RHEL 6.x
  • Install it in the VM
  • Shutdown the VM

Preparing the Template

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=80.0.0.0
NETWORK_MASK=255.255.255.0
GATEWAY=80.0.0.1
DNS="8.8.8.8 8.8.4.4"

And then in the VM contextualization those parameters for `eth0` can be expressed as:

CONTEXT=[
  ETH0_IP = "$NIC[IP, NETWORK=\"public\"]",
  ETH0_NETWORK = "$NETWORK[NETWORK_ADDRESS, NETWORK=\"public\"]",
  ETH0_MASK = "$NETWORK[NETWORK_MASK, NETWORK=\"public\"]",
  ETH0_GATEWAY = "$NETWORK[GATEWAY, NETWORK=\"public\"]",
  ETH0_DNS = "$NETWORK[DNS, NETWORK=\"public\"]",
]

Remember to change the name of the network in the context section. If you add more that one interface to a Virtual Machine you can add the 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.