solutious-rudy 0.8.5 → 0.9.0

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 (135) hide show
  1. data/CHANGES.txt +55 -14
  2. data/README.rdoc +26 -34
  3. data/Rudyfile +27 -32
  4. data/bin/rudy +47 -27
  5. data/bin/rudy-ec2 +2 -16
  6. data/bin/rudy-s3 +0 -10
  7. data/bin/rudy-sdb +11 -12
  8. data/lib/rudy.rb +49 -89
  9. data/lib/rudy/aws.rb +2 -43
  10. data/lib/rudy/aws/ec2.rb +57 -20
  11. data/lib/rudy/aws/ec2/address.rb +10 -11
  12. data/lib/rudy/aws/ec2/group.rb +10 -9
  13. data/lib/rudy/aws/ec2/image.rb +8 -8
  14. data/lib/rudy/aws/ec2/instance.rb +15 -16
  15. data/lib/rudy/aws/ec2/keypair.rb +14 -19
  16. data/lib/rudy/aws/ec2/snapshot.rb +16 -9
  17. data/lib/rudy/aws/ec2/volume.rb +37 -24
  18. data/lib/rudy/aws/ec2/zone.rb +5 -4
  19. data/lib/rudy/aws/s3.rb +2 -1
  20. data/lib/rudy/aws/sdb.rb +35 -86
  21. data/lib/rudy/backups.rb +24 -0
  22. data/lib/rudy/cli.rb +5 -131
  23. data/lib/rudy/cli/aws/ec2/addresses.rb +19 -27
  24. data/lib/rudy/cli/aws/ec2/candy.rb +32 -7
  25. data/lib/rudy/cli/aws/ec2/groups.rb +9 -13
  26. data/lib/rudy/cli/aws/ec2/images.rb +5 -133
  27. data/lib/rudy/cli/aws/ec2/instances.rb +25 -25
  28. data/lib/rudy/cli/aws/ec2/keypairs.rb +7 -11
  29. data/lib/rudy/cli/aws/ec2/snapshots.rb +5 -9
  30. data/lib/rudy/cli/aws/ec2/volumes.rb +22 -23
  31. data/lib/rudy/cli/aws/ec2/zones.rb +2 -3
  32. data/lib/rudy/cli/aws/sdb/domains.rb +5 -6
  33. data/lib/rudy/cli/aws/sdb/objects.rb +33 -0
  34. data/lib/rudy/cli/aws/sdb/select.rb +23 -0
  35. data/lib/rudy/cli/backups.rb +38 -0
  36. data/lib/rudy/cli/base.rb +98 -0
  37. data/lib/rudy/cli/candy.rb +1 -2
  38. data/lib/rudy/cli/config.rb +7 -4
  39. data/lib/rudy/cli/disks.rb +6 -8
  40. data/lib/rudy/cli/execbase.rb +53 -0
  41. data/lib/rudy/cli/machines.rb +14 -18
  42. data/lib/rudy/cli/metadata.rb +24 -10
  43. data/lib/rudy/cli/routines.rb +31 -5
  44. data/lib/rudy/config.rb +17 -22
  45. data/lib/rudy/config/objects.rb +44 -30
  46. data/lib/rudy/disks.rb +25 -0
  47. data/lib/rudy/exceptions.rb +95 -0
  48. data/lib/rudy/global.rb +46 -23
  49. data/lib/rudy/guidelines.rb +3 -2
  50. data/lib/rudy/huxtable.rb +66 -57
  51. data/lib/rudy/machines.rb +41 -263
  52. data/lib/rudy/metadata.rb +212 -38
  53. data/lib/rudy/metadata/backup.rb +123 -78
  54. data/lib/rudy/metadata/disk.rb +152 -170
  55. data/lib/rudy/metadata/machine.rb +179 -0
  56. data/lib/rudy/mixins.rb +2 -1
  57. data/lib/rudy/mixins/hash.rb +3 -1
  58. data/lib/rudy/mixins/symbol.rb +8 -0
  59. data/lib/rudy/routines.rb +127 -344
  60. data/lib/rudy/routines/base.rb +226 -0
  61. data/lib/rudy/routines/handlers/base.rb +48 -0
  62. data/lib/rudy/routines/handlers/depends.rb +49 -0
  63. data/lib/rudy/routines/handlers/disks.rb +239 -0
  64. data/lib/rudy/routines/handlers/group.rb +42 -0
  65. data/lib/rudy/routines/handlers/host.rb +72 -0
  66. data/lib/rudy/routines/handlers/keypair.rb +70 -0
  67. data/lib/rudy/routines/handlers/machines.rb +15 -0
  68. data/lib/rudy/routines/handlers/script.rb +85 -0
  69. data/lib/rudy/routines/handlers/user.rb +41 -0
  70. data/lib/rudy/routines/passthrough.rb +19 -23
  71. data/lib/rudy/routines/reboot.rb +82 -51
  72. data/lib/rudy/routines/shutdown.rb +61 -14
  73. data/lib/rudy/routines/startup.rb +111 -17
  74. data/lib/rudy/utils.rb +12 -59
  75. data/rudy.gemspec +85 -25
  76. data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
  77. data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
  78. data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
  79. data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
  80. data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
  81. data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
  82. data/tryouts/12_config/40_machines_tryouts.rb +53 -0
  83. data/tryouts/12_config/50_commands_tryouts.rb +17 -0
  84. data/tryouts/12_config/60_routines_tryouts.rb +16 -0
  85. data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
  86. data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
  87. data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
  88. data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
  89. data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
  90. data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
  91. data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
  92. data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
  93. data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
  94. data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
  95. data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
  96. data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
  97. data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
  98. data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
  99. data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
  100. data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
  101. data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
  102. data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
  103. data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
  104. data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
  105. data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
  106. data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
  107. data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
  108. data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
  109. data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
  110. data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
  111. data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
  112. data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
  113. data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
  114. data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
  115. data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
  116. data/tryouts/failer +6 -0
  117. data/tryouts/misc/console_tryout.rb +91 -0
  118. data/tryouts/misc/disks_tryout.rb +48 -0
  119. data/tryouts/misc/drydock_tryout.rb +48 -0
  120. data/tryouts/misc/nested_methods.rb +103 -0
  121. data/tryouts/misc/session_tryout.rb +46 -0
  122. data/tryouts/misc/tryouts.rb +33 -0
  123. data/tryouts/misc/usage_tryout.rb +23 -0
  124. metadata +119 -31
  125. data/bin/ird +0 -153
  126. data/lib/rudy/metadata/backups.rb +0 -67
  127. data/lib/rudy/metadata/debug.rb +0 -38
  128. data/lib/rudy/metadata/disks.rb +0 -67
  129. data/lib/rudy/metadata/objectbase.rb +0 -108
  130. data/lib/rudy/routines/helper.rb +0 -76
  131. data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
  132. data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
  133. data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
  134. data/lib/rudy/routines/helpers/userhelper.rb +0 -37
  135. data/support/rudy-ec2-startup +0 -200
@@ -19,9 +19,9 @@ module Rudy::AWS
19
19
 
20
20
  end
21
21
 
22
- class Zones
23
- include Rudy::AWS::ObjectBase
24
- include Rudy::AWS::EC2::Base
22
+ module Zones
23
+ include Rudy::AWS::EC2 # important! include,
24
+ extend self # then extend
25
25
 
26
26
  def list(*names)
27
27
  zones = list_as_hash(names)
@@ -31,13 +31,14 @@ module Rudy::AWS
31
31
 
32
32
  def list_as_hash(*names)
33
33
  names = names.flatten
34
- zlist = @ec2.describe_availability_zones(:zone_name => names)
34
+ zlist = @@ec2.describe_availability_zones(:zone_name => names)
35
35
  return unless zlist['availabilityZoneInfo'].is_a?(Hash)
36
36
  zones = {}
37
37
  zlist['availabilityZoneInfo']['item'].each do |zhash|
38
38
  zon = Zones.from_hash(zhash)
39
39
  zones[zon.name] = zon
40
40
  end
41
+ zones = nil if zones.empty?
41
42
  zones
42
43
  end
43
44
 
@@ -3,7 +3,8 @@ module Rudy::AWS
3
3
  class S3
4
4
 
5
5
  def initialize(access_key=nil, secret_key=nil, region=nil, debug=nil)
6
-
6
+ require 'aws/s3'
7
+
7
8
  url ||= 'http://sdb.amazonaws.com'
8
9
  # There is a bug with passing :server to EC2::Base.new so
9
10
  # we'll use the environment variable for now.
@@ -13,7 +13,6 @@ module Rudy
13
13
  class SDB
14
14
  class NoAccessKey < RuntimeError; end
15
15
  class NoSecretKey < RuntimeError; end
16
- include Rudy::AWS::ObjectBase
17
16
 
18
17
  require 'rudy/aws/sdb/error'
19
18
 
@@ -33,7 +32,7 @@ module Rudy
33
32
  @base_url = url
34
33
  @debug = debug || StringIO.new
35
34
  end
36
-
35
+
37
36
  def list_domains(max = nil, token = nil)
38
37
  params = { 'Action' => 'ListDomains' }
39
38
  params['NextToken'] =
@@ -63,12 +62,11 @@ module Rudy
63
62
  end
64
63
 
65
64
 
66
- # Takes a zipped Array or Hash of criteria.
65
+ # Takes a Hash of criteria.
67
66
  # Returns a string suitable for a SimpleDB Select
68
- def self.generate_select(fields, domain, *args)
69
- q = args.first.is_a?(Hash)? args.first : Hash[*args.flatten]
67
+ def self.generate_select(domain, fields={})
70
68
  query = []
71
- q.each_pair do |n,v|
69
+ fields.each_pair do |n,v|
72
70
  query << "#{Rudy::AWS.escape n}='#{Rudy::AWS.escape v}'"
73
71
  end
74
72
  str = "select * from #{domain} "
@@ -76,18 +74,6 @@ module Rudy
76
74
  str
77
75
  end
78
76
 
79
-
80
- # Takes a zipped Array or Hash of criteria.
81
- # Returns a string suitable for a SimpleDB Query
82
- def self.generate_query(*args)
83
- q = args.first.is_a?(Hash)? args.first : Hash[*args.flatten]
84
- query = []
85
- q.each do |n,v|
86
- query << "['#{Rudy::AWS.escape n}'='#{Rudy::AWS.escape v}']"
87
- end
88
- query.join(" intersection ")
89
- end
90
-
91
77
 
92
78
  def select(select, token = nil)
93
79
  params = {
@@ -122,72 +108,6 @@ module Rudy
122
108
  hash_results.empty? ? nil : hash_results
123
109
  end
124
110
 
125
- # <QueryResult><ItemName>in-c2ffrw</ItemName><ItemName>in-72yagt</ItemName><ItemName>in-52j8gj</ItemName>
126
- def query(domain, query, max = nil, token = nil)
127
- params = {
128
- 'Action' => 'Query',
129
- 'QueryExpression' => query,
130
- 'DomainName' => domain.to_s
131
- }
132
- params['NextToken'] =
133
- token unless token.nil? || token.empty?
134
- params['MaxNumberOfItems'] =
135
- max.to_s unless max.nil? || max.to_i == 0
136
-
137
-
138
- doc = call(:get, params)
139
- results = []
140
- if doc
141
- REXML::XPath.each(doc, '//ItemName/text()') do |item|
142
- results << item.to_s
143
- end
144
- end
145
-
146
- #return results, REXML::XPath.first(doc, '//NextToken/text()').to_s
147
- results.empty? ? nil : results
148
-
149
- end
150
-
151
-
152
-
153
- # <QueryWithAttributesResult><Item><Name>in-c2ffrw</Name><Attribute><Name>code</Name><Value>in-c2ffrw</Value></Attribute><Attribute><Name>date_created</Name><Value>2008-10-31</Value></Attribute></Item><Item>
154
- def query_with_attributes(domain, query, max = nil, token = nil)
155
- params = {
156
- 'Action' => 'QueryWithAttributes',
157
- 'QueryExpression' => query,
158
- 'DomainName' => domain.to_s
159
- }
160
- params['NextToken'] =
161
- token unless token.nil? || token.empty?
162
- params['MaxNumberOfItems'] =
163
- max.to_s unless max.nil? || max.to_i == 0
164
-
165
- doc = call(:get, params)
166
- results = []
167
- if doc
168
- REXML::XPath.each(doc, "//Item") do |item|
169
- name = REXML::XPath.first(item, './Name/text()').to_s
170
-
171
- attributes = {'Name' => name}
172
- REXML::XPath.each(item, "./Attribute") do |attr|
173
- key = REXML::XPath.first(attr, './Name/text()').to_s
174
- value = REXML::XPath.first(attr, './Value/text()').to_s
175
- ( attributes[key] ||= [] ) << value
176
- end
177
- results << attributes
178
- end
179
- #return results, REXML::XPath.first(doc, '//NextToken/text()').to_s
180
- end
181
-
182
- hash_results = {}
183
- results.each do |item|
184
- hash_results[item.delete('Name')] = item
185
- end
186
-
187
- hash_results
188
- end
189
-
190
-
191
111
 
192
112
  def put_attributes(domain, item, attributes, replace = true)
193
113
  replace = true if replace == :replace
@@ -252,7 +172,35 @@ module Rudy
252
172
 
253
173
 
254
174
  protected
175
+
176
+
177
+ # Execute AWS requests safely. This will trap errors and return
178
+ # a default value (if specified).
179
+ # * +default+ A default response value
180
+ # * +request+ A block which contains the AWS request
181
+ # Returns the return value from the request is returned untouched
182
+ # or the default value on error or if the request returned nil.
183
+ def execute_request(default=nil, timeout=nil, &request)
184
+ timeout ||= 15
185
+ raise "No block provided" unless request
186
+ response = nil
187
+ begin
188
+ Timeout::timeout(timeout) do
189
+ response = request.call
190
+ end
255
191
 
192
+ rescue Timeout::Error => ex
193
+ STDERR.puts "Timeout (#{timeout}): #{ex.message}!"
194
+ rescue SocketError => ex
195
+ #STDERR.puts ex.message
196
+ #STDERR.puts ex.backtrace
197
+ raise SocketError, "Check your Internets!" unless Rudy::Huxtable.global.offline
198
+ ensure
199
+ response ||= default
200
+ end
201
+ response
202
+ end
203
+
256
204
  def call(method, params)
257
205
  params.merge!( {
258
206
  'Version' => '2007-11-07',
@@ -276,7 +224,8 @@ module Rudy
276
224
  query = query.join('&')
277
225
  url = "#{@base_url}?#{query}"
278
226
  uri = URI.parse(url)
279
- @debug.puts("#{url}") if @debug
227
+
228
+ #Rudy::Huxtable.ld url if Rudy.debug?
280
229
 
281
230
  response = execute_request(nil) {
282
231
  Net::HTTP.new(uri.host, uri.port).send_request(method, uri.request_uri)
@@ -294,7 +243,7 @@ module Rudy
294
243
  error = doc.get_elements('*/Errors/Error')[0]
295
244
  raise(
296
245
  Module.class_eval(
297
- "AwsSdb::#{error.get_elements('Code')[0].text}Error"
246
+ "Rudy::AWS::SDB::#{error.get_elements('Code')[0].text}Error"
298
247
  ).new(
299
248
  error.get_elements('Message')[0].text,
300
249
  doc.get_elements('*/RequestID')[0].text
@@ -0,0 +1,24 @@
1
+ module Rudy
2
+
3
+ module Backups
4
+ RTYPE = 'back'.freeze
5
+
6
+ extend self
7
+ extend Rudy::Metadata::ClassMethods
8
+ include Rudy::Huxtable
9
+ extend Rudy::Huxtable
10
+
11
+ # Returns the most recent backup object for the given path
12
+ def get(path)
13
+ tmp = Rudy::Backup.new path
14
+ backups = Rudy::Backups.list :path => path
15
+ return nil unless backups.is_a?(Array) && !backups.empty?
16
+ backups.first
17
+ end
18
+
19
+ def from_hash(h)
20
+ Rudy::Backup.from_hash h
21
+ end
22
+ end
23
+
24
+ end
@@ -10,6 +10,10 @@ module Rudy
10
10
  # line interfaces. See the bin/ files if you're interested.
11
11
  #
12
12
  module CLI
13
+
14
+ require 'rudy/cli/execbase'
15
+ require 'rudy/cli/base'
16
+
13
17
  class NoCred < RuntimeError #:nodoc
14
18
  end
15
19
 
@@ -19,92 +23,7 @@ module Rudy
19
23
  # Should print messages as they come
20
24
  end
21
25
 
22
- class CommandBase < Drydock::Command
23
- include Rudy::Huxtable
24
-
25
- attr_reader :config
26
-
27
- protected
28
- def init
29
-
30
- if Drydock.debug?
31
- #Caesars.enable_debug
32
- Rudy.enable_debug
33
- end
34
-
35
- # The CLI wants output!
36
- Rudy::Huxtable.update_logger STDOUT
37
-
38
- # Send The Huxtables the global values from the command-line
39
- Rudy::Huxtable.update_global @global
40
-
41
- # Reload configuration. This must come after update_global
42
- # so it will catch the @@global.config path (if supplied).
43
- begin
44
- Rudy::Huxtable.update_config
45
- rescue Caesars::SyntaxError => ex
46
- STDERR.puts ex.message
47
- STDERR.puts ex.backtrace if @@global.verbose > 0
48
- exit 81
49
- end
50
-
51
- @@global.nocolor ? String.disable_color : String.enable_color
52
- @@global.yes ? Annoy.enable_skip : Annoy.disable_skip
53
-
54
- unless @@global.accesskey && @@global.secretkey
55
- STDERR.puts "No AWS credentials. Check your configs!"
56
- STDERR.puts "Try: rudy init"
57
- exit 1
58
- end
59
-
60
- if @@global.environment =~ /^prod/ && Drydock.debug?
61
- puts Rudy::Utils.banner("PRODUCTION ACCESS IS DISABLED IN DEBUG MODE")
62
- exit 1
63
- end
64
-
65
- end
66
-
67
- def execute_action(emsg="Failed", &action)
68
- begin
69
- ret = action.call
70
- raise emsg unless ret
71
- ret
72
- rescue Rudy::AWS::EC2::NoAMI => ex
73
- raise Drydock::OptError.new('-a', @alias)
74
- end
75
- end
76
-
77
- def execute_check(level=:medium)
78
- ret = Annoy.are_you_sure?(level)
79
- exit 0 unless ret
80
- ret
81
- end
82
-
83
- # Print a default header to the screen for every command.
84
- #
85
- def print_header
86
-
87
- # Send The Huxtables the global values again because they could be
88
- # updated after initialization but before the command was executed
89
- Rudy::Huxtable.update_global @global
90
-
91
- puts Rudy::CLI.generate_header(@@global, @@config) if @@global.print_header
92
-
93
- unless @@global.quiet
94
- if @@global.environment == "prod"
95
- msg = "YOU ARE PLAYING WITH PRODUCTION"
96
- puts Rudy::Utils.banner(msg, :normal), $/
97
- end
98
- puts Rudy::Utils.banner("THIS IS EC2"), $/ if Rudy.in_situ?
99
- end
100
- end
101
-
102
- def machine_separator(name, awsid)
103
- ('%s %-50s awsid: %s ' % [$/, name, awsid]).att(:reverse)
104
- end
105
-
106
- end
107
-
26
+
108
27
  def self.generate_header(global, config)
109
28
  return "" if global.quiet
110
29
  header = StringIO.new
@@ -128,52 +47,7 @@ module Rudy
128
47
  end
129
48
 
130
49
 
131
- # A base for all Drydock executables (bin/rudy etc...).
132
- class Base
133
- extend Drydock
134
-
135
- before do |obj|
136
- # Don't print Rudy header unless requested to
137
- obj.global.print_header = false if (obj.global.verbose == 0)
138
- @start = Time.now
139
- end
140
-
141
- after do |obj|
142
- if obj.global.verbose > 0
143
- puts
144
- @elapsed = Time.now - @start
145
- puts "Elapsed: %.2f seconds" % @elapsed.to_f if @elapsed > 0.1
146
- end
147
- end
148
-
149
-
150
- # These globals are used by all bin/ executables
151
- global :A, :accesskey, String, "AWS Access Key"
152
- global :S, :secretkey, String, "AWS Secret Access Key"
153
- global :R, :region, String, "Amazon service region (ie: #{Rudy::DEFAULT_REGION})"
154
- global :z, :zone, String, "Amazon Availability zone (ie: #{Rudy::DEFAULT_ZONE})"
155
- global :u, :user, String, "Provide a username (ie: #{Rudy::DEFAULT_USER})"
156
- global :k, :pkey, String, "Path to the private SSH key"
157
- global :f, :format, String, "Output format"
158
- global :n, :nocolor, "Disable output colors"
159
- global :C, :config, String, "Specify another configuration file to read (ie: #{Rudy::CONFIG_FILE})"
160
- global :Y, :yes, "Assume a correct answer to confirmation questions"
161
- global :q, :quiet, "Run with less output"
162
- global :O, :offline, "Be cool about the internet being down"
163
- global :v, :verbose, "Increase verbosity of output (i.e. -v or -vv or -vvv)" do
164
- @verbose ||= 0
165
- @verbose += 1
166
- end
167
- global :V, :version, "Display version number" do
168
- puts "Rudy version: #{Rudy::VERSION}"
169
- exit 0
170
- end
171
-
172
- end
173
-
174
-
175
50
  end
176
-
177
51
  end
178
52
 
179
53
  Rudy::Utils.require_glob(RUDY_LIB, 'rudy', 'cli', '**', '*.rb')
@@ -6,26 +6,24 @@ module AWS; module EC2;
6
6
  class Addresses < Rudy::CLI::CommandBase
7
7
 
8
8
  def addresses_create
9
- radd = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
10
- address = radd.create
9
+ address = Rudy::AWS::EC2::Addresses.create
11
10
  puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
12
11
  end
13
12
 
14
13
  def addresses_destroy_valid?
15
14
  raise Drydock::ArgError.new("IP address", @alias) unless @argv.ipaddress
16
- @radd = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
17
- raise "#{@argv.ipaddress} is not allocated to you" unless @radd.exists?(@argv.ipaddress)
18
- raise "#{@argv.ipaddress} is associated!" if @radd.associated?(@argv.ipaddress)
15
+ raise "#{@argv.ipaddress} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(@argv.ipaddress)
16
+ raise "#{@argv.ipaddress} is associated!" if Rudy::AWS::EC2::Addresses.associated?(@argv.ipaddress)
19
17
  true
20
18
  end
21
19
  def addresses_destroy
22
- address = @radd.get(@argv.ipaddress)
20
+ address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
23
21
  raise "Could not fetch #{address.ipaddress}" unless address
24
22
 
25
23
  puts "Destroying address: #{@argv.ipaddress}"
26
24
  puts "NOTE: this IP address will become available to other EC2 customers.".bright
27
25
  execute_check(:medium)
28
- execute_action { @radd.destroy(@argv.ipaddress) }
26
+ execute_action { Rudy::AWS::EC2::Addresses.destroy(@argv.ipaddress) }
29
27
  self.addresses
30
28
  end
31
29
 
@@ -35,24 +33,21 @@ module AWS; module EC2;
35
33
  true
36
34
  end
37
35
  def associate_addresses
38
- radd = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
39
- rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
40
-
41
- raise "Instance #{@argv.instid} does not exist!" unless rinst.exists?(@option.instance)
36
+ raise "Instance #{@argv.instid} does not exist!" unless Rudy::AWS::EC2::Instances.exists?(@option.instance)
42
37
 
43
38
  if @option.newaddress
44
39
  print "Creating address... "
45
- tmp = radd.create
40
+ tmp = Rudy::AWS::EC2::Addresses.create
46
41
  puts "#{tmp.ipaddress}"
47
42
  address = tmp.ipaddress
48
43
  else
49
44
  address = @argv.ipaddress
50
45
  end
51
46
 
52
- raise "#{address} is not allocated to you" unless radd.exists?(address)
53
- raise "#{address} is already associated!" if radd.associated?(address)
47
+ raise "#{address} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(address)
48
+ raise "#{address} is already associated!" if Rudy::AWS::EC2::Addresses.associated?(address)
54
49
 
55
- instance = rinst.get(@option.instance)
50
+ instance = Rudy::AWS::EC2::Instances.get(@option.instance)
56
51
 
57
52
  # If an instance was recently disassoiciated, the dns_public may
58
53
  # not be updated yet
@@ -61,8 +56,8 @@ module AWS; module EC2;
61
56
 
62
57
  puts "Associating #{address} to #{instance_name} (#{instance.groups.join(', ')})"
63
58
  execute_check(:low)
64
- execute_action { radd.associate(address, instance.awsid) }
65
- address = radd.get(address)
59
+ execute_action { Rudy::AWS::EC2::Addresses.associate(address, instance.awsid) }
60
+ address = Rudy::AWS::EC2::Addresses.get(address)
66
61
  puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
67
62
  end
68
63
 
@@ -71,24 +66,21 @@ module AWS; module EC2;
71
66
  true
72
67
  end
73
68
  def disassociate_addresses
74
- radd = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
75
- rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
76
- raise "#{@argv.ipaddress} is not allocated to you" unless radd.exists?(@argv.ipaddress)
77
- raise "#{@argv.ipaddress} is not associated!" unless radd.associated?(@argv.ipaddress)
69
+ raise "#{@argv.ipaddress} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(@argv.ipaddress)
70
+ raise "#{@argv.ipaddress} is not associated!" unless Rudy::AWS::EC2::Addresses.associated?(@argv.ipaddress)
78
71
 
79
- address = radd.get(@argv.ipaddress)
80
- instance = rinst.get(address.instid)
72
+ address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
73
+ instance = Rudy::AWS::EC2::Instances.get(address.instid)
81
74
 
82
75
  puts "Disassociating #{address.ipaddress} from #{instance.awsid} (#{instance.groups.join(', ')})"
83
76
  execute_check(:medium)
84
- execute_action { radd.disassociate(@argv.ipaddress) }
85
- address = radd.get(@argv.ipaddress)
77
+ execute_action { Rudy::AWS::EC2::Addresses.disassociate(@argv.ipaddress) }
78
+ address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
86
79
  puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
87
80
  end
88
81
 
89
82
  def addresses
90
- radd = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
91
- addresses = radd.list || []
83
+ addresses = Rudy::AWS::EC2::Addresses.list || []
92
84
 
93
85
  addresses.each do |address|
94
86
  puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)