Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
changes to allow multiple projects per snail instance
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbunsch committed Sep 21, 2009
1 parent e0c0700 commit 77d1558
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 206 deletions.
11 changes: 6 additions & 5 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ h2. Dependencies

h2. Installing and Running

* git clone git://github.com/moomerman/snail.git
* git clone git://github.com/marcinbunsch/snail.git
* cd snail
* create snail.yml with your aws key and secret key in (see below)
* create config/snail.yml with your aws key and secret key in (see below)
* ./snail.rb
* go to http://localhost:4567/

h2. Configuration (snail.yml)
h2. Configuration (config/snail.yml)

<pre>
<code>
aws_key: YOUR_KEY
aws_secret: YOUR_SECRET_KEY
project_name:
aws_key: YOUR_KEY
aws_secret: YOUR_SECRET_KEY
</code>
</pre>
3 changes: 3 additions & 0 deletions config/snail.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project_name:
aws_key: YOUR_KEY
aws_secret: YOUR_SECRET
7 changes: 7 additions & 0 deletions lib/actions/general.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
get '/' do
redirect '/projects'
end

get '/projects' do
erb :projects
end
30 changes: 30 additions & 0 deletions lib/actions/groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Security Groups

get '/:project/groups' do
@groups = @ec2.describe_security_groups
erb :groups
end

get '/:project/group/:group_name/delete' do
@ec2.delete_security_group(params[:group_name])
redirect '/groups'
end

get '/:project/group/:group_name/revoke' do
if params[:group]
@ec2.revoke_security_group_named_ingress(params[:group_name], params[:owner], params[:group])
else
@ec2.revoke_security_group_IP_ingress(params[:group_name], params[:from], params[:to], params[:protocol], params[:ip])
end
redirect '/groups'
end

post '/:project/group/:group_name/authorize' do
@ec2.authorize_security_group_IP_ingress(params[:group_name], params[:from], params[:to], params[:protocol], params[:ip])
redirect '/groups'
end

post '/:project/group' do
@ec2.create_security_group(params[:name], params[:description])
redirect '/groups'
end
25 changes: 25 additions & 0 deletions lib/actions/images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Images

get '/:project/images' do
@@images ||= @ec2.describe_images.find_all{|x| x[:aws_image_type] == 'machine'}
@i386 = @@images.find_all{|x| x[:aws_architecture] == 'i386'}.sort {|x,y| x[:aws_location] <=> y[:aws_location] }
@x86_64 = @@images.find_all{|x| x[:aws_architecture] == 'x86_64'}.sort {|x,y| x[:aws_location] <=> y[:aws_location] }
erb :images
end

get '/:project/images/:image_id/launch' do
@ec2.launch_instances(params[:image_id], :group_ids => 'default',
:user_data => "Woohoo!!!",
:addressing_type => "public",
:key_name => "default",
:availability_zone => "us-east-1c")
redirect '/instances'
end

get '/:project/images/search*' do
params[:query] ||= request.path_info.split('/')[3]
redirect '/images' if params[:query].empty?
@i386 = @@images.find_all{|x| x[:aws_architecture] == 'i386' and x.inspect =~ /#{params[:query]}/i}.sort {|x,y| x[:aws_location] <=> y[:aws_location] }
@x86_64 = @@images.find_all{|x| x[:aws_architecture] == 'x86_64' and x.inspect =~ /#{params[:query]}/i}.sort {|x,y| x[:aws_location] <=> y[:aws_location] }
erb :images
end
21 changes: 21 additions & 0 deletions lib/actions/instances.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Instances

get '/:project/instances' do
@instances = @ec2.describe_instances.reverse
erb :instances
end

get '/:project/instance/:instance_id/terminate' do
@output = @ec2.terminate_instances(params[:instance_id])
redirect '/instances'
end

get '/:project/instance/:instance_id/output' do
@output = @ec2.get_console_output(params[:instance_id])
erb :output
end

get '/:project/instance/:instance_id/reboot' do
@ec2.reboot_instances([params[:instance_id]])
redirect '/instances'
end
30 changes: 30 additions & 0 deletions lib/actions/ips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Elastic IP addresses

get '/:project/addresses' do
@addresses = @ec2.describe_addresses
@instances = @ec2.describe_instances.reverse
erb :addresses
end

get '/:project/addresses/allocate' do
@ec2.allocate_address
redirect '/addresses'
end

get '/:project/address/*/release' do
ip_address = request.path_info.split('/')[2]
@ec2.release_address(ip_address)
redirect '/addresses'
end

post '/:project/address/*/associate' do
ip_address = request.path_info.split('/')[2]
@ec2.associate_address(params[:instance_id], ip_address)
redirect '/addresses'
end

get '/:project/address/*/disassociate' do
ip_address = request.path_info.split('/')[2]
@ec2.disassociate_address(ip_address)
redirect '/addresses'
end
16 changes: 16 additions & 0 deletions lib/actions/keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SSH Key Pairs

get '/:project/keys' do
@keys = @ec2.describe_key_pairs
erb :keys
end

get '/:project/key/:key_name/delete' do
@ec2.delete_key_pair(params[:key_name])
redirect '/keys'
end

post '/:project/key' do
output = @ec2.create_key_pair(params[:key_name])
"<pre>" + output[:aws_material] + "</pre>"
end
19 changes: 19 additions & 0 deletions lib/actions/s3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# S3

get '/:project/buckets' do
@buckets = @s3.buckets.map{|b| b.name}
erb :buckets
end

get '/:project/bucket/:bucket_name/keys' do
@bucket = @s3.bucket(params[:bucket_name])
@keys = @bucket.keys
erb :s3_keys
end

get '/:project/bucket/*/key/*' do
bucket_name = request.path_info.split('/')[2]
key_name = request.path_info.split('/')[4]
@bucket = @s3.bucket(bucket_name)
send_data(@bucket.get(key_name))
end
Loading

0 comments on commit 77d1558

Please sign in to comment.