zergrush_cf 0.0.14 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2MxMTBlMWMzNDIwODZlYzcyMzI2ZTE5ZWI1YjMyZjFhMjc5Mzk3ZA==
4
+ MDU0MGY0MTA4MGVkNDAwNjEzNTg1YzlhZWZhMDFiOTg2ODBmMGZjNw==
5
5
  data.tar.gz: !binary |-
6
- NTMxZGI0MTMzNTU2ZjRiZjRlMmJlNDgwZjljMDI2MjE3NjM2YjJhMA==
6
+ NmZiZDEwZjY0NmQwOWRiNDNjMTZhZTkxMDViMjYzMzdjNGNiYTg3MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Yjc0MjNjMDdhOTYxNDZhZTNiNWRhNGY4NWU5NDg4MTBkYTA2MmM0NDZhN2U0
10
- YTBjN2QwYTJlNTk0M2MxODYxODZjZWEzZTBiNGNjYTllMDdjMzQyN2EyYjE5
11
- NTUxOTU0NjQwYThlZWQ2YmRmMWM4NTlhMjMzMzE3NTY0YzUyYjM=
9
+ NzFmYmM5MDJmODA4ZTY0ZWFmZjE4YTNhN2NmYzVjYmE0MjM4OWMzZjJjYTE3
10
+ ZDBmNGFjNTQ1ODQzMTIxZDA0YzM4OGVkMWE1YzZjMGYzOTAyZGYwNDIzZDZl
11
+ ODMyYTU3OGQ5NWM5M2ExOTM3ZDllOTI2ZDg4NDJlNDEyNjdkNWQ=
12
12
  data.tar.gz: !binary |-
13
- ZWU1MzcyZDc0OWM0ZTRlZDE0NzQxNjQ4Zjg3ZWEzZmIyNGU2MzBjZjFlYTRh
14
- MTdiZGNhNjhjNDVlMWY3NGE1Y2EzYmRiZTMyOTg5YWQ2ZDVhOTVmZTgyZjlj
15
- ODM1MGM2OGQ1YWM2YTI0ZDA0YTUzYTg5NDY1ZTRmODg2M2VjNGM=
13
+ YjZiMTE2NGZlNzQ5MWZjZDdiYzRjZjAxYTM0MDU0NDE4MWM2ZjFjMmM4ODRi
14
+ N2RiYjhlYmFhN2NkNzVlZGU1NWU2ZDI1NTcxNzY4MmNjMTE1NzUwOWI4MjE5
15
+ ZjVkZGRiYWUyZjJjYTM1ZGQ1NWQ1YmM5ZWJmM2IwOWY5NmVmZGE=
@@ -274,6 +274,80 @@ class CloudFormation < ZergGemPlugin::Plugin "/driver"
274
274
  abort ("ERROR: AWS error: #{fog_cf_error.ai}")
275
275
  end
276
276
 
277
+ def snapshot hive_location, task_name, task_hash, base
278
+ aws_key_id = task_hash["vm"]["driver"]["driveroptions"][0]["access_key_id"]
279
+ aws_secret = task_hash["vm"]["driver"]["driveroptions"][0]["secret_access_key"]
280
+
281
+ # eval possible environment variables
282
+ if aws_key_id =~ /^ENV\['.+'\]$/
283
+ aws_key_id = eval(aws_key_id)
284
+ end
285
+
286
+ if aws_secret =~ /^ENV\['.+'\]$/
287
+ aws_secret = eval(aws_secret)
288
+ end
289
+
290
+ abort("AWS key id is not specified in task") unless aws_key_id != nil
291
+ abort("AWS secret is not specified in task") unless aws_secret != nil
292
+
293
+ base_name = (base.nil?) ? "#{task_name}" : base
294
+
295
+ puts("creating AMI Snapshots of all EC2 instances. Will use base name of #{base_name}")
296
+
297
+ cf = Fog::AWS::CloudFormation.new(
298
+ :aws_access_key_id => aws_key_id,
299
+ :aws_secret_access_key => aws_secret
300
+ )
301
+
302
+ fogCompute = Fog::Compute.new(
303
+ :provider => 'AWS',
304
+ :aws_access_key_id => aws_key_id,
305
+ :aws_secret_access_key => aws_secret
306
+ )
307
+
308
+ rabbit_objects = initRabbitConnection(task_hash["vm"]["driver"]["driveroptions"][0]["rabbit"])
309
+
310
+ # create the cloudformation stack
311
+ stack_name = "#{task_name}"
312
+ processStack(stack_name, base_name, cf, fogCompute)
313
+ return 0
314
+
315
+ rescue Fog::Errors::Error => fog_cf_error
316
+ abort ("ERROR: AWS error: #{fog_cf_error.message}")
317
+ end
318
+
319
+ def processStack stack_name, base_name, fogCF, fogCompute
320
+ fogCF.describe_stack_resources({ 'StackName' => stack_name })[:body]['StackResources'].each { |stack_resource|
321
+ if stack_resource['ResourceType'] == 'AWS::EC2::Instance'
322
+ saveAmi(stack_resource, base_name, fogCompute)
323
+ elsif stack_resource['ResourceType'] == 'AWS::CloudFormation::Stack'
324
+ processStack(stack_resource['PhysicalResourceId'].split('/')[1], base_name, fogCF, fogCompute)
325
+ end
326
+ }
327
+ end
328
+
329
+ def saveAmi ec2res, base_name, fogCompute
330
+ liveInstance = fogCompute.describe_instances({ 'instance-id' => ec2res['PhysicalResourceId'] })[:body]
331
+ nameTag = liveInstance['reservationSet'][0]['instancesSet'][0]['tagSet']['Name'].split(':')[1].downcase
332
+
333
+ ap "Creating AMI #{base_name}-#{nameTag}. Stack resource:"
334
+ ap ec2res
335
+
336
+ imageSet = fogCompute.describe_images( { 'name' => "#{base_name}-#{nameTag}" } )[:body]
337
+ imageSet['imagesSet'].each { |image|
338
+ imageId = image['imageId']
339
+ ap "Deregistering old image #{imageId}..."
340
+ response = fogCompute.deregister_image(imageId)
341
+ abort("ERROR: deregistering #{imageId} failed!") unless response[:body]['return'] == 'true'
342
+ }
343
+
344
+ ap 'Saving new image...'
345
+ newId = fogCompute.create_image(ec2res['PhysicalResourceId'], "#{base_name}-#{nameTag}", "#{base_name}-#{nameTag} snapshot")[:body]['imageId']
346
+ ap "Created new AMI #{newId}"
347
+ ap "Tagging #{newId} with #{base_name}"
348
+ fogCompute.create_tags(newId, { base_name => base_name })
349
+ end
350
+
277
351
  def logEvents events
278
352
  events.each do |event|
279
353
  puts "Timestamp: #{Time.parse(event['Timestamp'].to_s).iso8601}"
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module ZergrushCF
25
- VERSION = "0.0.14"
25
+ VERSION = "0.0.17"
26
26
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_development_dependency "bundler", ">= 1.0.0"
19
19
  s.add_development_dependency "rake"
20
- s.add_development_dependency "zergrush", ">= 0.0.21"
20
+ s.add_development_dependency "zergrush", ">= 0.0.24"
21
21
 
22
22
  s.add_dependency "fog", ">=1.20.0"
23
23
  s.add_dependency "bunny", ">=1.2.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zergrush_cf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - MTN Satellite Communications
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.21
47
+ version: 0.0.24
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.21
54
+ version: 0.0.24
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: fog
57
57
  requirement: !ruby/object:Gem::Requirement