newrelic-amazon-ec2 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.gitignore +8 -0
  2. data/.yardopts +1 -0
  3. data/ChangeLog +293 -0
  4. data/LICENSE +66 -0
  5. data/README.rdoc +354 -0
  6. data/README_dev.rdoc +12 -0
  7. data/Rakefile +101 -0
  8. data/VERSION +1 -0
  9. data/amazon-ec2.gemspec +134 -0
  10. data/bin/ec2-gem-example.rb +137 -0
  11. data/bin/ec2-gem-profile.rb +10 -0
  12. data/bin/ec2sh +62 -0
  13. data/bin/setup.rb +28 -0
  14. data/deps.rip +1 -0
  15. data/lib/AWS.rb +292 -0
  16. data/lib/AWS/Autoscaling.rb +70 -0
  17. data/lib/AWS/Autoscaling/autoscaling.rb +273 -0
  18. data/lib/AWS/Cloudwatch.rb +32 -0
  19. data/lib/AWS/Cloudwatch/monitoring.rb +89 -0
  20. data/lib/AWS/EC2.rb +33 -0
  21. data/lib/AWS/EC2/availability_zones.rb +21 -0
  22. data/lib/AWS/EC2/console.rb +23 -0
  23. data/lib/AWS/EC2/elastic_ips.rb +81 -0
  24. data/lib/AWS/EC2/image_attributes.rb +133 -0
  25. data/lib/AWS/EC2/images.rb +101 -0
  26. data/lib/AWS/EC2/instances.rb +212 -0
  27. data/lib/AWS/EC2/keypairs.rb +61 -0
  28. data/lib/AWS/EC2/products.rb +21 -0
  29. data/lib/AWS/EC2/security_groups.rb +183 -0
  30. data/lib/AWS/EC2/snapshots.rb +59 -0
  31. data/lib/AWS/EC2/volumes.rb +115 -0
  32. data/lib/AWS/ELB.rb +71 -0
  33. data/lib/AWS/ELB/load_balancers.rb +178 -0
  34. data/lib/AWS/exceptions.rb +122 -0
  35. data/lib/AWS/responses.rb +21 -0
  36. data/newrelic-amazon-ec2.gemspec +136 -0
  37. data/perftools/ec2prof +0 -0
  38. data/perftools/ec2prof-results.dot +132 -0
  39. data/perftools/ec2prof-results.txt +100 -0
  40. data/perftools/ec2prof.symbols +102 -0
  41. data/test/test_Autoscaling_groups.rb +336 -0
  42. data/test/test_EC2.rb +68 -0
  43. data/test/test_EC2_availability_zones.rb +49 -0
  44. data/test/test_EC2_console.rb +54 -0
  45. data/test/test_EC2_elastic_ips.rb +144 -0
  46. data/test/test_EC2_image_attributes.rb +238 -0
  47. data/test/test_EC2_images.rb +197 -0
  48. data/test/test_EC2_instances.rb +429 -0
  49. data/test/test_EC2_keypairs.rb +123 -0
  50. data/test/test_EC2_products.rb +48 -0
  51. data/test/test_EC2_responses.rb +53 -0
  52. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  53. data/test/test_EC2_security_groups.rb +205 -0
  54. data/test/test_EC2_snapshots.rb +83 -0
  55. data/test/test_EC2_volumes.rb +142 -0
  56. data/test/test_ELB_load_balancers.rb +239 -0
  57. data/test/test_helper.rb +23 -0
  58. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  59. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  60. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  61. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  62. metadata +218 -0
@@ -0,0 +1,12 @@
1
+ = Dev Docs
2
+
3
+ Publishing the gem using Jeweler:
4
+
5
+ rake version:bump:patch release
6
+
7
+ rake rubyforge:release rubyforge:release:docs
8
+
9
+ Push the gem to gemcutter:
10
+
11
+ gem push pkg/amazon-ec2-X.Y.Z.gem
12
+
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'yard'
4
+
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "newrelic-amazon-ec2"
8
+ gem.summary = %Q{Amazon EC2 Ruby Gem}
9
+ gem.description = %Q{A Ruby library for accessing the Amazon Web Services Elastic Compute Cloud (EC2), Elastic Load Balancer (ELB), Cloudwatch, and Autoscaling API's.}
10
+ gem.email = "glenn@rempe.us"
11
+ gem.homepage = "http://github.com/newrelic/amazon-ec2"
12
+ gem.authors = ["Glenn Rempe"]
13
+ gem.rdoc_options = ["--title", "amazon-ec2 documentation", "--line-numbers", "--main", "README.rdoc"]
14
+ gem.rubyforge_project = 'amazon-ec2'
15
+ gem.add_dependency('xml-simple', '>= 1.0.12')
16
+ gem.add_development_dependency('mocha', '>= 0.9.7')
17
+ gem.add_development_dependency('test-spec', '>= 0.10.0')
18
+ gem.add_development_dependency('relevance-rcov', '>= 0.8.5.1')
19
+ gem.add_development_dependency('perftools.rb', '= 0.1.6')
20
+ end
21
+
22
+ # make the jeweler rubyforge tasks available.
23
+ Jeweler::RubyforgeTasks.new do |rubyforge|
24
+ rubyforge.doc_task = "rdoc"
25
+ end
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << "--exclude /gems/,/Library/,spec"
41
+ end
42
+ rescue LoadError
43
+ task :rcov do
44
+ abort "RCov is not available. In order to run rcov, you must: [sudo] gem install relevance-rcov"
45
+ end
46
+ end
47
+
48
+
49
+ task :default => :test
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ if File.exist?('VERSION.yml')
54
+ config = YAML.load(File.read('VERSION.yml'))
55
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
56
+ else
57
+ version = ""
58
+ end
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "amazon-ec2 #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
65
+
66
+ YARD::Rake::YardocTask.new do |t|
67
+ #t.files = ['lib/**/*.rb']
68
+ end
69
+
70
+ begin
71
+ require 'rake/contrib/sshpublisher'
72
+ namespace :rubyforge do
73
+
74
+ desc "Release gem and YARD documentation to RubyForge"
75
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
76
+
77
+ namespace :release do
78
+ desc "Publish YARD docs to RubyForge."
79
+ task :docs => [:doc] do
80
+ config = YAML.load(
81
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
82
+ )
83
+
84
+ host = "#{config['username']}@rubyforge.org"
85
+ remote_dir = "/var/www/gforge-projects/amazon-ec2/"
86
+ local_dir = 'doc'
87
+
88
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
89
+ end
90
+ end
91
+ end
92
+ rescue LoadError
93
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
94
+ end
95
+
96
+ desc "Generate a perftools.rb profile"
97
+ task :profile do
98
+ system("CPUPROFILE=perftools/ec2prof RUBYOPT='-r/Library/Ruby/Gems/1.8/gems/perftools.rb-0.3.2/lib/perftools.bundle' ruby -r'rubygems' bin/ec2-gem-profile.rb")
99
+ system("pprof.rb --text --ignore=Gem perftools/ec2prof > perftools/ec2prof-results.txt")
100
+ system("pprof.rb --dot --ignore=Gem perftools/ec2prof > perftools/ec2prof-results.dot")
101
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.2
@@ -0,0 +1,134 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{amazon-ec2}
8
+ s.version = "0.6.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Glenn Rempe"]
12
+ s.date = %q{2009-10-14}
13
+ s.description = %q{A Ruby library for accessing the Amazon Web Services Elastic Compute Cloud (EC2), Elastic Load Balancer (ELB), Cloudwatch, and Autoscaling API's.}
14
+ s.email = %q{glenn@rempe.us}
15
+ s.executables = ["ec2-gem-example.rb", "ec2-gem-profile.rb", "ec2sh", "setup.rb"]
16
+ s.extra_rdoc_files = [
17
+ "ChangeLog",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "README_dev.rdoc"
21
+ ]
22
+ s.files = [
23
+ ".gitignore",
24
+ ".yardopts",
25
+ "ChangeLog",
26
+ "LICENSE",
27
+ "README.rdoc",
28
+ "README_dev.rdoc",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "amazon-ec2.gemspec",
32
+ "bin/ec2-gem-example.rb",
33
+ "bin/ec2-gem-profile.rb",
34
+ "bin/ec2sh",
35
+ "bin/setup.rb",
36
+ "deps.rip",
37
+ "lib/AWS.rb",
38
+ "lib/AWS/Autoscaling.rb",
39
+ "lib/AWS/Autoscaling/autoscaling.rb",
40
+ "lib/AWS/Cloudwatch.rb",
41
+ "lib/AWS/Cloudwatch/monitoring.rb",
42
+ "lib/AWS/EC2.rb",
43
+ "lib/AWS/EC2/availability_zones.rb",
44
+ "lib/AWS/EC2/console.rb",
45
+ "lib/AWS/EC2/elastic_ips.rb",
46
+ "lib/AWS/EC2/image_attributes.rb",
47
+ "lib/AWS/EC2/images.rb",
48
+ "lib/AWS/EC2/instances.rb",
49
+ "lib/AWS/EC2/keypairs.rb",
50
+ "lib/AWS/EC2/products.rb",
51
+ "lib/AWS/EC2/security_groups.rb",
52
+ "lib/AWS/EC2/snapshots.rb",
53
+ "lib/AWS/EC2/volumes.rb",
54
+ "lib/AWS/ELB.rb",
55
+ "lib/AWS/ELB/load_balancers.rb",
56
+ "lib/AWS/exceptions.rb",
57
+ "lib/AWS/responses.rb",
58
+ "perftools/ec2prof",
59
+ "perftools/ec2prof-results.dot",
60
+ "perftools/ec2prof-results.txt",
61
+ "perftools/ec2prof.symbols",
62
+ "test/test_Autoscaling_groups.rb",
63
+ "test/test_EC2.rb",
64
+ "test/test_EC2_availability_zones.rb",
65
+ "test/test_EC2_console.rb",
66
+ "test/test_EC2_elastic_ips.rb",
67
+ "test/test_EC2_image_attributes.rb",
68
+ "test/test_EC2_images.rb",
69
+ "test/test_EC2_instances.rb",
70
+ "test/test_EC2_keypairs.rb",
71
+ "test/test_EC2_products.rb",
72
+ "test/test_EC2_responses.rb",
73
+ "test/test_EC2_s3_xmlsimple.rb",
74
+ "test/test_EC2_security_groups.rb",
75
+ "test/test_EC2_snapshots.rb",
76
+ "test/test_EC2_volumes.rb",
77
+ "test/test_ELB_load_balancers.rb",
78
+ "test/test_helper.rb",
79
+ "wsdl/2007-08-29.ec2.wsdl",
80
+ "wsdl/2008-02-01.ec2.wsdl",
81
+ "wsdl/2008-05-05.ec2.wsdl",
82
+ "wsdl/2008-12-01.ec2.wsdl"
83
+ ]
84
+ s.homepage = %q{http://github.com/grempe/amazon-ec2}
85
+ s.rdoc_options = ["--title", "amazon-ec2 documentation", "--line-numbers", "--main", "README.rdoc"]
86
+ s.require_paths = ["lib"]
87
+ s.rubyforge_project = %q{amazon-ec2}
88
+ s.rubygems_version = %q{1.3.4}
89
+ s.summary = %q{Amazon EC2 Ruby Gem}
90
+ s.test_files = [
91
+ "test/test_Autoscaling_groups.rb",
92
+ "test/test_EC2.rb",
93
+ "test/test_EC2_availability_zones.rb",
94
+ "test/test_EC2_console.rb",
95
+ "test/test_EC2_elastic_ips.rb",
96
+ "test/test_EC2_image_attributes.rb",
97
+ "test/test_EC2_images.rb",
98
+ "test/test_EC2_instances.rb",
99
+ "test/test_EC2_keypairs.rb",
100
+ "test/test_EC2_products.rb",
101
+ "test/test_EC2_responses.rb",
102
+ "test/test_EC2_s3_xmlsimple.rb",
103
+ "test/test_EC2_security_groups.rb",
104
+ "test/test_EC2_snapshots.rb",
105
+ "test/test_EC2_volumes.rb",
106
+ "test/test_ELB_load_balancers.rb",
107
+ "test/test_helper.rb"
108
+ ]
109
+
110
+ if s.respond_to? :specification_version then
111
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
112
+ s.specification_version = 3
113
+
114
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
115
+ s.add_runtime_dependency(%q<xml-simple>, [">= 1.0.12"])
116
+ s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
117
+ s.add_development_dependency(%q<test-spec>, [">= 0.10.0"])
118
+ s.add_development_dependency(%q<relevance-rcov>, [">= 0.8.5.1"])
119
+ s.add_development_dependency(%q<perftools.rb>, ["= 0.1.6"])
120
+ else
121
+ s.add_dependency(%q<xml-simple>, [">= 1.0.12"])
122
+ s.add_dependency(%q<mocha>, [">= 0.9.7"])
123
+ s.add_dependency(%q<test-spec>, [">= 0.10.0"])
124
+ s.add_dependency(%q<relevance-rcov>, [">= 0.8.5.1"])
125
+ s.add_dependency(%q<perftools.rb>, ["= 0.1.6"])
126
+ end
127
+ else
128
+ s.add_dependency(%q<xml-simple>, [">= 1.0.12"])
129
+ s.add_dependency(%q<mocha>, [">= 0.9.7"])
130
+ s.add_dependency(%q<test-spec>, [">= 0.10.0"])
131
+ s.add_dependency(%q<relevance-rcov>, [">= 0.8.5.1"])
132
+ s.add_dependency(%q<perftools.rb>, ["= 0.1.6"])
133
+ end
134
+ end
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Amazon Web Services EC2 Query API Ruby library
4
+ #
5
+ # Ruby Gem Name:: amazon-ec2
6
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
7
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
10
+ #++
11
+
12
+ require File.dirname(__FILE__) + '/../lib/AWS'
13
+ require 'pp'
14
+
15
+ # pull these from the local shell environment variables set in ~/.bash_login
16
+ # or using appropriate methods specific to your login shell.
17
+ #
18
+ # e.g. in ~/.bash_login
19
+ #
20
+ # # For amazon-ec2 and amazon s3 ruby gems
21
+ # export AMAZON_ACCESS_KEY_ID="FOO"
22
+ # export AMAZON_SECRET_ACCESS_KEY="BAR"
23
+
24
+ ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID']
25
+ SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY']
26
+
27
+ if ACCESS_KEY_ID.nil? || ACCESS_KEY_ID.empty?
28
+ puts "Error : You must add the shell environment variables AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY before calling #{$0}!"
29
+ exit
30
+ end
31
+
32
+ # us-east-1.ec2.amazonaws.com == ec2.amazonaws.com
33
+ # eu-west-1.ec2.amazonaws.com for the european region
34
+ # test different servers by running something like:
35
+ # export EC2_URL='https://ec2.amazonaws.com';./bin/ec2-gem-example.rb
36
+ if ENV['EC2_URL']
37
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host )
38
+ else
39
+ # default server is US ec2.amazonaws.com
40
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
41
+ end
42
+
43
+ puts "----- ec2.methods.sort -----"
44
+ p ec2.methods.sort
45
+
46
+ puts "----- listing images owned by 'amazon' -----"
47
+ ec2.describe_images(:owner_id => "amazon").imagesSet.item.each do |image|
48
+ image.keys.each do |key|
49
+ puts "#{key} => #{image[key]}"
50
+ end
51
+ end
52
+
53
+ puts "----- listing all running instances -----"
54
+ pp ec2.describe_instances()
55
+
56
+ puts "----- creating a security group -----"
57
+ pp ec2.create_security_group(:group_name => "ec2-example-rb-test-group", :group_description => "ec-example.rb test group description.")
58
+
59
+ puts "----- listing security groups -----"
60
+ pp ec2.describe_security_groups()
61
+
62
+ puts "----- deleting a security group -----"
63
+ pp ec2.delete_security_group(:group_name => "ec2-example-rb-test-group")
64
+
65
+ puts "----- listing my keypairs (verbose mode) -----"
66
+ pp ec2.describe_keypairs()
67
+
68
+ # ELB examples
69
+ # Autoscaling examples
70
+ if ENV['ELB_URL']
71
+ elb = AWS::ELB::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['ELB_URL']).host )
72
+ else
73
+ elb = AWS::ELB::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
74
+ end
75
+
76
+ puts "----- creating an elastic load balancer -----"
77
+ pp elb.create_load_balancer(
78
+ :availability_zones => ["us-east-1a"],
79
+ :load_balancer_name => "elb-test-load-balancer",
80
+ :listeners => [{:protocol => "tcp", :load_balancer_port => "80", :instance_port => "8080"}]
81
+ )
82
+
83
+ puts "----- listing elastic load balancers -----"
84
+ pp elb.describe_load_balancers(:load_balancer_names => ["elb-test-load-balancer"])
85
+
86
+ puts "----- deleting load balancer -----"
87
+ pp elb.delete_load_balancer(:load_balancer_name => "elb-test-load-balancer")
88
+
89
+ # Autoscaling examples
90
+ if ENV['AS_URL']
91
+ as = AWS::Autoscaling::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['AS_URL']).host )
92
+ else
93
+ as = AWS::Autoscaling::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
94
+ end
95
+
96
+ puts "---- creating a launch configuration group -----"
97
+ pp as.create_launch_configuration(
98
+ :image_id => "ami-ed46a784",
99
+ :instance_type => "m1.small",
100
+ :availability_zones => ["us-east-1a"],
101
+ :launch_configuration_name => "ec2-example-test-launch-configuration"
102
+ )
103
+
104
+ puts "---- creating an autoscaling group -----"
105
+ pp as.create_autoscaling_group( :autoscaling_group_name => "ec2-example-test-autoscaling-group",
106
+ :availability_zones => ["us-east-1a"],
107
+ :min_size => 0,
108
+ :max_size => 0,
109
+ :launch_configuration_name => "ec2-example-test-launch-configuration"
110
+ )
111
+
112
+ puts "---- listing autoscaling groups -----"
113
+ pp as.describe_autoscaling_groups(:autoscaling_group_names => [])
114
+
115
+ puts "---- creating a new autoscaling trigger ----"
116
+ pp as.create_or_updated_scaling_trigger(
117
+ :autoscaling_group_name => "ec2-example-test-autoscaling-group",
118
+ :measure_name => "CPUUtilization",
119
+ :statistic => "Average",
120
+ :period => 300,
121
+ :trigger_name => "test-auto-scaling-trigger-name",
122
+ :lower_threshold => 0.2,
123
+ :lower_breach_scale_increment => 0,
124
+ :upper_threshold => 1.5,
125
+ :upper_breach_scale_increment => 0,
126
+ :breach_duration => 1200,
127
+ :dimensions => ["AutoScalingGroupName", "ec2-example-test-autoscaling-group"]
128
+ )
129
+
130
+ puts "---- deleting scaling trigger -----"
131
+ pp as.delete_trigger(:trigger_name => "test-auto-scaling-trigger-name", :autoscaling_group_name => "ec2-example-test-autoscaling-group")
132
+
133
+ puts "---- deleting autoscaling group -----"
134
+ pp as.delete_autoscaling_group(:autoscaling_group_name => "ec2-example-test-autoscaling-group")
135
+
136
+ puts "---- deleting launch configuration group -----"
137
+ pp as.delete_launch_configuration(:launch_configuration_name => "ec2-example-test-launch-configuration")
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Basic single command application that we can call with perftools.rb to get consistent results.
4
+
5
+ require File.dirname(__FILE__) + '/../lib/AWS'
6
+ ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID']
7
+ SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY']
8
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
9
+ @images = ec2.describe_images
10
+
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Amazon Web Services EC2 Query API Ruby library
4
+ #
5
+ # Ruby Gem Name:: amazon-ec2
6
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
7
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
10
+ #++
11
+
12
+ # CREDITS : Credit for this bit of shameful ripoff coolness
13
+ # goes to Marcel Molina and his AWS::S3 gem. Thanks!
14
+
15
+ # Usage : running this starts up an irb session and
16
+ # sets up the connection to EC2 as a class variable called
17
+ # '@ec2'. So just do something like the following on the
18
+ # shell command line:
19
+
20
+ # macbook-pro:~ glenn$ ec2sh
21
+ # >> @ec2.describe_images
22
+ # => [#<AWS::EC2::Item image_location...
23
+
24
+ aws_lib = File.dirname(__FILE__) + '/../lib/AWS'
25
+ setup = File.dirname(__FILE__) + '/setup'
26
+ irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
27
+
28
+ if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] )
29
+
30
+ welcome_message = <<-MESSAGE
31
+
32
+ 'ec2sh' usage :
33
+ This is an interactive 'irb' command shell that allows you to use all
34
+ commands available to the amazon-ec2 gem. You'll find this to be a
35
+ great tool to help you debug issues and practice running commands
36
+ against the live EC2 servers prior to putting them in your code.
37
+
38
+ The EC2 connection is wired to the class instance '@ec2'. Make method calls
39
+ on this to execute commands on EC2. Adding a #to_s
40
+ at the end of any command should give you a full String representation of the
41
+ response.
42
+
43
+ Examples to try:
44
+
45
+ returns : all ec2 public methods
46
+ >> @ec2.methods.sort
47
+
48
+ returns : a string representation of ALL images
49
+ >> @ec2.describe_images.to_s
50
+
51
+ returns : an Array of AWS::Response objects, each an EC2 image and its data
52
+ >> @ec2.describe_images.imagesSet.item
53
+ >> @ec2.describe_images.imagesSet.item[0] (a hash representing a single item in that array)
54
+ >> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that item)
55
+
56
+ MESSAGE
57
+
58
+ puts welcome_message
59
+ exec "#{irb_name} -rubygems -r #{aws_lib} -r #{setup} --simple-prompt"
60
+ else
61
+ puts "You must define AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY as shell environment variables before running #{$0}!"
62
+ end