CloudyScripts 2.14.50 → 2.14.52
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ require 'rake/testtask'
|
|
12
12
|
|
13
13
|
spec = Gem::Specification.new do |s|
|
14
14
|
s.name = 'CloudyScripts'
|
15
|
-
s.version = '2.14.
|
15
|
+
s.version = '2.14.52' #<number cloud-stacks supported>.<number cloud-scripts>.<counting releases>
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
|
18
18
|
s.summary = 'Scripts to facilitate programming for infrastructure clouds.'
|
@@ -513,6 +513,15 @@ module StateTransitionHelper
|
|
513
513
|
return image_id
|
514
514
|
end
|
515
515
|
|
516
|
+
# Create an AMI from an EC2 instance
|
517
|
+
def create_image_from_instance(instance_id, name, description)
|
518
|
+
post_message("going to create AMI from instance #{instance_id}...")
|
519
|
+
@logger.debug "create AMI from instance #{instance_id} as #{name}"
|
520
|
+
res = ec2_handler().create_image(:instance_id => instance_id, :name => name, :description => description)
|
521
|
+
image_id = res['imageId']
|
522
|
+
return image_id
|
523
|
+
end
|
524
|
+
|
516
525
|
# Create a file-system on a given machine (assumes to be connected already).
|
517
526
|
# Input Parameters:
|
518
527
|
# * dns_name => IP used
|
@@ -4,7 +4,6 @@ require "help/remote_command_handler"
|
|
4
4
|
require "help/dm_crypt_helper"
|
5
5
|
require "help/ec2_helper"
|
6
6
|
require "AWS"
|
7
|
-
require 'pp'
|
8
7
|
|
9
8
|
# Copy a given snapshot to another region
|
10
9
|
# * start up instance in source-region, create a snapshot from the mounted EBS
|
@@ -141,23 +140,19 @@ class CopyMsWindowsAmi < Ec2Script
|
|
141
140
|
#NB: if we do not own this AMI, we have no snapshot, so we must launch an instance
|
142
141
|
class InitialState < CopyMsWindowsAmiState
|
143
142
|
def enter()
|
143
|
+
post_message("Retrieving AMI parammeters (snapshot ID, volume size, architecture)...")
|
144
144
|
local_region()
|
145
|
-
puts "Retrieving AMI parammeters"
|
146
145
|
@context[:snapshot_id] = @local_ec2_helper.ami_blkdevmap_ebs_prop(@context[:ami_id], 'snapshotId')
|
147
146
|
@context[:volume_size] = @local_ec2_helper.ami_blkdevmap_ebs_prop(@context[:ami_id], 'volumeSize')
|
148
147
|
@context[:architecture] = @local_ec2_helper.ami_prop(@context[:ami_id], 'architecture')
|
149
148
|
@context[:root_device_name] = @local_ec2_helper.ami_prop(@context[:ami_id], 'rootDeviceName')
|
150
|
-
|
151
|
-
#@context[:source_availability_zone] = "us-east-1a" unless @context[:source_availability_zone] != nil
|
152
|
-
#@context[:target_availability_zone] = "us-west-1a" unless @context[:target_availability_zone] != nil
|
153
|
-
|
149
|
+
|
154
150
|
#try to access snapshot, if not possible, launch and stop an AMI to create one
|
155
151
|
if !snapshot_accessible(@context[:snapshot_id])
|
156
|
-
|
157
|
-
|
152
|
+
post_message("The AMI's snapshot is NOT accessible, we must launch an instance to create one")
|
153
|
+
InitialStateLaunch.new(@context)
|
158
154
|
end
|
159
155
|
|
160
|
-
#raise Exception.new("DEBUG: FORCED Script exit")
|
161
156
|
InitialStateDone.new(@context)
|
162
157
|
end
|
163
158
|
end
|
@@ -165,15 +160,15 @@ class CopyMsWindowsAmi < Ec2Script
|
|
165
160
|
# Consitionnal State (launching an instance and creating a snapshot)
|
166
161
|
class InitialStateLaunch < CopyMsWindowsAmiState
|
167
162
|
def enter()
|
163
|
+
post_message("Launching and stopping an instance of the AMI to create a snapshot")
|
168
164
|
local_region()
|
169
|
-
puts "Launching and stopping an instance of the AMI to create a snapshot"
|
170
165
|
result = launch_instance(@context[:ami_id], @context[:source_key_name], @context[:source_security_groups])
|
171
166
|
instance_id = result.first
|
172
|
-
|
173
|
-
|
167
|
+
post_message("Instance launched with ID: #{instance_id}")
|
168
|
+
post_message("Waiting 3 minutes before stopping instance '#{instance_id}' for creating a Snapshot of the rootDevice")
|
174
169
|
sleep(180)
|
175
170
|
stop_instance(instance_id)
|
176
|
-
|
171
|
+
post_message("Instance '#{instance_id}' stopped, creating snapshot")
|
177
172
|
ebs_volume_id = ec2_helper.get_attached_volumes(instance_id)[0]['volumeId']
|
178
173
|
@context[:snapshot_id] = create_snapshot(ebs_volume_id, "Cloudy_Scripts Snapshot for copying AMIs")
|
179
174
|
|
@@ -184,14 +179,13 @@ class CopyMsWindowsAmi < Ec2Script
|
|
184
179
|
# Initial state: Launch an Amazon Linux AMI in the source Region
|
185
180
|
class InitialStateDone < CopyMsWindowsAmiState
|
186
181
|
def enter()
|
182
|
+
post_message("Launching an Helper instance in the source Region...")
|
187
183
|
local_region()
|
188
184
|
result = launch_instance(@context[:source_ami_id], @context[:source_key_name], @context[:source_security_groups])
|
189
185
|
@context[:source_instance_id] = result.first
|
190
186
|
@context[:source_dns_name] = result[1]
|
191
187
|
@context[:source_availability_zone] = result[2]
|
192
|
-
#@context[:source_root_device_name] = @local_ec2_helper.ami_prop(@context[:source_ami_id], 'rootDeviceName')
|
193
188
|
@context[:source_root_device_name] = result[6]
|
194
|
-
puts "DEBUG: Parameters: #{@context[:source_instance_id]}, #{@context[:source_dns_name]}, #{@context[:source_availability_zone]}, #{@context[:source_root_device_name]}"
|
195
189
|
|
196
190
|
SourceInstanceLaunchedState.new(@context)
|
197
191
|
end
|
@@ -205,6 +199,7 @@ class CopyMsWindowsAmi < Ec2Script
|
|
205
199
|
# - dump and compress the entire drive to the temp volume
|
206
200
|
class SourceInstanceLaunchedState < CopyMsWindowsAmiState
|
207
201
|
def enter()
|
202
|
+
post_message("Attaching volumes to the helper instance in the source Region...")
|
208
203
|
local_region()
|
209
204
|
# Step1: create and attach a volume from the Snapshot of the AMI to copy
|
210
205
|
@context[:source_volume_id] = create_volume_from_snapshot(@context[:snapshot_id],
|
@@ -276,9 +271,7 @@ class CopyMsWindowsAmi < Ec2Script
|
|
276
271
|
@context[:target_instance_id] = result.first
|
277
272
|
@context[:target_dns_name] = result[1]
|
278
273
|
@context[:target_availability_zone] = result[2]
|
279
|
-
#@context[:remote_root_device_name] = @remote_ec2_helper.ami_prop(@context[:target_ami_id], 'rootDeviceName')
|
280
274
|
@context[:target_root_device_name] = result[6]
|
281
|
-
puts "DEBUG: Parameters: #{@context[:target_instance_id]}, #{@context[:target_dns_name]}, #{@context[:target_availability_zone]}, #{@context[:target_root_device_name]}"
|
282
275
|
|
283
276
|
TargetInstanceLaunchedState.new(@context)
|
284
277
|
end
|
@@ -430,6 +423,7 @@ class CopyMsWindowsAmi < Ec2Script
|
|
430
423
|
@context[:helper_availability_zone] = result[2]
|
431
424
|
@context[:helper_root_device_name] = result[6]
|
432
425
|
|
426
|
+
post_message("Creating NEW AMI using instance #{@context[:helper_instance_id]}...")
|
433
427
|
#XXX:
|
434
428
|
# - wait for it to be running, and then stop it
|
435
429
|
# - wait for it to be stopped, and then start it with the new volume
|
@@ -446,8 +440,8 @@ class CopyMsWindowsAmi < Ec2Script
|
|
446
440
|
stop_instance(@context[:helper_instance_id])
|
447
441
|
|
448
442
|
#XXX: register as AMI
|
449
|
-
new_ami_id =
|
450
|
-
|
443
|
+
new_ami_id = create_image_from_instance(@context[:helper_instance_id], @context[:name], @context[:description])
|
444
|
+
post_message("New AMI created with ID: #{new_ami_id}")
|
451
445
|
@context[:result][:image_id] = new_ami_id
|
452
446
|
|
453
447
|
AmiRegisteredState.new(@context)
|
@@ -120,12 +120,8 @@ class CopyMsWindowsSnapshot < Ec2Script
|
|
120
120
|
class InitialState < CopyMsWindowsSnapshotState
|
121
121
|
def enter()
|
122
122
|
local_region()
|
123
|
-
|
123
|
+
post_message("Retrieving Snapshot parammeters (volume size)")
|
124
124
|
@context[:volume_size] = @local_ec2_helper.snapshot_prop(@context[:snapshot_id], :volumeSize).to_i
|
125
|
-
#puts "Setting Source and Target Availability Zone if not set"
|
126
|
-
#@context[:source_availability_zone] = "us-east-1a" unless @context[:source_availability_zone] != nil
|
127
|
-
#@context[:target_availability_zone] = "us-west-1a" unless @context[:target_availability_zone] != nil
|
128
|
-
puts "DEBUG: Parameters: #{@context[:snapshot_id]}, #{@context[:volume_size]}"
|
129
125
|
|
130
126
|
InitialStateDone.new(@context)
|
131
127
|
end
|
@@ -135,13 +131,12 @@ class CopyMsWindowsSnapshot < Ec2Script
|
|
135
131
|
class InitialStateDone < CopyMsWindowsSnapshotState
|
136
132
|
def enter()
|
137
133
|
local_region()
|
134
|
+
post_mesage("Lunching an Helper instance in source Region...")
|
138
135
|
result = launch_instance(@context[:source_ami_id], @context[:source_key_name], @context[:source_security_groups])
|
139
136
|
@context[:source_instance_id] = result.first
|
140
137
|
@context[:source_dns_name] = result[1]
|
141
138
|
@context[:source_availability_zone] = result[2]
|
142
|
-
#@context[:source_root_device_name] = @local_ec2_helper.ami_prop(@context[:source_ami_id], 'rootDeviceName')
|
143
139
|
@context[:source_root_device_name] = result[6]
|
144
|
-
puts "DEBUG: Parameters: #{@context[:source_instance_id]}, #{@context[:source_dns_name]}, #{@context[:source_availability_zone]}, #{@context[:source_root_device_name]}"
|
145
140
|
|
146
141
|
SourceInstanceLaunchedState.new(@context)
|
147
142
|
end
|
@@ -226,9 +221,7 @@ class CopyMsWindowsSnapshot < Ec2Script
|
|
226
221
|
@context[:target_instance_id] = result.first
|
227
222
|
@context[:target_dns_name] = result[1]
|
228
223
|
@context[:target_availability_zone] = result[2]
|
229
|
-
#@context[:remote_root_device_name] = @remote_ec2_helper.ami_prop(@context[:target_ami_id], 'rootDeviceName')
|
230
224
|
@context[:target_root_device_name] = result[6]
|
231
|
-
puts "DEBUG: Parameters: #{@context[:target_instance_id]}, #{@context[:target_dns_name]}, #{@context[:target_availability_zone]}, #{@context[:target_root_device_name]}"
|
232
225
|
|
233
226
|
TargetInstanceLaunchedState.new(@context)
|
234
227
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CloudyScripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 95
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 14
|
9
|
-
-
|
10
|
-
version: 2.14.
|
9
|
+
- 52
|
10
|
+
version: 2.14.52
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthias Jung
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-02-23 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|