solutious-rudy 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/CHANGES.txt +40 -16
  2. data/README.rdoc +6 -6
  3. data/bin/rudy +66 -10
  4. data/bin/rudy-ec2 +3 -1
  5. data/examples/authorize.rb +15 -0
  6. data/examples/gem-test.rb +11 -5
  7. data/examples/solaris.rb +35 -0
  8. data/examples/windows.rb +101 -0
  9. data/lib/rudy.rb +7 -1
  10. data/lib/rudy/aws.rb +2 -2
  11. data/lib/rudy/aws/ec2.rb +29 -22
  12. data/lib/rudy/aws/ec2/group.rb +1 -1
  13. data/lib/rudy/aws/ec2/image.rb +1 -29
  14. data/lib/rudy/aws/ec2/instance.rb +4 -32
  15. data/lib/rudy/aws/ec2/keypair.rb +1 -6
  16. data/lib/rudy/aws/ec2/snapshot.rb +2 -20
  17. data/lib/rudy/aws/ec2/volume.rb +11 -19
  18. data/lib/rudy/aws/ec2/zone.rb +1 -6
  19. data/lib/rudy/aws/sdb.rb +1 -1
  20. data/lib/rudy/cli/aws/ec2/addresses.rb +4 -10
  21. data/lib/rudy/cli/aws/ec2/groups.rb +0 -1
  22. data/lib/rudy/cli/aws/ec2/images.rb +1 -4
  23. data/lib/rudy/cli/aws/ec2/info.rb +63 -0
  24. data/lib/rudy/cli/aws/ec2/instances.rb +3 -5
  25. data/lib/rudy/cli/aws/ec2/keypairs.rb +3 -5
  26. data/lib/rudy/cli/aws/ec2/snapshots.rb +2 -6
  27. data/lib/rudy/cli/aws/ec2/zones.rb +2 -4
  28. data/lib/rudy/cli/backups.rb +20 -9
  29. data/lib/rudy/cli/base.rb +60 -3
  30. data/lib/rudy/cli/candy.rb +1 -1
  31. data/lib/rudy/cli/disks.rb +65 -7
  32. data/lib/rudy/cli/execbase.rb +0 -2
  33. data/lib/rudy/cli/images.rb +97 -0
  34. data/lib/rudy/cli/info.rb +48 -0
  35. data/lib/rudy/cli/keypairs.rb +43 -0
  36. data/lib/rudy/cli/machines.rb +48 -38
  37. data/lib/rudy/cli/networks.rb +68 -0
  38. data/lib/rudy/cli/routines.rb +3 -10
  39. data/lib/rudy/config/objects.rb +0 -1
  40. data/lib/rudy/disks.rb +4 -0
  41. data/lib/rudy/global.rb +1 -1
  42. data/lib/rudy/huxtable.rb +9 -3
  43. data/lib/rudy/machines.rb +1 -1
  44. data/lib/rudy/metadata.rb +4 -1
  45. data/lib/rudy/metadata/backup.rb +2 -2
  46. data/lib/rudy/metadata/disk.rb +7 -4
  47. data/lib/rudy/metadata/machine.rb +66 -2
  48. data/lib/rudy/routines.rb +2 -1
  49. data/lib/rudy/routines/base.rb +4 -157
  50. data/lib/rudy/routines/handlers/base.rb +6 -3
  51. data/lib/rudy/routines/handlers/disks.rb +127 -42
  52. data/lib/rudy/routines/handlers/group.rb +45 -10
  53. data/lib/rudy/routines/handlers/host.rb +16 -10
  54. data/lib/rudy/routines/handlers/keypair.rb +26 -10
  55. data/lib/rudy/routines/handlers/rye.rb +173 -0
  56. data/lib/rudy/routines/handlers/script.rb +2 -1
  57. data/lib/rudy/routines/passthrough.rb +2 -2
  58. data/lib/rudy/routines/reboot.rb +2 -2
  59. data/lib/rudy/routines/shutdown.rb +2 -2
  60. data/lib/rudy/routines/startup.rb +4 -2
  61. data/rudy.gemspec +15 -8
  62. data/tryouts/10_require_time/10_rudy_tryouts.rb +1 -1
  63. data/tryouts/12_config/20_defaults_tryouts.rb +1 -1
  64. data/tryouts/12_config/40_machines_tryouts.rb +1 -1
  65. data/tryouts/15_huxtable/20_user_tryouts.rb +1 -1
  66. data/tryouts/25_ec2/10_keypairs_tryouts.rb +1 -0
  67. data/tryouts/30_metadata/10_include_tryouts.rb +1 -1
  68. data/tryouts/30_metadata/13_object_tryouts.rb +4 -0
  69. data/tryouts/30_metadata/50_disk_tryouts.rb +4 -2
  70. data/tryouts/30_metadata/51_disk_digest_tryouts.rb +1 -1
  71. data/tryouts/30_metadata/53_disk_list_tryouts.rb +2 -1
  72. data/tryouts/30_metadata/56_disk_volume_tryouts.rb +1 -1
  73. data/tryouts/30_metadata/60_backup_tryouts.rb +4 -2
  74. data/tryouts/30_metadata/63_backup_list_tryouts.rb +1 -1
  75. data/tryouts/30_metadata/64_backup_disk_tryouts.rb +3 -1
  76. data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +1 -1
  77. data/tryouts/30_metadata/70_machine_tryouts.rb +5 -2
  78. data/tryouts/30_metadata/73_machine_list_tryouts.rb +1 -1
  79. data/tryouts/30_metadata/76_machine_instance_tryouts.rb +15 -3
  80. data/tryouts/30_metadata/77_machines_tryouts.rb +1 -1
  81. data/tryouts/40_routines/10_keypair_handler_tryouts.rb +6 -5
  82. data/tryouts/40_routines/11_group_handler_tryouts.rb +1 -1
  83. metadata +13 -6
  84. data/lib/rudy/cli/status.rb +0 -60
@@ -81,7 +81,7 @@ module AWS; module EC2;
81
81
  first_instance = false
82
82
  end
83
83
 
84
- puts @@global.verbose > 0 ? inst.inspect : inst.dump(@@global.format)
84
+ print_stobject(inst)
85
85
  end
86
86
  end
87
87
  end
@@ -173,10 +173,8 @@ module AWS; module EC2;
173
173
  opts[:id] = @argv.instid if @argv.instid
174
174
  opts[:id] &&= [opts[:id]].flatten
175
175
 
176
- lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], opts[:state], opts[:id]) do |inst|
177
- puts @@global.verbose > 0 ? inst.inspect : inst.dump(@@global.format)
178
- end
179
- puts "No instances running" if !lt || lt.empty?
176
+ ilist = Rudy::AWS::EC2::Instances.list_group(opts[:group], opts[:state], opts[:id])
177
+ ilist.nil? ? puts( "No instances running" ) : print_stobjects(ilist)
180
178
  end
181
179
  alias :instances :status
182
180
 
@@ -18,7 +18,7 @@ module AWS; module EC2;
18
18
  puts "Set the permissions to 0600 and keep it safe.", $/
19
19
  puts kp.private_key
20
20
  else
21
- puts @@global.verbose > 0 ? kp.inspect : kp.dump(@@global.format)
21
+ print_stobject kp
22
22
  end
23
23
  end
24
24
 
@@ -35,10 +35,8 @@ module AWS; module EC2;
35
35
  end
36
36
 
37
37
  def keypairs
38
- (Rudy::AWS::EC2::Keypairs.list || []).each do |kp|
39
- puts @@global.verbose > 0 ? kp.inspect : kp.dump(@@global.format)
40
- end
41
- puts "No keypairs" unless Rudy::AWS::EC2::Keypairs.any?
38
+ klist = Rudy::AWS::EC2::Keypairs.list
39
+ print_stobjects klist
42
40
  end
43
41
 
44
42
 
@@ -13,7 +13,7 @@ module AWS; module EC2;
13
13
  end
14
14
  def create_snapshots
15
15
  snap = execute_action { Rudy::AWS::EC2::Snapshots.create(@volume.awsid) }
16
- puts @@global.verbose > 0 ? snap.inspect : snap.dump(@@global.format)
16
+ print_stobject snap
17
17
  end
18
18
 
19
19
  def destroy_snapshots_valid?
@@ -26,15 +26,11 @@ module AWS; module EC2;
26
26
  puts "Destroying: #{@snap.awsid}"
27
27
  execute_check(:medium)
28
28
  execute_action { Rudy::AWS::EC2::Snapshots.destroy(@snap.awsid) }
29
- snapshots
30
29
  end
31
30
 
32
31
  def snapshots
33
32
  snaps = Rudy::AWS::EC2::Snapshots.list || []
34
- snaps.each do |snap|
35
- puts @@global.verbose > 0 ? snap.inspect : snap.dump(@@global.format)
36
- end
37
- puts "No snapshots" if snaps.empty?
33
+ print_stobjects snaps
38
34
  end
39
35
 
40
36
 
@@ -7,10 +7,8 @@ module AWS; module EC2;
7
7
 
8
8
 
9
9
  def zones
10
- Rudy::AWS::EC2::Zones.list_as_hash(@argv.name).each_value do |zon|
11
- puts zon.dump(@@global.format)
12
- end
13
- puts "No zones" unless Rudy::AWS::EC2::Zones.any?
10
+ zlist = Rudy::AWS::EC2::Zones.list(@argv.name)
11
+ print_stobjects zlist
14
12
  end
15
13
 
16
14
 
@@ -6,17 +6,12 @@ module Rudy
6
6
 
7
7
 
8
8
  def backups
9
- more, less = {}, []
10
- less = [:environment, :role] if @option.all
11
- # We first get the disk metadata
12
- b_list = Rudy::Backups.list(more, less) || []
13
- b_list.each do |back|
14
- puts @global.verbose > 0 ? "#{back.name}: #{back.inspect}" : back.name
15
- end
9
+ blist = get_backups
10
+ print_stobjects blist
16
11
  end
17
12
 
18
13
  def backups_wash
19
- dirt = (Rudy::Backups.list || []).select { |b| !b.snapshot_exists? }
14
+ dirt = (get_backups || []).select { |b| !b.snapshot_exists? }
20
15
  if dirt.empty?
21
16
  puts "Nothing to wash in #{current_machine_group}"
22
17
  return
@@ -28,11 +23,27 @@ module Rudy
28
23
  execute_check(:medium)
29
24
 
30
25
  dirt.each do |b|
31
- b.destroy(:force)
26
+ b.destroy
32
27
  end
33
28
 
34
29
  end
35
30
 
31
+ def backups_create_valid?
32
+ @dlist = Rudy::Disks.list
33
+ raise "No disks" if @dlist.nil?
34
+ raise "No path provided" unless @argv.first
35
+ raise "Disk does not exist" unless Rudy::Disks.exists? @argv.first
36
+ true
37
+ end
38
+
39
+ def backups_create
40
+ @dlist.each do |d|
41
+ puts "Creating backup for #{d.name}"
42
+ back = d.archive
43
+ puts back
44
+ end
45
+ end
46
+
36
47
  end
37
48
  end
38
49
  end
data/lib/rudy/cli/base.rb CHANGED
@@ -35,7 +35,7 @@ module Rudy::CLI
35
35
  @@global.auto ? Annoy.enable_skip : Annoy.disable_skip
36
36
 
37
37
  # ANSI codes look like garbage in DOS
38
- if Rudy.sysinfo.os.to_s == 'win32'
38
+ if Rudy.sysinfo.os.to_s == 'windows'
39
39
  String.disable_color
40
40
  raise Rudy::Error, 'Ruby 1.9 is not supported (yet)' if Rudy.sysinfo.ruby == [1,9,1]
41
41
  end
@@ -95,10 +95,67 @@ module Rudy::CLI
95
95
  end
96
96
  end
97
97
  end
98
-
98
+
99
+ # +stobjects+ is an Array of Storable objects
100
+ # +noverbose+ when not false, will force to print with Object#to_s
101
+ def print_stobjects(stobjects=[], noverbose=false)
102
+ stobjects.each do |m|
103
+ print_stobject m, noverbose
104
+ end
105
+ end
106
+
107
+ def print_stobject(obj, noverbose=false)
108
+ format = @@global.format
109
+ format = :yaml if @@global.verbose > 0 && @@global.format == :string
110
+ format = :string if noverbose
111
+ puts obj.dump(format)
112
+ end
113
+
99
114
  def machine_separator(name, awsid)
100
115
  ('%s %-50s awsid: %s ' % [$/, name, awsid]).att(:reverse)
101
116
  end
102
-
117
+
118
+
119
+ private
120
+
121
+ # See get_metadata
122
+ def get_machines(fields={}, less=[])
123
+ list = get_metadata Rudy::Machines, fields, less
124
+ if list.empty?
125
+ if @@global.position.nil?
126
+ raise Rudy::MachineGroupNotRunning, (@option.all ? nil : current_machine_group)
127
+ else
128
+ raise Rudy::MachineNotRunning, current_machine_name
129
+ end
130
+ end
131
+ list
132
+ end
133
+
134
+ # See get_metadata
135
+ def get_disks(fields={}, less=[])
136
+ get_metadata Rudy::Disks, fields, less
137
+ end
138
+
139
+ # See get_metadata
140
+ def get_backups(fields={}, less=[])
141
+ get_metadata Rudy::Backups, fields, less
142
+ end
143
+
144
+ # * +klass+ a Rudy::Metadata class. e.g. Rudy::Machines
145
+ #
146
+ # This method takes two optional args for adding or
147
+ # removing metadata attributes to modify the select query.
148
+ # When all is specified we want to find disks in every env
149
+ # environment and role to we remove these attributes from
150
+ # the select.
151
+ def get_metadata(klass, fields={}, less=[])
152
+ if @option.all
153
+ # Don't remove keys specified in fields
154
+ less += (Rudy::Metadata::COMMON_FIELDS - fields.keys)
155
+ end
156
+ klass.list(fields, less) || []
157
+ end
158
+
159
+
103
160
  end
104
161
  end
@@ -12,7 +12,7 @@ module Rudy
12
12
  puts "No machines"
13
13
  end
14
14
  end
15
-
15
+
16
16
  end
17
17
  end
18
18
  end
@@ -3,13 +3,9 @@
3
3
  module Rudy
4
4
  module CLI
5
5
  class Disks < Rudy::CLI::CommandBase
6
-
7
6
 
8
7
  def disks
9
- more, less = {}, []
10
- less = [:environment, :role] if @option.all
11
- # We first get the disk metadata
12
- disk_list = Rudy::Disks.list(more, less) || []
8
+ disk_list = get_disks
13
9
  # If there are no disks currently, there could be backups
14
10
  # so we grab those to create a list of disks.
15
11
  if @option.backups
@@ -23,7 +19,7 @@ module Rudy
23
19
  disk_list.each do |d|
24
20
  next if seen.member?(d.name)
25
21
  seen << d.name
26
- puts @@global.verbose > 0 ? d.inspect : d.dump(@@global.format)
22
+ print_stobject d
27
23
  if @option.backups
28
24
  d.backups.each_with_index do |b, index|
29
25
  puts ' %s' % b.name
@@ -34,7 +30,7 @@ module Rudy
34
30
  end
35
31
 
36
32
  def disks_wash
37
- dirt = (Rudy::Disks.list || []).select { |d| !d.volume_exists? }
33
+ dirt = (get_disks || []).select { |d| !d.volume_exists? }
38
34
  if dirt.empty?
39
35
  puts "Nothing to wash in #{current_machine_group}"
40
36
  return
@@ -51,6 +47,68 @@ module Rudy
51
47
 
52
48
  end
53
49
 
50
+ def disks_create_valid?
51
+ @mlist = Rudy::Machines.list
52
+ raise "No machines" if @mlist.nil?
53
+
54
+ raise "No path provided" unless @argv.first
55
+ if !@@global.force && Rudy::Disks.exists?( @argv.first)
56
+ raise "Disk exists" if Rudy::Disks.get(@argv.first).volume_attached?
57
+ end
58
+ raise "No size provided" unless @option.size
59
+
60
+ true
61
+ end
62
+
63
+
64
+ def disks_create
65
+ @mlist.each do |m|
66
+ puts machine_separator(m.name, m.instid)
67
+ rbox = Rudy::Routines::Handlers::RyeTools.create_box m
68
+ rbox.stash = m
69
+ disk = Rudy::Disk.new m.position, @argv.first
70
+ disk.device = @option.device if @option.device
71
+ disk.size = @option.size if @option.size
72
+ disk.refresh! if disk.exists? # We need the volume ID if available
73
+ li "Creating disk: #{disk.name}"
74
+ volumes = m.attached_volumes
75
+ # don't include the current disk in the count.
76
+ volumes.reject! { |v| v.awsid == disk.volid } if disk.volid && disk.volume_attached?
77
+ disk_index = volumes.size + 2
78
+ Rudy::Routines::Handlers::Disks.create rbox, disk, disk_index
79
+ end
80
+ end
81
+
82
+
83
+ def disks_destroy_valid?
84
+ @dlist = Rudy::Disks.list
85
+ raise "No disks" if @dlist.nil?
86
+
87
+ @mlist = Rudy::Machines.list
88
+ raise "No machines" if @mlist.nil? && !@@global.force
89
+
90
+ raise "No path provided" unless @argv.first
91
+ raise "Disk does not exist" unless Rudy::Disks.exists? @argv.first
92
+ true
93
+ end
94
+
95
+ def disks_destroy
96
+ execute_check(:medium)
97
+ if @mlist
98
+ @mlist.each do |m|
99
+ rbox = Rudy::Routines::Handlers::RyeTools.create_box m
100
+ rbox.stash = m
101
+ disk = Rudy::Disk.new m.position, @argv.first
102
+ li "Destroying disk: #{disk.name}"
103
+ Rudy::Routines::Handlers::Disks.destroy rbox, disk, 0
104
+ end
105
+ else
106
+ @dlist.each do |d|
107
+ li "Destroying disk: #{d.name}"
108
+ Rudy::Routines::Handlers::Disks.destroy nil, d, 0
109
+ end
110
+ end
111
+ end
54
112
  end
55
113
  end
56
114
  end
@@ -6,8 +6,6 @@ module Rudy::CLI
6
6
  class Base
7
7
  extend Drydock
8
8
 
9
- debug :off
10
-
11
9
  before do |obj|
12
10
  # Don't print Rudy header unless requested to
13
11
  obj.global.print_header = false if (obj.global.verbose == 0)
@@ -0,0 +1,97 @@
1
+
2
+ module Rudy
3
+ module CLI
4
+ class Images < Rudy::CLI::CommandBase
5
+
6
+ def bundle_valid?
7
+ raise "No S3 bucket provided. See rudy bundle -h" unless @@global.bucket
8
+ raise "No image name provided. See rudy bundle -h" unless @argv.name
9
+
10
+ @machines = Rudy::Machines.list
11
+ raise "No machines" if @machines.nil?
12
+
13
+ @machines = @machines.select { |m| m.windows? }
14
+ raise "No Windows machines" if @machines.nil?
15
+
16
+ true
17
+ end
18
+
19
+ def bundle
20
+
21
+ @machines.each do |m|
22
+ puts machine_separator(m.name, m.instid)
23
+
24
+ cmd = "ec2-bundle-instance"
25
+ args = [m.instid, "--region", @@global.region.to_s]
26
+ args += ["-b", @@global.bucket, "-p", @argv.name]
27
+ args += ["-o", @@global.accesskey, "-w", @@global.secretkey]
28
+ args += ["-K", @@global.pkey, "-C", @@global.cert]
29
+
30
+ # S3 returned 301 (Moved Permanently) for ACL on bucket [EU-BUCKET]
31
+ args += ["--no-bucket-setup"] if @@global.region.to_s == 'eu-west-1'
32
+
33
+ if @@global.verbose > 0
34
+ puts "Running: " << Rye.prepare_command(cmd, args), $/
35
+ end
36
+
37
+ unless @@global.quiet
38
+ puts "Bundling can take up to 60 minutes."
39
+ puts "Check the status with the following command:"
40
+ puts Rudy::Huxtable.generate_rudy_command('bundle-status').bright
41
+ puts $/, "When complete, register the image with the command:"
42
+ puts Rudy::Huxtable.generate_rudy_command('images', '-R', @argv.name).bright
43
+ end
44
+
45
+ execute_check(:medium)
46
+
47
+ ret = Rye.shell cmd, args
48
+ puts ret.stderr, ret.stdout
49
+ end
50
+ end
51
+
52
+ def bundle_status
53
+ cmd = 'ec2-describe-bundle-tasks'
54
+ args = ["--region", @@global.region.to_s]
55
+ args += ["-K", @@global.pkey, "-C", @@global.cert]
56
+
57
+ if @@global.verbose > 0
58
+ puts "Running: " << Rye.prepare_command(cmd, args), $/
59
+ end
60
+
61
+ ret = Rye.shell cmd, args
62
+ puts ret.stderr, ret.stdout
63
+
64
+ end
65
+
66
+ def register_images_valid?
67
+ raise "No S3 bucket provided. See rudy bundle -h" unless @@global.bucket
68
+ raise "No image name provided. See rudy bundle -h" unless @argv.name
69
+
70
+ true
71
+ end
72
+ def register_images
73
+ name = "#{@@global.bucket}/#{@argv.name}.manifest.xml"
74
+ puts Rudy::AWS::EC2::Images.register(name)
75
+ end
76
+
77
+ def deregister_images_valid?
78
+ unless @argv.first && Rudy::Utils.is_id?(:image, @argv.first)
79
+ raise "Must supply an AMI ID. See rudy images -h"
80
+ end
81
+ true
82
+ end
83
+ def deregister_images
84
+ execute_check(:low)
85
+ puts Rudy::AWS::EC2::Images.deregister(@argv.ami) ? "Done" : "Unknown error"
86
+ end
87
+
88
+ def images
89
+ @option.owner ||= 'self'
90
+ images = Rudy::AWS::EC2::Images.list(@option.owner, @argv) || []
91
+ print_stobjects images
92
+ end
93
+
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,48 @@
1
+
2
+
3
+ module Rudy
4
+ module CLI
5
+ class Info < Rudy::CLI::CommandBase
6
+
7
+ def info
8
+ process_region @@global.region
9
+ oregions = Rudy::AWS::VALID_REGIONS - [@@global.region.to_sym]
10
+ if @option.all
11
+ oregions.each do |region|
12
+ Rudy::AWS::EC2.connect @@global.accesskey, @@global.secretkey, region
13
+ process_region region
14
+ end
15
+ else
16
+ puts $/, "Other regions: " << oregions.join(', ')
17
+ end
18
+ end
19
+
20
+
21
+ private
22
+ def process_region(region)
23
+ puts " Region: %s %30s".att(:reverse) % [region, '']
24
+ puts " Machines".bright
25
+
26
+ (get_machines(:region => region) rescue []).collect do |m|
27
+ m.refresh!
28
+ puts " " << m.to_s.noatt
29
+ end
30
+
31
+ puts " Disks".bright
32
+ (get_disks(:region => region) || []).collect do |d|
33
+ d.refresh!
34
+ puts " " << d.to_s.noatt
35
+ end
36
+
37
+ puts " Backups".bright
38
+ (get_backups(:region => region) || []).collect do |b|
39
+ b.refresh!
40
+ puts " " << b.to_s.noatt
41
+ end
42
+
43
+ puts
44
+ end
45
+
46
+ end
47
+ end
48
+ end