CloudyScripts 0.0.5 → 0.0.6
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.
- data/Rakefile +1 -1
- data/lib/help/ec2_helper.rb +54 -0
- data/lib/scripts/ec2/ami2_ebs_conversion.rb +0 -1
- metadata +3 -2
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 = '0.0.
|
15
|
+
s.version = '0.0.6'
|
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.'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "AWS"
|
2
|
+
|
3
|
+
# Implements some helper methods around the EC2 API and methods that are
|
4
|
+
# not yet implemented in the amazon-ec2 gem
|
5
|
+
|
6
|
+
class AWS::EC2::Base
|
7
|
+
def describe_instance_attribute(options)
|
8
|
+
params = {}
|
9
|
+
params["InstanceId"] = options[:instance_id].to_s
|
10
|
+
params["Attribute"] = "rootDeviceName" unless options[:attributes][:rootDeviceName] == nil
|
11
|
+
return response_generator(:action => "DescribeInstanceAttribute", :params => params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Ec2Helper
|
16
|
+
# expects an instance of AWS::EC2::Base from the amazon-ec2 gem
|
17
|
+
def initialize(ec2_api)
|
18
|
+
@ec2_api = ec2_api
|
19
|
+
end
|
20
|
+
|
21
|
+
# Checks if the specified volume is acting as a root-device for the instance
|
22
|
+
# to which it is attached. It therefore first calls ec2_describe_volumes() to
|
23
|
+
# retrieve the instance linked to the volume specified, then calls
|
24
|
+
# ec2_describe_instance_attribute() to retrieve the rootDeviceName of that
|
25
|
+
# instance, and finally calls describe_instances() to retrieve all volumes
|
26
|
+
# to check against volume_id and rootDeviceName.
|
27
|
+
def is_root_device?(volume_id)
|
28
|
+
vols = @ec2_api.describe_volumes(:volume_id => volume_id)
|
29
|
+
if vols['volumeSet']['item'][0]['attachmentSet'] == nil || vols['volumeSet']['item'][0]['attachmentSet']['item'].size == 0
|
30
|
+
#not linked to any instance, cannot be a root-device
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
instance_id = vols['volumeSet']['item'][0]['attachmentSet']['item'][0]['instanceId']
|
34
|
+
res = @ec2_api.describe_instance_attribute(:instance_id => instance_id, :attributes => {:rootDeviceName => true})
|
35
|
+
if res["rootDeviceName"] == nil
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
rdn = res['rootDeviceName']['value']
|
39
|
+
res = @ec2_api.describe_instances(:instance_id => instance_id)
|
40
|
+
if res['reservationSet']['item'][0]['instancesSet']['item'][0]['blockDeviceMapping']['item'].size == 0
|
41
|
+
# volume unattached in the meantime
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
attached = res['reservationSet']['item'][0]['instancesSet']['item'][0]['blockDeviceMapping']['item']
|
45
|
+
attached.each() {|ebs|
|
46
|
+
volume = ebs['ebs']['volumeId']
|
47
|
+
device_name = ebs['deviceName']
|
48
|
+
if volume == volume_id && rdn == device_name
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
}
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
end
|
@@ -154,7 +154,6 @@ class Ami2EbsConversion < Ec2Script
|
|
154
154
|
@logger.debug "start up AMI #{@context[:ami_id]}"
|
155
155
|
res = @context[:ec2_api_handler].run_instances(:image_id => @context[:ami_id],
|
156
156
|
:security_group => @context[:security_group_name], :key_name => @context[:key_name])
|
157
|
-
puts "res = #{res.inspect}"#TODO:remove
|
158
157
|
instance_id = res['instancesSet']['item'][0]['instanceId']
|
159
158
|
@context[:instance_id] = instance_id
|
160
159
|
@logger.info "started instance #{instance_id}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CloudyScripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Jung
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-11 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- lib/cloudyscripts.rb
|
49
49
|
- lib/help/dm_crypt_helper.rb
|
50
|
+
- lib/help/ec2_helper.rb
|
50
51
|
- lib/help/remote_command_handler.rb
|
51
52
|
- lib/help/script_execution_state.rb
|
52
53
|
- lib/help/state_change_listener.rb
|