solutious-rudy 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -22,13 +22,12 @@ module Rudy::AWS
22
22
  end
23
23
  end
24
24
 
25
- class Addresses
26
- include Rudy::AWS::ObjectBase
27
- include Rudy::AWS::EC2::Base
28
-
29
-
25
+ module Addresses
26
+ include Rudy::AWS::EC2 # important! include,
27
+ extend self # then extend
28
+
30
29
  def create
31
- ret = @ec2.allocate_address
30
+ ret = @@ec2.allocate_address
32
31
  return false unless ret && ret['publicIp']
33
32
  address = Rudy::AWS::EC2::Address.new
34
33
  address.ipaddress = ret['publicIp']
@@ -42,7 +41,7 @@ module Rudy::AWS
42
41
  opts ={
43
42
  :public_ip => address || raise("No public IP address supplied")
44
43
  }
45
- ret = @ec2.release_address(opts)
44
+ ret = @@ec2.release_address(opts)
46
45
  (ret && ret['return'] == 'true')
47
46
  end
48
47
 
@@ -61,7 +60,7 @@ module Rudy::AWS
61
60
  :instance_id => instance,
62
61
  :public_ip => address
63
62
  }
64
- ret = @ec2.associate_address(opts)
63
+ ret = @@ec2.associate_address(opts)
65
64
  (ret && ret['return'] == 'true')
66
65
  end
67
66
 
@@ -76,7 +75,7 @@ module Rudy::AWS
76
75
  opts ={
77
76
  :public_ip => address
78
77
  }
79
- ret = @ec2.disassociate_address(opts)
78
+ ret = @@ec2.disassociate_address(opts)
80
79
  (ret && ret['return'] == 'true')
81
80
  end
82
81
 
@@ -93,7 +92,7 @@ module Rudy::AWS
93
92
  def list_as_hash(addresses=[])
94
93
  addresses ||= []
95
94
  addresses = [addresses].flatten.compact
96
- alist = @ec2.describe_addresses(:addresses=> addresses)
95
+ alist = @@ec2.describe_addresses(:addresses=> addresses)
97
96
 
98
97
  return nil unless alist['addressesSet'].is_a?(Hash)
99
98
 
@@ -102,7 +101,7 @@ module Rudy::AWS
102
101
  address = Addresses.from_hash(address)
103
102
  addresses[address.ipaddress] = address
104
103
  end
105
-
104
+ addresses = nil if addresses.empty?
106
105
  addresses
107
106
  end
108
107
 
@@ -42,7 +42,7 @@ module Rudy::AWS
42
42
  lines.join($/)
43
43
  end
44
44
 
45
- def inspect
45
+ def pretty
46
46
  lines = [@name.bright]
47
47
  field_names.each do |key|
48
48
  next unless self.respond_to?(key)
@@ -84,15 +84,15 @@ module Rudy::AWS
84
84
 
85
85
 
86
86
  module EC2
87
- class Groups
88
- include Rudy::AWS::ObjectBase
89
- include Rudy::AWS::EC2::Base
87
+ module Groups
88
+ include Rudy::AWS::EC2 # important! include,
89
+ extend self # then extend
90
90
 
91
91
  # Create a new EC2 security group
92
92
  # Returns list of created groups
93
93
  def create(name, desc=nil, addresses=[], ports=[], protocols=[], &each_group)
94
94
  desc ||= "Security Group #{name}"
95
- ret = @ec2.create_security_group(:group_name => name, :group_description => desc)
95
+ ret = @@ec2.create_security_group(:group_name => name, :group_description => desc)
96
96
  return false unless (ret && ret['return'] == 'true')
97
97
  authorize(name, addresses, ports, protocols)
98
98
  get(name, &each_group)
@@ -102,7 +102,7 @@ module Rudy::AWS
102
102
  # Returns true/false whether successful
103
103
  def destroy(name, &each_group)
104
104
  list(name, &each_group) if each_group
105
- ret = @ec2.delete_security_group(:group_name => name)
105
+ ret = @@ec2.delete_security_group(:group_name => name)
106
106
  (ret && ret['return'] == 'true')
107
107
  end
108
108
 
@@ -140,7 +140,7 @@ module Rudy::AWS
140
140
  # Returns an Array of Rudy::AWS::EC2::Group objects
141
141
  def list_as_hash(group_names=[], &each_group)
142
142
  group_names = [group_names].flatten.compact
143
- glist = @ec2.describe_security_groups(:group_name => group_names) || {}
143
+ glist = @@ec2.describe_security_groups(:group_name => group_names) || {}
144
144
  return unless glist['securityGroupInfo'].is_a?(Hash)
145
145
  groups = {}
146
146
  glist['securityGroupInfo']['item'].each do |oldg|
@@ -148,6 +148,7 @@ module Rudy::AWS
148
148
  groups[g.name] = g
149
149
  end
150
150
  groups.each_value { |g| each_group.call(g) } if each_group
151
+ groups = nil if groups.empty?
151
152
  groups
152
153
  end
153
154
 
@@ -274,7 +275,7 @@ module Rudy::AWS
274
275
  :to_port => to_port,
275
276
  :cidr_ip => ipa
276
277
  }
277
- ret = @ec2.send("#{meth}_security_group_ingress", opts)
278
+ ret = @@ec2.send("#{meth}_security_group_ingress", opts)
278
279
  (ret && ret['return'] == 'true')
279
280
  end
280
281
 
@@ -289,7 +290,7 @@ module Rudy::AWS
289
290
  :source_security_group_name => gname,
290
291
  :source_security_group_owner_id => gowner
291
292
  }
292
- ret = @ec2.send("#{meth}_security_group_ingress", opts)
293
+ ret = @@ec2.send("#{meth}_security_group_ingress", opts)
293
294
  (ret && ret['return'] == 'true')
294
295
  end
295
296
 
@@ -52,11 +52,11 @@ module Rudy::AWS
52
52
 
53
53
  end
54
54
 
55
- module EC2
56
-
57
- class Images
58
- include Rudy::AWS::ObjectBase
59
- include Rudy::AWS::EC2::Base
55
+ module EC2
56
+ module Images
57
+ include Rudy::AWS::EC2 # important! include,
58
+ extend self # then extend
59
+
60
60
 
61
61
  def list(owner=[], image_ids=[], executable_by=[], &each_image)
62
62
  images = list_as_hash(owner, image_ids, executable_by)
@@ -81,7 +81,7 @@ module Rudy::AWS
81
81
  :executable_by => executable_by || []
82
82
  }
83
83
 
84
- response = execute_request({}) { @ec2.describe_images(opts) }
84
+ response = Rudy::AWS::EC2.execute_request({}) { @@ec2.describe_images(opts) }
85
85
 
86
86
  return nil unless response['imagesSet'].is_a?(Hash) # No instances
87
87
 
@@ -105,7 +105,7 @@ module Rudy::AWS
105
105
  opts = {
106
106
  :image_id => id
107
107
  }
108
- ret = @ec2.deregister_image(opts)
108
+ ret = @@ec2.deregister_image(opts)
109
109
  return false unless ret && ret.is_a?(Hash)
110
110
  true
111
111
  end
@@ -116,7 +116,7 @@ module Rudy::AWS
116
116
  opts = {
117
117
  :image_location => path
118
118
  }
119
- ret = @ec2.register_image(opts)
119
+ ret = @@ec2.register_image(opts)
120
120
  return nil unless ret && ret.is_a?(Hash)
121
121
  ret['imageId']
122
122
  end
@@ -46,7 +46,7 @@ module Rudy::AWS
46
46
  lines.join($/)
47
47
  end
48
48
 
49
- def inspect
49
+ def pretty
50
50
  lines = []
51
51
  lines << liner_note
52
52
  field_names.each do |key|
@@ -67,9 +67,9 @@ module Rudy::AWS
67
67
 
68
68
 
69
69
  module EC2
70
- class Instances
71
- include Rudy::AWS::ObjectBase
72
- include Rudy::AWS::EC2::Base
70
+ module Instances
71
+ include Rudy::AWS::EC2 # important! include,
72
+ extend self # then extend
73
73
 
74
74
  unless defined?(KNOWN_STATES)
75
75
  KNOWN_STATES = [:running, :pending, :shutting_down, :terminated, :degraded].freeze
@@ -81,6 +81,7 @@ module Rudy::AWS
81
81
  #
82
82
  # +opts+ supports the following parameters:
83
83
  #
84
+ # * +:zone+
84
85
  # * +:ami+
85
86
  # * +:group+
86
87
  # * +:size+
@@ -112,13 +113,11 @@ module Rudy::AWS
112
113
  :instance_type => opts[:size].to_s,
113
114
  :kernel_id => nil
114
115
  }
115
- #p opts[:machine_data]
116
- #exit
117
116
 
118
- response = execute_request({}) { @ec2.run_instances(old_opts) }
117
+ response = Rudy::AWS::EC2.execute_request({}) { @@ec2.run_instances(old_opts) }
119
118
  return nil unless response['instancesSet'].is_a?(Hash)
120
119
  instances = response['instancesSet']['item'].collect do |inst|
121
- self.class.from_hash(inst)
120
+ self.from_hash(inst)
122
121
  end
123
122
  instances.each { |inst|
124
123
  each_inst.call(inst)
@@ -130,8 +129,8 @@ module Rudy::AWS
130
129
  instances = list(:running, inst_ids, &each_inst) || []
131
130
  raise NoRunningInstances if instances.empty?
132
131
  inst_ids = objects_to_instance_ids(inst_ids)
133
- response = execute_request({}) {
134
- @ec2.reboot_instances(:instance_id => inst_ids)
132
+ response = Rudy::AWS::EC2.execute_request({}) {
133
+ @@ec2.reboot_instances(:instance_id => inst_ids)
135
134
  }
136
135
  response['return'] == 'true'
137
136
  end
@@ -142,8 +141,8 @@ module Rudy::AWS
142
141
 
143
142
  inst_ids = objects_to_instance_ids(inst_ids)
144
143
 
145
- response = execute_request({}) {
146
- @ec2.terminate_instances(:instance_id => inst_ids)
144
+ response = Rudy::AWS::EC2.execute_request({}) {
145
+ @@ec2.terminate_instances(:instance_id => inst_ids)
147
146
  }
148
147
 
149
148
  #instancesSet:
@@ -228,8 +227,8 @@ module Rudy::AWS
228
227
  # This method always returns an Array.
229
228
  inst_ids = objects_to_instance_ids(inst_ids)
230
229
 
231
- response = execute_request({}) {
232
- @ec2.describe_instances(:instance_id => inst_ids)
230
+ response = Rudy::AWS::EC2.execute_request({}) {
231
+ @@ec2.describe_instances(:instance_id => inst_ids)
233
232
  }
234
233
 
235
234
  # requestId: c16878ac-28e4-4859-9878-ef93af45789c
@@ -280,8 +279,8 @@ module Rudy::AWS
280
279
  #
281
280
  def console(inst_id, &each_inst)
282
281
  inst_ids = objects_to_instance_ids([inst_id])
283
- response = execute_request({}) {
284
- @ec2.get_console_output(:instance_id => inst_ids.first)
282
+ response = Rudy::AWS::EC2.execute_request({}) {
283
+ @@ec2.get_console_output(:instance_id => inst_ids.first)
285
284
  }
286
285
  response['output']
287
286
  end
@@ -2,7 +2,7 @@
2
2
  module Rudy::AWS
3
3
  module EC2
4
4
 
5
- class KeyPair < Storable
5
+ class Keypair < Storable
6
6
 
7
7
  field :name
8
8
  field :fingerprint
@@ -25,20 +25,20 @@ module Rudy::AWS
25
25
 
26
26
  end
27
27
 
28
- class KeyPairs
29
- include Rudy::AWS::ObjectBase
30
- include Rudy::AWS::EC2::Base
28
+ module EC2::Keypairs
29
+ include Rudy::AWS::EC2 # important! include,
30
+ extend self # then extend
31
31
 
32
32
  def create(name)
33
33
  raise "No name provided" unless name
34
- ret = @ec2.create_keypair(:key_name => name)
35
- self.class.from_hash(ret)
34
+ ret = @@ec2.create_keypair(:key_name => name)
35
+ from_hash(ret)
36
36
  end
37
37
 
38
38
  def destroy(name)
39
- name = name.name if name.is_a?(Rudy::AWS::EC2::KeyPair)
39
+ name = name.name if name.is_a?(Rudy::AWS::EC2::Keypair)
40
40
  raise "No name provided" unless name.is_a?(String)
41
- ret = @ec2.delete_keypair(:key_name => name)
41
+ ret = @@ec2.delete_keypair(:key_name => name)
42
42
  (ret && ret['return'] == 'true') # BUG? Always returns true
43
43
  end
44
44
 
@@ -50,23 +50,24 @@ module Rudy::AWS
50
50
 
51
51
  def list_as_hash(*names)
52
52
  names = names.flatten
53
- klist = @ec2.describe_keypairs(:key_name => names)
53
+ klist = @@ec2.describe_keypairs(:key_name => names)
54
54
  return unless klist['keySet'].is_a?(Hash)
55
55
  keypairs = {}
56
56
  klist['keySet']['item'].each do |oldkp|
57
- kp = self.class.from_hash(oldkp)
57
+ kp = from_hash(oldkp)
58
58
  keypairs[kp.name] = kp
59
59
  end
60
+ keypairs = nil if keypairs.empty?
60
61
  keypairs
61
62
  end
62
63
 
63
- def self.from_hash(h)
64
+ def from_hash(h)
64
65
  # keyName: test-c5g4v3pe
65
66
  # keyFingerprint: 65:d0:ce:e7:6a:b0:88:4a:9c:c7:2d:b8:33:0c:fd:3b:c8:0f:0a:3c
66
67
  # keyMaterial: |-
67
68
  # -----BEGIN RSA PRIVATE KEY-----
68
69
  #
69
- keypair = Rudy::AWS::EC2::KeyPair.new
70
+ keypair = Rudy::AWS::EC2::Keypair.new
70
71
  keypair.fingerprint = h['keyFingerprint']
71
72
  keypair.name = h['keyName']
72
73
  keypair.private_key = h['keyMaterial']
@@ -91,13 +92,7 @@ module Rudy::AWS
91
92
  end
92
93
 
93
94
  end
94
-
95
- class Keypairs #:nodoc:
96
- def initialize(*args)
97
- raise "Oops! The correct class uses a capital 'P': Rudy::AWS::EC2::KeyPairs"
98
- end
99
- end
100
-
95
+
101
96
  end
102
97
  end
103
98
 
@@ -21,7 +21,7 @@ module Rudy::AWS
21
21
  @@sformat % [liner_note, @volid, @status]
22
22
  end
23
23
 
24
- def inspect
24
+ def pretty
25
25
  lines = []
26
26
  lines << liner_note
27
27
  field_names.each do |key|
@@ -38,9 +38,10 @@ module Rudy::AWS
38
38
 
39
39
  end
40
40
 
41
- class Snapshots
42
- include Rudy::AWS::ObjectBase
43
- include Rudy::AWS::EC2::Base
41
+ module Snapshots
42
+ include Rudy::AWS::EC2 # important! include,
43
+ extend self # then extend
44
+
44
45
 
45
46
  def list(snap_id=[])
46
47
  snapshots = list_as_hash(snap_id)
@@ -51,25 +52,26 @@ module Rudy::AWS
51
52
  end
52
53
  def list_as_hash(snap_id=[])
53
54
  snap_id = [snap_id].flatten.compact
54
- slist = @ec2.describe_snapshots(:snapshot_id => snap_id)
55
+ slist = @@ec2.describe_snapshots(:snapshot_id => snap_id)
55
56
  return unless slist['snapshotSet'].is_a?(Hash)
56
57
  snapshots = {}
57
58
  slist['snapshotSet']['item'].each do |snap|
58
- kp = self.class.from_hash(snap)
59
+ kp = self.from_hash(snap)
59
60
  snapshots[kp.awsid] = kp
60
61
  end
62
+ snapshots = nil if snapshots.empty?
61
63
  snapshots
62
64
  end
63
65
 
64
66
  def create(vol_id)
65
67
  vol_id = (vol_id.is_a?(Rudy::AWS::EC2::Volume)) ? vol_id.awsid : vol_id
66
- shash = @ec2.create_snapshot(:volume_id => vol_id)
68
+ shash = @@ec2.create_snapshot(:volume_id => vol_id)
67
69
  snap = Snapshots.from_hash(shash)
68
70
  snap
69
71
  end
70
72
 
71
73
  def destroy(snap_id)
72
- ret = @ec2.delete_snapshot(:snapshot_id => snap_id)
74
+ ret = @@ec2.delete_snapshot(:snapshot_id => snap_id)
73
75
  (ret && ret['return'] == 'true')
74
76
  end
75
77
 
@@ -99,10 +101,15 @@ module Rudy::AWS
99
101
  list(snap_id).first || nil
100
102
  end
101
103
 
102
- def exists?(id)
104
+ def exists?(snap_id)
103
105
  !get(snap_id).nil?
104
106
  end
105
107
 
108
+ def completed?(snap_id)
109
+ s = get(snap_id)
110
+ return false if s.nil?
111
+ s.completed?
112
+ end
106
113
  end
107
114
 
108
115
  end
@@ -7,14 +7,19 @@ module Rudy::AWS
7
7
 
8
8
  field :awsid
9
9
  field :status
10
- field :size
10
+ field :size => Integer
11
11
  field :snapid
12
- field :zone
13
- field :create_time
14
- field :attach_time
12
+ field :zone => Symbol
13
+ field :create_time => Time
14
+ field :attach_time => Time
15
15
  field :instid
16
16
  field :device
17
17
 
18
+ def postprocess
19
+ @zone &&= @zone.to_sym
20
+ @size &&= @size.to_i
21
+ end
22
+
18
23
  def liner_note
19
24
  info = attached? ? "attached to #{@instid}" : @status
20
25
  "%s (%s)" % [(self.awsid || '').bright, info]
@@ -26,7 +31,7 @@ module Rudy::AWS
26
31
  line
27
32
  end
28
33
 
29
- def inspect
34
+ def pretty
30
35
  lines = [liner_note]
31
36
  field_names.each do |n|
32
37
  lines << sprintf(" %12s: %s", n, self.send(n)) if self.send(n)
@@ -48,10 +53,11 @@ module Rudy::AWS
48
53
  end
49
54
 
50
55
 
51
- class Volumes
52
- include Rudy::AWS::ObjectBase
53
- include Rudy::AWS::EC2::Base
54
-
56
+ module Volumes
57
+ include Rudy::AWS::EC2 # important! include,
58
+ extend self # then extend
59
+
60
+
55
61
  unless defined?(KNOWN_STATES)
56
62
  KNOWN_STATES = [:available, :creating, :deleting, :attached, :detaching].freeze
57
63
  end
@@ -72,11 +78,11 @@ module Rudy::AWS
72
78
  # "availabilityZone"=>"us-east-1b",
73
79
  # "createTime"=>"2009-03-17T20:10:48.000Z",
74
80
  # "volumeId"=>"vol-48826421"
75
- vol = execute_request({}) { @ec2.create_volume(opts) }
81
+ vol = Rudy::AWS::EC2.execute_request({}) { @@ec2.create_volume(opts) }
76
82
 
77
83
  # TODO: use a waiter?
78
84
  #Rudy.waiter(1, 30) do
79
- # ret = @@ec2.volumes.available?(volume.awsid)
85
+ # ret = @@@ec2.volumes.available?(volume.awsid)
80
86
  #end
81
87
 
82
88
  reqid = vol['requestId']
@@ -86,7 +92,7 @@ module Rudy::AWS
86
92
  def destroy(vol_id)
87
93
  vol_id = Volumes.get_vol_id(vol_id)
88
94
  raise VolumeNotAvailable, vol_id unless available?(vol_id)
89
- ret = execute_request({}) { @ec2.delete_volume(:volume_id => vol_id) }
95
+ ret = Rudy::AWS::EC2.execute_request({}) { @@ec2.delete_volume(:volume_id => vol_id) }
90
96
  (ret['return'] == 'true')
91
97
  end
92
98
 
@@ -103,7 +109,7 @@ module Rudy::AWS
103
109
  :instance_id => inst_id,
104
110
  :device => device.to_s # Solaris devices are numbers
105
111
  }
106
- ret = execute_request(false) { @ec2.attach_volume(opts) }
112
+ ret = Rudy::AWS::EC2.execute_request(false) { @@ec2.attach_volume(opts) }
107
113
  (ret['status'] == 'attaching')
108
114
  end
109
115
 
@@ -111,16 +117,20 @@ module Rudy::AWS
111
117
  vol_id = Volumes.get_vol_id(vol_id)
112
118
  raise NoVolumeID unless vol_id
113
119
  raise VolumeNotAttached, vol_id unless attached?(vol_id)
114
- ret = execute_request({}) { @ec2.detach_volume(:volume_id => vol_id) }
120
+ ret = Rudy::AWS::EC2.execute_request({}) {
121
+ @@ec2.detach_volume(:volume_id => vol_id)
122
+ }
115
123
  (ret['status'] == 'detaching')
116
124
  end
117
125
 
118
126
 
119
- def list(state=nil, vol_id=[])
120
- list_as_hash(state, vol_id).values
127
+ def list(state=nil, vol_id=[], &each_vol)
128
+ volumes = list_as_hash(state, vol_id, &each_vol)
129
+ volumes &&= volumes.values
130
+ volumes
121
131
  end
122
132
 
123
- def list_as_hash(state=nil, vol_id=[])
133
+ def list_as_hash(state=nil, vol_id=[], &each_vol)
124
134
  state &&= state.to_sym
125
135
  state = nil if state == :any
126
136
  # A nil state is fine, but we don't want an unknown one!
@@ -130,7 +140,9 @@ module Rudy::AWS
130
140
  :volume_id => vol_id ? [vol_id].flatten : []
131
141
  }
132
142
 
133
- vlist = execute_request({}) { @ec2.describe_volumes(opts) }
143
+ vlist = Rudy::AWS::EC2.execute_request({}) {
144
+ @@ec2.describe_volumes(opts)
145
+ }
134
146
 
135
147
  volumes = {}
136
148
  return volumes unless vlist['volumeSet'].is_a?(Hash)
@@ -139,16 +151,21 @@ module Rudy::AWS
139
151
  next if state && v.state != state.to_s
140
152
  volumes[v.awsid] = v
141
153
  end
154
+ volumes.values.each { |v| each_vol.call(v) } if each_vol
155
+ volumes = nil if volumes.empty?
142
156
  volumes
143
157
  end
144
158
 
145
159
  def any?(state=nil,vol_id=[])
146
- !list(state, vol_id).nil?
160
+ vols = list(state, vol_id)
161
+ !vols.nil?
147
162
  end
148
163
 
149
164
  def exists?(vol_id)
150
165
  vol_id = Volumes.get_vol_id(vol_id)
151
166
  vol = get(vol_id)
167
+ return false if vol.nil?
168
+ return false if vol.deleting?
152
169
  !vol.nil?
153
170
  end
154
171
 
@@ -203,6 +220,7 @@ module Rudy::AWS
203
220
  vol.attach_time = item['attachTime']
204
221
  vol.instid = item['instanceId']
205
222
  end
223
+ vol.postprocess
206
224
  vol
207
225
  end
208
226
 
@@ -223,8 +241,3 @@ module Rudy::AWS
223
241
  end
224
242
  end
225
243
 
226
-
227
- class Rudy::AWS::EC2::Volumes
228
-
229
-
230
- end