Agile DevOps - People and Process then Automation!!!

Use Cloud and DevOps to build infrastructure by rapid agile iterative development using collaborative open source tools:
-Terraform or Cloud Formation for easy orchestration.
-chef cookbooks, puppet modules or ansible playbooks to build servers.
-Test Kitchen to deploy and test them.
-Packer for build server images or containers.
-EC2Dream a graphic user interface that provides a 'single pane of glass' to do agile devops primarily on cloud servers.
-Amazon AWS, Azure, Google Compute Engine, IBM, Openstack, Local and Hosted servers.

Scripting with Ruby


It is possible to write scripts with Amazon EC2 in many scripting languages: bash, python, perl.

However Ruby seems to be a good choice:
- Ruby code is much more readable than perl or python and fully object orientated.
- AWS supply a complete Ruby SDK.
- Fog provide a good and frequently updated cloud service library for all major clouds
- Rightscale provide an Amazon AWS interface called Right_AWS.
- Ruby runs efficiently on all Operating Systems.

Ruby AWS Gems
Three interfaces to Cloud from Ruby:
a. AWS SDK for Ruby
b. Fog
c. Right AWS
I am using the Right AWS gem from RightScale but migrating to the Fog interface.

1. Ruby Language Documentation

The Pragmatic Programmer's Guide
Ruby Programming for the Absolute Beginner
The Ruby Course Slides
Quick links for Ruby Programmers
Ruby Tutorial
Ruby API Doc
Techotopia Ruby_Essentials
Ruby Tutorial

Ruby Forum

Right AWS Documentation
RightScale AWS Forums

2. Installing Ruby and AWS.

If you use a rightscale image then java and ruby will already be installed. I have found you just need to update existing gems and install the rightscale AWS interface.
   gem update
   gem install right_aws

Otherwise you need to install
a. Java 1.5 or higher (For CentOS see http://wiki.centos.org/HowTos/JavaOnCentOS)
b. The Amazon Tools
c. Ruby
   yum install -y ruby
   yum install -y ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdoc
d. AWS Interface for Ruby
   gem install right_aws

To install the very latest version of RightAWS
a. download from http://rubyforge.org/projects/rightscale
b. install from the file:
   gem install right_aws-1.10.0.gem

3. Coding ruby scripts for AWS


Two parts to coding ruby for Amazon EC2:

a. Acessing metadata
The metadata is documented in Instance Metadata
and an example of accessing user-data is:

   url_user_data = 'http://169.254.169.254/2008-02-01/user-data'
   parameter = Net::HTTP.get_response(URI.parse(url_user_data)).body


b. Using the API
Ruby AWS follows the API so you can read the standard API docs see Amazon EC2 Query API
Typical first connect to EC2:
AMAZON_PUBLIC_KEY=<public key>
AMAZON_PRIVATE_KEY=<private key>
ec2 = RightAws::Ec2.new(AMAZON_PUBLIC_KEY, AMAZON_PRIVATE_KEY)

then issue commands (For example attach a volume):
vol = ec2.attach_volume(ec2_vol, instance_id, '/dev/sdf')


Some comands return values in hash objects that can be accessed as follows:
sa = ec2.describe_instances()
sa.each do |s|
  aws_image_id = s[:aws_image_id]
  aws_instance_id = s[:aws_instance_id]
  aws_state = s[:aws_state]
  print "image ",aws_image_id," instance ",aws_instance_id," State ",aws_state,"\n"
end


4. Scripts to do backup to S3

See s3sync.net

0 comments:

Post a Comment