cloudflock 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/bin/flock +32 -0
  2. data/bin/flock-profile +17 -0
  3. data/bin/flock-servers +24 -0
  4. data/bin/flock.default +24 -0
  5. data/lib/cloudflock/error.rb +26 -0
  6. data/lib/cloudflock/interface/cli/app/common/servers.rb +128 -0
  7. data/lib/cloudflock/interface/cli/app/servers/migrate.rb +357 -0
  8. data/lib/cloudflock/interface/cli/app/servers/profile.rb +88 -0
  9. data/lib/cloudflock/interface/cli/app/servers.rb +2 -0
  10. data/lib/cloudflock/interface/cli/console.rb +213 -0
  11. data/lib/cloudflock/interface/cli/opts/servers.rb +20 -0
  12. data/lib/cloudflock/interface/cli/opts.rb +87 -0
  13. data/lib/cloudflock/interface/cli.rb +15 -0
  14. data/lib/cloudflock/patch/fog.rb +113 -0
  15. data/lib/cloudflock/remote/ssh.rb +311 -0
  16. data/lib/cloudflock/target/servers/data/exceptions/base.txt +44 -0
  17. data/lib/cloudflock/target/servers/data/exceptions/platform/amazon.txt +10 -0
  18. data/lib/cloudflock/target/servers/data/exceptions/platform/debian.txt +0 -0
  19. data/lib/cloudflock/target/servers/data/exceptions/platform/redhat.txt +5 -0
  20. data/lib/cloudflock/target/servers/data/exceptions/platform/suse.txt +1 -0
  21. data/lib/cloudflock/target/servers/data/post-migration/chroot/base.txt +1 -0
  22. data/lib/cloudflock/target/servers/data/post-migration/chroot/platform/amazon.txt +19 -0
  23. data/lib/cloudflock/target/servers/data/post-migration/pre/base.txt +3 -0
  24. data/lib/cloudflock/target/servers/data/post-migration/pre/platform/amazon.txt +4 -0
  25. data/lib/cloudflock/target/servers/migrate.rb +466 -0
  26. data/lib/cloudflock/target/servers/platform/v1.rb +97 -0
  27. data/lib/cloudflock/target/servers/platform/v2.rb +93 -0
  28. data/lib/cloudflock/target/servers/platform.rb +133 -0
  29. data/lib/cloudflock/target/servers/profile.rb +394 -0
  30. data/lib/cloudflock/target/servers.rb +5 -0
  31. data/lib/cloudflock/version.rb +3 -0
  32. data/lib/cloudflock.rb +10 -0
  33. metadata +128 -0
@@ -0,0 +1,466 @@
1
+ require 'cloudflock/remote/ssh'
2
+ require 'thread'
3
+ require 'cpe'
4
+
5
+ # Public: Provides methods to facilitate as many discrete steps of a migration
6
+ # between like hosts as possible. The assumption is made that the destination
7
+ # host will be put into rescue mode, or will otherwise be able to recover if
8
+ # any files transferred overwrite extant files on the filesystem (e.g. glibc.)
9
+ # The steps are as granular as possible to avoid the requirement that every
10
+ # step is strictly followed.
11
+ #
12
+ # Examples
13
+ #
14
+ # # Perform setup of source and destination hosts, but don't migrate
15
+ # setup_managed(destination_host)
16
+ # setup_source(source_host)
17
+ #
18
+ # # Assume that all setup has been done; migrate the host with no watchdogs
19
+ # migrate_server(source_host, destination_host)
20
+ module CloudFlock::Target::Servers::Migrate extend self
21
+ # Internal: location of the directory containing data for exclusions/clean-up
22
+ DATA_LOCATION = File.expand_path('../../servers/data', __FILE__)
23
+
24
+ # Public: Monitor for managed cloud scripts to complete. Return true if they
25
+ # do, false otherwise.
26
+ #
27
+ # host - SSH object logged in to the destination host.
28
+ # timeout - Fixnum containing the number of seconds to wait. (default: 1200)
29
+ #
30
+ # Returns true or false depending on whether or not manages scripts have
31
+ # finished.
32
+ def setup_managed(host, timeout = 3600)
33
+ i = 0
34
+ finished = false
35
+ managed_check = %w{[ -f /tmp/rs_managed_cloud_automation_complete ] &&
36
+ printf 'DONE' || printf 'GOING'}.join(' ')
37
+ while i < timeout && !finished
38
+ i += sleep(60)
39
+ mc_task_status = host.set_timeout(60) do
40
+ host.query("MANAGED_CHECK", managed_check)
41
+ end
42
+ finished = true if mc_task_status == "DONE"
43
+ end
44
+
45
+ finished
46
+ end
47
+
48
+ # Public: Prepare the destination host for automated migration steps by
49
+ # installing rsync, mounting the primary disk to /mnt/migration_target,
50
+ # installing a temporary ssh public key for root, and backing up the original
51
+ # passwd, shadow and group files (in case of managed migration).
52
+ #
53
+ # host - SSH object logged in to the destination host.
54
+ # pubkey - String containing the text of the ssh public key to install for
55
+ # root.
56
+ #
57
+ # Returns nothing.
58
+ def setup_destination(host, pubkey)
59
+ host.set_timeout(300)
60
+
61
+ host.puts("mkdir /mnt/migration_target")
62
+ host.prompt
63
+
64
+ disk = host.query("DISK_XVDB1", "[ -e /dev/xvdb1 ] && printf 'xvdb1'")
65
+ disk = "sda1" if disk.empty?
66
+ host.puts("mount -o acl /dev/#{disk} /mnt/migration_target")
67
+ host.prompt
68
+
69
+ preserve_files = ["passwd", "shadow", "group"]
70
+ path = "/mnt/migration_target/etc"
71
+ preserve_files.each do |file|
72
+ copy_command = "[ -f #{path}migration.#{file} ] || cp -af " +
73
+ "#{path}/#{file} #{path}/migration.#{file}"
74
+ host.puts(copy_command)
75
+ host.prompt
76
+ end
77
+
78
+ package_manager = host.query("MANAGER", "which {yum,apt-get} 2>/dev/null")
79
+ host.set_timeout(120) do
80
+ host.puts("#{package_manager} install rsync -y")
81
+ host.prompt
82
+ end
83
+
84
+ host.puts("rsync")
85
+ host.expect(/rsync error/)
86
+ host.prompt
87
+
88
+ ssh_key = "mkdir $HOME/.ssh; chmod 0700 $HOME/.ssh; printf " +
89
+ "'#{pubkey}\\n' >> $HOME/.ssh/authorized_keys"
90
+ host.puts(ssh_key)
91
+ host.prompt
92
+ end
93
+
94
+ # Public: Prepare the source host for automated migration by populating the
95
+ # exclusions list in /root/.rackspace/migration_exceptions.txt and creating a
96
+ # temporary ssh public key in /tmp/RACKSPACE_MIGRATION/
97
+ #
98
+ # host - SSH object logged in to the source host.
99
+ # exclusions - String containing the exclusions list for the source host.
100
+ #
101
+ # Returns a String object containing the host's new ssh public key.
102
+ def setup_source(host, exclusions)
103
+ host.puts("mkdir /root/.rackspace")
104
+ host.prompt
105
+
106
+ exclude = "cat <<EOF > /root/.rackspace/migration_exceptions.txt" +
107
+ "\n#{exclusions}\nEOF"
108
+ host.puts(exclude)
109
+ host.prompt
110
+
111
+ ssh_keygen = %w{mkdir /tmp/RACKSPACE_MIGRATION && ssh-keygen -b 2048 -q -t
112
+ rsa -f /tmp/RACKSPACE_MIGRATION/migration_id_rsa -P
113
+ ''}.join(' ')
114
+ host.puts(ssh_keygen)
115
+ host.prompt
116
+
117
+ host.query("PUBKEY", "cat /tmp/RACKSPACE_MIGRATION/migration_id_rsa.pub")
118
+ end
119
+
120
+ # Public: Check for connectivity over RFC 1918 networks for a pair of hosts.
121
+ # Return the first network address which offers connectivity.
122
+ #
123
+ # source_host - SSH object logged in to the source host.
124
+ # destination_host - SSH object logged in to the destination host.
125
+ #
126
+ # Returns a String containing an IP address if connectivity is verified.
127
+ # Returns nil otherwise.
128
+ def check_servicenet(source_host, destination_host)
129
+ keygen_command = "ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub"
130
+ destination_rsa = destination_host.query("RSA_FINGERPRINT", keygen_command)
131
+ destination_rsa.gsub!(/^[^ ]* /, '').gsub!(/ .*/, '')
132
+
133
+ ip_discovery = %w{ifconfig|grep 'inet addr:10\.' | sed
134
+ 's/.*addr:\([^ ]*\) .*/\1/g' | xargs}.join(' ')
135
+ ips = destination_host.query("IFCONFIG", ip_discovery)
136
+
137
+ ips.split(/\s+/).each do |addr|
138
+ # Change NumberOfPasswordPrompts to 0, and StrictHostKeyChecking to yes
139
+ ssh_arguments = CloudFlock::Remote::SSH::SSH_ARGUMENTS.gsub(/1/, '0')
140
+ ssh_arguments.gsub!("-o StrictHostKeyChecking=no", '')
141
+ source_host.puts("ssh #{ssh_arguments} #{addr}")
142
+ remote_rsa = source_host.set_timeout(30) do
143
+ source_host.expect(/^RSA.*$/, true)
144
+ end
145
+ source_host.set_timeout(120) do
146
+ source_host.send("\C-c")
147
+ source_host.prompt
148
+ end
149
+ next if remote_rsa.nil?
150
+
151
+ return addr unless remote_rsa.to_s.match(destination_rsa).nil?
152
+ end
153
+
154
+ nil
155
+ end
156
+
157
+ # Public: Commense migration by launching 2 rsync processes: the first to
158
+ # move the bulk of the data in question and the second to provide a delta,
159
+ # ensuring a more complete dataset transfer.
160
+ #
161
+ # source_host - SSH object logged in to the source host.
162
+ # destination_host - SSH object logged in to the destination host.
163
+ # args - Hash containing additional parameters for operation.
164
+ # (default: {}):
165
+ # :target_addr - String containing the address to use when
166
+ # communicating with the destination host.
167
+ # :rsync_path - String containing path to rsync binary on
168
+ # the source machine. If this is nil, copy
169
+ # rsync from the destination machine to
170
+ # /root/.rackspace/ for the purposes of
171
+ # carrying out the migration.
172
+ # (default: nil)
173
+ #
174
+ # Returns a Thread object encapsulating the migration.
175
+ # Raises ArgumentError if args[:target_addr] is not set.
176
+ def migrate_server(source_host, args)
177
+ if args[:target_addr].nil?
178
+ raise ArgumentError, "Need target address for server"
179
+ end
180
+
181
+ # If we lack rsync, fetch it from the destination server
182
+ if args[:rsync_path].nil?
183
+ source_host.puts("mkdir /root/.rackspace")
184
+ source_host.prompt
185
+
186
+ rsync_install = "scp #{CloudFlock::Remote::SSH::SSH_ARGUMENTS} -i " +
187
+ "/tmp/RACKSPACE_MIGRATION/migration_id_rsa " +
188
+ "root@#{args[:host]}:/usr/bin/rsync " +
189
+ "/root/.rackspace/rsync"
190
+ source_host.puts(rsync_install)
191
+ source_host.prompt
192
+ args[:rsync_path] = "/root/.rackspace/rsync"
193
+ end
194
+
195
+ 2.times do
196
+ finished = false
197
+ until finished
198
+ source_host.send("\C-c")
199
+ sleep 45
200
+ source_host.puts
201
+ while source_host.prompt(true)
202
+ end
203
+
204
+ finished = migration_watcher(source_host, args)
205
+ end
206
+
207
+ sed_command = 'sed -i "s/\/var\/log//g" ' +
208
+ '/root/.rackspace/migration_exceptions.txt'
209
+ source_host.puts(sed_command)
210
+ source_host.prompt
211
+ end
212
+ end
213
+
214
+ # Internal: Execute rsync and return true if everything appears to have completed successfully
215
+ #
216
+ # source_host - SSH object logged in to the source host.
217
+ # args - Hash containing additional parameters for operation.
218
+ # Expected parameters are:
219
+ # :target_addr - String containing the address to use when
220
+ # communicating with the destination host.
221
+ # :rsync_path - String containing path to rsync binary on
222
+ # the source machine. If this is nil, copy
223
+ # rsync from the destination machine to
224
+ # /root/.rackspace/ for the purposes of
225
+ # carrying out the migration.
226
+ # (default: nil)
227
+ # :timeout - Fixnum containing the number of seconds
228
+ # to wait before reporting failure/hung
229
+ # rsync process. If this is set to -1, a
230
+ # failure will never be reported--use
231
+ # Watchdogs in this case to prevent
232
+ # indefinite migrations. (default: 14400)
233
+ #
234
+ # Returns true if rsync finishes.
235
+ # Returns false if rsync does not complete within timeout.
236
+ def migration_watcher(source_host, args)
237
+ rsync_command = "#{args[:rsync_path]} -azP -e 'ssh " +
238
+ "#{CloudFlock::Remote::SSH::SSH_ARGUMENTS} -i " +
239
+ "/tmp/RACKSPACE_MIGRATION/migration_id_rsa' " +
240
+ "--exclude-from='/root/.rackspace/" +
241
+ "migration_exceptions.txt' / " +
242
+ "root@#{args[:target_addr]}:/mnt/migration_target"
243
+ source_host.puts(rsync_command)
244
+
245
+ source_host.set_timeout(60)
246
+ if(args[:timeout] >= 0)
247
+ i = args[:timeout]/60 + 1
248
+ else
249
+ i = -1
250
+ end
251
+
252
+ begin
253
+ source_host.prompt
254
+ rescue Timeout::Error
255
+ i -= 1
256
+ retry unless i == 0
257
+ return false
258
+ end
259
+
260
+ true
261
+ end
262
+
263
+ # Public: Build exclusions list from generic and targeted exclusions
264
+ # definitions per CPE.
265
+ #
266
+ # cpe - CPE object to use in generating the default exclusions list.
267
+ #
268
+ # Returns a String containing the exclusions list generated.
269
+ def build_default_exclusions(cpe)
270
+ exclude = ""
271
+ exclude << File.open("#{DATA_LOCATION}/exceptions/base.txt", "r").read
272
+ vendor = cpe.vendor.downcase
273
+ version = cpe.version.to_s.downcase
274
+ path = "#{DATA_LOCATION}/exceptions/platform/"
275
+
276
+ if File.exists?("#{path}#{vendor}.txt")
277
+ exclude << File.open("#{path}#{vendor}.txt", "r").read
278
+ end
279
+ if File.exists?("#{path}#{vendor}_#{version}.txt")
280
+ exclude << File.open("#{path}#{vendor}_#{version}.txt", "r").read
281
+ end
282
+
283
+ exclude
284
+ end
285
+
286
+ # Public: Restore the rackconnect user in order to maintain Rack Connect
287
+ # functionality for a host on which Rack Connect automation has previously
288
+ # run.
289
+ #
290
+ # destination_host - SSH object logged in to the destination host.
291
+ #
292
+ # Returns true if the rackconnect user is restored, false otherwise.
293
+ def cleanup_rackconnect_destination(destination_host)
294
+ return false unless restore_user(destination_host, "rackconnect")
295
+
296
+ sudoers = "cat <<EOF >> /etc/sudoers\n\nrackconnect ALL=(ALL) NOPASSWD: " +
297
+ "ALL\nDefaults:rackconnect !requiretty\nEOF"
298
+
299
+ destination_host.puts(sudoers)
300
+ destination_host.prompt
301
+
302
+ true
303
+ end
304
+
305
+ # Public: Restore the rack user in order to maintain access on hosts which
306
+ # belong to a Managed Cloud account, on which Managed Cloud automation has
307
+ # already run.
308
+ #
309
+ # destination_host - SSH object logged in to the destination host.
310
+ #
311
+ # Returns true if the rack user is restored, false otherwise.
312
+ def cleanup_manage_destination(destination_host)
313
+ return false unless restore_user(destination_host, "rack")
314
+
315
+ sudoers = "cat <<EOF >> /etc/sudoers\n\nrack ALL=(ALL) NOPASSWD: ALL\nEOF"
316
+ destination_host.puts(sudoers)
317
+ destination_host.prompt
318
+
319
+ true
320
+ end
321
+
322
+ # Internal: Create user and restore entries from backup passwd and shadow
323
+ # files.
324
+ #
325
+ # destination_host - SSH object logged in to the host on which to restore a
326
+ # user.
327
+ # username - String containing the user to restore.
328
+ #
329
+ # Returns true if success, false otherwise.
330
+ def restore_user(destination_host, username)
331
+ username.strip!
332
+ sanity_check = "(grep '^#{username}:' /etc/migration.passwd && grep " +
333
+ "'^#{username}:' /etc/migration.shadow) >/dev/null " +
334
+ "2>/dev/null && printf 'PRESENT'"
335
+
336
+ sane = destination_host.query("USER_CHECK", sanity_check)
337
+ return false if sane.empty?
338
+
339
+ steps = ["useradd #{username}",
340
+ "chown -R #{username}.#{username} /home/#{username}",
341
+ "sed -i '/^#{username}:.*$/d' /etc/shadow",
342
+ "grep '^#{username}:' /etc/migration.shadow >> /etc/shadow"]
343
+ steps.each do |step|
344
+ destination_host.puts(step)
345
+ destination_host.prompt
346
+ end
347
+
348
+ true
349
+ end
350
+
351
+ # Public: Perform post-migration clean up of a destination host. Base
352
+ # clean up off of cleanup scripts located at data/cleanup/.
353
+ #
354
+ # destination_host - SSH object logged in to the destination host.
355
+ # cpe - CPE object describing the platform in question.
356
+ #
357
+ # Returns nothing.
358
+ def clean_destination(destination_host, cpe)
359
+ clean_pre = ""
360
+ clean_chroot = ""
361
+ clean_post = ""
362
+
363
+ vendor = cpe.vendor.downcase
364
+ version = cpe.version.to_s.downcase
365
+
366
+ # Build pre-chroot, chroot and post-chroot scripts
367
+ ["pre", "chroot", "post"].each do |name|
368
+ clean = eval("clean_#{name}")
369
+ clean << "#/bin/bash\n\n"
370
+ path = "#{DATA_LOCATION}/post-migration/#{name}"
371
+
372
+ if File.exists? "#{path}/base.txt"
373
+ clean << File.open("#{path}/base.txt", "r").read
374
+ end
375
+ if File.exists? "#{path}/platform/#{vendor}.txt"
376
+ clean << File.open("#{path}/platform/#{vendor}.txt", "r").read
377
+ end
378
+ if File.exists? "#{path}/platform/#{vendor}_#{version}.txt"
379
+ clean << File.open("#{path}/platform/#{vendor}_#{version}.txt", "r").read
380
+ end
381
+ end
382
+
383
+ pre_command = "cat <<EOF > /root/migration_clean_pre.sh\n" +
384
+ "#{clean_pre.gsub(/\$/, '\\$')}\nEOF"
385
+ chroot_command = "cat <<EOF > /mnt/migration_target/root/migration_" +
386
+ "clean_chroot.sh\n#{clean_chroot.gsub(/\$/, '\\$')}\nEOF"
387
+ post_command = "cat <<EOF > /root/migration_clean_post.sh\n" +
388
+ "#{clean_post.gsub(/\$/, '\\$')}\nEOF"
389
+ [pre_command, chroot_command, post_command].each do |command|
390
+ destination_host.puts(command)
391
+ destination_host.prompt
392
+ end
393
+
394
+ # Perform pre-chroot steps
395
+ long_run(destination_host, "/bin/bash /root/migration_clean_pre.sh")
396
+
397
+ # Chroot into the new environment
398
+ destination_host.puts("chroot /mnt/migration_target /bin/bash")
399
+
400
+ # Set host prompt, etc
401
+ destination_host.puts("export PS1='#{CloudFlock::Remote::SSH::PROMPT} '")
402
+ destination_host.get_root('')
403
+
404
+ # Perform chroot steps
405
+ long_run(destination_host, "/bin/bash /root/migration_clean_chroot.sh")
406
+ destination_host.puts("rm -f /root/migration_clean_chroot.sh")
407
+ destination_host.prompt
408
+
409
+ # Add Rack Connect and Managed users
410
+ cleanup_manage_destination(destination_host)
411
+ cleanup_rackconnect_destination(destination_host)
412
+
413
+ destination_host.puts("exit")
414
+ destination_host.prompt
415
+
416
+ # Perform post-chroot steps
417
+ long_run(destination_host, "/bin/bash /root/migration_clean_post.sh")
418
+ end
419
+
420
+ # Internal: Insure that new output is being produced by a running process
421
+ # which is expected to run over an indeterminate amount of time to catch
422
+ # hanging processes, but not punish properly running ones.
423
+ #
424
+ # host - SSH object pointing to the host in question.
425
+ # command - String containing the command to be executed.
426
+ # timeout - Fixnum containing the maximum number of seconds for new output
427
+ # to be produced. (default: 30)
428
+ #
429
+ # Returns nothing.
430
+ # Raises any exception passed other than Timeout::Error (IE ProcessError).
431
+ def long_run(host, command, timeout=30)
432
+ unless host.kind_of?(CloudFlock::Remote::SSH)
433
+ raise ArgumentError, "Host must be a SSH Object"
434
+ end
435
+ unless command.kind_of?(String)
436
+ raise ArgumentError, "Command must be a String"
437
+ end
438
+
439
+ last_line = ''
440
+ newline_count = 0
441
+ fail_count = 0
442
+ fail_max = 10
443
+
444
+ host.puts(command.strip)
445
+ host.set_timeout(timeout) do
446
+ begin
447
+ host.prompt
448
+ rescue Timeout::Error
449
+ lines = host.buffer.split(/\n/)
450
+ current_line = lines[-1]
451
+ current_count = lines.length
452
+
453
+ if last_line == current_line && newline_count == current_count
454
+ fail_count += 1
455
+ raise LongRunFailed if fail_count == fail_max
456
+ else
457
+ fail_count = 0
458
+ last_line = current_line
459
+ newline_count = current_count
460
+ end
461
+
462
+ retry
463
+ end
464
+ end
465
+ end
466
+ end
@@ -0,0 +1,97 @@
1
+ require 'cloudflock/target/servers/platform'
2
+
3
+ # Public: Serves as a small class to easily map host specifications to Image
4
+ # and Flavor IDs in Rackspace Cloud.
5
+ #
6
+ # Examples
7
+ #
8
+ # # Build platform data for a given CPE object
9
+ # platform = Platform.new(cpe)
10
+ # platform.image_id
11
+ # # => Fixnum
12
+ class CloudFlock::Target::Servers::Platform::V1 <
13
+ CloudFlock::Target::Servers::Platform
14
+ # Public: Build the class constant Hashes for mapping given Platforms to
15
+ # Rackspace Cloud Image IDs.
16
+ #
17
+ # Returns nothing.
18
+ def build_image_maps
19
+ self.class.const_set(:UNMANAGED_MAP, {
20
+ amazon:
21
+ {
22
+ "*" => 118
23
+ },
24
+ arch:
25
+ {
26
+ "*" => 118
27
+ },
28
+ centos:
29
+ {
30
+ "5" => 114, "6" => 118
31
+ },
32
+ debian:
33
+ {
34
+ "5" => 103, "6" => 104
35
+ },
36
+ fedora:
37
+ {
38
+ "14" => 106, "15" => 116,
39
+ "16" => 120, "17" => 126
40
+ },
41
+ gentoo:
42
+ {
43
+ "*" => 108
44
+ },
45
+ redhat:
46
+ {
47
+ "5" => 110, "6" => 111
48
+ },
49
+ ubuntu:
50
+ {
51
+ "*" => 10,
52
+ "10.04" => 49, "10.10" => 49,
53
+ "11.04" => 115, "11.10" => 119,
54
+ "12.04" => 125, "12.10" => 125
55
+ }
56
+ })
57
+
58
+ self.class.const_set(:MANAGED_MAP, {
59
+ amazon:
60
+ {
61
+ "*" => 212
62
+ },
63
+ centos:
64
+ {
65
+ "5" => 200, "6" => 212
66
+ },
67
+ redhat:
68
+ {
69
+ "5" => 202, "6" => 204
70
+ },
71
+ ubuntu:
72
+ {
73
+ "*" => 206,
74
+ "10.04" => 206, "10.10" => 206,
75
+ "11.04" => 210, "11.10" => 214,
76
+ "12.04" => 216
77
+ }
78
+ })
79
+ end
80
+
81
+ # Public: Build the class constant Hash for mapping server sizes to available
82
+ # Rackspace Cloud Flavor IDs.
83
+ #
84
+ # Returns nothing.
85
+ def build_flavor_maps
86
+ self.class.const_set(:FLAVOR_LIST, [
87
+ {id: 1, mem: 256, hdd: 10},
88
+ {id: 2, mem: 512, hdd: 20},
89
+ {id: 3, mem: 1024, hdd: 40},
90
+ {id: 4, mem: 2048, hdd: 80},
91
+ {id: 5, mem: 4096, hdd: 160},
92
+ {id: 6, mem: 8192, hdd: 320},
93
+ {id: 7, mem: 15872, hdd: 620},
94
+ {id: 8, mem: 30720, hdd: 1200}
95
+ ])
96
+ end
97
+ end
@@ -0,0 +1,93 @@
1
+ require 'cloudflock/target/servers/platform'
2
+
3
+ # Public: Override the Platform class provided by the servers provider to build
4
+ # Image ID maps corresponding to to Rackspace Open Cloud UUIDs.
5
+ class CloudFlock::Target::Servers::Platform::V2 <
6
+ CloudFlock::Target::Servers::Platform
7
+ # Public: Build the class constant Hashes for mapping given Platforms to
8
+ # Rackspace Open Cloud Image IDs.
9
+ #
10
+ # Returns nothing.
11
+ def build_image_maps
12
+ self.class.const_set(:UNMANAGED_MAP, {
13
+ amazon:
14
+ {
15
+ "*" => "a3a2c42f-575f-4381-9c6d-fcd3b7d07d17"
16
+ },
17
+ arch:
18
+ {
19
+ "*" => "c94f5e59-0760-467a-ae70-9a37cfa6b94e"
20
+ },
21
+ centos:
22
+ {
23
+ "5" => "03318d19-b6e6-4092-9b5c-4758ee0ada60",
24
+ "6" => "a3a2c42f-575f-4381-9c6d-fcd3b7d07d17"
25
+ },
26
+ debian:
27
+ {
28
+ "6" => "a10eacf7-ac15-4225-b533-5744f1fe47c1"
29
+ },
30
+ fedora:
31
+ {
32
+ "16" => "bca91446-e60e-42e7-9e39-0582e7e20fb9",
33
+ "17" => "d42f821e-c2d1-4796-9f07-af5ed7912d0e"
34
+ },
35
+ gentoo:
36
+ {
37
+ "*" => "110d5bd8-a0dc-4cf5-8e75-149a58c17bbf"
38
+ },
39
+ redhat:
40
+ {
41
+ "5" => "644be485-411d-4bac-aba5-5f60641d92b5",
42
+ "6" => "d6dd6c70-a122-4391-91a8-decb1a356549"
43
+ },
44
+ ubuntu:
45
+ {
46
+ "10.04" => "d531a2dd-7ae9-4407-bb5a-e5ea03303d98",
47
+ "11.04" => "8bf22129-8483-462b-a020-1754ec822770",
48
+ "11.10" => "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",
49
+ "12.04" => "5cebb13a-f783-4f8c-8058-c4182c724ccd"
50
+ }
51
+ })
52
+
53
+ self.class.const_set(:MANAGED_MAP, {
54
+ amazon:
55
+ {
56
+ "*" => "c195ef3b-9195-4474-b6f7-16e5bd86acd0"
57
+ },
58
+ centos:
59
+ {
60
+ "5" => "03318d19-b6e6-4092-9b5c-4758ee0ada60",
61
+ "6" => "c195ef3b-9195-4474-b6f7-16e5bd86acd0"
62
+ },
63
+ redhat:
64
+ {
65
+ "5" => "644be485-411d-4bac-aba5-5f60641d92b5",
66
+ "6" => "d6dd6c70-a122-4391-91a8-decb1a356549"
67
+ },
68
+ ubuntu:
69
+ {
70
+ "10.04" => "d531a2dd-7ae9-4407-bb5a-e5ea03303d98",
71
+ "11.04" => "8bf22129-8483-462b-a020-1754ec822770",
72
+ "11.10" => "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",
73
+ "12.04" => "5cebb13a-f783-4f8c-8058-c4182c724ccd"
74
+ }
75
+ })
76
+ end
77
+
78
+ # Public: Build the class constant Hash for mapping server sizes to available
79
+ # Rackspace Cloud Flavor IDs.
80
+ #
81
+ # Returns nothing.
82
+ def build_flavor_maps
83
+ self.class.const_set(:FLAVOR_LIST, [
84
+ {id: 2, mem: 512, hdd: 20},
85
+ {id: 3, mem: 1024, hdd: 40},
86
+ {id: 4, mem: 2048, hdd: 80},
87
+ {id: 5, mem: 4096, hdd: 160},
88
+ {id: 6, mem: 8192, hdd: 320},
89
+ {id: 7, mem: 15872, hdd: 620},
90
+ {id: 8, mem: 30720, hdd: 1200}
91
+ ])
92
+ end
93
+ end