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
@@ -20,7 +20,6 @@ require 'rudy/cli'
20
20
  module RudyCLI_EC2
21
21
  extend Drydock
22
22
 
23
- debug :off
24
23
  default :instances
25
24
 
26
25
  # ----------------------------------- AMAZON EC2 COMMANDS --------
@@ -105,11 +104,6 @@ module RudyCLI_EC2
105
104
  option :o, :owner, String, "Amazon Account Number or one of: amazon, self"
106
105
  option :l, :all, "Display all registered machine images (warning: slow)"
107
106
  #option :p, :private, "Private images only"
108
- option :b, :bucket, String, "The name of the bucket that will store the image"
109
- option :n, :name, String, "The name of the image file (to create)"
110
- option :u, :user, String, "Username to connect as (used for creating an image)"
111
- action :C, :create, "Create an image"
112
- #action :P, :prepare, "Prepare a running instance to be used as an image"
113
107
  action :R, :register, "Register an image"
114
108
  action :D, :destroy, "Deregister an image (does not remove image files from S3)"
115
109
  argv :ami
@@ -142,14 +136,14 @@ module RudyCLI_EC2
142
136
  command_alias :instances, :in
143
137
  command_alias :instances, :i
144
138
 
145
- about "Amazon EC2 KeyPairs"
139
+ about "Amazon EC2 EC2::Keypairs"
146
140
  usage "rudy-ec2 keypairs"
147
141
  usage "rudy-ec2 keypairs -C name"
148
142
  usage "rudy-ec2 keypairs -D name"
149
143
  action :D, :destroy, "Unregister keypair from EC2 (this is permanent!)"
150
144
  action :C, :create, "Create and register a keypair with EC2"
151
145
  argv :name
152
- command :keypairs => Rudy::CLI::AWS::EC2::KeyPairs
146
+ command :keypairs => Rudy::CLI::AWS::EC2::Keypairs
153
147
  command_alias :keypairs, :keypair
154
148
  command_alias :keypairs, :k
155
149
 
@@ -211,12 +205,6 @@ module RudyCLI_EC2
211
205
 
212
206
  end
213
207
 
214
- #puts Rudy::Utils.banner("THIS IS RUBY #{RUBY_VERSION}") if Drydock.debug?
215
-
216
- # We call Drydock specifically otherwise it will run at_exit. Rye also
217
- # uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
218
- # blocks in reverse order so if Drydock is required first, it's block
219
- # will run after Rye shuts down the ssh-agent.
220
208
  begin
221
209
  Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
222
210
  rescue Drydock::ArgError, Drydock::OptError => ex
@@ -233,8 +221,6 @@ rescue => ex
233
221
  rescue Interrupt
234
222
  puts "#{$/}Exiting... "
235
223
  exit 1
236
- rescue SystemExit
237
- # Don't balk
238
224
  end
239
225
 
240
226
 
@@ -44,18 +44,10 @@ module RudyCLI_S3
44
44
  # ------------------------------------------------------------------
45
45
 
46
46
  default :buckets
47
- debug :off
48
-
49
47
 
50
48
  end
51
49
 
52
50
 
53
- #puts Rudy::Utils.banner("THIS IS RUBY #{RUBY_VERSION}") if Drydock.debug?
54
-
55
- # We call Drydock specifically otherwise it will run at_exit. Rye also
56
- # uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
57
- # blocks in reverse order so if Drydock is required first, it's block
58
- # will run after Rye shuts down the ssh-agent.
59
51
  begin
60
52
  Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
61
53
  rescue Drydock::ArgError, Drydock::OptError => ex
@@ -72,7 +64,5 @@ rescue => ex
72
64
  rescue Interrupt
73
65
  puts "#{$/}Exiting... "
74
66
  exit 1
75
- rescue SystemExit
76
- # Don't balk
77
67
  end
78
68
 
@@ -28,24 +28,25 @@ module RudyCLI_SDB
28
28
  action :D, :destroy, "Destroy a domain"
29
29
  argv :name
30
30
  command :domains => Rudy::CLI::AWS::SDB::Domains
31
+ command_alias :domains, :domain
32
+
33
+ about "Displays objects contained in a SimpleDB domain"
34
+ argv :name, :key
35
+ command :objects => Rudy::CLI::AWS::SDB::Objects
36
+ command_alias :objects, :object
37
+
38
+ about "Execute a SimpleDB select query"
39
+ argv :query
40
+ command :query => Rudy::CLI::AWS::SDB::Select
31
41
 
32
42
 
33
43
  # -------------------------------- RUDY-SDB MISCELLANEOUS --------
34
44
  # ------------------------------------------------------------------
35
45
 
36
46
  default :domains
37
- debug :off
38
-
39
-
40
- end
41
-
42
47
 
43
- #puts Rudy::Utils.banner("THIS IS RUBY #{RUBY_VERSION}") if Drydock.debug?
48
+ end
44
49
 
45
- # We call Drydock specifically otherwise it will run at_exit. Rye also
46
- # uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
47
- # blocks in reverse order so if Drydock is required first, it's block
48
- # will run after Rye shuts down the ssh-agent.
49
50
  begin
50
51
  Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
51
52
  rescue Drydock::ArgError, Drydock::OptError => ex
@@ -62,7 +63,5 @@ rescue => ex
62
63
  rescue Interrupt
63
64
  puts "#{$/}Exiting... "
64
65
  exit 1
65
- rescue SystemExit
66
- # Don't balk
67
66
  end
68
67
 
@@ -4,32 +4,35 @@ unless defined?(RUDY_HOME)
4
4
  RUDY_LIB = File.join(File.dirname(__FILE__), '..', 'lib')
5
5
  end
6
6
 
7
- local_libs = %w{net-ssh net-scp amazon-ec2 aws-s3 caesars drydock rye storable sysinfo annoy}
8
- #local_libs.each { |dir| $:.unshift File.join(RUDY_HOME, '..', dir, 'lib') }
7
+ local_libs = %w{net-ssh net-scp amazon-ec2 aws-s3 caesars drydock rye storable sysinfo annoy gibbler}
8
+ local_libs.each { |dir| $:.unshift File.join(RUDY_HOME, '..', dir, 'lib') }
9
9
  #require 'rubygems'
10
10
 
11
+ begin; require 'json'; rescue LoadError; end # Silence!
12
+
11
13
  require 'digest/md5'
12
14
  require 'stringio'
13
15
  require 'ostruct'
14
16
  require 'yaml'
15
- require 'json'
16
17
  require 'logger'
17
18
  require 'socket'
18
19
  require 'timeout'
20
+ require 'gibbler'
19
21
  require 'tempfile'
20
22
  require 'rudy/mixins'
23
+ require 'gibbler/aliases'
21
24
  require 'storable'
22
25
  require 'sysinfo'
26
+ require 'attic'
23
27
  require 'annoy'
24
28
  require 'rye'
25
29
 
26
30
 
27
-
28
31
  # = Rudy
29
32
  #
30
33
  #
31
34
  # Rudy is a development and deployment tool for the Amazon Elastic Compute Cloud
32
- # (EC2). <a href="http://solutious.com/products/rudy/getting-started.html">Getting Started</a> today!
35
+ # (EC2). <a href="http://solutious.com/projects/rudy/getting-started">Getting Started</a> today!
33
36
  #
34
37
  #
35
38
  module Rudy
@@ -38,8 +41,8 @@ module Rudy
38
41
  module VERSION #:nodoc:
39
42
  unless defined?(MAJOR)
40
43
  MAJOR = 0.freeze
41
- MINOR = 8.freeze
42
- TINY = 5.freeze
44
+ MINOR = 9.freeze
45
+ TINY = 0.freeze
43
46
  end
44
47
  def self.to_s; [MAJOR, MINOR, TINY].join('.'); end
45
48
  def self.to_f; self.to_s.to_f; end
@@ -59,109 +62,66 @@ module Rudy
59
62
 
60
63
  CONFIG_DIR = File.join(@@sysinfo.home, '.rudy').freeze
61
64
  CONFIG_FILE = File.join(Rudy::CONFIG_DIR, 'config').freeze
65
+ SSH_KEY_DIR = File.expand_path('~/.ssh').freeze
62
66
 
63
- DEFAULT_REGION = :'us-east-1'.freeze
64
67
  DEFAULT_ZONE = :'us-east-1b'.freeze
65
- DEFAULT_ENVIRONMENT = :'stage'.freeze
66
- DEFAULT_ROLE = :'app'.freeze
67
- DEFAULT_POSITION = '01'.freeze
68
-
69
- DEFAULT_USER = :'rudy'.freeze
70
-
68
+ DEFAULT_REGION = DEFAULT_ZONE.to_s.gsub(/[a-z]$/, '').to_sym.freeze
69
+ DEFAULT_ENVIRONMENT = :stage.freeze
70
+ DEFAULT_ROLE = :app.freeze
71
+
71
72
  DEFAULT_EC2_HOST = "ec2.amazonaws.com"
72
73
  DEFAULT_EC2_PORT = 443
73
74
 
74
75
  MAX_INSTANCES = 5.freeze
75
76
 
76
- SUPPORTED_SCM_NAMES = [:svn, :git].freeze
77
-
78
77
  ID_MAP = {
79
- :disk => 'disk',
80
- :instance => 'i',
81
- :backup => 'back',
82
- :machine => 'm',
83
- :volume => 'vol',
84
- :snapshot => 'snap',
85
- :kernel => 'aki',
86
- :image => 'ami',
87
- :ram => 'ari',
88
- :log => 'log',
89
- :key => 'key',
90
- :awspk => 'pk',
91
- :awscert => 'cert',
78
+ :instance => 'i',
79
+ :machine => 'm',
92
80
  :reservation => 'r',
93
- :dns_public => 'ec2',
94
- :dns_private => 'domU',
81
+ :pkey => 'pk',
82
+ :volume => 'vol',
83
+ :kernel => 'aki',
84
+ :image => 'ami',
85
+ :ramdisk => 'ari',
86
+ :group => 'grp',
87
+ :log => 'log',
88
+ :key => 'key',
89
+ :dns_public => 'ec2',
90
+ :disk => 'disk',
91
+ :backup => 'back',
92
+ :snapshot => 'snap',
93
+ :cert => 'cert',
94
+ :dns_private => 'domU'
95
95
  }.freeze
96
96
 
97
97
  end
98
98
 
99
- def Rudy.debug?; @@debug == true; end
100
99
  def Rudy.quiet?; @@quiet == true; end
101
- def Rudy.yes?; @@yes == true; end
102
- def Rudy.enable_debug; @@debug = true; end
103
100
  def Rudy.enable_quiet; @@quiet = true; end
104
- def Rudy.enable_yes; @@yes = true; end
105
- def Rudy.disable_debug; @@debug = false; end
106
101
  def Rudy.disable_quiet; @@quiet = false; end
102
+
103
+ def Rudy.yes?; @@yes == true; end
104
+ def Rudy.enable_yes; @@yes = true; end
107
105
  def Rudy.disable_yes; @@yes = false; end
108
106
 
107
+ def Rudy.debug?; @@debug == true; end
108
+ def Rudy.enable_debug; @@debug = true; end
109
+ def Rudy.disable_debug; @@debug = false; end
110
+
111
+
109
112
  def Rudy.sysinfo; @@sysinfo; end
110
113
  def sysinfo; @@sysinfo; end
111
114
 
112
- class Error < RuntimeError
113
- def initialize(obj=nil); @obj = obj; end
114
- def message; "#{self.class}: #{@obj}"; end
115
- end
116
- class InsecureKeyPermissions < Rudy::Error
117
- def message
118
- lines = ["Insecure file permissions for #{@obj}"]
119
- lines << "Try: chmod 600 #{@obj}"
120
- lines.join($/)
121
- end
122
- end
123
-
124
- #--
125
- # TODO: Update exception Syntax based on:
126
- # http://blog.rubybestpractices.com/posts/gregory/anonymous_class_hacks.html
127
- #++
128
- class NoConfig < Rudy::Error
129
- def message; "No configuration found!"; end
130
- end
131
- class NoGlobal < Rudy::Error
132
- def message; "No globals defined!"; end
133
- end
134
- class NoMachinesConfig < Rudy::Error
135
- def message; "No machines configuration. Check your configs!"; end
136
- end
137
- class NoRoutinesConfig < Rudy::Error
138
- def message; "No routines configuration. Check your configs!"; end
139
- end
140
- class ServiceUnavailable < Rudy::Error
141
- def message; "#{@obj} is not available. Check your internets!"; end
142
- end
143
- class MachineGroupAlreadyRunning < Rudy::Error
144
- def message; "Machine group #{@obj} is already running."; end
145
- end
146
- class MachineGroupNotRunning < Rudy::Error
147
- def message; "Machine group #{@obj} is not running."; end
148
- end
149
- class MachineGroupNotDefined < Rudy::Error
150
- def message; "#{@obj} is not defined in machines config."; end
151
- end
152
- class PrivateKeyFileExists < Rudy::Error
153
- def message; "Private key #{@obj} already exists."; end
154
- end
155
- class PrivateKeyNotFound < Rudy::Error
156
- def message; "Private key file #{@obj} not found."; end
157
- end
158
115
  end
159
116
 
160
- require 'rudy/utils' # The
161
- require 'rudy/global' # order
162
- require 'rudy/config' # of
163
- require 'rudy/huxtable' # requires
164
- require 'rudy/aws' # is
165
- require 'rudy/metadata' # important
166
- require 'rudy/machines'
117
+ require 'rudy/exceptions'
118
+ require 'rudy/utils' # The
119
+ require 'rudy/global' # order
120
+ require 'rudy/config' # of
121
+ require 'rudy/huxtable' # requires
122
+ require 'rudy/aws' # is
123
+ require 'rudy/metadata' # super
124
+ require 'rudy/machines' # important.
125
+ require 'rudy/backups'
126
+ require 'rudy/disks'
167
127
  require 'rudy/routines'
@@ -1,7 +1,7 @@
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
@@ -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'
@@ -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