A VM Sample with Context & Network 3.0
The purpose of this section is to demonstrate how to quickly deploy a VM with OpenNebula in a few easy steps. We will assume that you have properly configured OpenNebula and that you have at least one worker node running KVM (this guide does not work with Xen for the moment).
$ cd $ mkdir one-templates $ cd one-templates $ wget http://dev.opennebula.org/attachments/download/355/ttylinux.tar.gz $ tar xvzf ttylinux.tar.gz
For this example we are going to use the simplest possible network configuration. We provide a file with the package which is a network template example, called small_network.net. You should edit that file and change the LEASES entries to available IPs from your network.
You should also change the BRIDGE entry if you Hypervisor is configured to use a different bridge.
Once the file is prepared we can create the network:
$ onevnet create small_network.net
Modify the image.one file and set the PATH. Then register the Image with
$ oneimage create image.one
The VM template that you have just downloaded, ttylinux.one, has a few parameters that you should adjust to your convenience:
Do not uncomment the CONTEXT section just yet, though.
You should choose the ip_public field to be an IP which does not match any of the predefined LEASES of small_network.net (only for demonstration purposes).
Finally copy your public key to the directory where you downloaded the VM. Be sure to rename id_dsa.pub to id_rsa.pub in the VM template if you are using an RSA key.
We are ready to deploy the VM. To do so simply do:
$ onevm create ttylinux.one
It will take a minute or so to copy the image to /var/lib/one and to boot up the system. In the meantime we can figure out what IP the VM will have so that we can ssh into it.
$ onevm show ttylinux|grep IP IP=192.168.1.6,
By now, the VM should be up and running:
$ onevm list ID USER NAME STAT CPU MEM HOSTNAME TIME 3 oneadmin myttyser runn 0 65536 localhost 00 00:06:49
Note: If the STAT attribute is not runn you should read the logs to see why it did not boot. You can find these logs in /var/log/one/<id>.log (vm specific log) and /var/log/one/oned.log.
We can ssh into the VM. The user is root and the password is password:
$ ssh firstname.lastname@example.org Warning: Permanently added '192.168.1.6' (RSA) to the list of known hosts. email@example.com's password: Chop wood, carry water. #
You might have been wondering how did the VM get automagically configured with an IP from the pool of IPs defined by the ONE Network associated to the VM template. Basically, we developed a script that runs during the bootup procedure which configures the IP address based on the MAC address of the VM. This is more thoroughly explained here.
We have not yet used the CONTEXT feature of OpenNebula which not only provides a simple way to configure the IP of the VM, but which also allows us to configure users, public keys, the host name, and any other thing we might think of. You can read a more detailed explanation on how to contextualize here.
Edit the ttylinux.one template, uncomment the CONTEXT section and redeploy the VM.
Now we can ssh to the VM without entering a password, since the id_dsa.pub has been copied to the authorized_keys of both root and the username account you have define in the template.
$ ssh firstname.lastname@example.org Chop wood, carry water. $
As you can see the IP specified in the CONTEXT section overrides the IP generated by OpenNebula.