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 (132) hide show
  1. data/CHANGES.txt +110 -18
  2. data/README.rdoc +40 -44
  3. data/Rudyfile +35 -50
  4. data/bin/rudy +88 -57
  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 +59 -91
  9. data/lib/rudy/aws.rb +4 -45
  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 +18 -19
  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 +39 -26
  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 +45 -20
  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 +104 -0
  37. data/lib/rudy/cli/candy.rb +1 -2
  38. data/lib/rudy/cli/config.rb +20 -7
  39. data/lib/rudy/cli/disks.rb +7 -9
  40. data/lib/rudy/cli/execbase.rb +56 -0
  41. data/lib/rudy/cli/machines.rb +242 -45
  42. data/lib/rudy/cli/metadata.rb +24 -10
  43. data/lib/rudy/cli/networks.rb +34 -0
  44. data/lib/rudy/cli/routines.rb +32 -6
  45. data/lib/rudy/cli/status.rb +60 -0
  46. data/lib/rudy/config.rb +55 -32
  47. data/lib/rudy/config/objects.rb +44 -30
  48. data/lib/rudy/disks.rb +25 -0
  49. data/lib/rudy/exceptions.rb +99 -0
  50. data/lib/rudy/global.rb +67 -28
  51. data/lib/rudy/guidelines.rb +3 -2
  52. data/lib/rudy/huxtable.rb +67 -58
  53. data/lib/rudy/machines.rb +41 -263
  54. data/lib/rudy/metadata.rb +212 -38
  55. data/lib/rudy/metadata/backup.rb +123 -78
  56. data/lib/rudy/metadata/disk.rb +153 -170
  57. data/lib/rudy/metadata/machine.rb +179 -0
  58. data/lib/rudy/mixins.rb +2 -1
  59. data/lib/rudy/mixins/hash.rb +3 -1
  60. data/lib/rudy/mixins/symbol.rb +8 -0
  61. data/lib/rudy/routines.rb +127 -344
  62. data/lib/rudy/routines/base.rb +229 -0
  63. data/lib/rudy/routines/handlers/base.rb +48 -0
  64. data/lib/rudy/routines/handlers/depends.rb +49 -0
  65. data/lib/rudy/routines/handlers/disks.rb +249 -0
  66. data/lib/rudy/routines/handlers/group.rb +44 -0
  67. data/lib/rudy/routines/handlers/host.rb +70 -0
  68. data/lib/rudy/routines/handlers/keypair.rb +70 -0
  69. data/lib/rudy/routines/handlers/machines.rb +15 -0
  70. data/lib/rudy/routines/handlers/script.rb +85 -0
  71. data/lib/rudy/routines/handlers/user.rb +45 -0
  72. data/lib/rudy/routines/passthrough.rb +19 -23
  73. data/lib/rudy/routines/reboot.rb +98 -50
  74. data/lib/rudy/routines/shutdown.rb +65 -14
  75. data/lib/rudy/routines/startup.rb +112 -17
  76. data/lib/rudy/utils.rb +35 -68
  77. data/rudy.gemspec +82 -25
  78. data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
  79. data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
  80. data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
  81. data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
  82. data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
  83. data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
  84. data/tryouts/12_config/40_machines_tryouts.rb +53 -0
  85. data/tryouts/12_config/50_commands_tryouts.rb +17 -0
  86. data/tryouts/12_config/60_routines_tryouts.rb +16 -0
  87. data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
  88. data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
  89. data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
  90. data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
  91. data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
  92. data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
  93. data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
  94. data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
  95. data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
  96. data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
  97. data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
  98. data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
  99. data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
  100. data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
  101. data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
  102. data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
  103. data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
  104. data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
  105. data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
  106. data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
  107. data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
  108. data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
  109. data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
  110. data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
  111. data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
  112. data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
  113. data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
  114. data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
  115. data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
  116. data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
  117. data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
  118. data/tryouts/exploration/console.rb +91 -0
  119. data/tryouts/exploration/machine.rb +23 -0
  120. data/tryouts/failer +6 -0
  121. metadata +116 -32
  122. data/bin/ird +0 -153
  123. data/lib/rudy/metadata/backups.rb +0 -67
  124. data/lib/rudy/metadata/debug.rb +0 -38
  125. data/lib/rudy/metadata/disks.rb +0 -67
  126. data/lib/rudy/metadata/objectbase.rb +0 -108
  127. data/lib/rudy/routines/helper.rb +0 -76
  128. data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
  129. data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
  130. data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
  131. data/lib/rudy/routines/helpers/userhelper.rb +0 -37
  132. data/support/rudy-ec2-startup +0 -200
data/lib/rudy/aws.rb CHANGED
@@ -1,17 +1,17 @@
1
1
 
2
2
 
3
- require 'EC2' # Motley
4
- require 'aws/s3' # crew
3
+ require 'EC2' # amazon-ec2 gem
4
+
5
5
 
6
6
  module Rudy
7
7
  module AWS
8
8
  extend self
9
9
 
10
10
  unless defined?(Rudy::AWS::VALID_REGIONS)
11
- VALID_REGIONS = ['eu-west-1', 'us-east-1'].freeze
11
+ VALID_REGIONS = [:'eu-west-1', :'us-east-1'].freeze
12
12
  end
13
13
 
14
- def valid_region?(r); VALID_REGIONS.member?(r.to_s || ''); end
14
+ def valid_region?(r); VALID_REGIONS.member?(r.to_sym || ''); end
15
15
 
16
16
  # Modifies +str+ by removing <tt>[\0\n\r\032\\\\]</tt> and escaping <tt>[\'\"]</tt>
17
17
  def escape(str)
@@ -20,48 +20,7 @@ module Rudy
20
20
  def escape!(str)
21
21
  str.to_s.tr!("[\0\n\r\032\\\\]", '').gsub!(/([\'\"])/, '\\1\\1')
22
22
  end
23
-
24
- module ObjectBase
25
- include Rudy::Huxtable
26
-
27
- protected
28
-
29
- # Execute AWS requests safely. This will trap errors and return
30
- # a default value (if specified).
31
- # * +default+ A default response value
32
- # * +request+ A block which contains the AWS request
33
- # Returns the return value from the request is returned untouched
34
- # or the default value on error or if the request returned nil.
35
- def execute_request(default=nil, timeout=nil, &request)
36
- timeout ||= 30
37
- raise "No block provided" unless request
38
- response = nil
39
- begin
40
- Timeout::timeout(timeout) do
41
- response = request.call
42
- end
43
- # Raise the EC2 exceptions
44
- rescue ::EC2::Error, ::EC2::InvalidInstanceIDMalformed => ex
45
- raise Rudy::AWS::Error, ex.message
46
23
 
47
- # NOTE: The InternalError is returned for non-existent volume IDs.
48
- # It's probably a bug so we're ignoring it -- Dave.
49
- rescue ::EC2::InternalError => ex
50
- raise Rudy::AWS::Error, ex.message
51
-
52
- rescue Timeout::Error => ex
53
- STDERR.puts "Timeout (#{timeout}): #{ex.message}!"
54
- rescue SocketError => ex
55
- #STDERR.puts ex.message
56
- #STDERR.puts ex.backtrace
57
- raise SocketError, "Check your Internets!" unless @@global.offline
58
- ensure
59
- response ||= default
60
- end
61
- response
62
- end
63
- end
64
-
65
24
  require 'rudy/aws/sdb'
66
25
  require 'rudy/aws/ec2'
67
26
  require 'rudy/aws/s3'
data/lib/rudy/aws/ec2.rb CHANGED
@@ -1,23 +1,59 @@
1
1
 
2
2
  module Rudy; module AWS
3
3
  module EC2
4
- module Base
5
- attr_accessor :ec2
6
- def initialize(access_key=nil, secret_key=nil, region=nil, logger=nil)
7
-
8
- if region
9
- raise InvalidRegion, region unless Rudy::AWS.valid_region?(region)
10
- host = "#{region}.ec2.amazonaws.com"
11
- elsif ENV['EC2_URL']
12
- host = URL.parse(ENV['EC2_URL']).host
4
+ # include Rudy::Huxtable
5
+
6
+ def self.connect(access_key=nil, secret_key=nil, region=nil, logger=nil)
7
+
8
+ if region
9
+ raise InvalidRegion, region unless Rudy::AWS.valid_region?(region)
10
+ host = "#{region}.ec2.amazonaws.com"
11
+ elsif ENV['EC2_URL']
12
+ host = URL.parse(ENV['EC2_URL']).host
13
+ end
14
+
15
+ host ||= DEFAULT_EC2_HOST
16
+ port ||= DEFAULT_EC2_PORT
17
+
18
+ @@ec2 = ::EC2::Base.new(:port => port, :server=> host, :access_key_id => access_key, :secret_access_key => secret_key)
19
+ @@logger = logger
20
+ end
21
+
22
+ protected
23
+
24
+ # Execute AWS requests safely. This will trap errors and return
25
+ # a default value (if specified).
26
+ # * +default+ A default response value
27
+ # * +request+ A block which contains the AWS request
28
+ # Returns the return value from the request is returned untouched
29
+ # or the default value on error or if the request returned nil.
30
+ def self.execute_request(default=nil, timeout=nil, &request)
31
+ timeout ||= 15
32
+ raise "No block provided" unless request
33
+ response = nil
34
+ begin
35
+ Timeout::timeout(timeout) do
36
+ response = request.call
13
37
  end
38
+ # Raise the EC2 exceptions
39
+ rescue ::EC2::Error, ::EC2::InvalidInstanceIDMalformed => ex
40
+ raise Rudy::AWS::Error, ex.message
41
+
42
+ # NOTE: The InternalError is returned for non-existent volume IDs.
43
+ # It's probably a bug so we're ignoring it -- Dave.
44
+ rescue ::EC2::InternalError => ex
45
+ raise Rudy::AWS::Error, ex.message
14
46
 
15
- host ||= DEFAULT_EC2_HOST
16
- port ||= DEFAULT_EC2_PORT
17
-
18
- @ec2 = ::EC2::Base.new(:port => port, :server=> host, :access_key_id => access_key, :secret_access_key => secret_key)
19
- @logger = logger
47
+ rescue Timeout::Error => ex
48
+ STDERR.puts "Timeout (#{timeout}): #{ex.message}!"
49
+ rescue SocketError => ex
50
+ #STDERR.puts ex.message
51
+ #STDERR.puts ex.backtrace
52
+ raise SocketError, "Check your Internets!" unless @@global.offline
53
+ ensure
54
+ response ||= default
20
55
  end
56
+ response
21
57
  end
22
58
 
23
59
  class NoRunningInstances < Rudy::Error; end
@@ -25,7 +61,7 @@ module Rudy; module AWS
25
61
  class InvalidRegion < Rudy::Error; end
26
62
  class UnknownState < Rudy::Error; end
27
63
  class NoGroup < Rudy::Error; end
28
- class NoKeyPair < Rudy::Error; end
64
+ class NoKeypair < Rudy::Error; end
29
65
  class NoAMI < Rudy::Error; end
30
66
 
31
67
  class NoAddress < Rudy::Error; end
@@ -34,13 +70,13 @@ module Rudy; module AWS
34
70
  class AddressAssociated < Rudy::Error; end
35
71
  class ErrorCreatingAddress < Rudy::Error; end
36
72
  class AddressNotAssociated < Rudy::Error; end
37
- class InsecureKeyPairPermissions < Rudy::Error; end
73
+ class InsecureKeypairPermissions < Rudy::Error; end
38
74
 
39
- class InsecureKeyPairPermissions < Rudy::Error; end
40
- class ErrorCreatingKeyPair < Rudy::Error; end
75
+ class InsecureKeypairPermissions < Rudy::Error; end
76
+ class ErrorCreatingKeypair < Rudy::Error; end
41
77
  class NoPrivateKeyFile < Rudy::Error; end
42
- class KeyPairExists < Rudy::Error; end
43
- class KeyPairAlreadyDefined < Rudy::Error
78
+ class KeypairExists < Rudy::Error; end
79
+ class KeypairAlreadyDefined < Rudy::Error
44
80
  def message
45
81
  "A keypair is defined for #{@obj}. Check your Rudy config."
46
82
  end
@@ -49,6 +85,7 @@ module Rudy; module AWS
49
85
  class VolumeAlreadyAttached < Rudy::Error; end
50
86
  class VolumeNotAvailable < Rudy::Error; end
51
87
  class VolumeNotAttached < Rudy::Error; end
88
+ class UnknownVolume < Rudy::Error; end
52
89
  class NoInstanceID < Rudy::Error; end
53
90
  class NoVolumeID < Rudy::Error; end
54
91
  class UnknownState < Rudy::Error; end
@@ -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
@@ -7,7 +7,7 @@ module Rudy::AWS
7
7
  field :aki
8
8
  field :ari
9
9
  field :launch_index => Time
10
- field :launch_time
10
+ field :created
11
11
  field :keyname
12
12
  field :size
13
13
  field :ami
@@ -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
@@ -264,7 +263,7 @@ module Rudy::AWS
264
263
  instances = nil if instances.empty? # Don't return an empty hash
265
264
  instances
266
265
  end
267
-
266
+
268
267
  # System console output.
269
268
  #
270
269
  # * +inst_id+ instance ID (String) or Instance object.
@@ -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
@@ -375,7 +374,7 @@ module Rudy::AWS
375
374
  inst = Rudy::AWS::EC2::Instance.new
376
375
  inst.aki = h['kernelId']
377
376
  inst.ami = h['imageId']
378
- inst.launch_time = h['launchTime']
377
+ inst.created = h['launchTime']
379
378
  inst.keyname = h['keyName']
380
379
  inst.launch_index = h['amiLaunchIndex']
381
380
  inst.size = h['instanceType']