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
@@ -5,7 +5,8 @@ module Rudy::AWS
5
5
  class Rule < Storable
6
6
  field :ports => Range # Port range
7
7
  field :protocol => String
8
- def to_s
8
+
9
+ def to_s(with_title=false)
9
10
  if self.ports.first == self.ports.last
10
11
  "%s(%s)" % [self.protocol, self.ports.last]
11
12
  else
@@ -22,22 +23,44 @@ module Rudy::AWS
22
23
  field :addresses => Hash # key: address/mask, value Array of Rule object
23
24
  field :groups => Hash # key: group, value Array of Rule object
24
25
 
26
+
27
+ def liner_note
28
+ info = "(authorized accounts: #{@groups.keys.join(', ')})"
29
+ info = '' if @groups.empty?
30
+ "%s %s" % [@name.bright, info]
31
+ end
32
+
33
+
25
34
  # Print info about a security group
26
35
  #
27
36
  # * +group+ is a Rudy::AWS::EC2::Group object
28
- def to_s
29
- lines = ["%12s: %s" % ['GROUP', self.name.bright]]
30
-
37
+ def to_s(with_title=false)
38
+ lines = [liner_note]
31
39
  (self.addresses || {}).each_pair do |address,rules|
32
- lines << "%6s %s: %s" % ['', address.to_s, rules.collect { |p| p.to_s}.join(', ')]
40
+ lines << "%18s -> %s" % [address.to_s, rules.collect { |p| p.to_s}.join(', ')]
33
41
  end
34
-
35
- (self.groups || {}).each_pair do |group,rules|
36
- lines << "%6s %s: %s" % ['', group, rules.collect { |p| p.to_s}.join(', ') ]
42
+ lines.join($/)
43
+ end
44
+
45
+ def inspect
46
+ lines = [@name.bright]
47
+ field_names.each do |key|
48
+ next unless self.respond_to?(key)
49
+ next if [:addresses, :groups].member?(key)
50
+ val = self.send(key)
51
+ lines << sprintf(" %12s: %s", key, (val.is_a?(Array) ? val.join(', ') : val))
52
+ end
53
+ @addresses.each_pair do |a,r|
54
+ rules = r.collect { |r| r.to_s }.join(', ') if r
55
+ lines << sprintf(" %12s: %s (%s)", 'address', a.to_s, rules)
56
+ end
57
+ @groups.each_pair do |g,r|
58
+ rules = r.collect { |r| r.to_s }.join(', ')
59
+ lines << sprintf(" %12s: %s (%s)", 'group', g.to_s, rules)
37
60
  end
38
-
39
61
  lines.join($/)
40
62
  end
63
+
41
64
 
42
65
  # * +ipaddress+ is a String, ipaddress/mask/protocol
43
66
  # * +rule+ is a Rule object
@@ -60,13 +83,53 @@ module Rudy::AWS
60
83
 
61
84
 
62
85
 
63
- class EC2
86
+ module EC2
64
87
  class Groups
65
88
  include Rudy::AWS::ObjectBase
89
+ include Rudy::AWS::EC2::Base
66
90
 
67
- def list(group_names=[])
91
+ # Create a new EC2 security group
92
+ # Returns list of created groups
93
+ def create(name, desc=nil, addresses=[], ports=[], protocols=[], &each_group)
94
+ desc ||= "Security Group #{name}"
95
+ ret = @ec2.create_security_group(:group_name => name, :group_description => desc)
96
+ return false unless (ret && ret['return'] == 'true')
97
+ authorize(name, addresses, ports, protocols)
98
+ get(name, &each_group)
99
+ end
100
+
101
+ # Delete an EC2 security group
102
+ # Returns true/false whether successful
103
+ def destroy(name, &each_group)
104
+ list(name, &each_group) if each_group
105
+ ret = @ec2.delete_security_group(:group_name => name)
106
+ (ret && ret['return'] == 'true')
107
+ end
108
+
109
+ # Authorize a port/protocol for a specific IP address
110
+ def authorize(name, addresses=[], ports=[], protocols=[], &each_group)
111
+ modify_rules(:authorize, name, addresses, ports, protocols, &each_group)
112
+ end
113
+ alias :authorise :authorize
114
+
115
+ # Revoke a port/protocol for a specific IP address
116
+ # Takes the same arguments as authorize
117
+ def revoke(name, addresses=[], ports=[], protocols=[], &each_group)
118
+ modify_rules(:revoke, name, addresses, ports, protocols, &each_group)
119
+ end
120
+
121
+ def authorize_group(name, gname, owner, &each_group)
122
+ modify_group_rules(:authorize, name, gname, owner, &each_group)
123
+ end
124
+ alias :authorise_group :authorize_group
125
+
126
+ def revoke_group(name, gname, owner, &each_group)
127
+ modify_group_rules(:revoke, name, gname, owner, &each_group)
128
+ end
129
+
130
+ def list(group_names=[], &each_group)
68
131
  group_names ||= []
69
- groups = list_as_hash(group_names)
132
+ groups = list_as_hash(group_names, &each_group)
70
133
  groups &&= groups.values
71
134
  groups
72
135
  end
@@ -75,15 +138,16 @@ module Rudy::AWS
75
138
  # associated to the account will be returned.
76
139
  #
77
140
  # Returns an Array of Rudy::AWS::EC2::Group objects
78
- def list_as_hash(group_names=[])
79
- group_names ||= []
80
- glist = @aws.describe_security_groups(:group_name => group_names) || {}
141
+ def list_as_hash(group_names=[], &each_group)
142
+ group_names = [group_names].flatten.compact
143
+ glist = @ec2.describe_security_groups(:group_name => group_names) || {}
81
144
  return unless glist['securityGroupInfo'].is_a?(Hash)
82
145
  groups = {}
83
146
  glist['securityGroupInfo']['item'].each do |oldg|
84
147
  g = Groups.from_hash(oldg)
85
148
  groups[g.name] = g
86
149
  end
150
+ groups.each_value { |g| each_group.call(g) } if each_group
87
151
  groups
88
152
  end
89
153
 
@@ -92,21 +156,6 @@ module Rudy::AWS
92
156
  !groups.empty?
93
157
  end
94
158
 
95
- # Create a new EC2 security group
96
- # Returns true/false whether successful
97
- def create(name, desc=nil)
98
- ret = @aws.create_security_group(:group_name => name, :group_description => desc || "Group #{name}")
99
- return false unless (ret && ret['return'] == 'true')
100
- get(name)
101
- end
102
-
103
- # Delete an EC2 security group
104
- # Returns true/false whether successful
105
- def destroy(name)
106
- ret = @aws.delete_security_group(:group_name => name)
107
- (ret && ret['return'] == 'true')
108
- end
109
-
110
159
  # * +name+ a string
111
160
  def get(name)
112
161
  (list([name]) || []).first
@@ -117,53 +166,6 @@ module Rudy::AWS
117
166
  #
118
167
  #end
119
168
 
120
- def modify_rules(meth, name, from_port, to_port, protocol='tcp', ipa='0.0.0.0/0')
121
- opts = {
122
- :group_name => name,
123
- :ip_protocol => protocol,
124
- :from_port => from_port,
125
- :to_port => to_port,
126
- :cidr_ip => ipa
127
- }
128
-
129
- ret = @aws.send("#{meth}_security_group_ingress", opts)
130
- (ret && ret['return'] == 'true')
131
- end
132
- private :modify_rules
133
-
134
- def modify_group_rules(meth, name, gname=nil, gowner=nil)
135
- opts = {
136
- :group_name => name,
137
- :source_security_group_name => gname,
138
- :source_security_group_owner_id => gowner
139
- }
140
- ret = @aws.send("#{meth}_security_group_ingress", opts)
141
- (ret && ret['return'] == 'true')
142
- end
143
- private :modify_group_rules
144
-
145
- # Authorize a port/protocol for a specific IP address
146
- def authorize(*args)
147
- modify_rules(:authorize, *args)
148
- end
149
- alias :authorise :authorize
150
-
151
- def authorize_group(*args)
152
- modify_group_rules(:authorize, *args)
153
- end
154
- alias :authorise_group :authorize_group
155
-
156
- def revoke_group(*args)
157
- modify_group_rules(:revoke, *args)
158
- end
159
-
160
- # Revoke a port/protocol for a specific IP address
161
- # Takes the same arguments as authorize
162
- def revoke(*args)
163
- modify_rules(:revoke, *args)
164
- end
165
-
166
-
167
169
  # Does the security group +name+ exist?
168
170
  def exists?(name)
169
171
  begin
@@ -227,13 +229,71 @@ module Rudy::AWS
227
229
  end
228
230
  if oldp['ipRanges'].is_a?(Hash)
229
231
  oldp['ipRanges']['item'].each do |olda|
230
- name = "#{olda['cidrIp']}/#{oldp['ipProtocol']}"
232
+ name = "#{olda['cidrIp']}"
231
233
  newg.add_address(name, newp) # ipaddress/mask/protocol
232
234
  end
233
235
  end
234
236
  end
235
237
  newg
236
238
  end
239
+
240
+
241
+ private
242
+
243
+
244
+ def modify_rules(meth, name, addresses, ports, protocols, &each_group)
245
+ list(name, &each_group) if each_group
246
+
247
+ ports = [[22,22],[80,80],[443,443]] if !ports || ports.empty?
248
+ protocols = ["tcp"] if !protocols || protocols.empty?
249
+ addresses = [Rudy::Utils::external_ip_address] if !addresses || addresses.empty?
250
+
251
+ # Make sure the IP addresses have ranges
252
+ addresses.collect! { |ip| (ip.match /\/\d+/) ? ip : "#{ip}/32" }
253
+ protocols.collect! { |p| p.to_s }
254
+ ret = false
255
+ protocols.each do |protocol|
256
+ addresses.each do |address|
257
+ ports.each do |port|
258
+ port_lo, port_hi = port.is_a?(Array) ? [port[0], port[1]] : [port, port]
259
+ @logger.puts "#{meth} for ports #{port[0]}:#{port[1]} (#{protocol}) for #{addresses.join(', ')}" if @logger
260
+ ret = modify_rule(meth, name, port[0].to_i, (port[1] || port[0]).to_i, protocol, address)
261
+ raise "Unknown error during #{meth}" unless ret
262
+ end
263
+ end
264
+ end
265
+
266
+ ret
267
+ end
268
+
269
+ def modify_rule(meth, name, from_port, to_port, protocol, ipa)
270
+ opts = {
271
+ :group_name => name,
272
+ :ip_protocol => protocol,
273
+ :from_port => from_port,
274
+ :to_port => to_port,
275
+ :cidr_ip => ipa
276
+ }
277
+ ret = @ec2.send("#{meth}_security_group_ingress", opts)
278
+ (ret && ret['return'] == 'true')
279
+ end
280
+
281
+
282
+ def modify_group_rules(meth, name, gname, gowner, &each_group)
283
+ list(name, &each_group) if each_group
284
+ # probably works, needs to be tested
285
+ #gowner &&= gowner.tr!('-', '') # Remove dashes from aws account number
286
+
287
+ opts = {
288
+ :group_name => name,
289
+ :source_security_group_name => gname,
290
+ :source_security_group_owner_id => gowner
291
+ }
292
+ ret = @ec2.send("#{meth}_security_group_ingress", opts)
293
+ (ret && ret['return'] == 'true')
294
+ end
295
+
296
+
237
297
 
238
298
  end
239
299
  end
@@ -1,21 +1,102 @@
1
1
 
2
2
 
3
3
  module Rudy::AWS
4
- class EC2
4
+ class EC2::Image < Storable
5
+ @@sformat = " -> %8s; %12s; %12s; %12s; %8s"
6
+
7
+ field :awsid
8
+ field :owner
9
+ field :aki
10
+ field :ari
11
+ field :state
12
+ field :arch
13
+ field :visibility
14
+ field :location
15
+ field :kind
16
+
17
+ def liner_note
18
+ info = @location
19
+ # Highlight "debian-5" in /dir/debian-5.manifest.xml
20
+ #info = info.split(/\//)
21
+ #info[-1].gsub!(/(.+?)((\.img)?\.manifest\.xml)/) { |m,n| ($1 || "").bright << $2 }
22
+ #info = info.join('/')
23
+ "%s %-6s (%s)" % [self.awsid.bright, self.arch, info]
24
+ end
25
+
26
+ def to_s(with_title=false)
27
+ lines = []
28
+ lines << liner_note
29
+ #if self.available?
30
+ # p = public? ? "public" : "private"
31
+ # k, r = @aki || 'aki-unknown', @ari || 'ari-unknown'
32
+ # lines << @@sformat % %w{arch owner aki ari visibility} if with_title
33
+ # lines << @@sformat % [@arch, @owner, k, r, p]
34
+ #end
35
+ lines.join($/)
36
+ end
37
+
38
+ def inspect
39
+ lines = []
40
+ lines << liner_note
41
+ field_names.each do |key|
42
+ next unless self.respond_to?(key)
43
+ val = self.send(key)
44
+ lines << sprintf(" %22s: %s", key, (val.is_a?(Array) ? val.join(', ') : val))
45
+ end
46
+ lines.join($/)
47
+ end
48
+
49
+ def available?; @state && @state == "available"; end
50
+ def public?; @visibility && @visibility == 'public'; end
51
+ def private?; !public? end
52
+
53
+ end
54
+
55
+ module EC2
5
56
 
6
57
  class Images
7
58
  include Rudy::AWS::ObjectBase
59
+ include Rudy::AWS::EC2::Base
8
60
 
61
+ def list(owner=[], image_ids=[], executable_by=[], &each_image)
62
+ images = list_as_hash(owner, image_ids, executable_by)
63
+ images &&= images.values
64
+ images
65
+ end
9
66
 
10
- def list()
67
+ def list_as_hash(owner=[], image_ids=[], executable_by=[], &each_image)
68
+ owner &&= [owner].flatten.compact
69
+ image_ids &&= [image_ids].flatten.compact
70
+ executable_by &&= [executable_by].flatten.compact
71
+
72
+ # Remove dashes from aws account numbers
73
+ owner &&= owner.collect { |o| o.tr('-', '') }
74
+ # If we got Image objects, we want just the IDs.
75
+ # This method always returns an Array.
76
+ image_ids = objects_to_image_ids(image_ids)
77
+
11
78
  opts = {
12
- :image_id => [],
13
- :owner_id => [],
14
- :executable_by => []
79
+ :owner_id => owner || [],
80
+ :image_id => image_ids || [],
81
+ :executable_by => executable_by || []
15
82
  }
16
- ret = @aws.describe_images_by_owner(opts) || []
17
- puts ret.to_yaml
18
- []
83
+
84
+ response = execute_request({}) { @ec2.describe_images(opts) }
85
+
86
+ return nil unless response['imagesSet'].is_a?(Hash) # No instances
87
+
88
+ resids = []
89
+ images = {}
90
+ response['imagesSet']['item'].each do |res|
91
+ resids << res['reservationId']
92
+ img = Images.from_hash(res)
93
+ images[img.awsid] = img
94
+ end
95
+
96
+ images.each_value { |image| each_image.call(image) } if each_image
97
+
98
+ images = nil if images.empty? # Don't return an empty hash
99
+ images
19
100
  end
20
101
 
21
102
  # +id+ AMI ID to deregister (ami-XXXXXXX)
@@ -24,7 +105,7 @@ module Rudy::AWS
24
105
  opts = {
25
106
  :image_id => id
26
107
  }
27
- ret = @aws.deregister_image(opts)
108
+ ret = @ec2.deregister_image(opts)
28
109
  puts ret.to_yaml
29
110
  true
30
111
  end
@@ -35,12 +116,53 @@ module Rudy::AWS
35
116
  opts = {
36
117
  :image_location => path
37
118
  }
38
- ret = @aws.register_image(opts)
119
+ ret = @ec2.register_image(opts)
39
120
  puts ret.to_yaml
40
121
  true
41
122
  end
42
- end
43
-
123
+
124
+ # imageOwnerId: "203338247012"
125
+ # kernelId: aki-a71cf9ce
126
+ # ramdiskId: ari-a51cf9cc
127
+ # imageState: available
128
+ # imageId: ami-dd34d3b4
129
+ # architecture: i386
130
+ # isPublic: "false"
131
+ # imageLocation: solutious-rudy-us/debian-squeeze-m1.small-v5.manifest.xml
132
+ # imageType: machine
133
+ def Images.from_hash(h)
134
+ img = Rudy::AWS::EC2::Image.new
135
+ img.owner = h['imageOwnerId']
136
+ img.aki = h['kernelId']
137
+ img.ari = h['ramdiskId']
138
+ img.state = h['imageState']
139
+ img.awsid = h['imageId']
140
+ img.arch = h['architecture']
141
+ img.visibility = h['isPublic'] == 'true' ? 'public' : 'private'
142
+ img.location = h['imageLocation']
143
+ img.kind = h['imageType']
144
+ img
145
+ end
146
+
147
+
148
+ private
44
149
 
150
+ # * +img_ids+ an Array of images IDs (Strings) or Image objects.
151
+ # Note: This method removes nil values and always returns an Array.
152
+ # Returns an Array of image IDs.
153
+ def objects_to_image_ids(img_ids)
154
+ img_ids = [img_ids].flatten # Make sure it's an Array
155
+ img_ids = img_ids.collect do |img|
156
+ next if img.nil? || img.to_s.empty?
157
+ if !img.is_a?(Rudy::AWS::EC2::Image) && !Rudy::Utils.is_id?(:image, img)
158
+ raise %Q("#{img}" is not an image ID or object)
159
+ end
160
+ img.is_a?(Rudy::AWS::EC2::Image) ? img.awsid : img
161
+ end
162
+ img_ids
163
+ end
164
+
165
+ end
166
+
45
167
  end
46
168
  end