rudy 0.4.0 → 0.6.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 +54 -30
  2. data/README.rdoc +100 -12
  3. data/Rakefile +103 -8
  4. data/Rudyfile +119 -0
  5. data/bin/ird +175 -0
  6. data/bin/rudy +259 -156
  7. data/bin/rudy-ec2 +228 -95
  8. data/bin/rudy-s3 +76 -0
  9. data/bin/rudy-sdb +67 -0
  10. data/lib/annoy.rb +270 -0
  11. data/lib/console.rb +30 -9
  12. data/lib/escape.rb +305 -0
  13. data/lib/rudy.rb +151 -182
  14. data/lib/rudy/aws.rb +56 -49
  15. data/lib/rudy/aws/ec2.rb +47 -292
  16. data/lib/rudy/aws/ec2/address.rb +157 -0
  17. data/lib/rudy/aws/ec2/group.rb +301 -0
  18. data/lib/rudy/aws/ec2/image.rb +168 -0
  19. data/lib/rudy/aws/ec2/instance.rb +434 -0
  20. data/lib/rudy/aws/ec2/keypair.rb +104 -0
  21. data/lib/rudy/aws/ec2/snapshot.rb +98 -0
  22. data/lib/rudy/aws/ec2/volume.rb +230 -0
  23. data/lib/rudy/aws/ec2/zone.rb +77 -0
  24. data/lib/rudy/aws/s3.rb +54 -0
  25. data/lib/rudy/aws/sdb.rb +298 -0
  26. data/lib/rudy/aws/sdb/error.rb +46 -0
  27. data/lib/rudy/{metadata/backup.rb → backup.rb} +26 -51
  28. data/lib/rudy/cli.rb +157 -0
  29. data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
  30. data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
  31. data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
  32. data/lib/rudy/cli/aws/ec2/images.rb +196 -0
  33. data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
  34. data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
  35. data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
  36. data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
  37. data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
  38. data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
  39. data/lib/rudy/cli/aws/s3/store.rb +22 -0
  40. data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
  41. data/lib/rudy/cli/candy.rb +8 -0
  42. data/lib/rudy/{command → cli}/config.rb +34 -24
  43. data/lib/rudy/cli/disks.rb +35 -0
  44. data/lib/rudy/cli/machines.rb +94 -0
  45. data/lib/rudy/cli/routines.rb +57 -0
  46. data/lib/rudy/config.rb +77 -72
  47. data/lib/rudy/config/objects.rb +29 -0
  48. data/lib/rudy/disks.rb +248 -0
  49. data/lib/rudy/global.rb +121 -0
  50. data/lib/rudy/huxtable.rb +340 -0
  51. data/lib/rudy/machines.rb +245 -0
  52. data/lib/rudy/metadata.rb +123 -13
  53. data/lib/rudy/routines.rb +47 -0
  54. data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
  55. data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
  56. data/lib/rudy/routines/release.rb +34 -0
  57. data/lib/rudy/routines/shutdown.rb +57 -0
  58. data/lib/rudy/routines/startup.rb +58 -0
  59. data/lib/rudy/scm/svn.rb +1 -1
  60. data/lib/rudy/utils.rb +322 -4
  61. data/lib/storable.rb +26 -17
  62. data/lib/sysinfo.rb +274 -0
  63. data/lib/tryouts.rb +6 -13
  64. data/rudy.gemspec +128 -42
  65. data/support/randomize-root-password +45 -0
  66. data/support/rudy-ec2-startup +9 -9
  67. data/support/update-ec2-ami-tools +20 -0
  68. data/test/05_config/00_setup_test.rb +20 -0
  69. data/test/05_config/30_machines_test.rb +69 -0
  70. data/test/20_sdb/00_setup_test.rb +16 -0
  71. data/test/20_sdb/10_domains_test.rb +115 -0
  72. data/test/25_ec2/00_setup_test.rb +29 -0
  73. data/test/25_ec2/10_keypairs_test.rb +41 -0
  74. data/test/25_ec2/20_groups_test.rb +131 -0
  75. data/test/25_ec2/30_addresses_test.rb +38 -0
  76. data/test/25_ec2/40_volumes_test.rb +49 -0
  77. data/test/25_ec2/50_snapshots_test.rb +74 -0
  78. data/test/26_ec2_instances/00_setup_test.rb +28 -0
  79. data/test/26_ec2_instances/10_instances_test.rb +83 -0
  80. data/test/26_ec2_instances/50_images_test.rb +13 -0
  81. data/test/30_sdb_metadata/00_setup_test.rb +21 -0
  82. data/test/30_sdb_metadata/10_disks_test.rb +109 -0
  83. data/test/30_sdb_metadata/20_backups_test.rb +102 -0
  84. data/test/coverage.txt +51 -0
  85. data/test/helper.rb +36 -0
  86. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  87. data/vendor/highline-1.5.1/INSTALL +35 -0
  88. data/vendor/highline-1.5.1/LICENSE +7 -0
  89. data/vendor/highline-1.5.1/README +63 -0
  90. data/vendor/highline-1.5.1/Rakefile +82 -0
  91. data/vendor/highline-1.5.1/TODO +6 -0
  92. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  93. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  94. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  95. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  96. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  97. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  98. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  99. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  100. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  101. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  102. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  103. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  104. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  105. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  106. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  107. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  108. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  109. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  110. data/vendor/highline-1.5.1/setup.rb +1360 -0
  111. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  112. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  113. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  114. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  115. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  116. metadata +141 -38
  117. data/lib/aws_sdb.rb +0 -3
  118. data/lib/aws_sdb/error.rb +0 -42
  119. data/lib/aws_sdb/service.rb +0 -215
  120. data/lib/rudy/aws/simpledb.rb +0 -53
  121. data/lib/rudy/command/addresses.rb +0 -46
  122. data/lib/rudy/command/backups.rb +0 -175
  123. data/lib/rudy/command/base.rb +0 -841
  124. data/lib/rudy/command/deploy.rb +0 -12
  125. data/lib/rudy/command/disks.rb +0 -213
  126. data/lib/rudy/command/environment.rb +0 -73
  127. data/lib/rudy/command/groups.rb +0 -61
  128. data/lib/rudy/command/images.rb +0 -91
  129. data/lib/rudy/command/instances.rb +0 -85
  130. data/lib/rudy/command/machines.rb +0 -161
  131. data/lib/rudy/command/metadata.rb +0 -41
  132. data/lib/rudy/command/release.rb +0 -174
  133. data/lib/rudy/command/volumes.rb +0 -66
  134. data/lib/rudy/metadata/disk.rb +0 -138
  135. data/tryouts/console_tryout.rb +0 -91
@@ -1,85 +0,0 @@
1
- #
2
- #
3
- #
4
- #
5
- #
6
- #
7
- #
8
- #
9
- #
10
- #
11
- #
12
-
13
- module Rudy
14
- module Command
15
- class Instances < Rudy::Command::Base
16
-
17
- def restart_instances_valid?
18
- raise "No instance ID provided" if @argv.filter.nil?
19
- raise "No EC2 .pem keys provided" unless has_pem_keys?
20
- raise "No SSH key provided for #{@global.user}!" unless has_keypair?
21
- raise "No SSH key provided for root!" unless has_keypair?(:root)
22
-
23
-
24
- @list = @ec2.instances.list(machine_group)
25
- raise "#{@argv.filter} is not in the current machine group" unless @list.has_key?(@argv.filter)
26
-
27
- raise "I will not help you destroy production!" if @global.environment == "prod" # TODO: use_caution?, locked?
28
-
29
- exit unless are_you_sure?(5)
30
- true
31
- end
32
- def restart_instances
33
- puts "Restarting #{@argv.filter}!"
34
- @ec2.instances.restart @argv.filter
35
- end
36
-
37
- def instances
38
- filter = @argv.first
39
- filter = machine_group if filter.nil? && !@option.all
40
- if instance_id?(filter)
41
- inst = @ec2.instances.get(filter)
42
- raise "The instance #{filter} does not exist" if inst.empty?
43
- list = {inst[:aws_instance_id] => inst}
44
- else
45
- raise "The security group #{filter} does not exist" if filter && !@ec2.groups.exists?(filter)
46
- list = @ec2.instances.list(filter)
47
- if list.empty?
48
- msg = "There are no instances running"
49
- msg << " in the group #{filter}" if filter
50
- raise msg
51
- end
52
- end
53
-
54
- list.each_pair do |id, inst|
55
- print_instance inst
56
- end
57
-
58
- end
59
-
60
- def destroy_instances_valid?
61
- filter = argv.first
62
- raise "No instance ID provided" if filter.nil?
63
- raise "I will not help you destroy production!" if @global.environment == "prod" || filter =~ /^prod/
64
- exit unless are_you_sure?
65
- true
66
- end
67
-
68
- def destroy_instances
69
- filter = argv.first
70
-
71
- if @ec2.groups.exists?(filter)
72
- list = @ec2.instances.list(filter)
73
- raise "The group #{filter} has no running instances" if list.empty?
74
- instance = list.keys.first
75
- else
76
- instance = filter
77
- end
78
- puts "Destroying #{instance}!"
79
- @ec2.instances.destroy instance
80
- end
81
-
82
- end
83
- end
84
- end
85
-
@@ -1,161 +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
- puts "Terminating instances..."
33
- @ec2.instances.destroy @list.keys
34
- sleep 5
35
-
36
- execute_routines(@list.values, :shutdown, :after)
37
-
38
- puts "Done!"
39
- end
40
-
41
- def startup_valid?
42
- rig = @ec2.instances.list(machine_group)
43
- raise "There is already an instance running in #{machine_group}" if rig && !rig.empty?
44
- raise "No SSH key provided for #{keypairname}!" unless has_keypair?
45
- true
46
- end
47
- def startup
48
- puts "Starting a machine in #{machine_group}".att(:bright)
49
- switch_user("root")
50
- exit unless are_you_sure?(3)
51
-
52
- #execute_routines([], :startup, :before_local)
53
-
54
- @option.image ||= machine_image
55
-
56
- instances = @ec2.instances.create(@option.image, machine_group.to_s, File.basename(keypairpath), machine_data.to_yaml, @global.zone)
57
- inst = instances.first
58
-
59
- if @option.address ||= machine_address
60
- puts "Associating #{@option.address} to #{inst[:aws_instance_id]}"
61
- @ec2.addresses.associate(inst[:aws_instance_id], @option.address)
62
- end
63
-
64
- wait_for_machine(inst[:aws_instance_id])
65
- inst = @ec2.instances.get(inst[:aws_instance_id])
66
-
67
- #inst = @ec2.instances.list(machine_group).values
68
-
69
- execute_disk_routines(inst, :startup)
70
- execute_routines(inst, :startup, :after)
71
-
72
- puts "Done!"
73
- end
74
-
75
- def restart_valid?
76
- shutdown_valid?
77
- end
78
- def restart
79
- puts "Restarting #{machine_group}: #{@list.keys.join(', ')}".att(:bright)
80
- switch_user("root")
81
- exit unless are_you_sure?(5)
82
-
83
- @list.each do |id, inst|
84
- execute_routines(@list.values, :restart, :before)
85
- end
86
-
87
- puts "Restarting instances: #{@list.keys.join(', ')}".att(:bright)
88
- @ec2.instances.restart @list.keys
89
- sleep 10 # Wait for state to change and SSH to shutdown
90
-
91
- @list.keys.each do |id|
92
- wait_for_machine(id)
93
- end
94
-
95
- execute_disk_routines(@list.values, :restart)
96
-
97
- @list.each do |id, inst|
98
- execute_routines(@list.values, :restart, :after)
99
- end
100
-
101
- puts "Done!"
102
- end
103
-
104
-
105
- def status_valid?
106
- raise "No EC2 .pem keys provided" unless has_pem_keys?
107
- raise "No SSH key provided for #{@global.user}!" unless has_keypair?
108
- raise "No SSH key provided for root!" unless has_keypair?(:root)
109
-
110
- @list = @ec2.instances.list(machine_group)
111
- raise "No machines running in #{machine_group}" unless @list
112
- true
113
- end
114
- def status
115
- puts "There are no machines running in #{machine_group}" if @list.empty?
116
- @list.each_pair do |id, inst|
117
- print_instance inst
118
- end
119
- end
120
-
121
-
122
- #def update_valid?
123
- # raise "No EC2 .pem keys provided" unless has_pem_keys?
124
- # raise "No SSH key provided for #{@global.user}!" unless has_keypair?
125
- # raise "No SSH key provided for root!" unless has_keypair?(:root)
126
- #
127
- # @script = File.join(RUDY_HOME, 'support', 'rudy-ec2-startup')
128
- #
129
- # raise "Cannot find startup script" unless File.exists?(@script)
130
- #
131
- #
132
- # true
133
- #end
134
- #
135
- #
136
- #def update
137
- # puts "Updating Rudy "
138
- # switch_user("root")
139
- #
140
- # exit unless are_you_sure?
141
- # scp do |scp|
142
- # puts "Updating Rudy startup script (#{@script})"
143
- # scp.upload!(@script, "/etc/init.d/") do |ch, name, sent, total|
144
- # puts "#{name}: #{sent}/#{total}"
145
- # end
146
- # end
147
- #
148
- # ssh do |session|
149
- # session.exec!("chmod 700 /etc/init.d/rudy-ec2-startup")
150
- # puts "Installing Rudy (#{Rudy::VERSION})"
151
- # puts session.exec!("gem sources -a http://gems.github.com")
152
- # puts session.exec!("gem install --no-ri --no-rdoc solutious-rudy -v #{Rudy::VERSION}")
153
- # end
154
- #end
155
-
156
-
157
- end
158
- end
159
- end
160
-
161
-
@@ -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
-
@@ -1,174 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module Command
5
- class Release < Rudy::Command::Base
6
-
7
-
8
-
9
-
10
- def release_valid?
11
-
12
- relroutine = @config.routines.find_deferred(@global.environment, @global.role, :release)
13
- raise "No release routines defined for #{machine_group}" if relroutine.nil?
14
-
15
- raise "No EC2 .pem keys provided" unless has_pem_keys?
16
- raise "No SSH key provided for #{@global.user} in #{machine_group}!" unless has_keypair?
17
- raise "No SSH key provided for root in #{machine_group}!" unless has_keypair?(:root)
18
-
19
- @list = @ec2.instances.list(machine_group)
20
- unless @list.empty?
21
- msg = "#{machine_group} is in use, probably with another release. #{$/}"
22
- msg << 'Sort it out and run "rudy shutdown" before continuing.'
23
- raise msg
24
- end
25
-
26
- @scm, @scm_params = find_scm(:release)
27
-
28
- raise "No SCM defined for release routine" unless @scm
29
- raise "#{Dir.pwd} is not a working copy" unless @scm.working_copy?(Dir.pwd)
30
- raise "There are local changes. Please revert or check them in." unless @scm.everything_checked_in?
31
- raise "Invalid base URI (#{@scm_params[:base]})." unless @scm.valid_uri?(@scm_params[:base])
32
-
33
- true
34
- end
35
-
36
-
37
-
38
- def rerelease_valid?
39
- relroutine = @config.routines.find_deferred(@global.environment, @global.role, :rerelease)
40
- raise "No rerelease routines defined for #{machine_group}" if relroutine.nil?
41
-
42
- raise "No EC2 .pem keys provided" unless has_pem_keys?
43
- raise "No SSH key provided for #{@global.user} in #{machine_group}!" unless has_keypair?
44
- raise "No SSH key provided for root in #{machine_group}!" unless has_keypair?(:root)
45
-
46
- @list = @ec2.instances.list(machine_group)
47
- if @list.empty?
48
- msg = "There are no machines running in #{machine_group}. #{$/}"
49
- msg << 'You must run "rudy release" before you can rerelease.'
50
- raise msg
51
- end
52
-
53
- @scm, @scm_params = find_scm(:rerelease)
54
-
55
- raise "No SCM defined for release routine" unless @scm
56
- raise "#{Dir.pwd} is not a working copy" unless @scm.working_copy?(Dir.pwd)
57
- raise "There are local changes. Please revert or check them in." unless @scm.everything_checked_in?
58
- raise "Invalid base URI (#{@scm_params[:base]})." unless @scm.valid_uri?(@scm_params[:base])
59
-
60
- true
61
- end
62
-
63
- def rerelease
64
- puts "Updating release from working copy".att(:bright)
65
-
66
- tag, revision = @scm.local_info
67
- puts "tag: #{tag}"
68
- puts "rev: #{revision}"
69
-
70
- execute_disk_routines(@list.values, :rerelease)
71
-
72
- if @scm
73
-
74
- puts "Running SCM command".att(:bright)
75
- ssh do |session|
76
- cmd = "svn #{@scm_params[:command]}"
77
- puts "#{cmd}"
78
- session.exec!("cd #{@scm_params[:path]}")
79
- session.exec!(cmd)
80
- puts "#{@scm_params[:command]} complete"
81
- end
82
-
83
- end
84
-
85
- execute_routines(@list.values, :rerelease, :after)
86
-
87
- end
88
-
89
- # <li>Creates a release tag based on the working copy on your machine</li>
90
- # <li>Starts a new stage instance</li>
91
- # <li>Executes release routines</li>
92
- def release
93
- # TODO: store metadata about release with local username and hostname
94
- puts "Creating release from working copy".att(:bright)
95
-
96
- exit unless are_you_sure?
97
-
98
- tag = @scm.create_release(@global.local_user, @option.msg)
99
- puts "Done! (#{tag})"
100
-
101
- if @option.switch
102
- puts "Switching working copy to new tag".att(:bright)
103
- @scm.switch_working_copy(tag)
104
- end
105
-
106
- @option.image ||= machine_image
107
-
108
- switch_user("root")
109
-
110
- puts "Starting #{machine_group}".att(:bright)
111
-
112
- instances = @ec2.instances.create(@option.image, machine_group.to_s, File.basename(keypairpath), machine_data.to_yaml, @global.zone)
113
- inst = instances.first
114
-
115
- if @option.address ||= machine_address
116
- puts "Associating #{@option.address} to #{inst[:aws_instance_id]}".att(:bright)
117
- @ec2.addresses.associate(inst[:aws_instance_id], @option.address)
118
- end
119
-
120
- wait_for_machine(inst[:aws_instance_id])
121
- inst = @ec2.instances.get(inst[:aws_instance_id])
122
-
123
- #inst = @ec2.instances.list(machine_group).values
124
-
125
-
126
- execute_disk_routines(inst, :release)
127
-
128
- if @scm
129
-
130
- puts "Running SCM command".att(:bright)
131
- ssh do |session|
132
- cmd = "svn #{@scm_params[:command]} #{tag} #{@scm_params[:path]}"
133
- puts "#{cmd}"
134
- session.exec!(cmd)
135
- puts "#{@scm_params[:command]} complete"
136
- end
137
-
138
- end
139
-
140
- execute_routines(inst, :release, :after)
141
-
142
- print_instance inst
143
-
144
- puts "Done!"
145
- end
146
-
147
-
148
- def find_scm(routine)
149
- env, rol, att = @global.environment, @global.role
150
-
151
- # Look for the source control engine, checking all known scm values.
152
- # The available one will look like [environment][role][release][svn]
153
- params = nil
154
- scm_name = nil
155
- SUPPORTED_SCM_NAMES.each do |v|
156
- scm_name = v
157
- params = @config.routines.find(env, rol, routine, scm_name)
158
- break if params
159
- end
160
-
161
- if params
162
- klass = eval "Rudy::SCM::#{scm_name.to_s.upcase}"
163
- scm = klass.new(:base => params[:base])
164
- end
165
-
166
- [scm, params]
167
-
168
- end
169
- private :find_scm
170
-
171
- end
172
- end
173
- end
174
-