solutious-rudy 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +19 -1
- data/README.rdoc +66 -35
- data/Rakefile +1 -0
- data/Rudyfile +97 -6
- data/bin/ird +7 -4
- data/bin/rudy +120 -212
- data/bin/rudy-ec2 +240 -0
- data/bin/rudy-s3 +76 -0
- data/bin/rudy-sdb +67 -0
- data/lib/annoy.rb +61 -18
- data/lib/console.rb +10 -5
- data/lib/rudy/aws/ec2/address.rb +76 -40
- data/lib/rudy/aws/ec2/group.rb +138 -78
- data/lib/rudy/aws/ec2/image.rb +134 -12
- data/lib/rudy/aws/ec2/instance.rb +116 -89
- data/lib/rudy/aws/ec2/keypair.rb +26 -14
- data/lib/rudy/aws/ec2/snapshot.rb +23 -12
- data/lib/rudy/aws/ec2/volume.rb +198 -202
- data/lib/rudy/aws/ec2/zone.rb +77 -0
- data/lib/rudy/aws/ec2.rb +56 -25
- data/lib/rudy/aws/s3.rb +54 -0
- data/lib/rudy/aws/sdb/error.rb +46 -0
- data/lib/rudy/aws/sdb.rb +298 -0
- data/lib/rudy/aws.rb +29 -57
- data/lib/rudy/{metadata/backup.rb → backup.rb} +8 -8
- data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
- data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
- data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
- data/lib/rudy/cli/aws/ec2/images.rb +196 -0
- data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
- data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
- data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
- data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
- data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
- data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
- data/lib/rudy/cli/aws/s3/store.rb +22 -0
- data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
- data/lib/rudy/cli/{deploy.rb → candy.rb} +2 -6
- data/lib/rudy/cli/config.rb +25 -20
- data/lib/rudy/cli/disks.rb +18 -108
- data/lib/rudy/cli/machines.rb +94 -0
- data/lib/rudy/cli/routines.rb +47 -70
- data/lib/rudy/cli.rb +104 -89
- data/lib/rudy/config/objects.rb +5 -43
- data/lib/rudy/config.rb +8 -24
- data/lib/rudy/disks.rb +248 -0
- data/lib/rudy/global.rb +121 -0
- data/lib/rudy/huxtable.rb +232 -147
- data/lib/rudy/machines.rb +245 -0
- data/lib/rudy/metadata.rb +136 -0
- data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
- data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
- data/lib/rudy/routines/release.rb +27 -8
- data/lib/rudy/routines/shutdown.rb +47 -32
- data/lib/rudy/routines/startup.rb +47 -37
- data/lib/rudy/routines.rb +30 -37
- data/lib/rudy/scm/svn.rb +1 -1
- data/lib/rudy/utils.rb +262 -4
- data/lib/rudy.rb +76 -248
- data/lib/storable.rb +19 -16
- data/lib/sysinfo.rb +1 -1
- data/rudy.gemspec +88 -68
- data/support/rudy-ec2-startup +5 -5
- data/test/05_config/00_setup_test.rb +3 -7
- data/test/20_sdb/00_setup_test.rb +2 -17
- data/test/20_sdb/10_domains_test.rb +18 -16
- data/test/25_ec2/00_setup_test.rb +5 -10
- data/test/25_ec2/10_keypairs_test.rb +13 -5
- data/test/25_ec2/20_groups_test.rb +48 -56
- data/test/25_ec2/30_addresses_test.rb +13 -10
- data/test/25_ec2/40_volumes_test.rb +11 -8
- data/test/25_ec2/50_snapshots_test.rb +17 -12
- data/test/26_ec2_instances/00_setup_test.rb +3 -8
- data/test/26_ec2_instances/10_instances_test.rb +21 -19
- data/test/30_sdb_metadata/00_setup_test.rb +2 -9
- data/test/30_sdb_metadata/10_disks_test.rb +47 -37
- data/test/30_sdb_metadata/20_backups_test.rb +9 -9
- data/test/helper.rb +5 -3
- data/vendor/highline-1.5.1/CHANGELOG +222 -0
- data/vendor/highline-1.5.1/INSTALL +35 -0
- data/vendor/highline-1.5.1/LICENSE +7 -0
- data/vendor/highline-1.5.1/README +63 -0
- data/vendor/highline-1.5.1/Rakefile +82 -0
- data/vendor/highline-1.5.1/TODO +6 -0
- data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
- data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
- data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
- data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
- data/vendor/highline-1.5.1/examples/limit.rb +12 -0
- data/vendor/highline-1.5.1/examples/menus.rb +65 -0
- data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
- data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
- data/vendor/highline-1.5.1/examples/password.rb +7 -0
- data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
- data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
- data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
- data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
- data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
- data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
- data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
- data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
- data/vendor/highline-1.5.1/lib/highline.rb +758 -0
- data/vendor/highline-1.5.1/setup.rb +1360 -0
- data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
- data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
- data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
- data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
- data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
- metadata +81 -69
- data/lib/aws_sdb/error.rb +0 -42
- data/lib/aws_sdb/service.rb +0 -215
- data/lib/aws_sdb.rb +0 -3
- data/lib/rudy/aws/simpledb.rb +0 -71
- data/lib/rudy/cli/addresses.rb +0 -85
- data/lib/rudy/cli/backups.rb +0 -175
- data/lib/rudy/cli/domains.rb +0 -17
- data/lib/rudy/cli/groups.rb +0 -77
- data/lib/rudy/cli/images.rb +0 -111
- data/lib/rudy/cli/instances.rb +0 -142
- data/lib/rudy/cli/keypairs.rb +0 -47
- data/lib/rudy/cli/manager.rb +0 -51
- data/lib/rudy/cli/release.rb +0 -174
- data/lib/rudy/cli/volumes.rb +0 -121
- data/lib/rudy/command/addresses.rb +0 -69
- data/lib/rudy/command/backups.rb +0 -65
- data/lib/rudy/command/disks-old.rb +0 -322
- data/lib/rudy/command/disks.rb +0 -9
- data/lib/rudy/command/domains.rb +0 -34
- data/lib/rudy/command/groups.rb +0 -118
- data/lib/rudy/command/instances.rb +0 -278
- data/lib/rudy/command/keypairs.rb +0 -149
- data/lib/rudy/command/manager.rb +0 -65
- data/lib/rudy/command/volumes.rb +0 -127
- data/lib/rudy/metadata/disk.rb +0 -149
- data/lib/rudy/metadata/machine.rb +0 -34
- data/lib/rudy/routines/disk_handler.rb +0 -190
- data/lib/rudy/routines/script_runner.rb +0 -65
- data/test/50_commands/00_setup_test.rb +0 -11
- data/test/50_commands/10_keypairs_test.rb +0 -79
- data/test/50_commands/20_groups_test.rb +0 -77
- data/test/50_commands/40_volumes_test.rb +0 -55
- data/test/50_commands/50_instances_test.rb +0 -110
- data/tryouts/console_tryout.rb +0 -91
- data/tryouts/disks.rb +0 -55
- data/tryouts/nested_methods.rb +0 -36
- data/tryouts/session_tryout.rb +0 -46
@@ -1,278 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Rudy
|
4
|
-
class Instances
|
5
|
-
include Rudy::Huxtable
|
6
|
-
|
7
|
-
|
8
|
-
def create(opts={}, &each_inst)
|
9
|
-
|
10
|
-
rgroup = Rudy::Groups.new(:config => @config, :global => @global)
|
11
|
-
|
12
|
-
# TODO: Handle itype on create
|
13
|
-
opts = { :ami => current_machine_image,
|
14
|
-
:group => current_machine_group,
|
15
|
-
:user => current_user,
|
16
|
-
:size => "m1.small",
|
17
|
-
:keypair => user_keypairpath(:root), # Must be a root key
|
18
|
-
:address => current_machine_address,
|
19
|
-
:machine_data => machine_data.to_yaml }.merge(opts)
|
20
|
-
|
21
|
-
raise NoGroup.new(opts[:group]) unless rgroup.exists?(opts[:group])
|
22
|
-
raise NoRootKeyPair.new(opts[:group]) if !opts[:keypair] && !has_keypair?(:root)
|
23
|
-
|
24
|
-
keypair_name = KeyPairs.path_to_name(opts[:keypair])
|
25
|
-
|
26
|
-
instances = @@ec2.instances.create(opts[:ami], opts[:group], keypair_name, opts[:machine_data], @global.zone)
|
27
|
-
|
28
|
-
|
29
|
-
#instances = [@@ec2.instances.get("i-39009850")]
|
30
|
-
instances_with_dns = []
|
31
|
-
instances.each_with_index do |inst_tmp,index|
|
32
|
-
Rudy.bug('hs672h48') && next if inst_tmp.nil?
|
33
|
-
|
34
|
-
@logger.puts "Instance: #{inst_tmp.awsid}"
|
35
|
-
if opts[:address] && index == 0 # We currently only support assigned an address to the first machine
|
36
|
-
@logger.puts "Associating #{opts[:address]} to #{inst_tmp.awsid}"
|
37
|
-
@@ec2.addresses.associate(inst_tmp.awsid, opts[:address])
|
38
|
-
end
|
39
|
-
|
40
|
-
@logger.puts "Waiting for the instance to startup "
|
41
|
-
begin
|
42
|
-
# TODO: Puts "it's up" and :bell => 3 into waiter
|
43
|
-
Rudy.waiter(2, 120, @logger) { !@@ec2.instances.pending?(inst_tmp.awsid) }
|
44
|
-
raise Exception unless @@ec2.instances.running?(inst_tmp.awsid)
|
45
|
-
@logger.puts "It's up!"
|
46
|
-
Rudy.bell(3)
|
47
|
-
rescue Timeout::Error, Interrupt, Exception
|
48
|
-
@logger.puts "It's not up yet. Check later: " << "rudy status #{inst_tmp.awsid}".color(:blue)
|
49
|
-
next
|
50
|
-
end
|
51
|
-
|
52
|
-
# The DNS names are now available so we need to grab that data from AWS
|
53
|
-
instance = @@ec2.instances.get(inst_tmp.awsid)
|
54
|
-
instances_with_dns << instance
|
55
|
-
|
56
|
-
@logger.puts $/, "Waiting for the SSH daemon "
|
57
|
-
begin
|
58
|
-
Rudy.waiter(1, 60, @logger) { Rudy::Utils.service_available?(instance.dns_name_public, 22) }
|
59
|
-
@logger.puts "It's up!"
|
60
|
-
Rudy.bell(2)
|
61
|
-
rescue Timeout::Error, Interrupt, Exception
|
62
|
-
@logger.puts "SSH isn't up yet. Check later: " << "rudy status #{inst_tmp.awsid}".color(:blue)
|
63
|
-
next
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
instances_with_dns.each { |inst| each_inst.call(inst) } if each_inst
|
70
|
-
instances_with_dns
|
71
|
-
end
|
72
|
-
|
73
|
-
def destroy(group=nil, inst_id=[], &each_inst)
|
74
|
-
group ||= current_machine_group
|
75
|
-
raise "No machines running in #{group}" unless running?(group)
|
76
|
-
instances = @@ec2.instances.list_group(group, :running, inst_id)
|
77
|
-
instances &&= [instances].flatten
|
78
|
-
instances.each { |inst| each_inst.call(inst) } if each_inst
|
79
|
-
@logger.puts $/, "Terminating instances...", $/
|
80
|
-
@@ec2.instances.destroy(instances, :skip_check)
|
81
|
-
end
|
82
|
-
|
83
|
-
# * +state+ instance state (:running, :terminated, :pending, :shutting_down)
|
84
|
-
# * +group+ machine group name. The default is the current machine group
|
85
|
-
# (as determined by the globals) if none is supplied. A value of :any will
|
86
|
-
# return machines from all groups.
|
87
|
-
# * +inst_ids+ An Array of instance IDs (Strings) or Instance objects to
|
88
|
-
# filter the list by. Any instances not in the group will be ignored.
|
89
|
-
# * +each_inst+ a block to execute for every instance in the list.
|
90
|
-
# Returns an Array of Rudy::AWS::EC2::Instance objects
|
91
|
-
def list(state=nil, group=nil, inst_ids=[], &each_inst)
|
92
|
-
group ||= current_machine_group
|
93
|
-
unless group == :any
|
94
|
-
instances = @@ec2.instances.list_group(group, state, inst_ids) || []
|
95
|
-
else
|
96
|
-
instances = @@ec2.instances.list(state, inst_ids) || []
|
97
|
-
end
|
98
|
-
instances.each { |inst| each_inst.call(inst) } if each_inst
|
99
|
-
instances
|
100
|
-
end
|
101
|
-
|
102
|
-
# See Rudy::Instances#list for arguments.
|
103
|
-
# Returns a Hash of Rudy::AWS::EC2::Instance objects (the keys are instance IDs)
|
104
|
-
def list_as_hash(state=nil, group=nil, inst_ids=[], &each_inst)
|
105
|
-
group ||= current_machine_group
|
106
|
-
if group == :any
|
107
|
-
instances = @@ec2.instances.list_group_as_hash(group, state, inst_ids) || {}
|
108
|
-
else
|
109
|
-
instances = @@ec2.instances.list_as_hash(state, inst_ids) || {}
|
110
|
-
end
|
111
|
-
instances.each_pair { |inst_id,inst| each_inst.call(inst) } if each_inst
|
112
|
-
instances
|
113
|
-
end
|
114
|
-
|
115
|
-
# System console output.
|
116
|
-
#
|
117
|
-
# NOTE: Amazon sends the console output as a Base64 encoded string. This method
|
118
|
-
# decrypts it before returning it.
|
119
|
-
#
|
120
|
-
# Returns output for the first machine in the group (if provided) or the first
|
121
|
-
# instance ID (if provided)
|
122
|
-
def console(group=nil, inst_ids=[])
|
123
|
-
group ||= current_machine_group
|
124
|
-
instances = @@ec2.instances.list_group(group, :any, inst_ids)
|
125
|
-
return if instances.nil?
|
126
|
-
output = @@ec2.instances.console_output(instances.first.awsid)
|
127
|
-
return unless output
|
128
|
-
Base64.decode64(output)
|
129
|
-
end
|
130
|
-
|
131
|
-
def connect(group=nil, cmd=nil, inst_ids=[], print_only=false)
|
132
|
-
group ||= current_machine_group
|
133
|
-
instances = @@ec2.instances.list_group(group, :running, inst_ids)
|
134
|
-
raise "No machines running" if instances.nil?
|
135
|
-
raise "No keypair configured for user #{current_user}" unless current_user_keypairpath
|
136
|
-
|
137
|
-
# TODO: If a group is supplied we need to discover the keypair.
|
138
|
-
|
139
|
-
instances.each do |inst|
|
140
|
-
msg = cmd ? %Q{"#{cmd}" on} : "Connecting to"
|
141
|
-
@logger.puts $/, "#{msg} #{inst.dns_name_public}", $/
|
142
|
-
ret = ssh_command(inst.dns_name_public, current_user_keypairpath, @global.user, cmd, print_only)
|
143
|
-
puts ret if ret # ssh command returns false with "ssh_exchange_identification: Connection closed by remote host"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
# * +:recursive: recursively transfer directories (default: false)
|
149
|
-
# * +:preserve: preserve atimes and ctimes (default: false)
|
150
|
-
# * +:task+ one of: :upload (default), :download.
|
151
|
-
# * +:paths+ an array of paths to copy. The last element is the "to" path.
|
152
|
-
def copy(group=nil, inst_ids=[], opts={})
|
153
|
-
group ||= current_machine_group
|
154
|
-
instances = @@ec2.instances.list_group(group, :running, inst_ids)
|
155
|
-
raise "No machines running" if instances.nil?
|
156
|
-
raise "No keypair configured for user #{current_user}" unless current_user_keypairpath
|
157
|
-
raise "You must supply at least one source path" if !opts[:paths] || opts[:paths].empty?
|
158
|
-
raise "You must supply a destination path" unless opts[:dest]
|
159
|
-
|
160
|
-
|
161
|
-
opts = {
|
162
|
-
:task => :upload,
|
163
|
-
:recursive => false,
|
164
|
-
:preserve => false
|
165
|
-
}.merge(opts)
|
166
|
-
|
167
|
-
|
168
|
-
instances.each do |inst|
|
169
|
-
msg = opts[:task] == :upload ? "Upload to" : "Download from"
|
170
|
-
@logger.puts $/, "#{msg} #{inst.awsid}"
|
171
|
-
|
172
|
-
if opts[:print]
|
173
|
-
scp_command inst.dns_name_public, current_user_keypairpath, @global.user, opts[:paths], opts[:dest], (opts[:task] == :download), false, opts[:print]
|
174
|
-
return
|
175
|
-
end
|
176
|
-
|
177
|
-
scp_opts = {
|
178
|
-
:recursive => opts[:recursive],
|
179
|
-
:preserve => opts[:preserve],
|
180
|
-
:chunk_size => 16384
|
181
|
-
}
|
182
|
-
|
183
|
-
scp(opts[:task], inst.dns_name_public, @global.user, current_user_keypairpath, opts[:paths], opts[:dest], scp_opts)
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
@logger.puts
|
188
|
-
end
|
189
|
-
|
190
|
-
|
191
|
-
# * +group+ machine group name
|
192
|
-
def any?(group=nil)
|
193
|
-
group ||= current_machine_group
|
194
|
-
|
195
|
-
@@ec2.instances.any_group?(group)
|
196
|
-
end
|
197
|
-
|
198
|
-
def exists?(inst_id)
|
199
|
-
@@ec2.instances.exists?(inst_id)
|
200
|
-
end
|
201
|
-
|
202
|
-
# *NOTE REGARDING THE STATUS METHODS*:
|
203
|
-
#
|
204
|
-
# We currently return true IF ANY instances are operating
|
205
|
-
# in the given state. This is faulty but we can't fix it
|
206
|
-
# until we have a way to know how many instances should be
|
207
|
-
# running in any given group.
|
208
|
-
#
|
209
|
-
# Are *any* instances in the group in the running state?
|
210
|
-
def running?(group=nil)
|
211
|
-
!list(:running, group).empty?
|
212
|
-
end
|
213
|
-
|
214
|
-
# Are *any* instances in the group in the terminated state?
|
215
|
-
def terminated?(group=nil)
|
216
|
-
!list(:terminated, group).empty?
|
217
|
-
end
|
218
|
-
|
219
|
-
# Are *any* instances in the group in the shutting-down state?
|
220
|
-
def shutting_down?(group=nil)
|
221
|
-
!list(:shutting_down, group).empty?
|
222
|
-
end
|
223
|
-
|
224
|
-
# Are *any* instances in the group in the pending state?
|
225
|
-
def pending?(group=nil)
|
226
|
-
!list(:pending, group).empty?
|
227
|
-
end
|
228
|
-
|
229
|
-
# Are *any* instances in the group in the a non-running state?
|
230
|
-
def unavailable?(group=nil)
|
231
|
-
# We go through @@ec2 so we don't reimplement the "unavailable logic"
|
232
|
-
instances = list(:any, group)
|
233
|
-
@@ec2.instances.unavailable?(instances)
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
private
|
240
|
-
|
241
|
-
def machine_data
|
242
|
-
data = {
|
243
|
-
# Give the machine an identity
|
244
|
-
:zone => @global.zone,
|
245
|
-
:environment => @global.environment,
|
246
|
-
:role => @global.role,
|
247
|
-
:position => @global.position,
|
248
|
-
|
249
|
-
# Add hosts to the /etc/hosts file
|
250
|
-
:hosts => {
|
251
|
-
:dbmaster => "127.0.0.1",
|
252
|
-
}
|
253
|
-
}
|
254
|
-
data.to_hash
|
255
|
-
end
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
260
|
-
class NoGroup < RuntimeError
|
261
|
-
def initialize(group)
|
262
|
-
@group = group
|
263
|
-
end
|
264
|
-
def message
|
265
|
-
"Group #{@group} does not exist. See: rudy groups -h"
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
class NoRootKeyPair < RuntimeError
|
270
|
-
def initialize(group)
|
271
|
-
@group = group
|
272
|
-
end
|
273
|
-
def message
|
274
|
-
"No root keypair for #{@group}. See: rudy keypairs -h"
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
|
2
|
-
module Rudy
|
3
|
-
class KeyPairs
|
4
|
-
include Rudy::Huxtable
|
5
|
-
|
6
|
-
|
7
|
-
def create(n=nil, opts={})
|
8
|
-
raise KeyPairAlreadyDefined.new(current_machine_group) if !n && has_root_keypair?
|
9
|
-
|
10
|
-
n ||= name(n)
|
11
|
-
|
12
|
-
opts = {
|
13
|
-
:force => false
|
14
|
-
}.merge(opts)
|
15
|
-
|
16
|
-
delete_pk(n) if opts[:force] == true && File.exists?(self.path(n))
|
17
|
-
raise KeyPairExists, self.path(n) if File.exists?(self.path(n))
|
18
|
-
|
19
|
-
kp = @@ec2.keypairs.create(n)
|
20
|
-
raise ErrorCreatingKeyPair, n unless kp.is_a?(Rudy::AWS::EC2::KeyPair)
|
21
|
-
|
22
|
-
Rudy.trap_known_errors do
|
23
|
-
@logger.puts "Writing #{self.path(n)}"
|
24
|
-
Rudy::Utils.write_to_file(self.path(n), kp.private_key, 'w', 0600)
|
25
|
-
end
|
26
|
-
|
27
|
-
Rudy.trap_known_errors do
|
28
|
-
@logger.puts "Writing #{self.public_path(n)}"
|
29
|
-
Rudy::Utils.write_to_file(self.public_path(n), kp.public_key, 'w', 0600)
|
30
|
-
end
|
31
|
-
|
32
|
-
@logger.puts "NOTE: If you move #{self.path(n)} you need to also update your Rudy machines config.".color(:blue)
|
33
|
-
|
34
|
-
kp
|
35
|
-
end
|
36
|
-
|
37
|
-
#def check_permissions(n=nil)
|
38
|
-
# n ||= name(n)
|
39
|
-
# raise NoPrivateKeyFile, self.path(n) unless File.exists?(self.path(n))
|
40
|
-
# raise InsecureKeyPairPermissions, self.path(n) unless File::Stat....
|
41
|
-
# p n
|
42
|
-
#end
|
43
|
-
|
44
|
-
|
45
|
-
def destroy(n=nil)
|
46
|
-
n ||= name(n)
|
47
|
-
raise "KeyPair #{n} doesn't exist" unless exists?(n)
|
48
|
-
@logger.puts "No private key file: #{self.path(n)}. Continuing..." unless File.exists?(self.path(n))
|
49
|
-
@logger.puts "Unregistering KeyPair with Amazon"
|
50
|
-
ret = @@ec2.keypairs.destroy(n)
|
51
|
-
if ret
|
52
|
-
ret = delete_files(n) if ret # only delete local file if remote keypair is successfully destroyed
|
53
|
-
else
|
54
|
-
@logger.puts "Keypair not destroyed successfully."
|
55
|
-
end
|
56
|
-
ret
|
57
|
-
end
|
58
|
-
|
59
|
-
# Lists the keypairs registered with Amazon
|
60
|
-
def list(n=nil, &each_object)
|
61
|
-
n &&= [n].flatten.compact
|
62
|
-
keypairs = @@ec2.keypairs.list(n)
|
63
|
-
keypairs.each { |n,kp| each_object.call(kp) } if each_object
|
64
|
-
keypairs || []
|
65
|
-
end
|
66
|
-
|
67
|
-
def get(n=nil)
|
68
|
-
n ||= name(n)
|
69
|
-
keypairs = @@ec2.keypairs.list(n) || []
|
70
|
-
keypairs.first
|
71
|
-
end
|
72
|
-
|
73
|
-
def list_as_hash(n=nil, &each_object)
|
74
|
-
n &&= [n].flatten.compact
|
75
|
-
keypairs = @@ec2.keypairs.list_as_hash(n)
|
76
|
-
keypairs.each_pair { |n,kp| each_object.call(kp) } if each_object
|
77
|
-
keypairs || {}
|
78
|
-
end
|
79
|
-
|
80
|
-
def exists?(n=nil)
|
81
|
-
n ||= name(n)
|
82
|
-
@@ec2.keypairs.exists?(n)
|
83
|
-
end
|
84
|
-
|
85
|
-
def any?(n=nil)
|
86
|
-
n ||= name(n)
|
87
|
-
@@ec2.keypairs.any?
|
88
|
-
end
|
89
|
-
|
90
|
-
def name(n=nil)
|
91
|
-
n ||= "key-#{current_machine_group}"
|
92
|
-
n
|
93
|
-
end
|
94
|
-
|
95
|
-
def path(n=nil)
|
96
|
-
n ||= name(n)
|
97
|
-
File.join(self.config_dirname, "#{n}")
|
98
|
-
end
|
99
|
-
|
100
|
-
def public_path(n=nil)
|
101
|
-
n ||= name(n)
|
102
|
-
File.join(self.config_dirname, "#{n}.pub")
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
# We use the base file name to determine the registered keypair name.
|
107
|
-
def KeyPairs.path_to_name(path)
|
108
|
-
return unless path
|
109
|
-
return path unless File.exists?(path)
|
110
|
-
File.basename(path)
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
def delete_files(n=nil)
|
115
|
-
n ||= name(n)
|
116
|
-
@logger.puts "Deleting #{self.path(n)}"
|
117
|
-
#return false unless File.exists?(self.path(n))
|
118
|
-
ret = (File.unlink(self.path(n)) > 0) # raise exception on error. handle?
|
119
|
-
|
120
|
-
@logger.puts "Deleting #{self.public_path(n)}"
|
121
|
-
#return false unless File.exists?(self.public_path(n))
|
122
|
-
ret && (File.unlink(self.public_path(n)) > 0)
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
class Keypairs
|
127
|
-
def initialize(*args)
|
128
|
-
raise "Oops! The correct class uses a capital 'P': Rudy::KeyPairs"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
module Rudy
|
134
|
-
class KeyPairs
|
135
|
-
class InsecureKeyPairPermissions < RuntimeError; end
|
136
|
-
class NoPrivateKeyFile < RuntimeError; end
|
137
|
-
class ErrorCreatingKeyPair < RuntimeError; end
|
138
|
-
class KeyPairExists < RuntimeError; end
|
139
|
-
class KeyPairAlreadyDefined < RuntimeError
|
140
|
-
attr_reader :group
|
141
|
-
def initialize(group)
|
142
|
-
@group = group
|
143
|
-
end
|
144
|
-
def message
|
145
|
-
"A keypair is defined for #{group}. Check your Rudy config."
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
data/lib/rudy/command/manager.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Rudy
|
4
|
-
class Manager
|
5
|
-
include Rudy::Huxtable
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
__END__
|
13
|
-
|
14
|
-
|
15
|
-
def create_domain(name=nil)
|
16
|
-
name ||= Rudy::RUDY_DOMAIN
|
17
|
-
@@sdb.domains.create(name)
|
18
|
-
end
|
19
|
-
|
20
|
-
def domains
|
21
|
-
(@@sdb.domains.list || []).flatten
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def update_valid?
|
27
|
-
raise "No EC2 .pem keys provided" unless has_pem_keys?
|
28
|
-
raise "No SSH key provided for #{@global.user}!" unless has_keypair?
|
29
|
-
raise "No SSH key provided for root!" unless has_keypair?(:root)
|
30
|
-
|
31
|
-
@option.group ||= machine_group
|
32
|
-
|
33
|
-
@scripts = %w[rudy-ec2-startup update-ec2-ami-tools randomize-root-password]
|
34
|
-
@scripts.collect! {|script| File.join(RUDY_HOME, 'support', script) }
|
35
|
-
@scripts.each do |script|
|
36
|
-
raise "Cannot find #{script}" unless File.exists?(script)
|
37
|
-
end
|
38
|
-
|
39
|
-
true
|
40
|
-
end
|
41
|
-
|
42
|
-
def update
|
43
|
-
puts "Updating Rudy on machines in #{@option.group}"
|
44
|
-
switch_user("root")
|
45
|
-
|
46
|
-
exit unless Annoy.are_you_sure?
|
47
|
-
scp do |scp|
|
48
|
-
@scripts.each do |script|
|
49
|
-
puts "Uploading #{File.basename(script)}"
|
50
|
-
scp.upload!(script, "/etc/init.d/")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
ssh do |session|
|
55
|
-
@scripts.each do |script|
|
56
|
-
session.exec!("chmod 700 /etc/init.d/#{File.basename(script)}")
|
57
|
-
end
|
58
|
-
|
59
|
-
puts "Installing Rudy (#{Rudy::VERSION})"
|
60
|
-
session.exec!("mkdir -p /etc/ec2")
|
61
|
-
session.exec!("gem sources -a http://gems.github.com")
|
62
|
-
puts session.exec!("gem install --no-ri --no-rdoc rudy -v #{Rudy::VERSION}")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
data/lib/rudy/command/volumes.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
|
2
|
-
module Rudy
|
3
|
-
class Volumes
|
4
|
-
include Rudy::Huxtable
|
5
|
-
|
6
|
-
|
7
|
-
def create(size, zone=nil, snapshot=nil)
|
8
|
-
raise "No size supplied" unless size
|
9
|
-
zone ||= @global.zone
|
10
|
-
|
11
|
-
@logger.puts "Creating Volume "
|
12
|
-
vol = @@ec2.volumes.create(size, zone, snapshot)
|
13
|
-
Rudy.waiter(1, 30, @logger) do
|
14
|
-
vol = get(vol.awsid) # update the volume until it says it's available
|
15
|
-
(vol && vol.status == "available")
|
16
|
-
end
|
17
|
-
|
18
|
-
vol
|
19
|
-
end
|
20
|
-
|
21
|
-
def attach(volume, instance, device="/dev/sdh")
|
22
|
-
volume = get(volume)
|
23
|
-
instance = instance.is_a?(Rudy::AWS::EC2::Instance) ? instance.awsid : instance
|
24
|
-
raise "Volume #{volume.awsid} already attached" if volume.attached?
|
25
|
-
raise "No instance supplied" unless instance
|
26
|
-
raise "No device supplied" unless device
|
27
|
-
|
28
|
-
ret = false
|
29
|
-
begin
|
30
|
-
@logger.puts "Attaching Volume... "
|
31
|
-
ret = @@ec2.volumes.attach(instance, volume.awsid, device)
|
32
|
-
raise "Unknown error" unless ret
|
33
|
-
|
34
|
-
Rudy.waiter(1, 30, @logger) do
|
35
|
-
ret = attached?(volume.awsid)
|
36
|
-
end
|
37
|
-
|
38
|
-
rescue => ex
|
39
|
-
@logger.puts ex.backtrace if debug?
|
40
|
-
raise "Error attaching #{volume.awsid} to #{instance}: #{ex.message}"
|
41
|
-
end
|
42
|
-
|
43
|
-
ret
|
44
|
-
end
|
45
|
-
|
46
|
-
def destroy(volume)
|
47
|
-
volume = get(volume)
|
48
|
-
|
49
|
-
|
50
|
-
ret = false
|
51
|
-
begin
|
52
|
-
|
53
|
-
detach(volume) if volume.attached?
|
54
|
-
raise "Volume is still attached. Cannot destroy." unless available?(volume.awsid)
|
55
|
-
|
56
|
-
ret = @@ec2.volumes.destroy(volume.awsid)
|
57
|
-
|
58
|
-
rescue => ex
|
59
|
-
puts ex.backtrace if debug?
|
60
|
-
raise "Error destroying volume #{volume.awsid}: #{ex.message}"
|
61
|
-
end
|
62
|
-
ret
|
63
|
-
end
|
64
|
-
|
65
|
-
def detach(volume)
|
66
|
-
volume = get(volume)
|
67
|
-
raise "#{volume.awsid} is not attached" unless attached?(volume.awsid)
|
68
|
-
|
69
|
-
ret = false
|
70
|
-
begin
|
71
|
-
@logger.puts "Dettaching #{volume.awsid} "
|
72
|
-
@@ec2.volumes.detach(volume.awsid)
|
73
|
-
Rudy.waiter(1, 30) do
|
74
|
-
ret = @@ec2.volumes.available?(volume.awsid)
|
75
|
-
end
|
76
|
-
|
77
|
-
rescue => ex
|
78
|
-
puts ex.backtrace if debug?
|
79
|
-
raise "Error detaching volume #{volume.awsid}: #{ex.message}"
|
80
|
-
end
|
81
|
-
|
82
|
-
ret
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
def attached?(volume)
|
87
|
-
@@ec2.volumes.attached?(volume)
|
88
|
-
end
|
89
|
-
|
90
|
-
def deleting?(volume)
|
91
|
-
@@ec2.volumes.deleting?(volume)
|
92
|
-
end
|
93
|
-
|
94
|
-
def available?(volume)
|
95
|
-
@@ec2.volumes.available?(volume)
|
96
|
-
end
|
97
|
-
|
98
|
-
def in_use?(volume)
|
99
|
-
@@ec2.volumes.in_use?(volume)
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
def list(state=nil, vol_id=[])
|
104
|
-
@@ec2.volumes.list(state, vol_id)
|
105
|
-
end
|
106
|
-
|
107
|
-
def list_as_hash(state=nil, vol_id=[])
|
108
|
-
@@ec2.volumes.list_as_hash(state, vol_id)
|
109
|
-
end
|
110
|
-
|
111
|
-
def any?(state=nil, vol_id=[])
|
112
|
-
@@ec2.volumes.any?(state, vol_id)
|
113
|
-
end
|
114
|
-
|
115
|
-
def exists?(vol_id)
|
116
|
-
@@ec2.volumes.exists?(vol_id)
|
117
|
-
end
|
118
|
-
|
119
|
-
# * +volopt* is a volume ID or an Rudy::AWS::EC2::Volume object
|
120
|
-
def get(volopt)
|
121
|
-
return volopt if volopt.is_a?(Rudy::AWS::EC2::Volume)
|
122
|
-
@@ec2.volumes.get(volopt)
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
end
|