~~NOTOC~~

A VM Sample with Context & Network 2.2

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). ===== Downloading the pre-configured VM ===== We have prepared and contextualized a VM which is available for download [[http://dev.opennebula.org/attachments/download/355/ttylinux.tar.gz|here]]. The VM runs [[http://minimalinux.org/ttylinux|ttylinux]]. $ cd $ mkdir one-templates $ cd one-templates $ wget http://dev.opennebula.org/attachments/download/355/ttylinux.tar.gz $ tar xvzf ttylinux.tar.gz ===== Preparing the Network ===== 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 ===== Preparing the Image ===== Modify the image.one file and set the PATH. Then register the Image with ''oneimage''. $ oneimage create image.one ===== Modifying the Template ===== The VM template that you have just downloaded, ttylinux.one, has a few parameters that you should adjust to your convenience: * files = "/path/to/init.sh /path/to/id_dsa.pub", * username = "opennebula" * ip_public = "x.x.x.x" 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. ===== Running the VM ===== 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 $ONE_LOCATION/var and to boot up the system. In the mean time 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 $ONE_LOCATION/var//vm.log (vm specific log) and $ONE_LOCATION/var/oned.log. We can ssh into the VM. The user is **root** and the password is **password**: $ ssh root@192.168.1.6 Warning: Permanently added '192.168.1.6' (RSA) to the list of known hosts. root@192.168.1.6'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 [[.:vgg#using_the_leases_within_the_virtual_machine|here]]. ===== Running the VM Again with a CONTEXT ===== 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 [[.:cong|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 opennebula@192.168.0.7 Chop wood, carry water. $ As you can see the IP specified in the CONTEXT section overrides the IP generated by OpenNebula.