grempe-amazon-ec2 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -141,12 +141,6 @@ If you're not in front of a terminal shell now (perhaps you’re browsing this s
141
141
  >> @ec2.describe_images.imagesSet.item[0] (an OpenStruct of a single item in that array)
142
142
  >> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that OpenStruct item)
143
143
 
144
- returns : an XML representation of all images
145
- >> puts @ec2.describe_images.xml
146
-
147
- returns : an XML representation of all images owned by Amazon
148
- >> puts @ec2.describe_images(:owner_id => 'amazon').xml
149
-
150
144
  >> @ec2.describe_images.imagesSet.item[0].to_s
151
145
  => "#<EC2::Response:0x100A465B4 imageId=\"ami-018e6b68\" imageLocation=\"rbuilder-online/phonehome-1.5.6-x86_10132.img.manifest.xml\" imageOwnerId=\"099034111737\" imageState=\"available\" isPublic=\"true\" parent=#<EC2::Response:0x100A469A6 ...>>"
152
146
 
@@ -240,10 +234,7 @@ Try out the following bit of code. This should walk through each image returned
240
234
 
241
235
  === Important notes regarding the structure of EC2::Response Objects
242
236
 
243
- One of the key benefits of this new version of the library is that all responses from EC2 are bundled up in a real data structure and no longer require parsing of text. EC2::Response inherits from the OpenStruct class and we populate it directly from the XML given to us by EC2 in response to any command we issue. This means that future changes to the API and what is returned by EC2 will largely be handled transparently by the gem. This is a huge benefit. What this means though, is that you may have to do a little homework on what actually gets returned by EC2 as XML. For example, when you make a #describe_images call in 'ec2sh' what you will get back will look like:
244
-
245
- $ ec2sh
246
- >> puts @ec2.describe_images(:owner_id => 'amazon').xml
237
+ One of the key benefits of this new version of the library is that all responses from EC2 are bundled up in a real data structure and no longer require parsing of text. The hash returned is populated directly from the XML given to us by EC2 in response to any command we issue. This means that future changes to the API and what is returned by EC2 will largely be handled transparently by the gem. This is a huge benefit. What this means though, is that you may have to do a little homework on what actually gets returned by EC2 as XML. For example, when you make a #describe_images call in 'ec2sh' what AWS returns behind the scenes looks like:
247
238
 
248
239
  <?xml version="1.0"?>
249
240
  <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19/">
@@ -293,14 +284,14 @@ One of the key benefits of this new version of the library is that all responses
293
284
  </imagesSet>
294
285
  </DescribeImagesResponse>
295
286
 
296
- You can see in the XML the structure that you will need to follow when constructing queries for information and parsing responses from EC2.
287
+ You can see here the XML the structure that you will need to follow when constructing queries for information and parsing responses from EC2.
297
288
 
298
289
  So, for example, if you wanted to get the image ID of the third image listed in the response above you would need to do:
299
290
 
300
291
  >> puts @ec2.describe_images(:owner_id => 'amazon').imagesSet.item[2].imageId
301
292
  ami-23b6534a
302
293
 
303
- EC2 will typically return sets of things (imagesSet, reservationSet, etc.) which we map to ruby Arrays (.imagesSet.item in the example above). If you want to iterate over a response set you will need to iterate over this array. The Arrays will typically contain additional EC2::Response objects that represent each individual item. You’ll find that you can use the 'ec2sh' to help you understand the structure more completely if you try issuing commands there as a way to practice seeing what will be returned and making sure you get exactly what you want. You can always call the EC2::Response#xml method like I did above to see the exact XML returned which allows you to easily derive the structure for the Ruby OpenStruct object.
294
+ EC2 will typically return sets of things (imagesSet, reservationSet, etc.) which we map to ruby Arrays (.imagesSet.item in the example above). If you want to iterate over a response set you will need to iterate over this array. The Arrays will typically contain additional EC2::Response objects that represent each individual item. You’ll find that you can use the 'ec2sh' to help you understand the structure more completely if you try issuing commands there as a way to practice seeing what will be returned and making sure you get exactly what you want.
304
295
 
305
296
 
306
297
  == Additional Resources
data/bin/ec2sh CHANGED
@@ -9,15 +9,15 @@
9
9
  # Home:: http://github.com/grempe/amazon-ec2/tree/master
10
10
  #++
11
11
 
12
- # CREDITS : Credit for this bit of shameful ripoff coolness
12
+ # CREDITS : Credit for this bit of shameful ripoff coolness
13
13
  # goes to Marcel Molina and his AWS::S3 gem. Thanks!
14
14
 
15
- # Usage : running this starts up an irb session and
15
+ # Usage : running this starts up an irb session and
16
16
  # sets up the connection to EC2 as a class variable called
17
- # '@ec2'. So just do something like the following on the
17
+ # '@ec2'. So just do something like the following on the
18
18
  # shell command line:
19
19
 
20
- # macbook-pro:~ glenn$ ec2sh
20
+ # macbook-pro:~ glenn$ ec2sh
21
21
  # >> @ec2.describe_images
22
22
  # => [#<EC2::Item image_location...
23
23
 
@@ -26,46 +26,35 @@ setup = File.dirname(__FILE__) + '/setup'
26
26
  irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
27
27
 
28
28
  if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] )
29
-
29
+
30
30
  welcome_message = <<-MESSAGE
31
-
31
+
32
32
  'ec2sh' usage :
33
- This is an interactive 'irb' command shell that allows you to use all
33
+ This is an interactive 'irb' command shell that allows you to use all
34
34
  commands available to the amazon-ec2 gem. You'll find this to be a
35
35
  great tool to help you debug issues and practice running commands
36
36
  against the live EC2 servers prior to putting them in your code.
37
-
38
- The EC2 connection is wired to the class instance '@ec2'. Make method calls
39
- on this to execute commands on EC2. Adding a #to_s
37
+
38
+ The EC2 connection is wired to the class instance '@ec2'. Make method calls
39
+ on this to execute commands on EC2. Adding a #to_s
40
40
  at the end of any command should give you a full String representation of the
41
- response. The #xml data is available for each response
42
- which allows you to view the full and complete XML response returned by
43
- EC2 without any parsing applied. This is useful for viewing the
44
- hierarchy of an entire response in a friendly way (if XML is friendly
45
- to you!). Understanding the hierarchy of the XML response is critical
46
- to making effective use of this library.
47
-
41
+ response.
42
+
48
43
  Examples to try:
49
-
44
+
50
45
  returns : all ec2 public methods
51
46
  >> @ec2.methods.sort
52
-
47
+
53
48
  returns : a string representation of ALL images
54
49
  >> @ec2.describe_images.to_s
55
-
50
+
56
51
  returns : an Array of EC2::Response objects, each an EC2 image and its data
57
52
  >> @ec2.describe_images.imagesSet.item
58
53
  >> @ec2.describe_images.imagesSet.item[0] (an OpenStruct of a single item in that array)
59
54
  >> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that OpenStruct item)
60
-
61
- returns : an XML representation of all images
62
- >> puts @ec2.describe_images.xml
63
-
64
- returns : an XML representation of all images owned by Amazon
65
- >> puts @ec2.describe_images(:owner_id => 'amazon').xml
66
-
55
+
67
56
  MESSAGE
68
-
57
+
69
58
  puts welcome_message
70
59
  exec "#{irb_name} -r #{ec2_lib} -r #{setup} --simple-prompt"
71
60
  else
data/lib/EC2/responses.rb CHANGED
@@ -47,7 +47,7 @@ module EC2
47
47
  def self.parse(options = {})
48
48
  options = {
49
49
  :xml => "",
50
- :parse_options => { 'ForceArray' => ['item'], 'SuppressEmpty' => nil }
50
+ :parse_options => { 'forcearray' => ['item'], 'suppressempty' => nil, 'keeproot' => false }
51
51
  }.merge(options)
52
52
 
53
53
  # NOTE: Parsing the response as a nested set of Response objects was extremely
@@ -91,13 +91,13 @@ context "EC2 instances " do
91
91
  <name>running</name>
92
92
  </instanceState>
93
93
  <privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
94
- <dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
94
+ <dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
95
95
  <keyName>example-key-name</keyName>
96
96
  <productCodesSet>
97
97
  <item><productCode>774F4FF8</productCode></item>
98
98
  </productCodesSet>
99
99
  <instanceType>m1.small</instanceType>
100
- <launchTime>2007-08-07T11:54:42.000Z</launchTime>
100
+ <launchTime>2007-08-07T11:54:42.000Z</launchTime>
101
101
  </item>
102
102
  </instancesSet>
103
103
  </item>
@@ -0,0 +1,80 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ # NOTE : These tests exercise amazon-ec2 when used with the aws/s3 gem
14
+ # which was demonstrating some breaking behavior. The fix was to
15
+ # add the XmlSimple option "'keeproot' => false" in responses.rb
16
+
17
+ context "EC2 aws-s3 compat test" do
18
+
19
+ setup do
20
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
21
+
22
+ @describe_instances_response_body = <<-RESPONSE
23
+ <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
24
+ <reservationSet>
25
+ <item>
26
+ <reservationId>r-44a5402d</reservationId>
27
+ <ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId>
28
+ <groupSet>
29
+ <item>
30
+ <groupId>default</groupId>
31
+ </item>
32
+ </groupSet>
33
+ <instancesSet>
34
+ <item>
35
+ <instanceId>i-28a64341</instanceId>
36
+ <imageId>ami-6ea54007</imageId>
37
+ <instanceState>
38
+ <code>0</code>
39
+ <name>running</name>
40
+ </instanceState>
41
+ <privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
42
+ <dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
43
+ <keyName>example-key-name</keyName>
44
+ <productCodesSet>
45
+ <item><productCode>774F4FF8</productCode></item>
46
+ </productCodesSet>
47
+ <instanceType>m1.small</instanceType>
48
+ <launchTime>2007-08-07T11:54:42.000Z</launchTime>
49
+ </item>
50
+ </instancesSet>
51
+ </item>
52
+ </reservationSet>
53
+ </DescribeInstancesResponse>
54
+ RESPONSE
55
+
56
+ end
57
+
58
+ specify "should be able to be described and return the correct Ruby response class" do
59
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
60
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
61
+ @ec2.describe_instances.should.be.an.instance_of Hash
62
+ response = @ec2.describe_instances
63
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
64
+ end
65
+
66
+ specify "should be able to be described and return the correct Ruby response class when the aws/s3 lib is required" do
67
+ begin
68
+ require 'aws/s3s'
69
+ @ec2.stubs(:make_request).with('DescribeInstances', {}).
70
+ returns stub(:body => @describe_instances_response_body, :is_a? => true)
71
+ @ec2.describe_instances.should.be.an.instance_of Hash
72
+ response = @ec2.describe_instances
73
+ response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
74
+ rescue LoadError
75
+ # do nothing. no aws/s3 gem installed to test against
76
+ end
77
+ end
78
+
79
+ end
80
+
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Rempe
@@ -9,7 +9,7 @@ autorequire: EC2
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-27 00:00:00 -07:00
12
+ date: 2009-01-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -112,6 +112,7 @@ test_files:
112
112
  - test/test_EC2_keypairs.rb
113
113
  - test/test_EC2_products.rb
114
114
  - test/test_EC2_responses.rb
115
+ - test/test_EC2_s3_xmlsimple.rb
115
116
  - test/test_EC2_security_groups.rb
116
117
  - test/test_EC2_snapshots.rb
117
118
  - test/test_EC2_volumes.rb