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 +32 -17
  2. data/README.rdoc +74 -40
  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 +41 -36
  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 +171 -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 +17 -10
  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 +14 -7
  84. data/lib/rudy/cli/status.rb +0 -60
@@ -8,13 +8,8 @@ module Rudy::AWS
8
8
  field :region
9
9
  field :state
10
10
 
11
- def liner_note
12
- "%-10s %9s %s" % [self.name, self.region, self.state]
13
- end
14
-
15
11
  def to_s(titles=false)
16
- str = titles ? "%-20s %s#{$/}" % ['name', 'region', 'state'] : ""
17
- str << liner_note
12
+ [@name.bright, @region, @state].join '; '
18
13
  end
19
14
 
20
15
  end
@@ -181,7 +181,7 @@ module Rudy
181
181
  # Returns the return value from the request is returned untouched
182
182
  # or the default value on error or if the request returned nil.
183
183
  def execute_request(default=nil, timeout=nil, &request)
184
- timeout ||= 15
184
+ timeout ||= 30
185
185
  raise "No block provided" unless request
186
186
  response = nil
187
187
  begin
@@ -7,7 +7,7 @@ module AWS; module EC2;
7
7
 
8
8
  def addresses_create
9
9
  address = Rudy::AWS::EC2::Addresses.create
10
- puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
10
+ print_stobject address
11
11
  end
12
12
 
13
13
  def addresses_destroy_valid?
@@ -24,7 +24,6 @@ module AWS; module EC2;
24
24
  puts "NOTE: this IP address will become available to other EC2 customers.".bright
25
25
  execute_check(:medium)
26
26
  execute_action { Rudy::AWS::EC2::Addresses.destroy(@argv.ipaddress) }
27
- self.addresses
28
27
  end
29
28
 
30
29
  def associate_addresses_valid?
@@ -58,7 +57,7 @@ module AWS; module EC2;
58
57
  execute_check(:low)
59
58
  execute_action { Rudy::AWS::EC2::Addresses.associate(address, instance.awsid) }
60
59
  address = Rudy::AWS::EC2::Addresses.get(address)
61
- puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
60
+ print_stobject address
62
61
  end
63
62
 
64
63
  def disassociate_addresses_valid?
@@ -76,17 +75,12 @@ module AWS; module EC2;
76
75
  execute_check(:medium)
77
76
  execute_action { Rudy::AWS::EC2::Addresses.disassociate(@argv.ipaddress) }
78
77
  address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
79
- puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
78
+ print_stobject address
80
79
  end
81
80
 
82
81
  def addresses
83
82
  addresses = Rudy::AWS::EC2::Addresses.list || []
84
-
85
- addresses.each do |address|
86
- puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
87
- end
88
-
89
- puts "No Addresses" if addresses.empty?
83
+ print_stobjects addresses
90
84
  end
91
85
 
92
86
 
@@ -33,7 +33,6 @@ module AWS; module EC2;
33
33
  execute_check(:medium)
34
34
  execute_action { Rudy::AWS::EC2::Groups.destroy(@argv.name) }
35
35
  @argv.clear # so groups will print all other groups
36
- groups
37
36
  end
38
37
 
39
38
  def revoke_groups_valid?; modify_group_valid?; end
@@ -21,10 +21,7 @@ module AWS; module EC2;
21
21
  end
22
22
 
23
23
  images = Rudy::AWS::EC2::Images.list(@option.owner, @argv) || []
24
- images.each do |img|
25
- puts @@global.verbose > 0 ? img.inspect : img.dump(@@global.format)
26
- end
27
- puts "No images" if images.empty?
24
+ print_stobjects images
28
25
  end
29
26
 
30
27
  def destroy_images_valid?
@@ -0,0 +1,63 @@
1
+
2
+
3
+ module Rudy; module CLI
4
+ module AWS; module EC2;
5
+
6
+ class Info < Rudy::CLI::CommandBase
7
+
8
+ def info
9
+ process_region @@global.region
10
+ oregions = Rudy::AWS::VALID_REGIONS - [@@global.region.to_sym]
11
+ if @option.all
12
+ oregions.each do |region|
13
+ Rudy::AWS::EC2.connect @@global.accesskey, @@global.secretkey, region
14
+ process_region region
15
+ end
16
+ else
17
+ puts $/, "Other regions: " << oregions.join(', ')
18
+ end
19
+ end
20
+
21
+
22
+ private
23
+ def process_region(region)
24
+ puts " Region: %s %30s".att(:reverse) % [region, '']
25
+ puts " Instances".bright
26
+ istatus = @option.all ? :any : :running
27
+ (Rudy::AWS::EC2::Instances.list(istatus) || []).collect do |inst|
28
+ #puts " %s (%s): %s; %s; %s" % [inst.awsid, inst.state, inst.dns_public || '[no dns]', inst.size, inst.created]
29
+ puts " #{inst.to_s.noatt}"
30
+ end
31
+
32
+ puts " Volumes".bright
33
+ (Rudy::AWS::EC2::Volumes.list || []).collect do |vol|
34
+ puts " %s (%s): %sGB; %s" % [vol.awsid, vol.instid || vol.status, vol.size, vol.created]
35
+ end
36
+
37
+ puts " Snapshots".bright
38
+ (Rudy::AWS::EC2::Snapshots.list || []).collect do |snap|
39
+ puts " %s: %s; %s" % [snap.awsid, snap.volid, snap.created]
40
+ end
41
+
42
+ puts " Addresses".bright
43
+ (Rudy::AWS::EC2::Addresses.list || []).collect do |o|
44
+ puts " %s (%s)" % [o.ipaddress, o.instid || 'available']
45
+ end
46
+
47
+ puts " Groups".bright
48
+ puts (Rudy::AWS::EC2::Groups.list || []).collect { |o| " #{o.name}" }
49
+
50
+ puts " Keypairs".bright
51
+ puts (Rudy::AWS::EC2::Keypairs.list || []).collect { |o| " #{o.name}" }
52
+
53
+ puts " Images".bright
54
+ (Rudy::AWS::EC2::Images.list('self') || []).collect do |o|
55
+ puts " %s: %s; %s; %s" % [o.awsid, o.location, o.arch, o.visibility]
56
+ end
57
+ puts
58
+ end
59
+
60
+ end
61
+
62
+ end; end
63
+ end; end
@@ -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
@@ -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