amazon-ec2 0.2.15 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -14,8 +14,8 @@ module EC2
14
14
 
15
15
  #Amazon Developer Guide Docs:
16
16
  #
17
- # The DescribeAvailabilityZones operation describes availability zones that are currently
18
- # available to the account and their states.
17
+ # The DescribeAvailabilityZones operation describes availability zones that are currently
18
+ # available to the account and their states.
19
19
  #
20
20
  # An optional list of zone names can be passed.
21
21
  #
@@ -39,4 +39,3 @@ module EC2
39
39
  end
40
40
  end
41
41
  end
42
-
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -41,4 +41,4 @@ module EC2
41
41
  end
42
42
  end
43
43
 
44
- end
44
+ end
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -64,6 +64,7 @@ module EC2
64
64
  # :user_data => String (default : nil)
65
65
  # :addressing_type => String (default : "public")
66
66
  # :instance_type => String (default : "m1.small")
67
+ # :kernel_id => String (default : nil)
67
68
  # :availability_zone => String (default : nil)
68
69
  # :base64_encoded => Boolean (default : false)
69
70
  #
@@ -77,6 +78,7 @@ module EC2
77
78
  :user_data => nil,
78
79
  :addressing_type => "public",
79
80
  :instance_type => "m1.small",
81
+ :kernel_id => nil,
80
82
  :availability_zone => nil,
81
83
  :base64_encoded => false }.merge(options)
82
84
 
@@ -111,6 +113,7 @@ module EC2
111
113
  params["UserData"] = user_data unless user_data.nil?
112
114
  params["AddressingType"] = options[:addressing_type]
113
115
  params["InstanceType"] = options[:instance_type]
116
+ params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
114
117
  params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
115
118
 
116
119
  return response_generator(:action => "RunInstances", :params => params)
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -40,4 +40,4 @@ module EC2
40
40
  end
41
41
  end
42
42
 
43
- end
43
+ end
@@ -2,12 +2,23 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
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
- response = Response.new(XmlSimple.xml_in(options[:xml], options[:parse_options]))
54
-
55
- # set the xml attribute of the response object to contain the original XML that was
56
- # returned by amazon. This allows anyone to bypass our parsing if desired and just
57
- # get right at the raw XML response.
58
- response.xml = options[:xml]
59
- return response
60
- end
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
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.
70
56
 
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
57
+ response = XmlSimple.xml_in(options[:xml], options[:parse_options])
91
58
 
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
59
+ return response
171
60
  end
172
61
 
173
- end # class Response < OpenStruct
62
+ end # class Response
174
63
 
175
64
  end # module EC2
@@ -2,10 +2,10 @@
2
2
  # Amazon Web Services EC2 Query API Ruby library
3
3
  #
4
4
  # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
6
  # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
7
  # License:: Distributes under the same terms as Ruby
8
- # Home:: http://amazon-ec2.rubyforge.org
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
9
  #++
10
10
 
11
11
  module EC2
@@ -0,0 +1,94 @@
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://github.com/grempe/amazon-ec2/tree/master
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