<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vladimir Vuksan&#039;s blog &#187; Ruby</title>
	<atom:link href="http://blog.vuksan.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vuksan.com</link>
	<description>Documenting the systems and network infrastructure madness</description>
	<lastBuildDate>Tue, 03 Jan 2012 03:50:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Provision to cloud in 5 minutes using fog</title>
		<link>http://blog.vuksan.com/2010/07/20/provision-to-cloud-in-5-minutes-using-fog/</link>
		<comments>http://blog.vuksan.com/2010/07/20/provision-to-cloud-in-5-minutes-using-fog/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 12:30:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Systems Management]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.vuksan.com/?p=281</guid>
		<description><![CDATA[Most recently I have been working on disaster recovery project where we are assembling documentation, processes and code to be able to fire up our whole environment in the cloud in case of a major disaster. At Velocity Conference I met Wesley Beary who is the main developer for fog, a Ruby cloud computing library. [...]]]></description>
			<content:encoded><![CDATA[<p>Most recently I have been working on disaster recovery project where we are assembling documentation, processes and code to be able to fire up our whole environment in the cloud in case of a major disaster. At Velocity Conference I met <a href="http://twitter.com/geemus">Wesley Beary</a> who is the main developer for <a href="http://github.com/geemus/fog/">fog</a>, a Ruby cloud computing library. What appealed to me about fog is that it has varying support for different clouds so that we are not stuck using a provider due to our non-portable code. Now off to couple quick example to get you going.</p>
<p>To install fog you will need to install Ruby Gems. If you have them type</p>
<pre>  sudo gem install fog</pre>
<p>The install may fail if you don't have the libxslt and libxml2 dev libraries. On my Ubuntu laptop I resolved it by doing</p>
<pre>  sudo apt-get install libxslt1-dev libxml2-dev</pre>
<p>On Centos/RHEL 5 I had to do</p>
<pre>   yum install libxslt-devel libxml2-devel</pre>
<p>Create a file called config.rb which contains your credentials e.g.</p>
<pre>#!/usr/bin/ruby

@aws_access_key_id = "XXXXXXXXXXXXXXXXXX"
@aws_secret_access_key = "AXXZZZZZZZZZZZZZZZZZZ"
@aws_region = "us-east-1"</pre>
<p>Let's start with the basics. Let's get our currently running instances and what images are available</p>
<pre>#!/usr/bin/ruby

require 'rubygems'
require 'fog'

# Import EC2 credentials e.g. @aws_access_key_id and @aws_access_key_id
require './config.rb'

# Set up a connection
connection = Fog::AWS::EC2.new(
    :aws_access_key_id =&gt; @aws_access_key_id,
    :aws_secret_access_key =&gt; @aws_secret_access_key )

# Get a list of all the running servers/instances
instance_list = connection.servers.all

num_instances = instance_list.length
puts "We have " + num_instances.to_s()  + " servers"

# Print out a table of instances with choice columns
instance_list.table([:id, :flavor_id, :ip_address, :private_ip_address, :image_id ])

###################################################################
# Get a list of our images
###################################################################
my_images_raw = connection.describe_images('Owner' =&gt; 'self')
my_images = my_images_raw.body["imagesSet"]

puts "\n###################################################################################"
puts "Following images are available for deployment"
puts "\nImage ID\tArch\t\tImage Location"

#  List image ID, architecture and location
for key in 0...my_images.length
  print my_images[key]["imageId"], "\t" , my_images[key]["architecture"] , "\t\t" , my_images[key]["imageLocation"],  "\n";
end</pre>
<p>Let's spin up a m1.large instance</p>
<pre>#!/usr/bin/ruby
require 'rubygems'
require 'fog'
# Import EC2 credentials e.g. @aws_access_key_id and @aws_access_key_id
require './config.rb'

# Set up a connection
connection = Fog::AWS::EC2.new(
 :aws_access_key_id =&gt; @aws_access_key_id,
 :aws_secret_access_key =&gt; @aws_secret_access_key )

server = connection.servers.create(:image_id =&gt; 'ami-1234567',
 :flavor_id =&gt;  'm1.large')

# wait for it to be ready to do stuff
server.wait_for { print "."; ready? }

puts "Public IP Address: #{server.ip_address}"
puts "Private IP Address: #{server.private_ip_address}"</pre>
<p>This may take a while so please be patient.  You could obviously spin up a number of these instances without waiting for any of them to be available then use connection.servers.all to get a list of running instances.</p>
<p>Now let's destroy a running instance</p>
<pre>#!/usr/bin/ruby
require 'rubygems'
require 'fog'
# Import EC2 credentials e.g. @aws_access_key_id and @aws_access_key_id
require './config.rb'

# Set up a connection
connection = Fog::AWS::EC2.new(
    :aws_access_key_id =&gt; @aws_access_key_id,
    :aws_secret_access_key =&gt; @aws_secret_access_key )

instance_id = "1-123456"

server = connection.servers.get(instance_id)

puts "Flavor: #{server.flavor_id}"
puts "Public IP Address: #{server.ip_address}"
puts "Private IP Address: #{server.private_ip_address}"

server.destroy</pre>
<p>There is tons more out there although this gets me going <img src='http://blog.vuksan.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Now off to playing with R.I. Pienaar's <a href="http://github.com/ripienaar/ec2-boot-init">ec2-boot-init.</a></p>
<p>Thanks to Wesley Beary for answering questions about fog and Ian Meyer for pointing out <a href="http://github.com/opscode/chef/blob/master/chef/lib/chef/knife/ec2_server_create.rb">Chef Fog code</a>.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 8px; width: 1px; height: 1px; overflow: hidden;">#!/usr/bin/ruby</p>
<p>require 'rubygems'<br />
require 'fog'<br />
require 'pp'</p>
<p># Import EC2 credentials e.g. @aws_access_key_id and @aws_access_key_id<br />
require './config.rb'</p>
<p># Set up a connection<br />
connection = Fog::AWS::EC2.new(<br />
:aws_access_key_id =&gt; @aws_access_key_id,<br />
:aws_secret_access_key =&gt; @aws_secret_access_key )</p>
<p># Get a list of all the running servers/instances<br />
instance_list = connection.servers.all</p>
<p>num_instances = instance_list.length<br />
puts "We have " + num_instances.to_s()  + " servers"</p>
<p># Print out a table of instances with choice columns<br />
instance_list.table([:id, :flavor_id, :ip_address, :private_ip_address, :image_id ])</p>
<p>###################################################################<br />
# Get a list of our images<br />
###################################################################<br />
my_images_raw = connection.describe_images('Owner' =&gt; 'self')</p>
<p>my_images = my_images_raw.body["imagesSet"]</p>
<p>puts "\n###################################################################################"<br />
puts "Following images are available for deployment"<br />
puts "\nImage ID\tArch\t\tImage Location"</p>
<p>for key in 0...my_images.length<br />
print my_images[key]["imageId"], "\t" , my_images[key]["architecture"] , "\t\t" , my_images[key]["imageLocation"],  "\n";<br />
end</p>
<p>###################################################################<br />
# Get a list of all instance flavors<br />
###################################################################<br />
flavors = connection.flavors()</p>
<p>print "\n\n============\nFlavors\n============\n"<br />
#flavors.table([:bits, :cores, :disk, :ram, :name])<br />
flavors.table</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.vuksan.com/2010/07/20/provision-to-cloud-in-5-minutes-using-fog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

