From ae746b7b8a0c1990c1efe8bd796ca9cddc9d87c6 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 10 Sep 2012 17:48:01 +0200 Subject: [PATCH] appenv: Initial commit --- env/README.md | 156 +++++++++++ env/bin/appenv | 206 ++++++++++++++ env/cli/appenv_helper.rb | 112 ++++++++ env/lib/onecast.rb | 64 +++++ env/lib/onechef.rb | 157 +++++++++++ env/share/guest/etc/one-context.d/99-one-chef | 265 ++++++++++++++++++ 6 files changed, 960 insertions(+) create mode 100644 env/README.md create mode 100755 env/bin/appenv create mode 100644 env/cli/appenv_helper.rb create mode 100644 env/lib/onecast.rb create mode 100644 env/lib/onechef.rb create mode 100755 env/share/guest/etc/one-context.d/99-one-chef diff --git a/env/README.md b/env/README.md new file mode 100644 index 0000000000..c26b894ef3 --- /dev/null +++ b/env/README.md @@ -0,0 +1,156 @@ + +# Overview + +Installing services can sometimes be tedious. Getting the VM ins good shape, installing the packages needed, deploying the application and configuring it. On case of disaster or scaling the service you will need to perform again these tasks. To automate all this burden we now have Configuration Management software like [chef](http://www.opscode.com/chef/), [puppet](http://puppetlabs.com/puppet/what-is-puppet/) or [cfengine](http://cfengine.com/). + +With this software we can script the installation and configuration of applications and services. You can also describe the services and their configuration that will be installed on a node so we can automate its installation. We will also be sure that each installation will be equal to other using the same configuration. + +The tool oneenv will make use of [chef-solo](http://wiki.opscode.com/display/chef/Chef+Solo). It lets you register chef configurations and instantiate them using predefined templates and images. + +# Guide + +The first step you need to do is to prepare an OS image to be able to use chef recipes from contextualization (link to guide) or download an already prepared image from the marketplace. Then we need to create a template referring to this image. + +The next step will be describing our new node. You can follow the [chef guide](http://wiki.opscode.com/display/chef/Nodes) to understand these files. For these examples we are going to use this file: + + { + "name": "wordpress", + "run_list": [ + "recipe[mysql::server]", + "recipe[wordpress]" + ], + "wordpress": { + "db": { + "database": "${WP_DB_NAME|wordpress}", + "user": "${WP_DB_USER|wordpress}", + "password": "${WP_DB_PASSWORD|password}" + } + }, + "mysql": { + "server_root_password": "${MYSQL_ROOT_PASSWORD|password}" + } + } + +The node files are JSON encoded and contain the recipes that are going to be run on the VM and parameters that will be used to install and configure the software. You will notice that there are some strange values in this form: + + ${WP_DB_NAME|wordpress} + +oneenv comes with a template engine that will let you create node files with variables. These variables are named and can contain default values. the form is: + + ${NAME[|]} + +The name will be used to refer to it on VM instantiation (we will see this later on) and the default value will substitute the variable if it is not explicitly specified. + +We save this file as node.json and now comes the registration part. oneenv will let us register it in the OpenNebula database. To register the node file we can use the command `oneenv create`: + + $ oneenv create node.json + 21 + +The number returned is the identifier to our newly registered node file. We can also specify some parameters: + + -n, --name name Name of the role + -t, --templates t1,t2 Templates compatible with the role + -c, --cookbooks cookbooks URL to extra cookbooks + +On VM creation the recipes specified in the node file will be automatically downloaded from the standard chef cookbooks repository but we can specify a URL of a tar.gz containing extra cookbooks that you have created. For example: + + $ oneenv create --name my_blog --templates ubuntu,centos --cookbooks http://some.url.com/cookbooks.tar.gz node.json + 22 + +We can list the nodes we already have defined: + + $ oneenv list + ID NAME + 21 wordpress + 22 my_blog + +And show the properties: + + $ ./oneenv show my_blog + ROLE 22 INFORMATION + ID : 22 + NAME : my_blog + USER : oneadmin + GROUP : oneadmin + COMPATIBLE TEMPLATES: ubuntu, centos + COOKBOOKS : http://some.url.com/cookbooks.tar.gz + + PERMISSIONS + OWNER : um- + GROUP : --- + OTHER : --- + + DEFAULT VARIABLES + WP_DB_NAME : wordpress + WP_DB_USER : wordpress + WP_DB_PASSWORD : password + MYSQL_ROOT_PASSWORD : password + + ROLE DEFINITION + { + "name": "wordpress", + "run_list": [ + "recipe[mysql::server]", + "recipe[wordpress]" + ], + "wordpress": { + "db": { + "database": "${WP_DB_NAME|wordpress}", + "user": "${WP_DB_USER|wordpress}", + "password": "${WP_DB_PASSWORD|password}" + } + }, + "mysql": { + "server_root_password": "${MYSQL_ROOT_PASSWORD|password}" + } + } + +There we can see the node file and its properties. It is also handy the default variables. Those are the ones we can change on instantiation. + +We will be also able to update the node file using `oneenv update `. A text editor will be run letting us modify the node file. + +To instantiate a VM that will use this node we will use the command `oneenv instantiate