CloudyScripts 2.14.62 → 2.14.63

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.
@@ -42,8 +42,9 @@ class CopyMsWindowsAmi < Ec2Script
42
42
  end
43
43
 
44
44
  def check_input_parameters()
45
+ post_message("Checking parameters...")
45
46
  # MS Windows AMI, source and target region
46
- if @input_params[:ami_id] == nil && !(@input_params[:ami_id] =~ /^ami-.*$/)
47
+ if @input_params[:ami_id] == nil || !(@input_params[:ami_id] =~ /^ami-.*$/)
47
48
  raise Exception.new("Invalid AMI ID specified: #{@input_params[:ami_id]}")
48
49
  end
49
50
  if @local_ec2_helper.ami_prop(@input_params[:ami_id], 'rootDeviceType') != "ebs"
@@ -73,7 +74,6 @@ class CopyMsWindowsAmi < Ec2Script
73
74
  @input_params[:source_security_group] = "default"
74
75
  end
75
76
  if !@local_ec2_helper.check_open_port(@input_params[:source_security_group], 22)
76
- #raise Exception.new("Port 22 must be opened for security group '#{@input_params[:source_security_group]}' to connect via SSH in source region")
77
77
  post_message("'#{@input_params[:source_security_group]}' Security Group not opened port 22 for connect via SSH in source region")
78
78
  @input_params[:source_security_group] = nil
79
79
  else
@@ -83,12 +83,32 @@ class CopyMsWindowsAmi < Ec2Script
83
83
  @input_params[:target_security_group] = "default"
84
84
  end
85
85
  if !@remote_ec2_helper.check_open_port(@input_params[:target_security_group], 22)
86
- #raise Exception.new("Port 22 must be opened for security group '#{@input_params[:target_security_group]}' to connect via SSH in target region")
87
86
  post_message("'#{@input_params[:target_security_group]}' Security Group not opened port 22 for connect via SSH in target region")
88
87
  @input_params[:target_security_group] = nil
89
88
  else
90
89
  post_message("'#{@input_params[:target_security_group]}' Security Group opened port 22 for connect via SSH in target region")
91
90
  end
91
+ # AWS KeyPair, source an dtarget
92
+ if @input_params[:source_key_name] == nil || @input_params[:source_key_name].empty?()
93
+ raise Exception.new("No Key Pair name specified for source region")
94
+ else
95
+ begin
96
+ @local_ec2_helper.check_keypair(@input_params[:source_key_name])
97
+ rescue Exception => e
98
+ post_message("'#{@input_params[:source_key_name]}' Key Pair not found in source region")
99
+ raise Exception.new("Key Pair not found in source region: #{e.to_s}")
100
+ end
101
+ end
102
+ if @input_params[:target_key_name] == nil || @input_params[:target_key_name].empty?()
103
+ raise Exception.new("No Key Pair name specified for target region")
104
+ else
105
+ begin
106
+ @remote_ec2_helper.check_keypair(@input_params[:target_key_name])
107
+ rescue Exception => e
108
+ post_message("'#{@input_params[:target_key_name]}' Key Pair not found in target region")
109
+ raise Exception.new("Key Pair not found in target region: #{e.to_s}")
110
+ end
111
+ end
92
112
  # Device to use for volume
93
113
  if @input_params[:root_device_name] == nil
94
114
  @input_params[:root_device_name] = "/dev/sda1"
@@ -109,9 +129,30 @@ class CopyMsWindowsAmi < Ec2Script
109
129
  if @input_params[:target_ssh_username] == nil
110
130
  @input_params[:target_ssh_username] = "root"
111
131
  end
132
+ if @input_params[:source_ssh_keydata] == nil
133
+ raise Exception.new("No Private Key for source region")
134
+ else
135
+ begin
136
+ check_ssh_key(@input_params[:source_ssh_keydata])
137
+ rescue Exception => e
138
+ post_message("not a Private Key: #{e.to_s}")
139
+ raise Exception.new("Invalid Private Key for source region: #{e.to_s}")
140
+ end
141
+ end
142
+ if @input_params[:target_ssh_keydata] == nil
143
+ raise Exception.new("No Private Key for target region")
144
+ else
145
+ begin
146
+ check_ssh_key(@input_params[:target_ssh_keydata])
147
+ rescue Exception => e
148
+ post_message("not a Private Key:: #{e.to_s}")
149
+ raise Exception.new("Invalid Private Key for target region: #{e.to_s}")
150
+ end
151
+ end
112
152
  if @input_params[:fs_type] == nil
113
153
  @input_params[:fs_type] = "ext3"
114
154
  end
155
+ # AWS Name and Description
115
156
  if @input_params[:description] == nil || !check_aws_desc(@input_params[:description])
116
157
  @input_params[:description] = "Created by CloudyScripts - #{self.class.name}"
117
158
  end
@@ -237,7 +278,7 @@ class CopyMsWindowsAmi < Ec2Script
237
278
  @context[:source_volume_id] = create_volume_from_snapshot(@context[:snapshot_id],
238
279
  @context[:source_availability_zone])
239
280
  source_device = @context[:device_name]
240
- attach_volume(@context[:source_volume_id], @context[:source_instance_id], source_device)
281
+ attach_volume(@context[:source_volume_id], @context[:source_instance_id], source_device, Ec2Script::CS_AWS_TIMEOUT)
241
282
  connect(@context[:source_dns_name], @context[:source_ssh_username], nil, @context[:source_ssh_keydata])
242
283
  # detect if there is a shift for device mapping (between AWS and the operating system of the system)
243
284
  root_device_name = get_root_device_name()
@@ -259,7 +300,7 @@ class CopyMsWindowsAmi < Ec2Script
259
300
  # Step2: create and attach a temp volume of the same size to dump and compress the entire drive
260
301
  @context[:source_temp_volume_id] = create_volume(@context[:source_availability_zone], @context[:volume_size])
261
302
  temp_device = @context[:temp_device_name]
262
- attach_volume(@context[:source_temp_volume_id], @context[:source_instance_id], temp_device)
303
+ attach_volume(@context[:source_temp_volume_id], @context[:source_instance_id], temp_device, Ec2Script::CS_AWS_TIMEOUT)
263
304
  aws_device_letter = temp_device.split('/')[2].gsub('sd', '').gsub('xvd', '').gsub(/[0-9]/, '')
264
305
  while !aws_letter.eql?(os_letter)
265
306
  aws_letter.succ!
@@ -328,7 +369,7 @@ class CopyMsWindowsAmi < Ec2Script
328
369
  # Step1: create and attach a temp volume for receiving archive of the drive
329
370
  @context[:target_temp_volume_id] = create_volume(@context[:target_availability_zone], @context[:volume_size])
330
371
  temp_device = @context[:temp_device_name]
331
- attach_volume(@context[:target_temp_volume_id], @context[:target_instance_id], temp_device)
372
+ attach_volume(@context[:target_temp_volume_id], @context[:target_instance_id], temp_device, Ec2Script::CS_AWS_TIMEOUT)
332
373
  connect(@context[:target_dns_name], @context[:target_ssh_username], nil, @context[:target_ssh_keydata])
333
374
  # detect if there is a shift for device mapping (between AWS and the operating system of the system)
334
375
  root_device_name = get_root_device_name()
@@ -353,7 +394,7 @@ class CopyMsWindowsAmi < Ec2Script
353
394
  # Step3: create and attach a volume for uncompressing and restoring the entire drive
354
395
  @context[:target_volume_id] = create_volume(@context[:target_availability_zone], @context[:volume_size])
355
396
  target_device = @context[:device_name]
356
- attach_volume(@context[:target_volume_id], @context[:target_instance_id], target_device)
397
+ attach_volume(@context[:target_volume_id], @context[:target_instance_id], target_device, Ec2Script::CS_AWS_TIMEOUT)
357
398
  aws_device_letter = target_device.split('/')[2].gsub('sd', '').gsub('xvd', '').gsub(/[0-9]/, '')
358
399
  if !aws_letter.eql?(os_letter)
359
400
  post_message("Detected specific kernel with shift between AWS and Kernel OS for device naming")
@@ -470,7 +511,7 @@ class CopyMsWindowsAmi < Ec2Script
470
511
  stop_instance(@context[:helper_instance_id])
471
512
  root_volume_id = get_root_volume_id(@context[:helper_instance_id])
472
513
  detach_volume(root_volume_id, @context[:helper_instance_id])
473
- attach_volume(@context[:target_volume_id], @context[:helper_instance_id], @context[:helper_root_device_name])
514
+ attach_volume(@context[:target_volume_id], @context[:helper_instance_id], @context[:helper_root_device_name], Ec2Script::CS_AWS_TIMEOUT)
474
515
  start_instance(@context[:helper_instance_id])
475
516
 
476
517
  #XXX: return running instance for now
@@ -505,34 +546,100 @@ class CopyMsWindowsAmi < Ec2Script
505
546
  class AmiRegisteredState < CopyMsWindowsAmiState
506
547
  def enter()
507
548
  post_message("Cleaning Source and Target Regions...")
549
+ error = []
508
550
  local_region()
509
- connect(@context[:source_dns_name], @context[:source_ssh_username], nil, @context[:source_ssh_keydata])
510
- mount_point = "/mnt/tmp_#{@context[:source_temp_volume_id]}"
511
- unmount_fs(mount_point)
512
- disconnect()
513
- detach_volume(@context[:source_temp_volume_id], @context[:source_instance_id])
514
- detach_volume(@context[:source_volume_id], @context[:source_instance_id])
515
- shut_down_instance(@context[:source_instance_id])
516
- delete_volume(@context[:source_temp_volume_id])
517
- delete_volume(@context[:source_volume_id])
551
+ begin
552
+ connect(@context[:source_dns_name], @context[:source_ssh_username], nil, @context[:source_ssh_keydata])
553
+ mount_point = "/mnt/tmp_#{@context[:source_temp_volume_id]}"
554
+ unmount_fs(mount_point)
555
+ disconnect()
556
+ rescue Exception => e
557
+ error << e
558
+ post_message("Unable to umount temporary volume '/mnt/tmp_#{@context[:source_temp_volume_id]}' in source region: #{e.to_s}")
559
+ end
560
+ begin
561
+ detach_volume(@context[:source_temp_volume_id], @context[:source_instance_id])
562
+ rescue Exception => e
563
+ error << e
564
+ post_message("Unable to detach temporary volume '#{@context[:source_temp_volume_id]}' in source region: #{e.to_s}")
565
+ end
566
+ begin
567
+ detach_volume(@context[:source_volume_id], @context[:source_instance_id])
568
+ rescue Exception => e
569
+ error << e
570
+ post_message("Unable to detach volume '#{@context[:source_volume_id]}' in source region: #{e.to_s}")
571
+ end
572
+ begin
573
+ shut_down_instance(@context[:source_instance_id])
574
+ rescue Exception => e
575
+ error << e
576
+ post_message("Unable to shutdown instance '#{@context[:source_instance_id]}' in source region: #{e.to_s}")
577
+ end
578
+ begin
579
+ delete_volume(@context[:source_temp_volume_id])
580
+ rescue Exception => e
581
+ error << e
582
+ post_message("Unable to delete volume '#{@context[:source_temp_volume_id]}' in source region: #{e.to_s}")
583
+ end
584
+ begin
585
+ delete_volume(@context[:source_volume_id])
586
+ rescue Exception => e
587
+ error << e
588
+ post_message("Unable to delete volume '#{@context[:source_volume_id]}' in source region: #{e.to_s}")
589
+ end
590
+
518
591
  #XXX: delete Security Group according to its name
519
592
  if @context[:source_security_group].eql?(Ec2Script::CS_SEC_GRP_NAME)
520
- delete_security_group(@context[:source_security_group])
593
+ begin
594
+ delete_security_group(@context[:source_security_group])
595
+ rescue Exception => e
596
+ error << e
597
+ post_message("Unable to delete Security Group '#{@context[:source_security_group]}' in source region: #{e.to_s}")
598
+ end
521
599
  end
522
600
 
523
601
  #
524
602
  remote_region()
525
- connect(@context[:target_dns_name], @context[:target_ssh_username], nil, @context[:target_ssh_keydata])
526
- mount_point = "/mnt/tmp_#{@context[:target_temp_volume_id]}"
527
- unmount_fs(mount_point)
528
- disconnect()
529
- detach_volume(@context[:target_temp_volume_id], @context[:target_instance_id])
530
- shut_down_instance(@context[:target_instance_id])
531
- delete_volume(@context[:target_temp_volume_id])
603
+ begin
604
+ connect(@context[:target_dns_name], @context[:target_ssh_username], nil, @context[:target_ssh_keydata])
605
+ mount_point = "/mnt/tmp_#{@context[:target_temp_volume_id]}"
606
+ unmount_fs(mount_point)
607
+ disconnect()
608
+ rescue Exception => e
609
+ error << e
610
+ post_message("Unable to umount temporary volume '/mnt/tmp_#{@context[:target_temp_volume_id]}' in target region: #{e.to_s}")
611
+ end
612
+ begin
613
+ detach_volume(@context[:target_temp_volume_id], @context[:target_instance_id])
614
+ rescue Exception => e
615
+ error << e
616
+ post_message("Unable to detach temporary volume '#{@context[:target_temp_volume_id]}' in target region: #{e.to_s}")
617
+ end
618
+ begin
619
+ shut_down_instance(@context[:target_instance_id])
620
+ rescue Exception => e
621
+ error << e
622
+ post_message("Unable to shutdown instance '#{@context[:target_instance_id]}' in target region: #{e.to_s}")
623
+ end
624
+ begin
625
+ delete_volume(@context[:target_temp_volume_id])
626
+ rescue Exception => e
627
+ error << e
628
+ post_message("Unable to delete temporary volume '#{@context[:target_temp_volume_id]}' in target region: #{e.to_s}")
629
+ end
532
630
  #delete_volume(@context[:target_volume_id])
533
631
  #XXX: delete Security Group according to its name
534
632
  if @context[:target_security_group].eql?(Ec2Script::CS_SEC_GRP_NAME)
535
- delete_security_group(@context[:target_security_group])
633
+ begin
634
+ delete_security_group(@context[:target_security_group])
635
+ rescue Exception => e
636
+ error << e
637
+ post_message("Unable to delete Security Group '#{@context[:target_security_group]}' in target region: #{e.to_s}")
638
+ end
639
+ end
640
+
641
+ if error.size() > 0
642
+ raise Exception.new("Cleanup error(s)")
536
643
  end
537
644
 
538
645
  Done.new(@context)
@@ -71,6 +71,17 @@ class CopyMsWindowsSnapshot < Ec2Script
71
71
  else
72
72
  post_message("'#{@input_params[:target_security_group]}' Security Group opened port 22 for connect via SSH in target region")
73
73
  end
74
+ # AWS KeyPair, source an dtarget
75
+ if @input_params[:source_key_name] == nil || @input_params[:source_key_name].empty?()
76
+ raise Exception.new("No KeyPair name specified for source region")
77
+ else
78
+ @local_ec2_helper.check_keypair(@input_params[:source_key_name])
79
+ end
80
+ if @input_params[:target_key_name] == nil || @input_params[:target_key_name].empty?()
81
+ raise Exception.new("No KeyPair name specified for target region")
82
+ else
83
+ @remote_ec2_helper.check_keypair(@input_params[:target_key_name])
84
+ end
74
85
  # Device to use for volume
75
86
  if @input_params[:root_device_name] == nil
76
87
  @input_params[:root_device_name] = "/dev/sda1"
@@ -91,9 +102,22 @@ class CopyMsWindowsSnapshot < Ec2Script
91
102
  if @input_params[:target_ssh_username] == nil
92
103
  @input_params[:target_ssh_username] = "root"
93
104
  end
105
+ if @input_params[:source_ssh_keydata] == nil
106
+ raise Exception.new("No Private Key for source region")
107
+ else
108
+ post_message("Checking SSH key for source region...")
109
+ check_ssh_key(@input_params[:source_ssh_keydata])
110
+ end
111
+ if @input_params[:target_ssh_keydata] == nil
112
+ raise Exception.new("No Private Key for target region")
113
+ else
114
+ post_message("Checking SSH key for target region...")
115
+ check_ssh_key(@input_params[:target_ssh_keydata])
116
+ end
94
117
  if @input_params[:fs_type] == nil
95
118
  @input_params[:fs_type] = "ext3"
96
119
  end
120
+ # AWS Name and Description
97
121
  if @input_params[:description] == nil || !check_aws_desc(@input_params[:description])
98
122
  @input_params[:description] = "Created by CloudyScripts - #{self.class.name}"
99
123
  end
@@ -186,7 +210,7 @@ class CopyMsWindowsSnapshot < Ec2Script
186
210
  @context[:source_volume_id] = create_volume_from_snapshot(@context[:snapshot_id],
187
211
  @context[:source_availability_zone])
188
212
  source_device = @context[:device_name]
189
- attach_volume(@context[:source_volume_id], @context[:source_instance_id], source_device)
213
+ attach_volume(@context[:source_volume_id], @context[:source_instance_id], source_device, Ec2Script::CS_AWS_TIMEOUT)
190
214
  connect(@context[:source_dns_name], @context[:source_ssh_username], nil, @context[:source_ssh_keydata])
191
215
  # detect if there is a shift for device mapping (between AWS and the operating system of the system)
192
216
  root_device_name = get_root_device_name()
@@ -212,7 +236,7 @@ class CopyMsWindowsSnapshot < Ec2Script
212
236
  @context[:source_temp_volume_id] = create_volume(@context[:source_availability_zone], @context[:volume_size] + 4)
213
237
  end
214
238
  temp_device = @context[:temp_device_name]
215
- attach_volume(@context[:source_temp_volume_id], @context[:source_instance_id], temp_device)
239
+ attach_volume(@context[:source_temp_volume_id], @context[:source_instance_id], temp_device, Ec2Script::CS_AWS_TIMEOUT)
216
240
  aws_device_letter = temp_device.split('/')[2].gsub('sd', '').gsub('xvd', '').gsub(/[0-9]/, '')
217
241
  while !aws_letter.eql?(os_letter)
218
242
  aws_letter.succ!
@@ -291,7 +315,7 @@ class CopyMsWindowsSnapshot < Ec2Script
291
315
  @context[:target_temp_volume_id] = create_volume(@context[:target_availability_zone], @context[:volume_size] + 4)
292
316
  end
293
317
  temp_device = @context[:temp_device_name]
294
- attach_volume(@context[:target_temp_volume_id], @context[:target_instance_id], temp_device)
318
+ attach_volume(@context[:target_temp_volume_id], @context[:target_instance_id], temp_device, Ec2Script::CS_AWS_TIMEOUT)
295
319
  connect(@context[:target_dns_name], @context[:target_ssh_username], nil, @context[:target_ssh_keydata])
296
320
  # detect if there is a shift for device mapping (between AWS and the operating system of the system)
297
321
  root_device_name = get_root_device_name()
@@ -316,7 +340,7 @@ class CopyMsWindowsSnapshot < Ec2Script
316
340
  # Step3: create and attach a volume for uncompressing and restoring the entire drive
317
341
  @context[:target_volume_id] = create_volume(@context[:target_availability_zone], @context[:volume_size])
318
342
  target_device = @context[:device_name]
319
- attach_volume(@context[:target_volume_id], @context[:target_instance_id], target_device)
343
+ attach_volume(@context[:target_volume_id], @context[:target_instance_id], target_device, Ec2Script::CS_AWS_TIMEOUT)
320
344
  aws_device_letter = target_device.split('/')[2].gsub('sd', '').gsub('xvd', '').gsub(/[0-9]/, '')
321
345
  if !aws_letter.eql?(os_letter)
322
346
  post_message("Detected specific kernel with shift between AWS and Kernel OS for device naming")
@@ -38,6 +38,17 @@ class CopySnapshot< Ec2Script
38
38
 
39
39
  def check_input_parameters()
40
40
  local_ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
41
+ remote_ec2_helper = Ec2Helper.new(@input_params[:target_ec2_handler])
42
+ if @input_params[:source_key_name] == nil || @input_params[:source_key_name].empty?()
43
+ raise Exception.new("No KeyPair name specified for source region")
44
+ else
45
+ local_ec2_helper.check_keypair(@input_params[:source_key_name])
46
+ end
47
+ if @input_params[:target_key_name] == nil || @input_params[:target_key_name].empty?()
48
+ raise Exception.new("No KeyPair name specified for target region")
49
+ else
50
+ remote_ec2_helper.check_keypair(@input_params[:target_key_name])
51
+ end
41
52
  if @input_params[:source_security_group] == nil
42
53
  @input_params[:source_security_group] = "default"
43
54
  end
@@ -47,8 +58,7 @@ class CopySnapshot< Ec2Script
47
58
  else
48
59
  post_message("'#{@input_params[:source_security_group]}' Security Group opened port 22 for connect via SSH in source region")
49
60
  end
50
- remote_ec2_helper = Ec2Helper.new(@input_params[:target_ec2_handler])
51
- if @input_params[:target_security_group] == nil
61
+ if @input_params[:target_security_group] == nil
52
62
  @input_params[:target_security_group] = "default"
53
63
  end
54
64
  if !remote_ec2_helper.check_open_port(@input_params[:target_security_group], 22)
@@ -63,6 +73,18 @@ class CopySnapshot< Ec2Script
63
73
  if @input_params[:target_ssh_username] == nil
64
74
  @input_params[:target_ssh_username] = "root"
65
75
  end
76
+ if @input_params[:source_ssh_keydata] == nil
77
+ raise Exception.new("No Private Key for source region")
78
+ else
79
+ post_message("Checking SSH key for source region...")
80
+ check_ssh_key(@input_params[:source_ssh_keydata])
81
+ end
82
+ if @input_params[:target_ssh_keydata] == nil
83
+ raise Exception.new("No Private Key for target region")
84
+ else
85
+ post_message("Checking SSH key for target region...")
86
+ check_ssh_key(@input_params[:target_ssh_keydata])
87
+ end
66
88
  if @input_params[:description] == nil || !check_aws_desc(@input_params[:description])
67
89
  @input_params[:description] = "Created by CloudyScripts - #{self.class.name}"
68
90
  end
@@ -123,7 +145,7 @@ class CopySnapshot< Ec2Script
123
145
  @context[:source_availability_zone])
124
146
  device = "/dev/sdj" #TODO: make device configurable
125
147
  mount_point = "/mnt/tmp_#{@context[:source_volume_id]}"
126
- attach_volume(@context[:source_volume_id], @context[:source_instance_id], device)
148
+ attach_volume(@context[:source_volume_id], @context[:source_instance_id], device, Ec2Script::CS_AWS_TIMEOUT)
127
149
  connect(@context[:source_dns_name], @context[:source_ssh_username], nil, @context[:source_ssh_keydata])
128
150
  mount_fs(mount_point, device)
129
151
  # get partition label and filesystem type
@@ -168,7 +190,7 @@ class CopySnapshot< Ec2Script
168
190
  @context[:target_volume_id] = create_volume(@context[:target_availability_zone], volume_size)
169
191
  device = "/dev/sdj" #TODO: make device configurable
170
192
  mount_point = "/mnt/tmp_#{@context[:target_volume_id]}"
171
- attach_volume(@context[:target_volume_id], @context[:target_instance_id], device)
193
+ attach_volume(@context[:target_volume_id], @context[:target_instance_id], device, Ec2Script::CS_AWS_TIMEOUT)
172
194
  connect(@context[:target_dns_name], @context[:target_ssh_username], nil, @context[:target_ssh_keydata])
173
195
  create_labeled_fs(@context[:target_dns_name], device, @context[:fs_type], @context[:label])
174
196
  mount_fs(mount_point, device)
@@ -4,6 +4,7 @@ require "help/remote_command_handler"
4
4
  require "help/dm_crypt_helper"
5
5
  require "help/ec2_helper"
6
6
  require "AWS"
7
+ require "help/helper"
7
8
 
8
9
  # Script to download a specific snapshot as ZIP
9
10
  # * create a specific instance (with Apache Server),
@@ -34,6 +35,7 @@ class DownloadSnapshot < Ec2Script
34
35
  end
35
36
 
36
37
  def check_input_parameters()
38
+ post_message("Checking parameters...")
37
39
  if @input_params[:security_group_name] == nil
38
40
  @input_params[:security_group_name] = "default"
39
41
  end
@@ -41,16 +43,27 @@ class DownloadSnapshot < Ec2Script
41
43
  if @input_params[:security_group_name] == nil
42
44
  @input_params[:security_group_name] = "default"
43
45
  end
46
+ # AWS Security Group
44
47
  if !ec2_helper.check_open_port(@input_params[:security_group_name], 22)
45
- #raise Exception.new("Port 22 must be opened for security group #{@input_params[:security_group_name]} to connect via SSH")
46
48
  post_message("'#{@input_params[:security_group_name]}' Security Group not opened port 22 for connect via SSH")
47
49
  @input_params[:security_group_name] = nil
48
50
  end
49
- if !ec2_helper.check_open_port(@input_params[:security_group_name], 80)
50
- #raise Exception.new("Port 80 must be opened for security group #{@input_params[:security_group_name]} to make the download link work")
51
+ if @input_params[:security_group_name] != nil && !ec2_helper.check_open_port(@input_params[:security_group_name], 80)
51
52
  post_message("'#{@input_params[:security_group_name]}' Security Group not opened port 80 for download via HTTP")
52
53
  @input_params[:security_group_name] = nil
53
54
  end
55
+ # AWS KeyPair
56
+ if @input_params[:key_name] == nil || @input_params[:key_name].empty?()
57
+ raise Exception.new("No KeyPair name specified")
58
+ else
59
+ begin
60
+ ec2_helper.check_keypair(@input_params[:key_name])
61
+ rescue Exception => e
62
+ post_message("'#{@input_params[:key_name]}' Key pair not found")
63
+ raise Exception.new("#{e.to_s}")
64
+ end
65
+ end
66
+ # Device, Directory and file name
54
67
  if @input_params[:source_device] == nil
55
68
  @input_params[:source_device] = "/dev/sdj"
56
69
  end
@@ -66,9 +79,16 @@ class DownloadSnapshot < Ec2Script
66
79
  if @input_params[:wait_time] == nil
67
80
  @input_params[:wait_time] = 300
68
81
  end
82
+ # SSH Parameters
69
83
  if @input_params[:ssh_username] == nil
70
84
  @input_params[:ssh_username] = "root"
71
85
  end
86
+ if @input_params[:ssh_keydata] == nil
87
+ raise Exception.new("No Private Key for source region")
88
+ else
89
+ post_message("Checking SSH key for source region...")
90
+ check_ssh_key(@input_params[:ssh_keydata])
91
+ end
72
92
  end
73
93
 
74
94
  # Load the initial state for the script.
@@ -126,8 +146,8 @@ class DownloadSnapshot < Ec2Script
126
146
  class VolumesCreated < DownloadSnapshotState
127
147
  def enter
128
148
  @context[:script].post_message("Going to create two volumes. One with the snapshot data, one to store the zipped data for download.")
129
- attach_volume(@context[:source_volume_id], @context[:instance_id], @context[:source_device])
130
- attach_volume(@context[:dest_volume_id], @context[:instance_id], @context[:dest_device])
149
+ attach_volume(@context[:source_volume_id], @context[:instance_id], @context[:source_device], Ec2Script::CS_AWS_TIMEOUT)
150
+ attach_volume(@context[:dest_volume_id], @context[:instance_id], @context[:dest_device], Ec2Script::CS_AWS_TIMEOUT)
131
151
 
132
152
  VolumesAttached.new(@context)
133
153
  end
@@ -149,11 +169,12 @@ class DownloadSnapshot < Ec2Script
149
169
  @context[:script].post_message("Using '#{@context[:source_device]}' as source filesystem")
150
170
  end
151
171
  mount_fs(source_dir, @context[:source_device])
152
- @context[:fs_type], @context[:label] = get_partition_fs_type_and_label(source_dir)
172
+ #XXX: filesystem type and device label do not matter as we are creating an archive of the filesystem
173
+ #@context[:fs_type], @context[:label] = get_partition_fs_type_and_label(source_dir)
153
174
  # target
154
175
  dest_dir = @context[:zip_file_dest]
155
- #create_fs(@context[:dns_name], @context[:dest_device])
156
- create_labeled_fs(@context[:dns_name], @context[:dest_device], @context[:fs_type], @context[:label])
176
+ create_fs(@context[:dns_name], @context[:dest_device])
177
+ #create_labeled_fs(@context[:dns_name], @context[:dest_device], @context[:fs_type], @context[:label])
157
178
  mount_fs(dest_dir, @context[:dest_device])
158
179
 
159
180
  FileSystemsReady.new(@context)