solutious-rudy 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/CHANGES.txt +19 -1
  2. data/README.rdoc +66 -35
  3. data/Rakefile +1 -0
  4. data/Rudyfile +97 -6
  5. data/bin/ird +7 -4
  6. data/bin/rudy +120 -212
  7. data/bin/rudy-ec2 +240 -0
  8. data/bin/rudy-s3 +76 -0
  9. data/bin/rudy-sdb +67 -0
  10. data/lib/annoy.rb +61 -18
  11. data/lib/console.rb +10 -5
  12. data/lib/rudy/aws/ec2/address.rb +76 -40
  13. data/lib/rudy/aws/ec2/group.rb +138 -78
  14. data/lib/rudy/aws/ec2/image.rb +134 -12
  15. data/lib/rudy/aws/ec2/instance.rb +116 -89
  16. data/lib/rudy/aws/ec2/keypair.rb +26 -14
  17. data/lib/rudy/aws/ec2/snapshot.rb +23 -12
  18. data/lib/rudy/aws/ec2/volume.rb +198 -202
  19. data/lib/rudy/aws/ec2/zone.rb +77 -0
  20. data/lib/rudy/aws/ec2.rb +56 -25
  21. data/lib/rudy/aws/s3.rb +54 -0
  22. data/lib/rudy/aws/sdb/error.rb +46 -0
  23. data/lib/rudy/aws/sdb.rb +298 -0
  24. data/lib/rudy/aws.rb +29 -57
  25. data/lib/rudy/{metadata/backup.rb → backup.rb} +8 -8
  26. data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
  27. data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
  28. data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
  29. data/lib/rudy/cli/aws/ec2/images.rb +196 -0
  30. data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
  31. data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
  32. data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
  33. data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
  34. data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
  35. data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
  36. data/lib/rudy/cli/aws/s3/store.rb +22 -0
  37. data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
  38. data/lib/rudy/cli/{deploy.rb → candy.rb} +2 -6
  39. data/lib/rudy/cli/config.rb +25 -20
  40. data/lib/rudy/cli/disks.rb +18 -108
  41. data/lib/rudy/cli/machines.rb +94 -0
  42. data/lib/rudy/cli/routines.rb +47 -70
  43. data/lib/rudy/cli.rb +104 -89
  44. data/lib/rudy/config/objects.rb +5 -43
  45. data/lib/rudy/config.rb +8 -24
  46. data/lib/rudy/disks.rb +248 -0
  47. data/lib/rudy/global.rb +121 -0
  48. data/lib/rudy/huxtable.rb +232 -147
  49. data/lib/rudy/machines.rb +245 -0
  50. data/lib/rudy/metadata.rb +136 -0
  51. data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
  52. data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
  53. data/lib/rudy/routines/release.rb +27 -8
  54. data/lib/rudy/routines/shutdown.rb +47 -32
  55. data/lib/rudy/routines/startup.rb +47 -37
  56. data/lib/rudy/routines.rb +30 -37
  57. data/lib/rudy/scm/svn.rb +1 -1
  58. data/lib/rudy/utils.rb +262 -4
  59. data/lib/rudy.rb +76 -248
  60. data/lib/storable.rb +19 -16
  61. data/lib/sysinfo.rb +1 -1
  62. data/rudy.gemspec +88 -68
  63. data/support/rudy-ec2-startup +5 -5
  64. data/test/05_config/00_setup_test.rb +3 -7
  65. data/test/20_sdb/00_setup_test.rb +2 -17
  66. data/test/20_sdb/10_domains_test.rb +18 -16
  67. data/test/25_ec2/00_setup_test.rb +5 -10
  68. data/test/25_ec2/10_keypairs_test.rb +13 -5
  69. data/test/25_ec2/20_groups_test.rb +48 -56
  70. data/test/25_ec2/30_addresses_test.rb +13 -10
  71. data/test/25_ec2/40_volumes_test.rb +11 -8
  72. data/test/25_ec2/50_snapshots_test.rb +17 -12
  73. data/test/26_ec2_instances/00_setup_test.rb +3 -8
  74. data/test/26_ec2_instances/10_instances_test.rb +21 -19
  75. data/test/30_sdb_metadata/00_setup_test.rb +2 -9
  76. data/test/30_sdb_metadata/10_disks_test.rb +47 -37
  77. data/test/30_sdb_metadata/20_backups_test.rb +9 -9
  78. data/test/helper.rb +5 -3
  79. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  80. data/vendor/highline-1.5.1/INSTALL +35 -0
  81. data/vendor/highline-1.5.1/LICENSE +7 -0
  82. data/vendor/highline-1.5.1/README +63 -0
  83. data/vendor/highline-1.5.1/Rakefile +82 -0
  84. data/vendor/highline-1.5.1/TODO +6 -0
  85. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  86. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  87. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  88. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  89. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  90. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  91. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  92. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  93. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  94. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  95. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  96. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  97. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  98. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  99. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  100. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  101. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  102. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  103. data/vendor/highline-1.5.1/setup.rb +1360 -0
  104. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  105. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  106. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  107. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  108. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  109. metadata +81 -69
  110. data/lib/aws_sdb/error.rb +0 -42
  111. data/lib/aws_sdb/service.rb +0 -215
  112. data/lib/aws_sdb.rb +0 -3
  113. data/lib/rudy/aws/simpledb.rb +0 -71
  114. data/lib/rudy/cli/addresses.rb +0 -85
  115. data/lib/rudy/cli/backups.rb +0 -175
  116. data/lib/rudy/cli/domains.rb +0 -17
  117. data/lib/rudy/cli/groups.rb +0 -77
  118. data/lib/rudy/cli/images.rb +0 -111
  119. data/lib/rudy/cli/instances.rb +0 -142
  120. data/lib/rudy/cli/keypairs.rb +0 -47
  121. data/lib/rudy/cli/manager.rb +0 -51
  122. data/lib/rudy/cli/release.rb +0 -174
  123. data/lib/rudy/cli/volumes.rb +0 -121
  124. data/lib/rudy/command/addresses.rb +0 -69
  125. data/lib/rudy/command/backups.rb +0 -65
  126. data/lib/rudy/command/disks-old.rb +0 -322
  127. data/lib/rudy/command/disks.rb +0 -9
  128. data/lib/rudy/command/domains.rb +0 -34
  129. data/lib/rudy/command/groups.rb +0 -118
  130. data/lib/rudy/command/instances.rb +0 -278
  131. data/lib/rudy/command/keypairs.rb +0 -149
  132. data/lib/rudy/command/manager.rb +0 -65
  133. data/lib/rudy/command/volumes.rb +0 -127
  134. data/lib/rudy/metadata/disk.rb +0 -149
  135. data/lib/rudy/metadata/machine.rb +0 -34
  136. data/lib/rudy/routines/disk_handler.rb +0 -190
  137. data/lib/rudy/routines/script_runner.rb +0 -65
  138. data/test/50_commands/00_setup_test.rb +0 -11
  139. data/test/50_commands/10_keypairs_test.rb +0 -79
  140. data/test/50_commands/20_groups_test.rb +0 -77
  141. data/test/50_commands/40_volumes_test.rb +0 -55
  142. data/test/50_commands/50_instances_test.rb +0 -110
  143. data/tryouts/console_tryout.rb +0 -91
  144. data/tryouts/disks.rb +0 -55
  145. data/tryouts/nested_methods.rb +0 -36
  146. data/tryouts/session_tryout.rb +0 -46
data/bin/rudy-s3 ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # = Rudy S3
4
+ #
5
+ # === A Rudy interface to Amazon Simple Storage Service
6
+ #
7
+ #
8
+ #
9
+ # See rudy-s3 -h for usage
10
+ #
11
+
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') # Put our local lib in first place
13
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'highline-1.5.1', 'lib')
14
+ #%w{amazon-ec2 caesars rye}.each { |dir| $:.unshift File.join(File.dirname(__FILE__), '..', '..', dir, 'lib') }
15
+ #require 'rubygems'
16
+
17
+ require 'rudy'
18
+ require 'rudy/cli'
19
+ require 'drydock'
20
+
21
+ # Command-line interface for bin/rudy-s3
22
+ module RudyCLI_S3
23
+ extend Drydock
24
+
25
+ # ------------------------------------ AMAZON S3 COMMANDS --------
26
+ # ------------------------------------------------------------------
27
+
28
+ desc "Amazon S3 Buckets"
29
+ usage "rudy-s3 buckets"
30
+ option :l, :list, "List bucket objects"
31
+ action :C, :create, "Create a bucket"
32
+ action :D, :destroy, "Destroy a bucket"
33
+ argv :name
34
+ command :buckets => Rudy::CLI::AWS::S3::Buckets
35
+ command_alias :buckets, :b
36
+
37
+ #desc "Amazon S3 Storage Interface"
38
+ #usage "rudy-s3 store file-path"
39
+ #option :b, :bucket, String, "Bucket name"
40
+ #argv :path
41
+ #command :store => Rudy::CLI::AWS::S3::Store
42
+ #command_alias :store, :s
43
+
44
+
45
+
46
+ # --------------------------------- RUDY-S3 MISCELLANEOUS --------
47
+ # ------------------------------------------------------------------
48
+
49
+ default :buckets
50
+ debug :off
51
+
52
+
53
+ end
54
+
55
+
56
+ #puts Rudy::Utils.banner("THIS IS RUBY #{RUBY_VERSION}") if Drydock.debug?
57
+
58
+ # We call Drydock specifically otherwise it will run at_exit. Rye also
59
+ # uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
60
+ # blocks in reverse order so if Drydock is required first, it's block
61
+ # will run after Rye shuts down the ssh-agent.
62
+ begin
63
+ Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
64
+ rescue Drydock::ArgError, Drydock::OptError=> ex
65
+ STDERR.puts ex.message
66
+ STDERR.puts ex.usage
67
+ rescue Rudy::Error => ex
68
+ STDERR.puts ex.message
69
+ rescue => ex
70
+ STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
71
+ STDERR.puts ex.backtrace if Drydock.debug?
72
+ rescue SystemExit
73
+ # Don't balk
74
+ end
75
+
76
+
data/bin/rudy-sdb ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # = Rudy SDB
4
+ #
5
+ # === A Rudy interface to Amazon Simple Storage Service
6
+ #
7
+ #
8
+ #
9
+ # See rudy-sdb -h for usage
10
+ #
11
+
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') # Put our local lib in first place
13
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'highline-1.5.1', 'lib')
14
+ #%w{amazon-ec2 caesars rye}.each { |dir| $:.unshift File.join(File.dirname(__FILE__), '..', '..', dir, 'lib') }
15
+ #require 'rubygems'
16
+
17
+ require 'rudy'
18
+ require 'rudy/cli'
19
+ require 'drydock'
20
+
21
+ # Command-line interface for bin/rudy-sdb
22
+ module RudyCLI_SDB
23
+ extend Drydock
24
+
25
+ # ----------------------------------- AMAZON SDB COMMANDS --------
26
+ # ------------------------------------------------------------------
27
+
28
+
29
+ desc "Displays the SimpleDB domains associated to your account"
30
+ action :C, :create, "Create a domain"
31
+ action :D, :destroy, "Destroy a domain"
32
+ argv :name
33
+ command :domains => Rudy::CLI::AWS::SDB::Domains
34
+
35
+
36
+ # -------------------------------- RUDY-SDB MISCELLANEOUS --------
37
+ # ------------------------------------------------------------------
38
+
39
+ default :domains
40
+ debug :off
41
+
42
+
43
+ end
44
+
45
+
46
+ #puts Rudy::Utils.banner("THIS IS RUBY #{RUBY_VERSION}") if Drydock.debug?
47
+
48
+ # We call Drydock specifically otherwise it will run at_exit. Rye also
49
+ # uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
50
+ # blocks in reverse order so if Drydock is required first, it's block
51
+ # will run after Rye shuts down the ssh-agent.
52
+ begin
53
+ Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
54
+ rescue Drydock::ArgError, Drydock::OptError=> ex
55
+ STDERR.puts ex.message
56
+ STDERR.puts ex.usage
57
+ rescue Rudy::Error => ex
58
+ STDERR.puts ex.message
59
+ rescue => ex
60
+ STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
61
+ STDERR.puts ex.backtrace if Drydock.debug?
62
+ rescue SystemExit
63
+ # Don't balk
64
+ end
65
+
66
+
67
+
data/lib/annoy.rb CHANGED
@@ -1,14 +1,17 @@
1
+ #---
2
+ # TODO: Use Matrix to give a more accurate annoyance factor
3
+ # TODO: Add trivia questions
4
+ #+++
1
5
 
2
6
  require 'timeout'
3
7
  require 'sysinfo'
8
+ require 'highline'
4
9
 
5
-
6
- # Annoy - your annoying friend that asks you questions all the time.
10
+ # = Annoy
7
11
  #
8
- # TODO: Use Matrix to give a more accurate annoyance factor
9
- # TODO: Add trivia questions
12
+ # Like your annoying friend that asks you questions all the time.
10
13
  #
11
- class Annoy #:nodoc:all
14
+ class Annoy
12
15
 
13
16
  attr_accessor :factor
14
17
  attr_accessor :flavor
@@ -18,9 +21,9 @@ class Annoy #:nodoc:all
18
21
  attr_accessor :system
19
22
 
20
23
  @@operators = {
21
- :low => %w(+ - *),
22
- :medium => %w(* % + -),
23
- :high => %w(* % + -),
24
+ :low => %w(+ -),
25
+ :medium => %w(* -),
26
+ :high => %w(& * -),
24
27
  :insane => %w(** << | & *)
25
28
  }.freeze
26
29
 
@@ -33,15 +36,22 @@ class Annoy #:nodoc:all
33
36
 
34
37
  @@randsize = {
35
38
  :low => 10,
36
- :medium => 100,
37
- :high => 1000,
39
+ :medium => 14,
40
+ :high => 50,
38
41
  :insane => 1000
39
42
  }.freeze
40
43
 
41
44
  @@period = 60.freeze # max seconds to wait
42
-
43
45
  @@flavors = [:numeric, :string].freeze
46
+ @@skip = false # skip questions
44
47
 
48
+ # Calling this method tells Annoy to not prompt for
49
+ # a response. All questions will return true.
50
+ def Annoy.enable_skip; @@skip = true; end
51
+ # Tells annoy to prompt for a response.
52
+ def Annoy.disable_skip; @@skip = false; end
53
+ # Returns true of Annoy is in skip mode
54
+ def Annoy.skip?; @@skip; end
45
55
 
46
56
  # * +factor+ annoyance factor, one of :low (default), :medium, :high, :insane
47
57
  # * +flavor+ annoyance flavor, one of :rand (default), :numeric, string
@@ -100,17 +110,36 @@ class Annoy #:nodoc:all
100
110
  # Returns true when the answer is correct, otherwise false.
101
111
  def Annoy.challenge?(msg="Please confirm.", factor=:medium, flavor=:rand, writer=STDOUT, period=nil)
102
112
  return true unless STDIN.tty? # Humans only!
113
+ return true if Annoy.skip?
103
114
  begin
104
115
  success = Timeout::timeout(period || @@period) do
105
116
  flavor = Annoy.get_flavor(flavor)
106
117
  question, answer = Annoy.question(factor, flavor)
107
- writer.print "#{msg} To continue, #{Annoy.verb(flavor)} #{question}: "
108
- writer.print "(#{answer}) " if ![:high, :insane].member?(factor) && flavor == :numeric
109
- writer.flush
110
- response = Annoy.get_response(writer)
111
- response = response.to_i if flavor == :numeric
112
- (response == answer)
118
+ msg = "#{msg} To continue, #{Annoy.verb(flavor)} #{question}: "
119
+ #writer.print msg
120
+ #if ![:medium, :high, :insane].member?(factor) && flavor == :numeric
121
+ #writer.print "(#{answer}) "
122
+ #writer.flush
123
+ #end
124
+ #response = Annoy.get_response(writer)
125
+
126
+ trap("SIGINT") { raise Annoy::GiveUp }
127
+
128
+ highline = HighLine.new
129
+ response = highline.ask(msg) { |q|
130
+ q.echo = '*' # Don't display response
131
+ q.overwrite = true # Erase the question afterwards
132
+ q.whitespace = :strip # Remove whitespace from the response
133
+ q.answer_type = Integer if flavor == :numeric
134
+ }
135
+
136
+ ret = (response == answer)
137
+ writer.puts "Incorrect" unless ret
138
+ ret
113
139
  end
140
+ rescue Annoy::GiveUp => ex
141
+ writer.puts $/, "Giving up!"
142
+ false
114
143
  rescue Timeout::Error => ex
115
144
  writer.puts $/, "Times up!"
116
145
  false
@@ -123,6 +152,12 @@ class Annoy #:nodoc:all
123
152
  Annoy.challenge?("Are you sure?", factor, flavor, writer)
124
153
  end
125
154
 
155
+ # Runs a challenge with the message, "Proceed?"
156
+ # See: Annoy.challenge?
157
+ def Annoy.proceed?(factor=:medium, flavor=:rand, writer=STDOUT)
158
+ Annoy.challenge?("Proceed?", factor, flavor, writer)
159
+ end
160
+
126
161
  # See: Annoy.challenge?
127
162
  # Uses the value of @flavor, @factor, and @writer
128
163
  def challenge?(msg="Please confirm.")
@@ -143,6 +178,7 @@ class Annoy #:nodoc:all
143
178
  # * +regexp+ The regular expression to match the answer.
144
179
  def Annoy.pose_question(msg, regexp, writer=STDOUT, period=nil)
145
180
  return true unless STDIN.tty? # Only ask a question if there's a human
181
+ return true if Annoy.skip?
146
182
  begin
147
183
  success = Timeout::timeout(period || @@period) do
148
184
  regexp &&= Regexp.new regexp
@@ -161,7 +197,9 @@ class Annoy #:nodoc:all
161
197
  private
162
198
  def Annoy.get_response(writer=STDOUT)
163
199
  return true unless STDIN.tty? # Humans only
164
- # TODO: Count the number of keystrokes to prevent copy/paste
200
+ return true if Annoy.skip?
201
+ # TODO: Count the number of keystrokes to prevent copy/paste.
202
+ # We can probably use Highline.
165
203
  # We likely need to be more specific but this will do for now.
166
204
  #if ::SystemInfo.new.os == :unix
167
205
  # begin
@@ -223,5 +261,10 @@ class Annoy #:nodoc:all
223
261
 
224
262
  end
225
263
 
264
+ # = Annoy::GiveUp
265
+ #
266
+ # This is what happens when you don't answer Annoy's questions.
267
+ class Annoy::GiveUp < RuntimeError
268
+ end
226
269
 
227
270
 
data/lib/console.rb CHANGED
@@ -4,7 +4,9 @@
4
4
  # See: man terminfo
5
5
  #+++
6
6
 
7
-
7
+ #
8
+ #
9
+ #
8
10
  class String
9
11
  @@print_with_attributes = true
10
12
  def String.disable_colour; @@print_with_attributes = false; end
@@ -58,7 +60,8 @@ class String
58
60
  Console.print_at(self, args)
59
61
  end
60
62
 
61
- # Returns the string with escape code attributes removed.
63
+ # Returns the string with ANSI escape codes removed.
64
+ #
62
65
  # NOTE: The non-printable attributes count towards the string size.
63
66
  # You can use this method to get the "visible" size:
64
67
  #
@@ -66,8 +69,10 @@ class String
66
69
  # "\e[34;47;5mMONKEY_JUNK\e[39;49;0m".size # => 31
67
70
  #
68
71
  def noatt
69
- gsub(/\e\[[\d;]*m/, '')
72
+ gsub(/\e\[?[0-9;]*[mc]?/, '')
70
73
  end
74
+ alias :noansi :noatt
75
+
71
76
  end
72
77
 
73
78
  class Object #:nodoc:all
@@ -175,8 +180,8 @@ module Console #:nodoc:all
175
180
  end
176
181
  def print_at(str, props={})
177
182
  print_at_lamb = lambda {
178
- #props[:x] ||= 0
179
- #props[:y] ||= 0
183
+ props[:x] ||= 0
184
+ props[:y] ||= 0
180
185
  props[:minus] = false unless props.has_key?(:minus)
181
186
  props[:x] = props[:x]-str.noatt.size if props[:x] && props[:minus] # Subtract the str length from the position
182
187
  Cursor.save
@@ -2,21 +2,86 @@
2
2
 
3
3
  module Rudy::AWS
4
4
 
5
- class EC2
5
+ module EC2
6
6
 
7
7
  class Address < Storable
8
8
  field :ipaddress
9
9
  field :instid
10
- def to_s
11
- msg = "Address: #{self.ipaddress}"
12
- msg << ", instance: #{self.instid}" if self.instid
13
- msg
10
+
11
+ def liner_note
12
+ info = self.associated? ? @instid : "available"
13
+ "%s (%s)" % [@ipaddress.to_s.bright, info]
14
+ end
15
+
16
+ def to_s(with_titles=false)
17
+ liner_note
18
+ end
19
+
20
+ def associated?
21
+ !@instid.nil? && !@instid.empty?
14
22
  end
15
23
  end
16
24
 
17
25
  class Addresses
18
26
  include Rudy::AWS::ObjectBase
27
+ include Rudy::AWS::EC2::Base
19
28
 
29
+
30
+ def create
31
+ ret = @ec2.allocate_address
32
+ return false unless ret && ret['publicIp']
33
+ address = Rudy::AWS::EC2::Address.new
34
+ address.ipaddress = ret['publicIp']
35
+ address
36
+ end
37
+
38
+ def destroy(address)
39
+ address = address.ipaddress if address.is_a?(Rudy::AWS::EC2::Address)
40
+ raise UnknownAddress unless exists?(address)
41
+
42
+ opts ={
43
+ :public_ip => address || raise("No public IP address supplied")
44
+ }
45
+ ret = @ec2.release_address(opts)
46
+ (ret && ret['return'] == 'true')
47
+ end
48
+
49
+
50
+ # Associate an elastic IP to an instance
51
+ def associate(address, instance)
52
+ raise NoInstanceID unless instance
53
+ raise NoAddress unless address
54
+
55
+ address = address.ipaddress if address.is_a?(Rudy::AWS::EC2::Address)
56
+ instance = instance.awsid if instance.is_a?(Rudy::AWS::EC2::Instance)
57
+ raise UnknownAddress unless exists?(address)
58
+ raise AddressAssociated if associated?(address)
59
+
60
+ opts ={
61
+ :instance_id => instance,
62
+ :public_ip => address
63
+ }
64
+ ret = @ec2.associate_address(opts)
65
+ (ret && ret['return'] == 'true')
66
+ end
67
+
68
+ # Disssociate an elastic IP from an instance
69
+ def disassociate(address)
70
+ raise NoAddress unless address
71
+ address = address.ipaddress if address.is_a?(Rudy::AWS::EC2::Address)
72
+ instance = instance.awsid if instance.is_a?(Rudy::AWS::EC2::Instance)
73
+ raise UnknownAddress unless exists?(address)
74
+ raise AddressNotAssociated unless associated?(address)
75
+
76
+ opts ={
77
+ :public_ip => address
78
+ }
79
+ ret = @ec2.disassociate_address(opts)
80
+ (ret && ret['return'] == 'true')
81
+ end
82
+
83
+
84
+
20
85
  # Returns a Array of Rudy::AWS::EC2::Address objects.
21
86
  def list(addresses=[])
22
87
  addresses = list_as_hash(addresses)
@@ -28,7 +93,7 @@ module Rudy::AWS
28
93
  def list_as_hash(addresses=[])
29
94
  addresses ||= []
30
95
  addresses = [addresses].flatten.compact
31
- alist = @aws.describe_addresses(:addresses=> addresses)
96
+ alist = @ec2.describe_addresses(:addresses=> addresses)
32
97
 
33
98
  return nil unless alist['addressesSet'].is_a?(Hash)
34
99
 
@@ -43,7 +108,7 @@ module Rudy::AWS
43
108
 
44
109
 
45
110
  def any?
46
- !(list_as_hash || {}).empty?
111
+ !list_as_hash.nil?
47
112
  end
48
113
 
49
114
  def get(address)
@@ -64,38 +129,6 @@ module Rudy::AWS
64
129
  address
65
130
  end
66
131
 
67
- # Associate an elastic IP to an instance
68
- def associate(instance, address)
69
- address = address.ipaddress if address.is_a?(Rudy::AWS::EC2::Address)
70
- instance = instance.awsid if instance.is_a?(Rudy::AWS::EC2::Instance)
71
- raise "Not a valid address" unless exists?(address)
72
- opts ={
73
- :instance_id => instance || raise("No instance ID supplied"),
74
- :public_ip => address || raise("No public IP address supplied")
75
- }
76
- ret = @aws.associate_address(opts)
77
- (ret && ret['return'] == 'true')
78
- end
79
-
80
-
81
- def create
82
- ret = @aws.allocate_address
83
- return false unless ret && ret['publicIp']
84
- address = Rudy::AWS::EC2::Address.new
85
- address.ipaddress = ret['publicIp']
86
- address
87
- end
88
-
89
- def destroy(address)
90
- address = address.ipaddress if address.is_a?(Rudy::AWS::EC2::Address)
91
- raise "Not a valid address" unless exists?(address)
92
- opts ={
93
- :public_ip => address || raise("No public IP address supplied")
94
- }
95
- ret = @aws.release_address(opts)
96
- (ret && ret['return'] == 'true')
97
- end
98
-
99
132
 
100
133
  # +address+ is an IP address or Rudy::AWS::EC2::Address object
101
134
  # Returns true if the given address is assigned to the current account
@@ -117,5 +150,8 @@ module Rudy::AWS
117
150
  false
118
151
  end
119
152
  end
153
+
120
154
  end
121
- end
155
+ end
156
+
157
+