Enhancing OpenNebula EC2 Driver - Part 2
This is part 2 of the tutorial. Part 1 is available here.
Contextualization
One really nice feature of OpenNebula is the contextualization mechanism. By defining a CONTEXT parameter in the instance template file, OpenNebula will take care of generating an ISO image and pass it to the instance created. You then include the script provided in $ONE_SRC_CODE_PATH/share/scripts/vmcontext.sh into the /etc/init.d directory in the VM root file system, chmod +x to set execution bit on and create a link in the /etc/rc2.d directory (or whatever path your OS need). Your instance will be configure at boot time!. See http://opennebula.org/documentation:rel3.0:cong>the documentation</a> for more information on this feature.
I wanted to use this feature on Amazon AMI as well and fortunately it is possible! Instead of passing a ISO image to the instance, you send "user-data" to it by using the '-d' or '-f' arguments when launching your instance with 'ec2-run-instances'.You can then later get the data in your instance by querying http://169.254.169.254/latest/user-data with curl...
So I changed the EC2 driver to fetch specific keywords in the template's CONTEXT parameter and use them to pass user-data to 'ec2-run-instances'.
Parameter | Attribute | Usage |
---|---|---|
CONTEXT | USERDATA | User data to send to the instance from the command line. Note: use only one attribute for user data, USERDATA or USERDATAFILE, not both...
Example(s): USERDATA="some data format" (ec2-run-instances [GENERAL OPTIONS] $AMI -d "$USERDATA" ...) |
CONTEXT | USERDATAFILE | User data to the instance from the content stored in the indicated file. Note: use only one attribute for user data, USERDATA or USERDATAFILE, not both...
Example(s): USERDATAFILE=/path/to/the/file (ec2-run-instances [GENERAL OPTIONS] $AMI -f $USERDATAFILE ...) |
Using EC2 Regions...
The next challenge was to add regions and datacenter management. With the standard driver you have to make multiple definitions of the vmm_ec2 driver in the $ONE_lOCATION/etc/oned.conf and a –region attribute to the arguments attribute of the driver’s definition.
Since onehost allow to define custom attributes to a host, I decided that the driver would rely on a custom EC2REGION attribute pointing to the corresponding AWS REGION. When invoked, onehost update <hostid> reads the EDITOR environment variable and pipes to it the editable attributes of the designated host. To avoid having to run it interactively, I created the following script that generates an uninteractive text editing job using ed.
The following example will set the attribute EC2REGION to eu-west-1 for the opennebula host number 1. Please make sure the region you specify corresponds to the real region of the EC2 fake host you created.
The patch is available in part 3.
blog comments powered by Disqus