solutious-rudy 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/CHANGES.txt +8 -9
  2. data/README.rdoc +48 -7
  3. data/Rakefile +102 -7
  4. data/Rudyfile +28 -0
  5. data/bin/ird +162 -0
  6. data/bin/rudy +287 -93
  7. data/lib/annoy.rb +227 -0
  8. data/lib/aws_sdb/service.rb +1 -1
  9. data/lib/console.rb +20 -4
  10. data/lib/escape.rb +305 -0
  11. data/lib/rudy.rb +265 -125
  12. data/lib/rudy/aws.rb +61 -26
  13. data/lib/rudy/aws/ec2.rb +20 -296
  14. data/lib/rudy/aws/ec2/address.rb +121 -0
  15. data/lib/rudy/aws/ec2/group.rb +241 -0
  16. data/lib/rudy/aws/ec2/image.rb +46 -0
  17. data/lib/rudy/aws/ec2/instance.rb +407 -0
  18. data/lib/rudy/aws/ec2/keypair.rb +92 -0
  19. data/lib/rudy/aws/ec2/snapshot.rb +87 -0
  20. data/lib/rudy/aws/ec2/volume.rb +234 -0
  21. data/lib/rudy/aws/simpledb.rb +33 -15
  22. data/lib/rudy/cli.rb +142 -0
  23. data/lib/rudy/cli/addresses.rb +85 -0
  24. data/lib/rudy/cli/backups.rb +175 -0
  25. data/lib/rudy/{command → cli}/config.rb +18 -13
  26. data/lib/rudy/cli/deploy.rb +12 -0
  27. data/lib/rudy/cli/disks.rb +125 -0
  28. data/lib/rudy/cli/domains.rb +17 -0
  29. data/lib/rudy/cli/groups.rb +77 -0
  30. data/lib/rudy/{command → cli}/images.rb +18 -6
  31. data/lib/rudy/cli/instances.rb +142 -0
  32. data/lib/rudy/cli/keypairs.rb +47 -0
  33. data/lib/rudy/cli/manager.rb +51 -0
  34. data/lib/rudy/{command → cli}/release.rb +10 -10
  35. data/lib/rudy/cli/routines.rb +80 -0
  36. data/lib/rudy/cli/volumes.rb +121 -0
  37. data/lib/rudy/command/addresses.rb +62 -39
  38. data/lib/rudy/command/backups.rb +60 -170
  39. data/lib/rudy/command/disks-old.rb +322 -0
  40. data/lib/rudy/command/disks.rb +5 -209
  41. data/lib/rudy/command/domains.rb +34 -0
  42. data/lib/rudy/command/groups.rb +105 -48
  43. data/lib/rudy/command/instances.rb +263 -70
  44. data/lib/rudy/command/keypairs.rb +149 -0
  45. data/lib/rudy/command/manager.rb +65 -0
  46. data/lib/rudy/command/volumes.rb +110 -49
  47. data/lib/rudy/config.rb +90 -70
  48. data/lib/rudy/config/objects.rb +67 -0
  49. data/lib/rudy/huxtable.rb +253 -0
  50. data/lib/rudy/metadata/backup.rb +23 -48
  51. data/lib/rudy/metadata/disk.rb +79 -68
  52. data/lib/rudy/metadata/machine.rb +34 -0
  53. data/lib/rudy/routines.rb +54 -0
  54. data/lib/rudy/routines/disk_handler.rb +190 -0
  55. data/lib/rudy/routines/release.rb +15 -0
  56. data/lib/rudy/routines/script_runner.rb +65 -0
  57. data/lib/rudy/routines/shutdown.rb +42 -0
  58. data/lib/rudy/routines/startup.rb +48 -0
  59. data/lib/rudy/utils.rb +57 -2
  60. data/lib/storable.rb +11 -5
  61. data/lib/sysinfo.rb +274 -0
  62. data/rudy.gemspec +84 -20
  63. data/support/randomize-root-password +45 -0
  64. data/support/rudy-ec2-startup +5 -5
  65. data/support/update-ec2-ami-tools +20 -0
  66. data/test/05_config/00_setup_test.rb +24 -0
  67. data/test/05_config/30_machines_test.rb +69 -0
  68. data/test/20_sdb/00_setup_test.rb +31 -0
  69. data/test/20_sdb/10_domains_test.rb +113 -0
  70. data/test/25_ec2/00_setup_test.rb +34 -0
  71. data/test/25_ec2/10_keypairs_test.rb +33 -0
  72. data/test/25_ec2/20_groups_test.rb +139 -0
  73. data/test/25_ec2/30_addresses_test.rb +35 -0
  74. data/test/25_ec2/40_volumes_test.rb +46 -0
  75. data/test/25_ec2/50_snapshots_test.rb +69 -0
  76. data/test/26_ec2_instances/00_setup_test.rb +33 -0
  77. data/test/26_ec2_instances/10_instances_test.rb +81 -0
  78. data/test/26_ec2_instances/50_images_test.rb +13 -0
  79. data/test/30_sdb_metadata/00_setup_test.rb +28 -0
  80. data/test/30_sdb_metadata/10_disks_test.rb +99 -0
  81. data/test/30_sdb_metadata/20_backups_test.rb +102 -0
  82. data/test/50_commands/00_setup_test.rb +11 -0
  83. data/test/50_commands/10_keypairs_test.rb +79 -0
  84. data/test/50_commands/20_groups_test.rb +77 -0
  85. data/test/50_commands/40_volumes_test.rb +55 -0
  86. data/test/50_commands/50_instances_test.rb +110 -0
  87. data/test/coverage.txt +51 -0
  88. data/test/helper.rb +35 -0
  89. data/tryouts/disks.rb +55 -0
  90. data/tryouts/nested_methods.rb +36 -0
  91. data/tryouts/session_tryout.rb +48 -0
  92. metadata +94 -25
  93. data/bin/rudy-ec2 +0 -108
  94. data/lib/rudy/command/base.rb +0 -839
  95. data/lib/rudy/command/deploy.rb +0 -12
  96. data/lib/rudy/command/environment.rb +0 -74
  97. data/lib/rudy/command/machines.rb +0 -170
  98. data/lib/rudy/command/metadata.rb +0 -41
  99. data/lib/rudy/metadata.rb +0 -26
@@ -1,12 +0,0 @@
1
-
2
-
3
-
4
-
5
- module Rudy
6
- module Command
7
- class Deploy < Rudy::Command::Base
8
-
9
- end
10
- end
11
- end
12
-
@@ -1,74 +0,0 @@
1
-
2
-
3
-
4
- module Rudy
5
- module Command
6
- class Environment < Rudy::Command::Base
7
-
8
- #---
9
- # TODO: http://net-ssh.rubyforge.org/ssh/v1/chapter-4.html
10
- #+++
11
-
12
-
13
- def connect
14
- check_keys
15
- machine = find_current_machine
16
- if @argv.cmd
17
- cmd = @argv.cmd.is_a?(Array) ? @argv.cmd.join(' ') : @argv.cmd
18
- else
19
- cmd = false
20
- end
21
-
22
- ret = ssh_command(machine[:dns_name], keypairpath, @global.user, cmd, @option.print)
23
- puts ret if ret # ssh command returns false with "ssh_exchange_identification: Connection closed by remote host"
24
-
25
- end
26
-
27
- def copy_valid?
28
- check_keys
29
- raise "No path specified (rudy copy FROM-PATH [FROM-PATH ...] TO-PATH)" unless argv.size >= 2
30
- true
31
- end
32
-
33
- # +paths+ an array of paths to copy. The last element is the "to" path.
34
- def copy
35
- machine = find_current_machine
36
-
37
- paths = @argv
38
- dest_path = paths.pop
39
-
40
- if @option.print
41
- scp_command machine[:dns_name], keypairpath, @global.user, paths, dest_path, @option.remote, false, @option.print
42
- return
43
- end
44
-
45
- @option.remote = true if @alias == 'download'
46
- @option.remote = false if @alias == 'upload'
47
-
48
- if @alias == 'scp' || @alias == 'copy'
49
- @alias = 'download' if @option.remote
50
- @alias = 'upload' unless @option.remote
51
- end
52
-
53
- scp do |scp|
54
- transfers = paths.collect { |path|
55
- scp.send(@alias, path, dest_path) do |ch, name, sent, total|
56
- #TODO: Nice printing in place
57
- #puts "#{name}: #{sent}/#{total}"
58
- end
59
-
60
- }
61
- transfers.each { |trans| trans.wait }
62
- end
63
- end
64
-
65
-
66
-
67
-
68
- end
69
- end
70
- end
71
-
72
- __END__
73
-
74
-
@@ -1,170 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module Command
5
- class Machines < Rudy::Command::Base
6
-
7
-
8
- def shutdown_valid?
9
- raise "No EC2 .pem keys provided" unless has_pem_keys?
10
- raise "No SSH key provided for #{@global.user}!" unless has_keypair?
11
- raise "No SSH key provided for root!" unless has_keypair?(:root)
12
-
13
- @list = @ec2.instances.list(machine_group)
14
- raise "No machines running in #{machine_group}" unless @list && !@list.empty?
15
-
16
- raise "I will not help you ruin production!" if @global.environment == "prod" # TODO: use_caution?, locked?
17
-
18
- true
19
- end
20
-
21
-
22
- def shutdown
23
- puts "Shutting down #{machine_group}: #{@list.keys.join(', ')}".att(:bright)
24
- switch_user("root")
25
- puts "This command also affects the volumes attached to the instances! (according to your routines config)"
26
- exit unless are_you_sure?(5)
27
-
28
- execute_routines(@list.values, :shutdown, :before)
29
-
30
- execute_disk_routines(@list.values, :shutdown)
31
-
32
-
33
- puts $/, "Terminating instances...".att(:bright), $/
34
-
35
- @ec2.instances.destroy @list.keys
36
- sleep 5
37
-
38
- execute_routines(@list.values, :shutdown, :after)
39
-
40
- puts "Done!"
41
- end
42
-
43
- def startup_valid?
44
- rig = @ec2.instances.list(machine_group)
45
- raise "There is already an instance running in #{machine_group}" if rig && !rig.empty?
46
- raise "No SSH key provided for #{keypairname}!" unless has_keypair?
47
- true
48
- end
49
- def startup
50
- puts "Starting a machine in #{machine_group}".att(:bright)
51
- switch_user("root")
52
- exit unless are_you_sure?(3)
53
-
54
- #execute_routines([], :startup, :before_local)
55
-
56
- @option.image ||= machine_image
57
-
58
- puts "using AMI: #{@option.image}"
59
-
60
- instances = @ec2.instances.create(@option.image, machine_group.to_s, File.basename(keypairpath), machine_data.to_yaml, @global.zone)
61
- inst = instances.first
62
-
63
- if @option.address ||= machine_address
64
- puts "Associating #{@option.address} to #{inst[:aws_instance_id]}"
65
- @ec2.addresses.associate(inst[:aws_instance_id], @option.address)
66
- end
67
-
68
- wait_for_machine(inst[:aws_instance_id])
69
- inst = @ec2.instances.get(inst[:aws_instance_id])
70
-
71
- #inst = @ec2.instances.list(machine_group).values
72
-
73
- execute_disk_routines(inst, :startup)
74
- execute_routines(inst, :startup, :after)
75
-
76
- puts "Done!"
77
- end
78
-
79
- def restart_valid?
80
- shutdown_valid?
81
- end
82
- def restart
83
- puts "Restarting #{machine_group}: #{@list.keys.join(', ')}".att(:bright)
84
- switch_user("root")
85
- exit unless are_you_sure?(5)
86
-
87
- @list.each do |id, inst|
88
- execute_routines(@list.values, :restart, :before)
89
- end
90
-
91
- puts "Restarting instances: #{@list.keys.join(', ')}".att(:bright)
92
- @ec2.instances.restart @list.keys
93
- sleep 10 # Wait for state to change and SSH to shutdown
94
-
95
- @list.keys.each do |id|
96
- wait_for_machine(id)
97
- end
98
-
99
- execute_disk_routines(@list.values, :restart)
100
-
101
- @list.each do |id, inst|
102
- execute_routines(@list.values, :restart, :after)
103
- end
104
-
105
- puts "Done!"
106
- end
107
-
108
-
109
- def status_valid?
110
- raise "No EC2 .pem keys provided" unless has_pem_keys?
111
- raise "No SSH key provided for #{@global.user}!" unless has_keypair?
112
- raise "No SSH key provided for root!" unless has_keypair?(:root)
113
-
114
- @list = @ec2.instances.list(machine_group)
115
- raise "No machines running in #{machine_group}" unless @list
116
- true
117
- end
118
- def status
119
- puts "There are no machines running in #{machine_group}" if @list.empty?
120
- @list.each_pair do |id, inst|
121
- print_instance inst
122
- end
123
- end
124
-
125
-
126
- def update_valid?
127
- raise "No EC2 .pem keys provided" unless has_pem_keys?
128
- raise "No SSH key provided for #{@global.user}!" unless has_keypair?
129
- raise "No SSH key provided for root!" unless has_keypair?(:root)
130
-
131
- @scripts = %w[rudy-ec2-startup update-ec2-ami-tools randomize-root-password]
132
- @scripts.collect! {|script| File.join(RUDY_HOME, 'support', script) }
133
- @scripts.each do |script|
134
- raise "Cannot find #{script}" unless File.exists?(script)
135
- end
136
-
137
- true
138
- end
139
-
140
-
141
- def update
142
- puts "Updating Rudy "
143
- switch_user("root")
144
-
145
- exit unless are_you_sure?
146
- scp do |scp|
147
- @scripts.each do |script|
148
- puts "Uploading #{File.basename(script)}"
149
- scp.upload!(script, "/etc/init.d/")
150
- end
151
- end
152
-
153
- ssh do |session|
154
- @scripts.each do |script|
155
- session.exec!("chmod 700 /etc/init.d/#{File.basename(script)}")
156
- end
157
-
158
- puts "Installing Rudy (#{Rudy::VERSION})"
159
- session.exec!("mkdir -p /etc/ec2")
160
- session.exec!("gem sources -a http://gems.github.com")
161
- puts session.exec!("gem install --no-ri --no-rdoc rudy -v #{Rudy::VERSION}")
162
- end
163
- end
164
-
165
-
166
- end
167
- end
168
- end
169
-
170
-
@@ -1,41 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module Command
5
- class Metadata < Rudy::Command::Base
6
-
7
-
8
- # Print Rudy's metadata to STDOUT
9
- def metadata
10
- group_metadata.each_pair do |n,h|
11
- puts n.att(:bright)
12
- puts h.inspect, ""
13
- end
14
- end
15
-
16
- def destroy_metadata_valid?
17
- false
18
- end
19
-
20
- def destroy_metadata
21
- @sdb.domains.destroy(RUDY_DOMAIN)
22
- end
23
-
24
-
25
-
26
- def info
27
- domains = @sdb.domains.list[:domains]
28
- puts "Domains: #{domains.join(", ")}"
29
- end
30
-
31
- private
32
- def check_environment
33
- raise "No Amazon keys provided!" unless has_keys?
34
- raise "No SSH keypairs provided!" unless has_keypair?
35
- true
36
- end
37
-
38
- end
39
- end
40
- end
41
-
data/lib/rudy/metadata.rb DELETED
@@ -1,26 +0,0 @@
1
-
2
- require 'aws_sdb'
3
-
4
- module Rudy
5
- module MetaData
6
- attr_accessor :sdb
7
- attr_accessor :ec2
8
-
9
- def initalize(sdb, ec2)
10
- @sdb = sdb
11
- @ec2 = ec2
12
- end
13
-
14
- end
15
-
16
- module MetaData
17
-
18
- module ObjectBase
19
- extend self
20
-
21
-
22
-
23
- end
24
-
25
- end
26
- end