grempe-amazon-ec2 0.2.15 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ec2-gem-example.rb +8 -7
- data/lib/EC2/responses.rb +20 -131
- data/lib/EC2/snapshots.rb +95 -0
- data/lib/EC2/volumes.rb +171 -0
- data/lib/EC2.rb +1 -1
- data/test/test_EC2_availability_zones.rb +1 -1
- data/test/test_EC2_console.rb +1 -1
- data/test/test_EC2_elastic_ips.rb +5 -5
- data/test/test_EC2_image_attributes.rb +9 -9
- data/test/test_EC2_images.rb +4 -4
- data/test/test_EC2_instances.rb +7 -7
- data/test/test_EC2_keypairs.rb +3 -3
- data/test/test_EC2_products.rb +1 -1
- data/test/test_EC2_responses.rb +13 -63
- data/test/test_EC2_security_groups.rb +5 -5
- data/test/test_EC2_snapshots.rb +83 -0
- data/test/test_EC2_volumes.rb +144 -0
- metadata +8 -28
data/bin/ec2-gem-example.rb
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
|
12
12
|
require 'rubygems'
|
13
13
|
require File.dirname(__FILE__) + '/../lib/EC2'
|
14
|
+
require 'pp'
|
14
15
|
|
15
16
|
# pull these from the local shell environment variables set in ~/.bash_login
|
16
17
|
# or using appropriate methods specific to your login shell.
|
@@ -36,23 +37,23 @@ p ec2.methods.sort
|
|
36
37
|
|
37
38
|
puts "----- listing images owned by 'amazon' -----"
|
38
39
|
ec2.describe_images(:owner_id => "amazon").imagesSet.item.each do |image|
|
39
|
-
image.
|
40
|
-
puts "#{
|
40
|
+
image.keys.each do |key|
|
41
|
+
puts "#{key} => #{image[key]}"
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
45
|
puts "----- listing all running instances -----"
|
45
|
-
|
46
|
+
pp ec2.describe_instances()
|
46
47
|
|
47
48
|
puts "----- creating a security group -----"
|
48
|
-
|
49
|
+
pp ec2.create_security_group(:group_name => "ec2-example-rb-test-group", :group_description => "ec-example.rb test group description.")
|
49
50
|
|
50
51
|
puts "----- listing security groups -----"
|
51
|
-
|
52
|
+
pp ec2.describe_security_groups()
|
52
53
|
|
53
54
|
puts "----- deleting a security group -----"
|
54
|
-
|
55
|
+
pp ec2.delete_security_group(:group_name => "ec2-example-rb-test-group")
|
55
56
|
|
56
57
|
puts "----- listing my keypairs (verbose mode) -----"
|
57
|
-
|
58
|
+
pp ec2.describe_keypairs()
|
58
59
|
|
data/lib/EC2/responses.rb
CHANGED
@@ -8,6 +8,17 @@
|
|
8
8
|
# Home:: http://amazon-ec2.rubyforge.org
|
9
9
|
#++
|
10
10
|
|
11
|
+
# This allows us to access hash values as if they were methods
|
12
|
+
# e.g. foo[:bar] can be accessed as foo.bar
|
13
|
+
|
14
|
+
class Hash
|
15
|
+
def method_missing(meth, *args, &block)
|
16
|
+
if args.size == 0
|
17
|
+
self[meth.to_s] || self[meth.to_sym]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
module EC2
|
12
23
|
|
13
24
|
# The make_request() and ec2_error? methods, which are shared by all, will raise any
|
@@ -23,14 +34,6 @@ module EC2
|
|
23
34
|
# may be raised by this library in YOUR code with a 'rescue' clauses. It is up to you
|
24
35
|
# how gracefully you want to handle these exceptions that are raised.
|
25
36
|
|
26
|
-
# Credits :
|
27
|
-
# I learned the magic of making an OpenStruct object able to respond as a fully Enumerable
|
28
|
-
# object (responds to .each, etc.) thanks to a great blog article on Struct and OpenStruct
|
29
|
-
# at http://errtheblog.com/post/30
|
30
|
-
#
|
31
|
-
# Thanks to Sean Knapp for the XmlSimple response patch which greatly simplified the response
|
32
|
-
# mechanism for the whole library while making it more accurate and much less brittle to boot!
|
33
|
-
#
|
34
37
|
|
35
38
|
require 'rubygems'
|
36
39
|
begin
|
@@ -39,137 +42,23 @@ module EC2
|
|
39
42
|
require 'xml-simple' unless defined? XmlSimple
|
40
43
|
end
|
41
44
|
|
42
|
-
|
43
|
-
class Response < OpenStruct
|
44
|
-
|
45
|
-
include Enumerable
|
46
|
-
|
45
|
+
class Response
|
47
46
|
|
48
47
|
def self.parse(options = {})
|
49
48
|
options = {
|
50
49
|
:xml => "",
|
51
50
|
:parse_options => { 'ForceArray' => ['item'], 'SuppressEmpty' => nil }
|
52
51
|
}.merge(options)
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
58
|
-
response
|
52
|
+
|
53
|
+
# NOTE: Parsing the response as a nested set of Response objects was extremely
|
54
|
+
# memory intensive and appeared to leak (the memory was not freed on subsequent requests).
|
55
|
+
# It was changed to return the raw XmlSimple response.
|
56
|
+
|
57
|
+
response = XmlSimple.xml_in(options[:xml], options[:parse_options])
|
58
|
+
|
59
59
|
return response
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
# Every member of an OpenStruct object has getters and setters, the latter of which
|
64
|
-
# has a method ending in "=". Find all of these methods, excluding those defined on
|
65
|
-
# parent classes.
|
66
|
-
def members
|
67
|
-
methods(false).sort.grep(/=/).map { |m| m[0...-1] }
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
# Required by the Enumerable module. Iterate over each item in the members array
|
72
|
-
# and pass as a value the block passed to each using yield.
|
73
|
-
def each
|
74
|
-
members.each do |method|
|
75
|
-
yield send(method)
|
76
|
-
end
|
77
|
-
self
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
# Same as the each method, but with both key and value.
|
82
|
-
#
|
83
|
-
#Sample Use:
|
84
|
-
# obj.each_pair { |k,v| puts "key: #{k}, value: #{v}" }
|
85
|
-
def each_pair
|
86
|
-
members.each do |method|
|
87
|
-
yield method, send(method)
|
88
|
-
end
|
89
|
-
self
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
# Alternative method for getting members.
|
94
|
-
def [](member)
|
95
|
-
send(member)
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
# Alternative method for setting members.
|
100
|
-
def []=(member, value)
|
101
|
-
send("#{member}=", value)
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
# Helper for converting to string which support a long and short version
|
106
|
-
# to avoid recursion problems with parents.
|
107
|
-
def to_string(short=false)
|
108
|
-
s = "#<#{self.class}:0x#{(2 ** 32 + object_id).to_s(16).upcase}"
|
109
|
-
if (short)
|
110
|
-
s += " ..."
|
111
|
-
else
|
112
|
-
each_pair { |k,v|
|
113
|
-
if (v == self.parent && v.kind_of?(Response))
|
114
|
-
v = v.to_string(true)
|
115
|
-
elsif (v.kind_of?(String))
|
116
|
-
v = "\"#{v.gsub("\"", "\\\"")}\""
|
117
|
-
elsif (v.kind_of?(NilClass))
|
118
|
-
v = "nil"
|
119
|
-
end
|
120
|
-
s += " #{k}=#{v}"
|
121
|
-
}
|
122
|
-
end
|
123
|
-
s += ">"
|
124
|
-
return s
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
# Override of to string method.
|
129
|
-
def to_s
|
130
|
-
return to_string
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
private
|
135
|
-
|
136
|
-
# Initialize the object by passing data to the OpenStruct initialize method
|
137
|
-
# and then converting ourself to guarantee we have top-to-bottom data
|
138
|
-
# representation as a Response object.
|
139
|
-
def initialize(data, parent=nil)
|
140
|
-
super(data)
|
141
|
-
self.parent = parent
|
142
|
-
Response.convert(self, parent)
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
# The "brains" of our Response class. This method takes an arbitray object and
|
147
|
-
# depending on its class attempts to convert it.
|
148
|
-
def self.convert(obj, parent)
|
149
|
-
if (obj.kind_of?(Response))
|
150
|
-
# Recursively convert the object.
|
151
|
-
obj.each_pair { |k,v|
|
152
|
-
if (v != obj.parent)
|
153
|
-
obj[k] = convert(v, obj)
|
154
|
-
end
|
155
|
-
}
|
156
|
-
return obj
|
157
|
-
elsif (obj.kind_of?(Hash))
|
158
|
-
# Hashes make good Responses already thanks to OpenStruct.
|
159
|
-
return Response.new(obj, parent)
|
160
|
-
elsif (obj.kind_of?(Array))
|
161
|
-
# With arrays, make sure each element is appropriately converted.
|
162
|
-
new_arr = []
|
163
|
-
obj.each { |elem|
|
164
|
-
new_arr << convert(elem, parent)
|
165
|
-
}
|
166
|
-
return new_arr
|
167
|
-
else
|
168
|
-
# At this point we're out of ideas, so let's hope it is a string.
|
169
|
-
return obj
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end # class Response < OpenStruct
|
62
|
+
end # class Response
|
174
63
|
|
175
64
|
end # module EC2
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library, EBS snaphshots support
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Yann Klis (mailto:yann.klis@novelys.com)
|
6
|
+
# Copyright:: Copyright (c) 2008 Yann Klis
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://amazon-ec2.rubyforge.org
|
9
|
+
#++
|
10
|
+
|
11
|
+
module EC2
|
12
|
+
|
13
|
+
class Base
|
14
|
+
|
15
|
+
#Amazon Developer Guide Docs:
|
16
|
+
#
|
17
|
+
# The DescribeSnapshots operation describes the status of Amazon EBS snapshots.
|
18
|
+
#
|
19
|
+
#Required Arguments:
|
20
|
+
#
|
21
|
+
# none
|
22
|
+
#
|
23
|
+
#Optional Arguments:
|
24
|
+
#
|
25
|
+
# :snapshot_id => Array (default : [])
|
26
|
+
#
|
27
|
+
|
28
|
+
def describe_snapshots( options = {} )
|
29
|
+
|
30
|
+
options = { :snapshot_id => [] }.merge(options)
|
31
|
+
|
32
|
+
params = pathlist("SnapshotId", options[:snapshot_id] )
|
33
|
+
|
34
|
+
return response_generator(:action => "DescribeSnapshots", :params => params)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
#Amazon Developer Guide Docs:
|
39
|
+
#
|
40
|
+
# The CreateSnapshot operation creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups, to launch instances from identical snapshots, and to save data before shutting down an instance.
|
41
|
+
#
|
42
|
+
#Required Arguments:
|
43
|
+
#
|
44
|
+
# :volume_id => String (default : '')
|
45
|
+
#
|
46
|
+
#Optional Arguments:
|
47
|
+
#
|
48
|
+
# none
|
49
|
+
#
|
50
|
+
|
51
|
+
def create_snapshot( options = {} )
|
52
|
+
|
53
|
+
# defaults
|
54
|
+
options = { :volume_id => '' }.merge(options)
|
55
|
+
|
56
|
+
raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
|
57
|
+
|
58
|
+
params = {
|
59
|
+
"VolumeId" => options[:volume_id]
|
60
|
+
}
|
61
|
+
|
62
|
+
return response_generator(:action => "CreateSnapshot", :params => params)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
#Amazon Developer Guide Docs:
|
67
|
+
#
|
68
|
+
# The DeleteSnapshot operation deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3.
|
69
|
+
#
|
70
|
+
#Required Arguments:
|
71
|
+
#
|
72
|
+
# :snapshot_id => String (default : '')
|
73
|
+
#
|
74
|
+
#Optional Arguments:
|
75
|
+
#
|
76
|
+
# none
|
77
|
+
#
|
78
|
+
|
79
|
+
def delete_snapshot( options = {} )
|
80
|
+
|
81
|
+
options = { :snapshot_id => '' }.merge(options)
|
82
|
+
|
83
|
+
raise ArgumentError, "No :snapshot_id provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
|
84
|
+
|
85
|
+
params = {
|
86
|
+
"SnapshotId" => options[:snapshot_id]
|
87
|
+
}
|
88
|
+
|
89
|
+
return response_generator(:action => "DeleteSnapshot", :params => params)
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
data/lib/EC2/volumes.rb
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library, EBS volumes support
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Yann Klis (mailto:yann.klis@novelys.com)
|
6
|
+
# Copyright:: Copyright (c) 2008 Yann Klis
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://amazon-ec2.rubyforge.org
|
9
|
+
#++
|
10
|
+
|
11
|
+
module EC2
|
12
|
+
|
13
|
+
class Base
|
14
|
+
|
15
|
+
#Amazon Developer Guide Docs:
|
16
|
+
#
|
17
|
+
# The DescribeVolumes operation lists one or more Amazon EBS volumes that you own, If you do not specify any volumes, Amazon EBS returns all volumes that you own.
|
18
|
+
#
|
19
|
+
#Required Arguments:
|
20
|
+
#
|
21
|
+
# none
|
22
|
+
#
|
23
|
+
#Optional Arguments:
|
24
|
+
#
|
25
|
+
# :volume_id => Array (default : [])
|
26
|
+
#
|
27
|
+
|
28
|
+
def describe_volumes( options = {} )
|
29
|
+
|
30
|
+
options = { :volume_id => [] }.merge(options)
|
31
|
+
|
32
|
+
params = pathlist("VolumeId", options[:volume_id] )
|
33
|
+
|
34
|
+
return response_generator(:action => "DescribeVolumes", :params => params)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
#Amazon Developer Guide Docs:
|
39
|
+
#
|
40
|
+
# The CreateVolume operation creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
|
41
|
+
#
|
42
|
+
#Required Arguments:
|
43
|
+
#
|
44
|
+
# :availability_zone => String (default : '')
|
45
|
+
#
|
46
|
+
#Optional Arguments:
|
47
|
+
#
|
48
|
+
# :size => String (default : '')
|
49
|
+
# :snapshot_id => String (default : '')
|
50
|
+
#
|
51
|
+
|
52
|
+
def create_volume( options = {} )
|
53
|
+
|
54
|
+
# defaults
|
55
|
+
options = { :availability_zone => '' }.merge(options)
|
56
|
+
|
57
|
+
raise ArgumentError, "No :availability_zone provided" if options[:availability_zone].nil? || options[:availability_zone].empty?
|
58
|
+
|
59
|
+
options = { :size => '' }.merge(options)
|
60
|
+
options = { :snapshot_id => '' }.merge(options)
|
61
|
+
|
62
|
+
params = {
|
63
|
+
"AvailabilityZone" => options[:availability_zone],
|
64
|
+
"Size" => options[:size],
|
65
|
+
"SnapshotId" => options[:snapshot_id]
|
66
|
+
}
|
67
|
+
|
68
|
+
return response_generator(:action => "CreateVolume", :params => params)
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
#Amazon Developer Guide Docs:
|
73
|
+
#
|
74
|
+
# The DeleteVolume operation deletes an Amazon EBS volume.
|
75
|
+
#
|
76
|
+
#Required Arguments:
|
77
|
+
#
|
78
|
+
# :volume_id => String (default : '')
|
79
|
+
#
|
80
|
+
#Optional Arguments:
|
81
|
+
#
|
82
|
+
# none
|
83
|
+
#
|
84
|
+
|
85
|
+
def delete_volume( options = {} )
|
86
|
+
|
87
|
+
options = { :volume_id => '' }.merge(options)
|
88
|
+
|
89
|
+
raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
|
90
|
+
|
91
|
+
params = {
|
92
|
+
"VolumeId" => options[:volume_id]
|
93
|
+
}
|
94
|
+
|
95
|
+
return response_generator(:action => "DeleteVolume", :params => params)
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
#Amazon Developer Guide Docs:
|
100
|
+
#
|
101
|
+
# The AttachVolume operation attaches an Amazon EBS volume to an instance.
|
102
|
+
#
|
103
|
+
#Required Arguments:
|
104
|
+
#
|
105
|
+
# :volume_id => String (default : '')
|
106
|
+
# :instance_id => String (default : '')
|
107
|
+
# :device => String (default : '')
|
108
|
+
#
|
109
|
+
#Optional Arguments:
|
110
|
+
#
|
111
|
+
# none
|
112
|
+
#
|
113
|
+
|
114
|
+
def attach_volume( options = {} )
|
115
|
+
|
116
|
+
options = { :volume_id => '' }.merge(options)
|
117
|
+
options = { :instance_id => '' }.merge(options)
|
118
|
+
options = { :device => '' }.merge(options)
|
119
|
+
|
120
|
+
raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
|
121
|
+
raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
|
122
|
+
raise ArgumentError, "No :volume_id provided" if options[:device].nil? || options[:device].empty?
|
123
|
+
|
124
|
+
params = {
|
125
|
+
"VolumeId" => options[:volume_id],
|
126
|
+
"InstanceId" => options[:instance_id],
|
127
|
+
"Device" => options[:device]
|
128
|
+
}
|
129
|
+
|
130
|
+
return response_generator(:action => "AttachVolume", :params => params)
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
#Amazon Developer Guide Docs:
|
135
|
+
#
|
136
|
+
# The DetachVolume operation detaches an Amazon EBS volume from an instance.
|
137
|
+
#
|
138
|
+
#Required Arguments:
|
139
|
+
#
|
140
|
+
# :volume_id => String (default : '')
|
141
|
+
#
|
142
|
+
#Optional Arguments:
|
143
|
+
#
|
144
|
+
# :instance_id => String (default : '')
|
145
|
+
# :device => String (default : '')
|
146
|
+
# :force => Boolean (default : '')
|
147
|
+
#
|
148
|
+
|
149
|
+
def detach_volume( options = {} )
|
150
|
+
|
151
|
+
options = { :volume_id => '' }.merge(options)
|
152
|
+
|
153
|
+
raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
|
154
|
+
|
155
|
+
options = { :instance_id => '' }.merge(options)
|
156
|
+
options = { :device => '' }.merge(options)
|
157
|
+
options = { :force => '' }.merge(options)
|
158
|
+
|
159
|
+
params = {
|
160
|
+
"VolumeId" => options[:volume_id],
|
161
|
+
"InstanceId" => options[:instance_id],
|
162
|
+
"Device" => options[:device],
|
163
|
+
"Force" => options[:force]
|
164
|
+
}
|
165
|
+
|
166
|
+
return response_generator(:action => "DetachVolume", :params => params)
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
data/lib/EC2.rb
CHANGED
@@ -22,7 +22,7 @@ module EC2
|
|
22
22
|
DEFAULT_HOST = 'ec2.amazonaws.com'
|
23
23
|
|
24
24
|
# This is the version of the API as defined by Amazon Web Services
|
25
|
-
API_VERSION = '2008-
|
25
|
+
API_VERSION = '2008-05-05'
|
26
26
|
|
27
27
|
# Builds the canonical string for signing. This strips out all '&', '?', and '='
|
28
28
|
# from the query string to be signed.
|
@@ -35,7 +35,7 @@ context "EC2 availability zones" do
|
|
35
35
|
specify "should be able to be described with describe_availability_zones" do
|
36
36
|
@ec2.stubs(:make_request).with('DescribeAvailabilityZones', { "ZoneName.1" => "us-east-1a", "ZoneName.2" => "us-east-1b" }).
|
37
37
|
returns stub(:body => @describe_availability_zones_response_body, :is_a? => true)
|
38
|
-
@ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] ).should.be.an.instance_of
|
38
|
+
@ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] ).should.be.an.instance_of Hash
|
39
39
|
|
40
40
|
response = @ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] )
|
41
41
|
|
data/test/test_EC2_console.rb
CHANGED
@@ -37,7 +37,7 @@ context "The EC2 console " do
|
|
37
37
|
specify "should return info written to a specific instances console" do
|
38
38
|
@ec2.stubs(:make_request).with('GetConsoleOutput', {"InstanceId"=>"i-2ea64347"}).
|
39
39
|
returns stub(:body => @get_console_output_response_body, :is_a? => true)
|
40
|
-
@ec2.get_console_output( :instance_id => "i-2ea64347" ).should.be.an.instance_of
|
40
|
+
@ec2.get_console_output( :instance_id => "i-2ea64347" ).should.be.an.instance_of Hash
|
41
41
|
response = @ec2.get_console_output( :instance_id => "i-2ea64347" )
|
42
42
|
response.instanceId.should.equal "i-28a64341"
|
43
43
|
response.timestamp.should.equal "2007-01-03 15:00:00"
|
@@ -57,7 +57,7 @@ context "EC2 elastic IP addresses " do
|
|
57
57
|
@ec2.stubs(:make_request).with('AllocateAddress', {}).
|
58
58
|
returns stub(:body => @allocate_address_body, :is_a? => true)
|
59
59
|
|
60
|
-
@ec2.allocate_address.should.be.an.instance_of
|
60
|
+
@ec2.allocate_address.should.be.an.instance_of Hash
|
61
61
|
|
62
62
|
response = @ec2.allocate_address
|
63
63
|
response.publicIp.should.equal "67.202.55.255"
|
@@ -79,7 +79,7 @@ context "EC2 elastic IP addresses " do
|
|
79
79
|
@ec2.stubs(:make_request).with('DescribeAddresses', {"PublicIp.1"=>"67.202.55.255"}).
|
80
80
|
returns stub(:body => @describe_addresses_response_body, :is_a? => true)
|
81
81
|
|
82
|
-
@ec2.describe_addresses( :public_ip => "67.202.55.255" ).should.be.an.instance_of
|
82
|
+
@ec2.describe_addresses( :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
|
83
83
|
|
84
84
|
response = @ec2.describe_addresses( :public_ip => "67.202.55.255" )
|
85
85
|
response.addressesSet.item[0].instanceId.should.equal "i-28a64341"
|
@@ -91,7 +91,7 @@ context "EC2 elastic IP addresses " do
|
|
91
91
|
@ec2.stubs(:make_request).with('ReleaseAddress', {"PublicIp" => "67.202.55.255"}).
|
92
92
|
returns stub(:body => @release_address_response_body, :is_a? => true)
|
93
93
|
|
94
|
-
@ec2.release_address( :public_ip => "67.202.55.255" ).should.be.an.instance_of
|
94
|
+
@ec2.release_address( :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
|
95
95
|
|
96
96
|
response = @ec2.release_address( :public_ip => "67.202.55.255" )
|
97
97
|
response.return.should.equal "true"
|
@@ -102,7 +102,7 @@ context "EC2 elastic IP addresses " do
|
|
102
102
|
@ec2.stubs(:make_request).with('AssociateAddress', {"InstanceId" => "i-2ea64347", "PublicIp"=>"67.202.55.255"}).
|
103
103
|
returns stub(:body => @associate_address_response_body, :is_a? => true)
|
104
104
|
|
105
|
-
@ec2.associate_address( :instance_id => "i-2ea64347", :public_ip => "67.202.55.255" ).should.be.an.instance_of
|
105
|
+
@ec2.associate_address( :instance_id => "i-2ea64347", :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
|
106
106
|
|
107
107
|
response = @ec2.associate_address( :instance_id => "i-2ea64347", :public_ip => "67.202.55.255" )
|
108
108
|
response.return.should.equal "true"
|
@@ -124,7 +124,7 @@ context "EC2 elastic IP addresses " do
|
|
124
124
|
@ec2.stubs(:make_request).with('DisassociateAddress', {'PublicIp' => '67.202.55.255'}).
|
125
125
|
returns stub(:body => @disassociate_address_response_body, :is_a? => true)
|
126
126
|
|
127
|
-
@ec2.disassociate_address( :public_ip => "67.202.55.255" ).should.be.an.instance_of
|
127
|
+
@ec2.disassociate_address( :public_ip => "67.202.55.255" ).should.be.an.instance_of Hash
|
128
128
|
|
129
129
|
response = @ec2.disassociate_address( :public_ip => "67.202.55.255" )
|
130
130
|
response.return.should.equal "true"
|
@@ -62,7 +62,7 @@ context "EC2 image_attributes " do
|
|
62
62
|
"UserId.1"=>"123",
|
63
63
|
"Group.1"=>"all"}).
|
64
64
|
returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
65
|
-
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id=>["123"], :group=>["all"]).should.be.an.instance_of
|
65
|
+
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id=>["123"], :group=>["all"]).should.be.an.instance_of Hash
|
66
66
|
end
|
67
67
|
|
68
68
|
|
@@ -72,7 +72,7 @@ context "EC2 image_attributes " do
|
|
72
72
|
"OperationType"=>"add",
|
73
73
|
"Group.1"=>"all"}).
|
74
74
|
returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
75
|
-
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]).should.be.an.instance_of
|
75
|
+
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]).should.be.an.instance_of Hash
|
76
76
|
end
|
77
77
|
|
78
78
|
|
@@ -82,7 +82,7 @@ context "EC2 image_attributes " do
|
|
82
82
|
"OperationType"=>"remove",
|
83
83
|
"Group.1"=>"all"}).
|
84
84
|
returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
85
|
-
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"remove", :group=>["all"]).should.be.an.instance_of
|
85
|
+
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"remove", :group=>["all"]).should.be.an.instance_of Hash
|
86
86
|
end
|
87
87
|
|
88
88
|
|
@@ -95,7 +95,7 @@ context "EC2 image_attributes " do
|
|
95
95
|
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
96
96
|
:attribute=>"launchPermission",
|
97
97
|
:operation_type=>"add",
|
98
|
-
:user_id=>["123"]).should.be.an.instance_of
|
98
|
+
:user_id=>["123"]).should.be.an.instance_of Hash
|
99
99
|
end
|
100
100
|
|
101
101
|
|
@@ -107,7 +107,7 @@ context "EC2 image_attributes " do
|
|
107
107
|
|
108
108
|
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
109
109
|
:attribute=>"productCodes",
|
110
|
-
:product_code=>["774F4FF8"]).should.be.an.instance_of
|
110
|
+
:product_code=>["774F4FF8"]).should.be.an.instance_of Hash
|
111
111
|
end
|
112
112
|
|
113
113
|
|
@@ -124,7 +124,7 @@ context "EC2 image_attributes " do
|
|
124
124
|
:attribute=>"launchPermission",
|
125
125
|
:operation_type=>"add",
|
126
126
|
:user_id=>["123", "345"],
|
127
|
-
:group=>["123", "all"]).should.be.an.instance_of
|
127
|
+
:group=>["123", "all"]).should.be.an.instance_of Hash
|
128
128
|
end
|
129
129
|
|
130
130
|
|
@@ -166,7 +166,7 @@ context "EC2 image_attributes " do
|
|
166
166
|
returns stub(:body => @describe_image_attribute_response_body_launch_permissions, :is_a? => true)
|
167
167
|
|
168
168
|
@ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "launchPermission").
|
169
|
-
should.be.an.instance_of
|
169
|
+
should.be.an.instance_of Hash
|
170
170
|
|
171
171
|
response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission")
|
172
172
|
response.imageId.should.equal "ami-61a54008"
|
@@ -181,7 +181,7 @@ context "EC2 image_attributes " do
|
|
181
181
|
returns stub(:body => @describe_image_attribute_response_body_product_codes, :is_a? => true)
|
182
182
|
|
183
183
|
@ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "productCodes").
|
184
|
-
should.be.an.instance_of
|
184
|
+
should.be.an.instance_of Hash
|
185
185
|
|
186
186
|
response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes")
|
187
187
|
response.imageId.should.equal "ami-61a54008"
|
@@ -214,7 +214,7 @@ context "EC2 image_attributes " do
|
|
214
214
|
@ec2.stubs(:make_request).with('ResetImageAttribute', {"ImageId"=>"ami-61a54008",
|
215
215
|
"Attribute"=>"launchPermission"}).
|
216
216
|
returns stub(:body => @reset_image_attribute_response_body, :is_a? => true)
|
217
|
-
@ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").should.be.an.instance_of
|
217
|
+
@ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").should.be.an.instance_of Hash
|
218
218
|
@ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").return.should.equal "true"
|
219
219
|
end
|
220
220
|
|
data/test/test_EC2_images.rb
CHANGED
@@ -60,7 +60,7 @@ context "An EC2 image " do
|
|
60
60
|
@ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
|
61
61
|
returns stub(:body => @register_image_response_body, :is_a? => true)
|
62
62
|
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
|
63
|
-
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of
|
63
|
+
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of Hash
|
64
64
|
end
|
65
65
|
|
66
66
|
|
@@ -73,9 +73,9 @@ context "An EC2 image " do
|
|
73
73
|
specify "should be able to be described and return the correct Ruby response class for parent and members" do
|
74
74
|
@ec2.stubs(:make_request).with('DescribeImages', {}).
|
75
75
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
76
|
-
@ec2.describe_images.should.be.an.instance_of
|
76
|
+
@ec2.describe_images.should.be.an.instance_of Hash
|
77
77
|
response = @ec2.describe_images
|
78
|
-
response.should.be.an.instance_of
|
78
|
+
response.should.be.an.instance_of Hash
|
79
79
|
end
|
80
80
|
|
81
81
|
|
@@ -182,7 +182,7 @@ context "An EC2 image " do
|
|
182
182
|
specify "should be able to be de-registered" do
|
183
183
|
@ec2.stubs(:make_request).with('DeregisterImage', {"ImageId"=>"ami-61a54008"}).
|
184
184
|
returns stub(:body => @deregister_image_response_body, :is_a? => true)
|
185
|
-
@ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of
|
185
|
+
@ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of Hash
|
186
186
|
@ec2.deregister_image(:image_id => "ami-61a54008" ).return.should.equal "true"
|
187
187
|
end
|
188
188
|
|
data/test/test_EC2_instances.rb
CHANGED
@@ -146,7 +146,7 @@ context "EC2 instances " do
|
|
146
146
|
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
147
147
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
148
148
|
|
149
|
-
@ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of
|
149
|
+
@ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of Hash
|
150
150
|
|
151
151
|
response = @ec2.run_instances( :image_id => "ami-60a54009" )
|
152
152
|
|
@@ -223,27 +223,27 @@ context "EC2 instances " do
|
|
223
223
|
specify "should be able specify an availability_zone" do
|
224
224
|
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "Placement.AvailabilityZone" => "zone123", "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
225
225
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
226
|
-
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :availability_zone => "zone123", :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of
|
226
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :availability_zone => "zone123", :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
|
227
227
|
end
|
228
228
|
|
229
229
|
specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
|
230
230
|
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
231
231
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
232
|
-
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of
|
232
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of Hash
|
233
233
|
end
|
234
234
|
|
235
235
|
|
236
236
|
specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
|
237
237
|
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
238
238
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
239
|
-
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => false ).should.be.an.instance_of
|
239
|
+
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => false ).should.be.an.instance_of Hash
|
240
240
|
end
|
241
241
|
|
242
242
|
|
243
243
|
specify "should be able to be described and return the correct Ruby response class" do
|
244
244
|
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
245
245
|
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
246
|
-
@ec2.describe_instances.should.be.an.instance_of
|
246
|
+
@ec2.describe_instances.should.be.an.instance_of Hash
|
247
247
|
response = @ec2.describe_instances
|
248
248
|
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
249
249
|
end
|
@@ -297,7 +297,7 @@ context "EC2 instances " do
|
|
297
297
|
specify "should be able to be rebooted when provided with an :instance_id" do
|
298
298
|
@ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
|
299
299
|
returns stub(:body => @reboot_instances_response_body, :is_a? => true)
|
300
|
-
@ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal
|
300
|
+
@ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal Hash
|
301
301
|
end
|
302
302
|
|
303
303
|
|
@@ -311,7 +311,7 @@ context "EC2 instances " do
|
|
311
311
|
specify "should be able to be terminated when provided with an :instance_id" do
|
312
312
|
@ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
|
313
313
|
returns stub(:body => @terminate_instances_response_body, :is_a? => true)
|
314
|
-
@ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal
|
314
|
+
@ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal Hash
|
315
315
|
|
316
316
|
@response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
|
317
317
|
|
data/test/test_EC2_keypairs.rb
CHANGED
@@ -69,7 +69,7 @@ context "EC2 keypairs " do
|
|
69
69
|
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
70
70
|
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
71
71
|
|
72
|
-
@ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of
|
72
|
+
@ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of Hash
|
73
73
|
|
74
74
|
response = @ec2.create_keypair( :key_name => "example-key-name" )
|
75
75
|
response.keyName.should.equal "example-key-name"
|
@@ -93,7 +93,7 @@ context "EC2 keypairs " do
|
|
93
93
|
specify "should be able to be described with describe_keypairs" do
|
94
94
|
@ec2.stubs(:make_request).with('DescribeKeyPairs', {"KeyName.1"=>"example-key-name"}).
|
95
95
|
returns stub(:body => @describe_keypairs_response_body, :is_a? => true)
|
96
|
-
@ec2.describe_keypairs( :key_name => "example-key-name" ).should.be.an.instance_of
|
96
|
+
@ec2.describe_keypairs( :key_name => "example-key-name" ).should.be.an.instance_of Hash
|
97
97
|
response = @ec2.describe_keypairs( :key_name => "example-key-name" )
|
98
98
|
response.keySet.item[0].keyName.should.equal "example-key-name"
|
99
99
|
response.keySet.item[0].keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
@@ -103,7 +103,7 @@ context "EC2 keypairs " do
|
|
103
103
|
specify "should be able to be deleted with delete_keypairs" do
|
104
104
|
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
105
105
|
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
106
|
-
@ec2.delete_keypair( :key_name => "example-key-name" ).should.be.an.instance_of
|
106
|
+
@ec2.delete_keypair( :key_name => "example-key-name" ).should.be.an.instance_of Hash
|
107
107
|
response = @ec2.delete_keypair( :key_name => "example-key-name" )
|
108
108
|
response.return.should.equal "true"
|
109
109
|
end
|
data/test/test_EC2_products.rb
CHANGED
@@ -29,7 +29,7 @@ context "An EC2 instance " do
|
|
29
29
|
@ec2.stubs(:make_request).with('ConfirmProductInstance', {"ProductCode"=>"774F4FF8", "InstanceId"=>"i-10a64379"}).
|
30
30
|
returns stub(:body => @confirm_product_instance_response_body, :is_a? => true)
|
31
31
|
|
32
|
-
@ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" ).should.be.an.instance_of
|
32
|
+
@ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" ).should.be.an.instance_of Hash
|
33
33
|
response = @ec2.confirm_product_instance( :product_code => "774F4FF8", :instance_id => "i-10a64379" )
|
34
34
|
response.ownerId.should.equal "254933287430"
|
35
35
|
response.result.should.equal "true"
|
data/test/test_EC2_responses.rb
CHANGED
@@ -21,82 +21,32 @@ context "The Response classes " do
|
|
21
21
|
RESPONSE
|
22
22
|
|
23
23
|
@response = EC2::Response.parse(:xml => @http_xml)
|
24
|
-
|
25
|
-
# test out adding arbitrary new values to the OpenStruct
|
26
|
-
@response.name = "foo"
|
27
|
-
@response.number = '123'
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
specify "should properly run the to_string(short) method for the short version" do
|
32
|
-
# sample response looks like: "#<EC2::Response:0x100A45F2E ...>". Our response should look
|
33
|
-
# exactly the same, except it should have different hex digits in the middle (after 0x)
|
34
|
-
# that are nine chars long.
|
35
|
-
@response.to_string(true).should =~ /^#<EC2::Response:0x[0-9A-F]{1,9} ...>/
|
36
24
|
end
|
37
25
|
|
38
26
|
|
39
|
-
specify "should
|
40
|
-
@response.
|
27
|
+
specify "should show the response as a formatted string when calling #inspect" do
|
28
|
+
@response.inspect.should.equal %{{"return"=>"true", "xmlns"=>"http://ec2.amazonaws.com/doc/2007-03-01"}}
|
41
29
|
end
|
42
30
|
|
43
31
|
|
44
|
-
specify "should
|
45
|
-
@response.
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
specify "should provide the same results from to_s as from to_string(false) " do
|
50
|
-
@response.to_s.should =~ /^#<EC2::Response:0x[0-9A-F]{1,9} name=\"foo\" number=\"123\" parent=nil return=\"true\"/
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
specify "should be a kind of type OpenStruct" do
|
55
|
-
@response.kind_of?(OpenStruct).should.equal true
|
56
|
-
@response.kind_of?(Enumerable).should.equal true
|
32
|
+
specify "should be a Hash" do
|
33
|
+
@response.kind_of?(Hash).should.equal true
|
57
34
|
end
|
58
35
|
|
59
36
|
|
60
37
|
specify "should return its members" do
|
61
|
-
@response.
|
62
|
-
test_array = ["return", "xmlns"
|
63
|
-
@response.
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
specify "should properly respond to its 'each' method" do
|
68
|
-
answer = @response.each do |f| f ; end
|
69
|
-
answer.name.should.equal "foo"
|
70
|
-
answer.number.should.equal '123'
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
specify "should respond to the '[]' method" do
|
75
|
-
@response[:name].should.equal "foo"
|
38
|
+
@response.keys.length.should.equal 2
|
39
|
+
test_array = ["return", "xmlns"].sort
|
40
|
+
@response.keys.sort.should.equal test_array
|
76
41
|
end
|
77
42
|
|
78
43
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
specify "should respond correctly to the 'each_pair' method" do
|
87
|
-
@response.each_pair {|k,v|
|
88
|
-
case k
|
89
|
-
when "name"
|
90
|
-
v.should.equal "foo"
|
91
|
-
when "number"
|
92
|
-
v.should.equal '123'
|
93
|
-
end
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
specify "should return the original amazon XML response in the 'xml' attribute of the response object." do
|
98
|
-
@response.xml.should.equal @http_xml
|
99
|
-
end
|
44
|
+
# Note: since we are now returning a hash of the xml, there should be no need for anyone to re-parse the xml.
|
45
|
+
# Therefore storing the xml on the object is a waste of memory, and is not done.
|
46
|
+
#
|
47
|
+
# specify "should return the original amazon XML response in the 'xml' attribute of the response object." do
|
48
|
+
# @response.xml.should.equal @http_xml
|
49
|
+
# end
|
100
50
|
|
101
51
|
|
102
52
|
end
|
@@ -84,7 +84,7 @@ context "EC2 security groups " do
|
|
84
84
|
specify "should be able to be created" do
|
85
85
|
@ec2.stubs(:make_request).with('CreateSecurityGroup', {"GroupName"=>"WebServers", "GroupDescription"=>"Web"}).
|
86
86
|
returns stub(:body => @create_security_group_response_body, :is_a? => true)
|
87
|
-
@ec2.create_security_group( :group_name => "WebServers", :group_description => "Web" ).should.be.an.instance_of
|
87
|
+
@ec2.create_security_group( :group_name => "WebServers", :group_description => "Web" ).should.be.an.instance_of Hash
|
88
88
|
end
|
89
89
|
|
90
90
|
|
@@ -108,7 +108,7 @@ context "EC2 security groups " do
|
|
108
108
|
specify "should be able to be deleted" do
|
109
109
|
@ec2.stubs(:make_request).with('DeleteSecurityGroup', {"GroupName"=>"WebServers"}).
|
110
110
|
returns stub(:body => @delete_security_group_response_body, :is_a? => true)
|
111
|
-
@ec2.delete_security_group( :group_name => "WebServers" ).should.be.an.instance_of
|
111
|
+
@ec2.delete_security_group( :group_name => "WebServers" ).should.be.an.instance_of Hash
|
112
112
|
end
|
113
113
|
|
114
114
|
|
@@ -128,7 +128,7 @@ context "EC2 security groups " do
|
|
128
128
|
specify "should be able to be described with describe_security_groups" do
|
129
129
|
@ec2.stubs(:make_request).with('DescribeSecurityGroups', { "GroupName.1" => "WebServers", "GroupName.2" => "RangedPortsBySource" }).
|
130
130
|
returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
|
131
|
-
@ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] ).should.be.an.instance_of
|
131
|
+
@ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] ).should.be.an.instance_of Hash
|
132
132
|
|
133
133
|
response = @ec2.describe_security_groups( :group_name => ["WebServers", "RangedPortsBySource"] )
|
134
134
|
|
@@ -178,7 +178,7 @@ context "EC2 security groups " do
|
|
178
178
|
:cidr_ip => "0.0.0.0/24",
|
179
179
|
:source_security_group_name => "Source SG Name",
|
180
180
|
:source_security_group_owner_id => "123"
|
181
|
-
).should.be.an.instance_of
|
181
|
+
).should.be.an.instance_of Hash
|
182
182
|
end
|
183
183
|
|
184
184
|
|
@@ -199,7 +199,7 @@ context "EC2 security groups " do
|
|
199
199
|
:cidr_ip => "0.0.0.0/24",
|
200
200
|
:source_security_group_name => "Source SG Name",
|
201
201
|
:source_security_group_owner_id => "123"
|
202
|
-
).should.be.an.instance_of
|
202
|
+
).should.be.an.instance_of Hash
|
203
203
|
end
|
204
204
|
|
205
205
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library, EBS snapshots support
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Yann Klis (mailto:yann.klis@novelys.com)
|
6
|
+
# Copyright:: Copyright (c) 2008 Yann Klis
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://amazon-ec2.rubyforge.org
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "EC2 snaphots " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@describe_snapshots_response_body = <<-RESPONSE
|
19
|
+
<DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
20
|
+
<snapshotId>snap-78a54011</snapshotId>
|
21
|
+
<volumeId>vol-4d826724</volumeId>
|
22
|
+
<status>pending</status>
|
23
|
+
<startTime>2008-05-07T12:51:50.000Z</startTime>
|
24
|
+
<progress>80%</progress>
|
25
|
+
</DescribeSnapshotsResponse>
|
26
|
+
RESPONSE
|
27
|
+
|
28
|
+
@create_snapshot_response_body = <<-RESPONSE
|
29
|
+
<CreateSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
30
|
+
<snapshotId>snap-78a54011</snapshotId>
|
31
|
+
<volumeId>vol-4d826724</volumeId>
|
32
|
+
<status>pending</status>
|
33
|
+
<startTime>2008-05-07T12:51:50.000Z</startTime>
|
34
|
+
<progress></progress>
|
35
|
+
</CreateSnapshotResponse>
|
36
|
+
RESPONSE
|
37
|
+
|
38
|
+
@delete_snapshot_response_body = <<-RESPONSE
|
39
|
+
<DeleteSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
40
|
+
<return>true</return>
|
41
|
+
</DeleteSnapshotResponse>
|
42
|
+
RESPONSE
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
specify "should be able to be described with describe_snapshots" do
|
48
|
+
@ec2.stubs(:make_request).with('DescribeSnapshots', {"SnapshotId.1"=>"snap-78a54011"}).
|
49
|
+
returns stub(:body => @describe_snapshots_response_body, :is_a? => true)
|
50
|
+
|
51
|
+
@ec2.describe_snapshots( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
|
52
|
+
|
53
|
+
response = @ec2.describe_snapshots( :snapshot_id => "snap-78a54011" )
|
54
|
+
response.snapshotId.should.equal "snap-78a54011"
|
55
|
+
response.volumeId.should.equal "vol-4d826724"
|
56
|
+
response.status.should.equal "pending"
|
57
|
+
response.progress.should.equal "80%"
|
58
|
+
end
|
59
|
+
|
60
|
+
specify "should be able to be created with a volume_id" do
|
61
|
+
@ec2.stubs(:make_request).with('CreateSnapshot', {"VolumeId" => "vol-4d826724"}).
|
62
|
+
returns stub(:body => @create_snapshot_response_body, :is_a? => true)
|
63
|
+
|
64
|
+
@ec2.create_snapshot( :volume_id => "vol-4d826724" ).should.be.an.instance_of Hash
|
65
|
+
|
66
|
+
response = @ec2.create_snapshot( :volume_id => "vol-4d826724" )
|
67
|
+
response.snapshotId.should.equal "snap-78a54011"
|
68
|
+
response.volumeId.should.equal "vol-4d826724"
|
69
|
+
response.status.should.equal "pending"
|
70
|
+
response.progress.should.equal nil
|
71
|
+
end
|
72
|
+
|
73
|
+
specify "should be able to be deleted with a snapsot_id" do
|
74
|
+
@ec2.stubs(:make_request).with('DeleteSnapshot', {"SnapshotId" => "snap-78a54011"}).
|
75
|
+
returns stub(:body => @delete_snapshot_response_body, :is_a? => true)
|
76
|
+
|
77
|
+
@ec2.delete_snapshot( :snapshot_id => "snap-78a54011" ).should.be.an.instance_of Hash
|
78
|
+
|
79
|
+
response = @ec2.delete_snapshot( :snapshot_id => "snap-78a54011" )
|
80
|
+
response.return.should.equal "true"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#--
|
2
|
+
# Amazon Web Services EC2 Query API Ruby library, EBS volumes support
|
3
|
+
#
|
4
|
+
# Ruby Gem Name:: amazon-ec2
|
5
|
+
# Author:: Yann Klis (mailto:yann.klis@novelys.com)
|
6
|
+
# Copyright:: Copyright (c) 2008 Yann Klis
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
# Home:: http://amazon-ec2.rubyforge.org
|
9
|
+
#++
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
|
+
|
13
|
+
context "EC2 volumes " do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
+
|
18
|
+
@describe_volumes_response_body = <<-RESPONSE
|
19
|
+
<DescribeVolumesResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
20
|
+
<volumeSet>
|
21
|
+
<item>
|
22
|
+
<volumeId>vol-4282672b</volumeId>
|
23
|
+
<size>800</size>
|
24
|
+
<status>in-use</status>
|
25
|
+
<createTime>2008-05-07T11:51:50.000Z</createTime>
|
26
|
+
<attachmentSet>
|
27
|
+
<item>
|
28
|
+
<volumeId>vol-4282672b</volumeId>
|
29
|
+
<instanceId>i-6058a509</instanceId>
|
30
|
+
<size>800</size>
|
31
|
+
<status>attached</status>
|
32
|
+
<attachTime>2008-05-07T12:51:50.000Z</attachTime>
|
33
|
+
</item>
|
34
|
+
</attachmentSet>
|
35
|
+
</item>
|
36
|
+
</volumeSet>
|
37
|
+
</DescribeVolumesResponse>
|
38
|
+
RESPONSE
|
39
|
+
|
40
|
+
@create_volume_response_body = <<-RESPONSE
|
41
|
+
<CreateVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
42
|
+
<volumeId>vol-4d826724</volumeId>
|
43
|
+
<size>800</size>
|
44
|
+
<status>creating</status>
|
45
|
+
<createTime>2008-05-07T11:51:50.000Z</createTime>
|
46
|
+
<zone>us-east-1a</zone>
|
47
|
+
<snapshotId></snapshotId>
|
48
|
+
</CreateVolumeResponse>
|
49
|
+
RESPONSE
|
50
|
+
|
51
|
+
@delete_volume_response_body = <<-RESPONSE
|
52
|
+
<ReleaseAddressResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
53
|
+
<return>true</return>
|
54
|
+
</ReleaseAddressResponse>
|
55
|
+
RESPONSE
|
56
|
+
|
57
|
+
@attach_volume_response_body = <<-RESPONSE
|
58
|
+
<AttachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
59
|
+
<volumeId>vol-4d826724</volumeId>
|
60
|
+
<instanceId>i-6058a509</instanceId>
|
61
|
+
<device>/dev/sdh</device>
|
62
|
+
<status>attaching</status>
|
63
|
+
<attachTime>2008-05-07T11:51:50.000Z</attachTime>
|
64
|
+
</AttachVolumeResponse>
|
65
|
+
RESPONSE
|
66
|
+
|
67
|
+
@detach_volume_response_body = <<-RESPONSE
|
68
|
+
<DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2008-05-05">
|
69
|
+
<volumeId>vol-4d826724</volumeId>
|
70
|
+
<instanceId>i-6058a509</instanceId>
|
71
|
+
<device>/dev/sdh</device>
|
72
|
+
<status>detaching</status>
|
73
|
+
<attachTime>2008-05-08T11:51:50.000Z</attachTime>
|
74
|
+
</DetachVolumeResponse>
|
75
|
+
RESPONSE
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
specify "should be able to be described with describe_volumes" do
|
81
|
+
@ec2.stubs(:make_request).with('DescribeVolumes', {"VolumeId.1"=>"vol-4282672b"}).
|
82
|
+
returns stub(:body => @describe_volumes_response_body, :is_a? => true)
|
83
|
+
|
84
|
+
@ec2.describe_volumes( :volume_id => ["vol-4282672b"] ).should.be.an.instance_of Hash
|
85
|
+
|
86
|
+
response = @ec2.describe_volumes( :volume_id => ["vol-4282672b"] )
|
87
|
+
response.volumeSet.item[0].volumeId.should.equal "vol-4282672b"
|
88
|
+
# FIXME
|
89
|
+
# response.volumeSet.item[0].size.should.equal "800"
|
90
|
+
response.volumeSet.item[0].attachmentSet.item[0].volumeId.should.equal "vol-4282672b"
|
91
|
+
response.volumeSet.item[0].attachmentSet.item[0].instanceId.should.equal "i-6058a509"
|
92
|
+
end
|
93
|
+
|
94
|
+
specify "should be able to be created with an availability_zone with size" do
|
95
|
+
@ec2.stubs(:make_request).with('CreateVolume', {"AvailabilityZone" => "us-east-1a", "Size"=>"800", "SnapshotId"=>""}).
|
96
|
+
returns stub(:body => @create_volume_response_body, :is_a? => true)
|
97
|
+
|
98
|
+
@ec2.create_volume( :availability_zone => "us-east-1a", :size => "800" ).should.be.an.instance_of Hash
|
99
|
+
|
100
|
+
response = @ec2.create_volume( :availability_zone => "us-east-1a", :size => "800" )
|
101
|
+
response.volumeId.should.equal "vol-4d826724"
|
102
|
+
# FIXME
|
103
|
+
# response.size.should.equal "800"
|
104
|
+
response.status.should.equal "creating"
|
105
|
+
response.zone.should.equal "us-east-1a"
|
106
|
+
end
|
107
|
+
|
108
|
+
specify "should be able to be deleted with a volume_id" do
|
109
|
+
@ec2.stubs(:make_request).with('DeleteVolume', {"VolumeId" => "vol-4282672b"}).
|
110
|
+
returns stub(:body => @delete_volume_response_body, :is_a? => true)
|
111
|
+
|
112
|
+
@ec2.delete_volume( :volume_id => "vol-4282672b" ).should.be.an.instance_of Hash
|
113
|
+
|
114
|
+
response = @ec2.delete_volume( :volume_id => "vol-4282672b" )
|
115
|
+
response.return.should.equal "true"
|
116
|
+
end
|
117
|
+
|
118
|
+
specify "should be able to be attached with a volume_id with an instance_id with a device" do
|
119
|
+
@ec2.stubs(:make_request).with('AttachVolume', {"VolumeId" => "vol-4d826724", "InstanceId"=>"i-6058a509", "Device"=>"/dev/sdh"}).
|
120
|
+
returns stub(:body => @attach_volume_response_body, :is_a? => true)
|
121
|
+
|
122
|
+
@ec2.attach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509", :device => "/dev/sdh" ).should.be.an.instance_of Hash
|
123
|
+
|
124
|
+
response = @ec2.attach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509", :device => "/dev/sdh" )
|
125
|
+
response.volumeId.should.equal "vol-4d826724"
|
126
|
+
response.instanceId.should.equal "i-6058a509"
|
127
|
+
response.device.should.equal "/dev/sdh"
|
128
|
+
response.status.should.equal "attaching"
|
129
|
+
end
|
130
|
+
|
131
|
+
specify "should be able to be detached with a volume_id with an instance_id" do
|
132
|
+
@ec2.stubs(:make_request).with('DetachVolume', {"VolumeId" => "vol-4d826724", "InstanceId"=>"i-6058a509", "Device"=>"", "Force"=>""}).
|
133
|
+
returns stub(:body => @detach_volume_response_body, :is_a? => true)
|
134
|
+
|
135
|
+
@ec2.detach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509" ).should.be.an.instance_of Hash
|
136
|
+
|
137
|
+
response = @ec2.detach_volume( :volume_id => "vol-4d826724", :instance_id => "i-6058a509" )
|
138
|
+
response.volumeId.should.equal "vol-4d826724"
|
139
|
+
response.instanceId.should.equal "i-6058a509"
|
140
|
+
response.device.should.equal "/dev/sdh"
|
141
|
+
response.status.should.equal "detaching"
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grempe-amazon-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glenn Rempe
|
@@ -21,33 +21,6 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.0.11
|
23
23
|
version:
|
24
|
-
- !ruby/object:Gem::Dependency
|
25
|
-
name: mocha
|
26
|
-
version_requirement:
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
requirements:
|
29
|
-
- - ">="
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: 0.9.0
|
32
|
-
version:
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: test-spec
|
35
|
-
version_requirement:
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9.0
|
41
|
-
version:
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rcov
|
44
|
-
version_requirement:
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 0.8.1.2.0
|
50
|
-
version:
|
51
24
|
description: An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.
|
52
25
|
email: glenn.rempe@gmail.com
|
53
26
|
executables:
|
@@ -77,6 +50,8 @@ files:
|
|
77
50
|
- lib/EC2/products.rb
|
78
51
|
- lib/EC2/responses.rb
|
79
52
|
- lib/EC2/security_groups.rb
|
53
|
+
- lib/EC2/snapshots.rb
|
54
|
+
- lib/EC2/volumes.rb
|
80
55
|
- lib/EC2.rb
|
81
56
|
- test/test_EC2.rb
|
82
57
|
- test/test_EC2_availability_zones.rb
|
@@ -89,6 +64,8 @@ files:
|
|
89
64
|
- test/test_EC2_products.rb
|
90
65
|
- test/test_EC2_responses.rb
|
91
66
|
- test/test_EC2_security_groups.rb
|
67
|
+
- test/test_EC2_snapshots.rb
|
68
|
+
- test/test_EC2_volumes.rb
|
92
69
|
- test/test_helper.rb
|
93
70
|
has_rdoc: true
|
94
71
|
homepage: http://github.com/grempe/amazon-ec2/
|
@@ -126,6 +103,7 @@ specification_version: 2
|
|
126
103
|
summary: An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.
|
127
104
|
test_files:
|
128
105
|
- test/test_EC2.rb
|
106
|
+
- test/test_EC2_availability_zones.rb
|
129
107
|
- test/test_EC2_console.rb
|
130
108
|
- test/test_EC2_elastic_ips.rb
|
131
109
|
- test/test_EC2_image_attributes.rb
|
@@ -135,4 +113,6 @@ test_files:
|
|
135
113
|
- test/test_EC2_products.rb
|
136
114
|
- test/test_EC2_responses.rb
|
137
115
|
- test/test_EC2_security_groups.rb
|
116
|
+
- test/test_EC2_snapshots.rb
|
117
|
+
- test/test_EC2_volumes.rb
|
138
118
|
- test/test_helper.rb
|