Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
adding the hello ec2 example and readme. bug fixes to support that ex…
Browse files Browse the repository at this point in the history
…ample
  • Loading branch information
BuzzTroll committed Mar 29, 2011
1 parent 9ec5332 commit f9e2563
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cloudinitd/bootfabtasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def bootpgm(pgm=None, conf=None, output=None, stagedir=None):
tarname = _iftar(relpgm)
if tarname:
destpgm = _tartask(stagedir, tarname, destpgm)
if conf:
if conf and conf != "None":
destconf = "%s/bootconf.json" % stagedir
put(conf, destconf)
with cd(stagedir):
Expand Down
2 changes: 2 additions & 0 deletions cloudinitd/cb_iaas.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def iaas_validate(svc, log=logging):
if not svc._s.localkey:
if svc._s.readypgm or svc._s.bootpgm:
raise ConfigException("If you are using a readypgm or a bootpgm you must have an ssh key")
msgs.append("You have no localsshkeyname set for this plan.")
rc = 1

if not svc._s.username:
if svc._s.readypgm or svc._s.bootpgm:
Expand Down
2 changes: 1 addition & 1 deletion cloudinitd/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _make_pollers(self):
if self._s.contextualized == 1:
cloudinitd.log(self._log, logging.DEBUG, "%s is already contextualized" % (self.name))
else:
if self._s.bootconf:
if self._s.bootpgm:
cmd = self._get_boot_cmd()
self._boot_poller = PopenExecutablePollable(cmd, log=self._log, allowed_errors=0, callback=self._context_cb, timeout=1200, done_cb=self.context_done_cb)
self._pollables.add_level([self._boot_poller])
Expand Down
144 changes: 144 additions & 0 deletions docs/plans/helloec2/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
Hello EC2
=========

This example shows how to launch a single VM with cloudinit.d. This is a
very rudimentary example designed to provide a quick introduction to
cloudinit.d. In it we will create the configuration files needed to
contact EC2 and launch a known AMI and to test that VM to determine when
it is ready.

Prerequisites
------------

Before you begin you will need 4 standard pieces of information from your
EC2 account.

- access key (this is akin to your EC2 login ID)
- access secret (this is akin to your EC2 password)
- ec2 key name
- path to the matching local ssh key

If you have ever launched a VM on EC2 you have all of this information. If
not you will need to sign up for an EC2 account to get it.

Further, in order to make this work your default security group on EC2
must have port 22 open.

Try it out
----------

Before we dive into the details of the example lets try it out First, boot
the plan (note: running this command successfully is subject to amazon
web services pricing, currently $0.025 per hour).

$ cloudinitd -v -v -v boot helloec2.conf
Starting up run 8d5e0753
Started IaaS work for sampleservice
Starting the launch plan.
Begin boot level 1...
Started sampleservice
SUCCESS service sampleservice boot
hostname: ec2-50-17-8-151.compute-1.amazonaws.com
instance: i-1255f67d
SUCCESS level 1

Here we see that we booted the plan. The option -v simply increases the
amount of output that we will see. The messages printed to the console
tell us the run name and that the plan was successfully launched.

Let us say that a few hours have past and we want to check on the status of
our ec2 cloud application. To do so we need to remember the run name
which was printed out above and then run:

Checking status on 8d5e0753
Begin status level 1...
Started sampleservice
SUCCESS service sampleservice status
hostname: ec2-50-17-8-151.compute-1.amazonaws.com
instance: i-1255f67d
SUCCESS level 1

The output here shows that everything is still successfully running.

Now we shall terminate the cloud application with the following command:

$ cloudinitd -v -v -v terminate 8d5e0753
Terminating 8d5e0753
Begin terminate level 1...
Started sampleservice
SUCCESS service sampleservice terminate
hostname: None
instance: None
SUCCESS level 1
deleting the db file /home/bresnaha/.cloudinitd/cloudinitd-8d5e0753.db

Configuration Plan
------------------

To find out what happened we must explore the configuration files. There
are two files, the top level configuration file helloec2.conf and the
level configuration file, helloec2_level1.conf.

We start by looking at the very simple helloec2.conf which contains the
following:

[runlevels]
level1: helloec2_level1.conf

all this does is tell cloudinit.d that there is 1 level and it is described
in the file helloec2_level1.conf. A more complicated application would
have more levels.

Now we look at the file helloec2_level1.conf:

[svc-sampleservice]

iaas_key: env.CLOUDBOOT_IAAS_ACCESS_KEY
iaas_secret: env.CLOUDBOOT_IAAS_SECRET_KEY
localsshkeypath: env.CLOUDBOOT_IAAS_SSHKEY
keyname: env.CLOUDBOOT_IAAS_SSHKEYNAME

ssh_username: ubuntu
image: ami-30f70059
allocation: t1.micro

bootpgm: bootpgm.py

in it we see that a single service call 'sampleservice' is described. The
first four lines tell cloudinit.d where the needed information described
above can be found. The prefix 'env.' is a directive to check the
environment variable of the following name for the value in question.

The next three lines describe the image to be launch. Here we will launch
the ubuntu10.10 AMI already stored in EC2. The allocation field allows
us to decide how much hardware we need. For the sake of of saving money
we have chosen the micro instance. The ssh_username field is the user name
that the VM image has configured to allow access via your local ssh key.
In the case of the ubuntu image this value is 'ubuntu'.

The final value is the bootpgm. This value is a script that will be uploaded
and run on the VM. This is your opportunity to contextualize your VM instance
with needed values. In our case we simply create a basic web page:

#!/usr/bin/env python

import sys
import os

f = open("hello.html", "w")
f.write("<html><body>Hello cloudinit.d!</body></html>")
f.close()

cmd = "sudo cp hello.html /var/www/"
os.system(cmd)

sys.exit(0)

This simple python script opens a file and writes an html message. It then
uses the pre-configured sudo access (common on ubuntu images) to copy the
web page to location that the apache2 web server will display.

Once you boot this plan goto: http://<ec2 hostname>/hello.html and you will
see the message created in the bootpgm.py script.


144 changes: 144 additions & 0 deletions docs/plans/helloec2/README.txt.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
Hello EC2
=========

This example shows how to launch a single VM with cloudinit.d. This is a
very rudemenatry example designed to provide a quick introduction to
cloudinit.d. In it we will create the configuration files needed to
contact EC2 and launch a known AMI and to test that VM to determine when
it is ready.

Prerequisits
------------

Before you begin you will need 4 standard pieces of information from your
EC2 account.

- access key (this is akin to your EC2 login ID)
- access secret (this is akin to your EC2 password)
- ec2 key name
- path to the matching local ssh key

If you have ever launched a VM on EC2 you have all of this information. If
not you will need to sign up for an EC2 account to get it.

Further, in order to make this work your default security group on EC2
must have port 22 open.

Try it out
----------

Before we dive into the details of the example lets try it out First, boot
the plan (note: running this command successfully is subject to amazon
web services pricing, currently $0.025 per hour).

$ cloudinitd -v -v -v boot helloec2.conf
Starting up run 8d5e0753
Started IaaS work for sampleservice
Starting the launch plan.
Begin boot level 1...
Started sampleservice
SUCCESS service sampleservice boot
hostname: ec2-50-17-8-151.compute-1.amazonaws.com
instance: i-1255f67d
SUCCESS level 1

Here we see that we booted the plan. The option -v simply increases the
amount of output that we will see. The messages printed to the console
tell us the run name and that the plan was successfully launched.

Let us say that a few hours have past and we want to check on the status of
our ec2 cloud application. To do so we need to remember the runname
which was printed out above and then run:

Checking status on 8d5e0753
Begin status level 1...
Started sampleservice
SUCCESS service sampleservice status
hostname: ec2-50-17-8-151.compute-1.amazonaws.com
instance: i-1255f67d
SUCCESS level 1

The output here shows that everything is still successfully running.

Now we shall terminate the cloud application with the following command:

$ cloudinitd -v -v -v terminate 8d5e0753
Terminating 8d5e0753
Begin terminate level 1...
Started sampleservice
SUCCESS service sampleservice terminate
hostname: None
instance: None
SUCCESS level 1
deleting the db file /home/bresnaha/.cloudinitd/cloudinitd-8d5e0753.db

Configuration Plan
------------------

To find out what happened we must explore the configuration files. There
are two files, the top level configuration file helloec2.conf and the
level configuration file, helloec2_level1.conf.

We start by looking at the very simple helloec2.conf which contains the
following:

[runlevels]
level1: helloec2_level1.conf

all this does is tell cloudinit.d that there is 1 level and it is described
in the file helloec2_level1.conf. A more complicated application would
have more levels.

Now we look at the file helloec2_level1.conf:

[svc-sampleservice]

iaas_key: env.CLOUDBOOT_IAAS_ACCESS_KEY
iaas_secret: env.CLOUDBOOT_IAAS_SECRET_KEY
localsshkeypath: env.CLOUDBOOT_IAAS_SSHKEY
keyname: env.CLOUDBOOT_IAAS_SSHKEYNAME

ssh_username: ubuntu
image: ami-30f70059
allocation: t1.micro

bootpgm: bootpgm.py

in it we see that a single service call 'sampleservice' is described. The
first four lines tell cloudinit.d where the needed information described
above can be found. The prefix 'env.' is a directive to check the
environment variable of the following name for the value in question.

The next three lines describe the image to be launch. Here we will launch
the ubuntu10.10 AMI already stored in EC2. The allocation field allows
us to decide how much hardware we need. For the sake of of saving money
we have choosen the micro instance. The ssh_username field is the user name
that the VM image has configured to allow access via your local ssh key.
In the case of the ubuntu image this value is 'ubuntu'.

The final value is the bootpgm. This value is a script that will be uploaded
and run on the VM. This is your opportunitty to contextualize your VM instance
with needed values. In our case we simply create a basic web page:

#!/usr/bin/env python

import sys
import os

f = open("hello.html", "w")
f.write("<html><body>Hello cloudinit.d!</body></html>")
f.close()

cmd = "sudo cp hello.html /var/www/"
os.system(cmd)

sys.exit(0)

This simple python script opens a file and writes an html message. It then
uses the preconfigured sudo access (common on ubuntu images) to copy the
web page to location that the apache2 web server will display.

Once you boot this plan goto: http://<ec2 hostname>/hello.html and you will
see the message created in the bootpgm.py script.


13 changes: 13 additions & 0 deletions docs/plans/helloec2/bootpgm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

import sys
import os

f = open("hello.html", "w")
f.write("<html><body>Hello cloudinit.d!</body></html>")
f.close()

cmd = "sudo cp hello.html /var/www/"
os.system(cmd)

sys.exit(0)
3 changes: 3 additions & 0 deletions docs/plans/helloec2/helloec2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[runlevels]
level1: helloec2_level1.conf

13 changes: 13 additions & 0 deletions docs/plans/helloec2/helloec2_level1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[svc-sampleservice]

iaas_key: env.CLOUDBOOT_IAAS_ACCESS_KEY
iaas_secret: env.CLOUDBOOT_IAAS_SECRET_KEY
localsshkeypath: env.CLOUDBOOT_IAAS_SSHKEY
keyname: env.CLOUDBOOT_IAAS_SSHKEYNAME

ssh_username: ubuntu
image: ami-30f70059
allocation: t1.micro

bootpgm: bootpgm.py

0 comments on commit f9e2563

Please sign in to comment.