solutious-rudy 0.9.3 → 0.9.4

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 (46) hide show
  1. data/CHANGES.txt +8 -1
  2. data/bin/rudy +4 -0
  3. data/bin/rudy-ec2 +1 -0
  4. data/lib/rudy.rb +1 -1
  5. data/lib/rudy/aws/ec2.rb +4 -5
  6. data/lib/rudy/aws/ec2/group.rb +0 -2
  7. data/lib/rudy/aws/sdb.rb +3 -3
  8. data/lib/rudy/cli/aws/ec2/addresses.rb +5 -5
  9. data/lib/rudy/cli/aws/ec2/candy.rb +16 -16
  10. data/lib/rudy/cli/aws/ec2/groups.rb +6 -6
  11. data/lib/rudy/cli/aws/ec2/images.rb +3 -3
  12. data/lib/rudy/cli/aws/ec2/info.rb +18 -18
  13. data/lib/rudy/cli/aws/ec2/instances.rb +15 -15
  14. data/lib/rudy/cli/aws/ec2/keypairs.rb +6 -6
  15. data/lib/rudy/cli/aws/ec2/snapshots.rb +1 -1
  16. data/lib/rudy/cli/aws/ec2/volumes.rb +10 -10
  17. data/lib/rudy/cli/backups.rb +5 -5
  18. data/lib/rudy/cli/base.rb +9 -9
  19. data/lib/rudy/cli/candy.rb +1 -1
  20. data/lib/rudy/cli/config.rb +6 -6
  21. data/lib/rudy/cli/disks.rb +5 -5
  22. data/lib/rudy/cli/images.rb +12 -12
  23. data/lib/rudy/cli/info.rb +9 -9
  24. data/lib/rudy/cli/keypairs.rb +5 -5
  25. data/lib/rudy/cli/machines.rb +26 -26
  26. data/lib/rudy/cli/metadata.rb +2 -2
  27. data/lib/rudy/cli/networks.rb +17 -8
  28. data/lib/rudy/cli/routines.rb +10 -10
  29. data/lib/rudy/config.rb +2 -2
  30. data/lib/rudy/config/objects.rb +1 -1
  31. data/lib/rudy/huxtable.rb +11 -5
  32. data/lib/rudy/machines.rb +4 -1
  33. data/lib/rudy/metadata/machine.rb +18 -9
  34. data/lib/rudy/routines.rb +4 -4
  35. data/lib/rudy/routines/handlers/base.rb +6 -6
  36. data/lib/rudy/routines/handlers/disks.rb +9 -9
  37. data/lib/rudy/routines/handlers/group.rb +1 -1
  38. data/lib/rudy/routines/handlers/rye.rb +7 -5
  39. data/lib/rudy/routines/handlers/script.rb +2 -2
  40. data/lib/rudy/routines/passthrough.rb +11 -4
  41. data/lib/rudy/routines/reboot.rb +16 -5
  42. data/lib/rudy/routines/shutdown.rb +14 -5
  43. data/lib/rudy/routines/startup.rb +5 -6
  44. data/lib/rudy/utils.rb +2 -2
  45. data/rudy.gemspec +1 -1
  46. metadata +2 -3
@@ -23,7 +23,7 @@ module Rudy
23
23
  end
24
24
 
25
25
  objlist.each_pair do |k,o|
26
- puts "#{k}: " << o.inspect
26
+ li "#{k}: " << o.inspect
27
27
  end
28
28
  end
29
29
 
@@ -38,7 +38,7 @@ module Rudy
38
38
  unless @@global.quiet
39
39
  msg = "NOTE: This will delete only the metadata and "
40
40
  msg << "not the EC2 object (volume, instance, etc...)"
41
- puts msg
41
+ li msg
42
42
  end
43
43
 
44
44
  execute_check(:medium)
@@ -7,10 +7,19 @@ module Rudy
7
7
  def networks
8
8
  name = current_group_name
9
9
  Rudy::AWS::EC2::Groups.list(name).each do |group|
10
- puts @@global.verbose > 0 ? group.inspect : group.dump(@@global.format)
10
+ li @@global.verbose > 0 ? group.inspect : group.dump(@@global.format)
11
11
  end
12
12
  end
13
13
 
14
+ def create_networks
15
+ Rudy::Routines::Handlers::Group.create rescue nil
16
+ networks
17
+ end
18
+
19
+ def destroy_networks
20
+ Rudy::Routines::Handlers::Group.destroy rescue nil
21
+ end
22
+
14
23
  def update_networks
15
24
  Rudy::Routines::Handlers::Group.authorize rescue nil
16
25
  networks
@@ -20,11 +29,11 @@ module Rudy
20
29
  ea = Rudy::Utils::external_ip_address || ''
21
30
  ia = Rudy::Utils::internal_ip_address || ''
22
31
  if @global.quiet
23
- puts ia unless @option.external && !@option.internal
24
- puts ea unless @option.internal && !@option.external
32
+ li ia unless @option.external && !@option.internal
33
+ li ea unless @option.internal && !@option.external
25
34
  else
26
- puts "%10s: %s" % ['Internal', ia] unless @option.external && !@option.internal
27
- puts "%10s: %s" % ['External', ea] unless @option.internal && !@option.external
35
+ li "%10s: %s" % ['Internal', ia] unless @option.external && !@option.internal
36
+ li "%10s: %s" % ['External', ea] unless @option.internal && !@option.external
28
37
  end
29
38
  @global.quiet = true # don't print elapsed time
30
39
  end
@@ -60,12 +69,12 @@ module Rudy
60
69
  opts = check_options
61
70
  if (@option.group || @option.owner)
62
71
  g = [opts[:owner], opts[:group]].join(':')
63
- puts "#{action.to_s.capitalize} access to #{group.bright} from #{g.bright}"
72
+ li "#{action.to_s.capitalize} access to #{group.bright} from #{g.bright}"
64
73
  else
65
74
  print "#{action.to_s.capitalize} access to #{group.bright}"
66
- puts " from #{opts[:addresses].join(', ').bright}"
75
+ li " from #{opts[:addresses].join(', ').bright}"
67
76
  print "on #{opts[:protocols].join(', ').bright} "
68
- puts "ports: #{opts[:ports].map { |p| "#{p.join(' to ').bright}" }.join(', ')}"
77
+ li "ports: #{opts[:ports].map { |p| "#{p.join(' to ').bright}" }.join(', ')}"
69
78
  end
70
79
  execute_check(:medium)
71
80
  execute_action {
@@ -24,7 +24,7 @@ module Rudy; module CLI;
24
24
 
25
25
  outform = @@global.format == :json ? :to_json : :to_yaml
26
26
 
27
- puts routine.to_hash.send(outform)
27
+ li routine.to_hash.send(outform)
28
28
  end
29
29
 
30
30
  def startup_valid?
@@ -34,7 +34,7 @@ module Rudy; module CLI;
34
34
  end
35
35
  def startup
36
36
  machines = @rr.execute || []
37
- puts $/, "The following machines are now available:" unless machines.empty?
37
+ li $/, "The following machines are now available:" unless machines.empty?
38
38
  print_stobjects machines, :noverbose
39
39
  end
40
40
 
@@ -45,7 +45,7 @@ module Rudy; module CLI;
45
45
  end
46
46
  def reboot
47
47
  machines = @rr.execute
48
- puts $/, "The following machines have been restarted:"
48
+ li $/, "The following machines have been restarted:"
49
49
  print_stobjects machines, :noverbose
50
50
  end
51
51
 
@@ -71,8 +71,8 @@ module Rudy; module CLI;
71
71
 
72
72
  machines = @rr.execute
73
73
 
74
- if @global.verbose > 1 && !machines.empty?
75
- puts $/, "The following machines were processed:"
74
+ if !@@global.quiet && !machines.empty?
75
+ li $/, "The following machines were processed:"
76
76
  print_stobjects machines, :noverbose
77
77
  end
78
78
 
@@ -86,11 +86,11 @@ module Rudy; module CLI;
86
86
  def shutdown
87
87
  routine = fetch_routine_config(:shutdown) rescue {}
88
88
 
89
- puts "All machines in #{current_machine_group} will be shutdown".bright
89
+ li "All machines in #{current_machine_group} will be shutdown".bright
90
90
  if routine && routine.disks
91
91
  if routine.disks.destroy
92
- puts "The following filesystems will be destroyed:".bright
93
- puts routine.disks.destroy.keys.join($/).bright
92
+ li "The following filesystems will be destroyed:".bright
93
+ li routine.disks.destroy.keys.join($/).bright
94
94
  end
95
95
  end
96
96
 
@@ -98,9 +98,9 @@ module Rudy; module CLI;
98
98
 
99
99
  machines = @rr.execute
100
100
 
101
- puts $/, "The following instances have been destroyed:"
101
+ li $/, "The following instances have been destroyed:"
102
102
  machines.each do |machine|
103
- puts '%s %s ' % [machine.name.bright, machine.instid]
103
+ li '%s %s ' % [machine.name.bright, machine.instid]
104
104
  end
105
105
 
106
106
  end
@@ -106,12 +106,12 @@ module Rudy
106
106
  def self.init_config_dir
107
107
 
108
108
  unless File.exists?(Rudy::CONFIG_DIR)
109
- puts "Creating #{Rudy::CONFIG_DIR}"
109
+ li "Creating #{Rudy::CONFIG_DIR}"
110
110
  Dir.mkdir(Rudy::CONFIG_DIR, 0700)
111
111
  end
112
112
 
113
113
  unless File.exists?(Rudy::CONFIG_FILE)
114
- puts "Creating #{Rudy::CONFIG_FILE}"
114
+ li "Creating #{Rudy::CONFIG_FILE}"
115
115
  rudy_config = Rudy::Utils.without_indent %Q`
116
116
  accounts { # Account Access Indentifiers
117
117
  aws { # amazon web services
@@ -112,7 +112,7 @@ class Rudy::Config
112
112
  # We can allow existing commands to be overridden but we
113
113
  # print a message to STDERR so the user knows what's up.
114
114
  if Rye::Cmd.can?(cmd)
115
- STDERR.puts "Redefining #{cmd}" if Rudy::Huxtable.global.verbose > 2
115
+ Rudy::Huxtable.le "Redefining #{cmd}" if Rudy::Huxtable.global.verbose > 2
116
116
  end
117
117
 
118
118
  if args.last.is_a?(Proc)
@@ -38,7 +38,10 @@ module Rudy
38
38
  end
39
39
 
40
40
  def self.update_global(ghash); @@global.update(ghash); end
41
- def self.update_logger(logger); @@logger = logger; end
41
+ def self.update_logger(logger)
42
+ return if logger.nil?
43
+ @@logger = logger
44
+ end
42
45
 
43
46
  def self.reset_config; @@config = Rudy::Config.new; end
44
47
  def self.reset_global; @@global = Rudy::Global.new; end
@@ -59,14 +62,17 @@ module Rudy
59
62
 
60
63
  # Puts +msg+ to +@@logger+
61
64
  def self.li(*msg); msg.each { |m| @@logger.puts m } if !@@global.quiet; end
62
- # Puts +msg+ to +@@logger+ if +Rudy.debug?+ returns true
63
- def self.ld(*msg); msg.each { |m| @@logger.puts "D: #{m}" } if Rudy.debug?; end
64
65
  # Puts +msg+ to +@@logger+ with "ERROR: " prepended
65
- def self.le(*msg); msg.each { |m| @@logger.puts " #{m}" }; end
66
+ def self.le(*msg); @@logger.puts " " << msg.join("#{$/} "); end
67
+ # Puts +msg+ to +@@logger+ if +Rudy.debug?+ returns true
68
+ def self.ld(*msg)
69
+ return unless Rudy.debug?
70
+ @@logger.puts "D: " << msg.join("#{$/}D: ")
71
+ end
66
72
 
67
73
  def li(*msg); Rudy::Huxtable.li *msg; end
68
- def ld(*msg); Rudy::Huxtable.ld *msg; end
69
74
  def le(*msg); Rudy::Huxtable.le *msg; end
75
+ def ld(*msg); Rudy::Huxtable.ld *msg; end
70
76
 
71
77
  def config_dirname
72
78
  raise "No config paths defined" unless @@config.is_a?(Rudy::Config) && @@config.paths.is_a?(Array)
@@ -44,13 +44,16 @@ module Rudy
44
44
  group = Array.new(size) do |i|
45
45
  m = Rudy::Machine.new(i + 1)
46
46
  m.create
47
+ li "Created: #{m.to_s}"
47
48
  m
48
49
  end
49
50
  else
50
51
  m = Rudy::Machine.new(Rudy::Huxtable.global.position)
51
52
  m.create
52
- [m]
53
+ li "Created: #{m.to_s}"
54
+ group = [m]
53
55
  end
56
+ group
54
57
  end
55
58
 
56
59
  def restart
@@ -126,6 +126,16 @@ module Rudy
126
126
  k.decrypt encrtypted_text
127
127
  end
128
128
 
129
+ def create_mock
130
+ refresh!
131
+ @dns_public = @dns_private = nil
132
+ inst = Rudy::AWS::EC2::Instances.list(:running).first
133
+ @instid = inst.awsid
134
+ self.save :replace
135
+ sleep 1
136
+ self
137
+ end
138
+
129
139
  def create
130
140
  raise "#{name} is already running" if instance_running?
131
141
 
@@ -140,11 +150,7 @@ module Rudy
140
150
  :machine_data => self.generate_machine_data.to_yaml
141
151
  }
142
152
 
143
- Rudy::Huxtable.ld "OPTS: #{opts.inspect}"
144
-
145
- #@dns_public = @dns_private = nil
146
- #inst = Rudy::AWS::EC2::Instances.list(:running).first
147
- #@instid = inst.awsid
153
+ ld "OPTS: #{opts.inspect}"
148
154
 
149
155
  Rudy::AWS::EC2::Instances.create(opts) do |inst|
150
156
  @instid = inst.awsid
@@ -157,19 +163,22 @@ module Rudy
157
163
  if @address
158
164
  # Make sure the address is associated to the current account
159
165
  if Rudy::AWS::EC2::Addresses.exists?(@address)
160
- puts "Associating #{@address} to #{@instid}"
166
+ li "Associating #{@address} to #{@instid}"
161
167
  Rudy::AWS::EC2::Addresses.associate(@address, @instid)
162
168
  else
163
- STDERR.puts "Unknown address: #{@address}"
169
+ le "Unknown address: #{@address}"
164
170
  end
165
171
  end
166
172
  rescue => ex
167
- STDERR.puts "Error: #{ex.message}"
168
- STDERR.puts ex.backtrace if Rudy.debug?
173
+ le "Error: #{ex.message}"
174
+ le ex.backtrace if Rudy.debug?
169
175
  end
170
176
  end
171
177
 
172
178
  self.save
179
+
180
+ sleep 1 # Eventual consistency in SimpleDB
181
+
173
182
  self
174
183
  end
175
184
 
@@ -87,7 +87,7 @@ module Rudy
87
87
  def self.runner(routine, rset, lbox, argv=nil)
88
88
  routine.each_pair do |name,definition|
89
89
  handler = Rudy::Routines.get_handler name
90
- Rudy::Huxtable.ld " executing handler: #{name}"
90
+ Rudy::Huxtable.li " #{name}:".bright
91
91
  self.rescue {
92
92
  handler.execute(name, definition, rset, lbox, argv)
93
93
  }
@@ -99,8 +99,8 @@ module Rudy
99
99
  begin
100
100
  ret = bloc_party.call
101
101
  rescue NameError, ArgumentError, RuntimeError, Errno::ECONNREFUSED => ex
102
- STDERR.puts " #{ex.class}: #{ex.message}".color(:red)
103
- STDERR.puts ex.backtrace if Rudy.debug?
102
+ Rudy::Huxtable.le "#{ex.class}: #{ex.message}".color(:red)
103
+ Rudy::Huxtable.le ex.backtrace if Rudy.debug?
104
104
  unless Rudy::Huxtable.global.parallel
105
105
  choice = Annoy.get_user_input('(S)kip (A)bort: ', nil, 3600) || ''
106
106
  if choice.match(/\AS/i)
@@ -110,7 +110,7 @@ module Rudy
110
110
  end
111
111
  end
112
112
  rescue Interrupt
113
- puts "Aborting..."
113
+ li "Aborting..."
114
114
  exit 12
115
115
  end
116
116
  ret
@@ -8,10 +8,10 @@ module Rudy; module Routines; module Handlers;
8
8
  begin
9
9
  ret = command.call if command
10
10
  return unless ret.is_a?(Rye::Rap)
11
- puts ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty?
11
+ li ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty?
12
12
  print_response(ret)
13
13
  rescue IOError => ex
14
- STDERR.puts " Connection Error (#{ex.message})".color(:red)
14
+ le " Connection Error (#{ex.message})".color(:red)
15
15
  choice = Annoy.get_user_input('(S)kip (R)etry (F)orce (A)bort: ', nil, 3600) || ''
16
16
  if choice.match(/\AS/i)
17
17
  return
@@ -38,11 +38,11 @@ module Rudy; module Routines; module Handlers;
38
38
  colour = rap.exit_code != 0 ? :red : :normal
39
39
  [:stderr].each do |sumpin|
40
40
  next if rap.send(sumpin).empty?
41
- STDERR.puts
42
- STDERR.puts((" #{sumpin.to_s.upcase} " << '-'*38).color(colour).bright)
43
- STDERR.puts " " << rap.send(sumpin).join("#{$/} ").color(colour)
41
+ le
42
+ le((" #{sumpin.to_s.upcase} " << '-'*38).color(colour).bright)
43
+ le " " << rap.send(sumpin).join("#{$/} ").color(colour)
44
44
  end
45
- STDERR.puts " Exit code: #{rap.exit_code}".color(colour) if rap.exit_code != 0
45
+ le " Exit code: #{rap.exit_code}".color(colour) if rap.exit_code != 0
46
46
  end
47
47
 
48
48
  end
@@ -82,7 +82,7 @@ module Rudy::Routines::Handlers;
82
82
 
83
83
  def create(rbox, disk, index)
84
84
  if disk.exists?
85
- puts "Disk found: #{disk.name}"
85
+ li "Disk found: #{disk.name}"
86
86
  disk.refresh!
87
87
  end
88
88
 
@@ -179,7 +179,7 @@ module Rudy::Routines::Handlers;
179
179
  raise Rudy::Disks::AlreadyMounted, disk.name if disk.mounted?
180
180
  end
181
181
 
182
- puts "Mounting at #{disk.path}... "
182
+ li "Mounting at #{disk.path}... "
183
183
 
184
184
 
185
185
  rbox.mkdir(:p, disk.path)
@@ -201,7 +201,7 @@ module Rudy::Routines::Handlers;
201
201
  raise Rudy::Disks::NotMounted, disk.name if !disk.mounted?
202
202
  end
203
203
 
204
- puts "Unmounting #{disk.path}... "
204
+ li "Unmounting #{disk.path}... "
205
205
 
206
206
  unless rbox.nil? || rbox.stash.windows?
207
207
  rbox.umount(disk.path)
@@ -232,11 +232,11 @@ module Rudy::Routines::Handlers;
232
232
 
233
233
  print "Creating #{disk.fstype} filesystem for #{disk.path}... "
234
234
  if rbox.stash.windows?
235
- puts "(index: #{index})"
235
+ li "(index: #{index})"
236
236
  windows_diskpart_partition rbox, disk, index
237
237
  disk.mounted = true
238
238
  else
239
- puts $/
239
+ li $/
240
240
  rbox.rudy_mkfs(:t, disk.fstype, :F, disk.device)
241
241
  end
242
242
 
@@ -257,7 +257,7 @@ module Rudy::Routines::Handlers;
257
257
  raise Rudy::Disks::InUse, disk.name if disk.volume_attached?
258
258
  end
259
259
 
260
- puts "Destroying #{disk.name}"
260
+ li "Destroying #{disk.name}"
261
261
  disk.destroy
262
262
  end
263
263
 
@@ -268,13 +268,13 @@ module Rudy::Routines::Handlers;
268
268
  raise Rudy::Disks::NotAttached, disk.name if !disk.volume_attached?
269
269
 
270
270
  back = disk.archive
271
- puts "Created backup: #{back.name}"
271
+ li "Created backup: #{back.name}"
272
272
  end
273
273
 
274
274
  def restore(rbox, disk, index)
275
275
 
276
276
  if disk.exists?
277
- puts "Disk found: #{disk.name}"
277
+ li "Disk found: #{disk.name}"
278
278
  disk.refresh!
279
279
  end
280
280
 
@@ -290,7 +290,7 @@ module Rudy::Routines::Handlers;
290
290
 
291
291
  disk.size, disk.fstype = latest_backup.size, latest_backup.fstype
292
292
 
293
- puts "Backup found: #{latest_backup.name}"
293
+ li "Backup found: #{latest_backup.name}"
294
294
 
295
295
  unless disk.volume_exists?
296
296
  msg = "Creating volume... "
@@ -70,7 +70,7 @@ module Rudy; module Routines; module Handlers;
70
70
  end
71
71
 
72
72
  ports.each do |port|
73
- #li "Authorizing port #{port} access for: #{addresses.join(', ')}"
73
+ li "#{action} port #{port} access for: #{addresses.join(', ')}"
74
74
  Rudy::AWS::EC2::Groups.send(action, name, addresses, [[port, port]]) rescue nil
75
75
  end
76
76
  end
@@ -13,7 +13,7 @@ module Rudy::Routines::Handlers;
13
13
  def create_box(hostname, opts={})
14
14
  ld [:hostname, hostname, opts, caller[0]]
15
15
  opts = {
16
- :info => (@@global.verbose >= 3), # rudy -vvv
16
+ :info => (@@global.verbose >= 2), # rudy -vv
17
17
  :debug => false,
18
18
  :user => current_machine_user,
19
19
  :ostype => current_machine_os || :unix,
@@ -35,14 +35,14 @@ module Rudy::Routines::Handlers;
35
35
  # We define hooks so we can still print each command and its output
36
36
  # when running the command blocks. NOTE: We only print this in
37
37
  # verbosity mode.
38
- if @@global.verbose > 0 && !@@global.parallel
38
+ if !@@global.parallel && !@@global.quiet
39
39
  # This block gets called for every command method call.
40
40
  box.pre_command_hook do |cmd, user, host, nickname|
41
41
  print_command user, nickname, cmd
42
42
  end
43
43
  end
44
44
 
45
- if @@global.verbose > 1
45
+ if @@global.verbose > 0 && !@@global.quiet
46
46
  # And this one gets called after each command method call.
47
47
  box.post_command_hook do |ret|
48
48
  print_response ret
@@ -68,7 +68,9 @@ module Rudy::Routines::Handlers;
68
68
  # NOTE: Windows machines are skipped and not added to the set.
69
69
  def create_set(hostnames, opts={})
70
70
  hostnames ||= []
71
-
71
+
72
+ ld "Creating set from:", hostnames.inspect
73
+
72
74
  opts = {
73
75
  :user => (current_machine_user).to_s,
74
76
  :parallel => @@global.parallel
@@ -164,7 +166,7 @@ module Rudy::Routines::Handlers;
164
166
  else
165
167
  le prefix << "#{ex.class}: #{ex.message}".color(:red)
166
168
  end
167
- le *ex.backtrace if @@global.verbose > 2
169
+ le ex.backtrace if @@global.verbose > 1
168
170
  end
169
171
 
170
172