amazon-ec2 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/ChangeLog +7 -4
  2. data/README.rdoc +12 -12
  3. data/README_dev.rdoc +6 -0
  4. data/Rakefile +2 -1
  5. data/VERSION +1 -1
  6. data/amazon-ec2.gemspec +25 -18
  7. data/bin/ec2-gem-example.rb +3 -3
  8. data/bin/ec2-gem-profile.rb +2 -2
  9. data/bin/ec2sh +4 -4
  10. data/bin/setup.rb +4 -2
  11. data/lib/{EC2.rb → AWS.rb} +33 -67
  12. data/lib/AWS/EC2.rb +67 -0
  13. data/lib/AWS/EC2/availability_zones.rb +43 -0
  14. data/lib/AWS/EC2/console.rb +46 -0
  15. data/lib/AWS/EC2/elastic_ips.rb +154 -0
  16. data/lib/AWS/EC2/image_attributes.rb +168 -0
  17. data/lib/AWS/EC2/images.rb +136 -0
  18. data/lib/AWS/EC2/instances.rb +218 -0
  19. data/lib/AWS/EC2/keypairs.rb +96 -0
  20. data/lib/AWS/EC2/products.rb +45 -0
  21. data/lib/AWS/EC2/security_groups.rb +234 -0
  22. data/lib/AWS/EC2/snapshots.rb +96 -0
  23. data/lib/AWS/EC2/volumes.rb +172 -0
  24. data/lib/AWS/ELB.rb +67 -0
  25. data/lib/AWS/ELB/load_balancers.rb +198 -0
  26. data/lib/{EC2 → AWS}/exceptions.rb +21 -2
  27. data/lib/{EC2 → AWS}/responses.rb +4 -5
  28. data/perftools/ec2prof-results.txt +4 -4
  29. data/perftools/ec2prof.symbols +4 -4
  30. data/test/test_EC2.rb +14 -14
  31. data/test/test_EC2_availability_zones.rb +2 -2
  32. data/test/test_EC2_console.rb +5 -5
  33. data/test/test_EC2_elastic_ips.rb +13 -13
  34. data/test/test_EC2_image_attributes.rb +35 -35
  35. data/test/test_EC2_images.rb +7 -7
  36. data/test/test_EC2_instances.rb +35 -35
  37. data/test/test_EC2_keypairs.rb +10 -10
  38. data/test/test_EC2_products.rb +7 -7
  39. data/test/test_EC2_responses.rb +2 -2
  40. data/test/test_EC2_s3_xmlsimple.rb +2 -2
  41. data/test/test_EC2_security_groups.rb +13 -13
  42. data/test/test_EC2_snapshots.rb +2 -2
  43. data/test/test_EC2_volumes.rb +2 -2
  44. data/test/test_ELB_load_balancers.rb +239 -0
  45. data/test/test_helper.rb +1 -1
  46. metadata +24 -17
  47. data/lib/EC2/availability_zones.rb +0 -41
  48. data/lib/EC2/console.rb +0 -44
  49. data/lib/EC2/elastic_ips.rb +0 -153
  50. data/lib/EC2/image_attributes.rb +0 -166
  51. data/lib/EC2/images.rb +0 -134
  52. data/lib/EC2/instances.rb +0 -216
  53. data/lib/EC2/keypairs.rb +0 -94
  54. data/lib/EC2/products.rb +0 -43
  55. data/lib/EC2/security_groups.rb +0 -232
  56. data/lib/EC2/snapshots.rb +0 -94
  57. data/lib/EC2/volumes.rb +0 -170
data/lib/AWS/EC2.rb ADDED
@@ -0,0 +1,67 @@
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 any lib files that we have bundled with this Ruby Gem in the lib/EC2 directory.
12
+ # Parts of the EC2 module and Base class are broken out into separate
13
+ # files for maintainability and are organized by the functional groupings defined
14
+ # in the EC2 API developers guide.
15
+ Dir[File.join(File.dirname(__FILE__), 'EC2/**/*.rb')].sort.each { |lib| require lib }
16
+
17
+ module AWS
18
+ module EC2
19
+
20
+ # Which host FQDN will we connect to for all API calls to AWS?
21
+ # If EC2_URL is defined in the users ENV we can use that. It is
22
+ # expected that this var is set with something like:
23
+ # export EC2_URL='https://ec2.amazonaws.com'
24
+ #
25
+ if ENV['EC2_URL']
26
+ EC2_URL = ENV['EC2_URL']
27
+ VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
28
+ raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
29
+ DEFAULT_HOST = URI.parse(EC2_URL).host
30
+ else
31
+ # default US host
32
+ DEFAULT_HOST = 'ec2.amazonaws.com'
33
+ end
34
+
35
+ # This is the version of the API as defined by Amazon Web Services
36
+ API_VERSION = '2008-12-01'
37
+
38
+ #Introduction:
39
+ #
40
+ # The library exposes one main interface class, 'AWS::EC2::Base'.
41
+ # This class provides all the methods for using the EC2 service
42
+ # including the handling of header signing and other security issues .
43
+ # This class uses Net::HTTP to interface with the EC2 Query API interface.
44
+ #
45
+ #Required Arguments:
46
+ #
47
+ # :access_key_id => String (default : "")
48
+ # :secret_access_key => String (default : "")
49
+ #
50
+ #Optional Arguments:
51
+ #
52
+ # :use_ssl => Boolean (default : true)
53
+ # :server => String (default : 'ec2.amazonaws.com')
54
+ # :proxy_server => String (default : nil)
55
+ #
56
+ class Base < AWS::Base
57
+ def api_version
58
+ API_VERSION
59
+ end
60
+
61
+ def default_host
62
+ DEFAULT_HOST
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,43 @@
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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The DescribeAvailabilityZones operation describes availability zones that are currently
19
+ # available to the account and their states.
20
+ #
21
+ # An optional list of zone names can be passed.
22
+ #
23
+ #Required Arguments:
24
+ #
25
+ # none
26
+ #
27
+ #Optional Arguments:
28
+ #
29
+ # :zone_name => Array (default : [])
30
+ #
31
+
32
+ def describe_availability_zones( options = {} )
33
+
34
+ options = { :zone_name => [] }.merge(options)
35
+
36
+ params = pathlist("ZoneName", options[:zone_name] )
37
+
38
+ return response_generator(:action => "DescribeAvailabilityZones", :params => params)
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,46 @@
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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The GetConsoleOutput operation retrieves console output that has been posted for the specified instance.
19
+ #
20
+ # Instance console output is buffered and posted shortly after instance boot, reboot and once the instance
21
+ # is terminated. Only the most recent 64 KB of posted output is available. Console output is available for
22
+ # at least 1 hour after the most recent post.
23
+ #
24
+ #Required Arguments:
25
+ #
26
+ # :instance_id => String (default : "")
27
+ #
28
+ #Optional Arguments:
29
+ #
30
+ # none
31
+ #
32
+ def get_console_output( options ={} )
33
+
34
+ options = {:instance_id => ""}.merge(options)
35
+
36
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
37
+
38
+ params = { "InstanceId" => options[:instance_id] }
39
+
40
+ return response_generator(:action => "GetConsoleOutput", :params => params)
41
+
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,154 @@
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
+ module AWS
12
+ module EC2
13
+ class Base < AWS::Base
14
+
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The AllocateAddress operation acquires an elastic IP address for use with your account.
19
+ #
20
+ #Required Arguments:
21
+ #
22
+ # none
23
+ #
24
+ #Optional Arguments:
25
+ #
26
+ # none
27
+ #
28
+ def allocate_address
29
+
30
+ return response_generator(:action => "AllocateAddress")
31
+
32
+ end
33
+
34
+ #Amazon Developer Guide Docs:
35
+ #
36
+ # The DescribeAddresses operation lists elastic IP addresses assigned to your account.
37
+ #
38
+ #Required Arguments:
39
+ #
40
+ # :public_ip => Array (default : [], can be empty)
41
+ #
42
+ #Optional Arguments:
43
+ #
44
+ # none
45
+ #
46
+ def describe_addresses( options = {} )
47
+
48
+ options = { :public_ip => [] }.merge(options)
49
+
50
+ params = pathlist("PublicIp", options[:public_ip])
51
+
52
+ return response_generator(:action => "DescribeAddresses", :params => params)
53
+
54
+ end
55
+
56
+ #Amazon Developer Guide Docs:
57
+ #
58
+ # The ReleaseAddress operation releases an elastic IP address associated with your account.
59
+ #
60
+ # If you run this operation on an elastic IP address that is already released, the address
61
+ # might be assigned to another account which will cause Amazon EC2 to return an error.
62
+ #
63
+ # Note : Releasing an IP address automatically disassociates it from any instance
64
+ # with which it is associated. For more information, see DisassociateAddress.
65
+ #
66
+ # Important! After releasing an elastic IP address, it is released to the IP
67
+ # address pool and might no longer be available to your account. Make sure
68
+ # to update your DNS records and any servers or devices that communicate
69
+ # with the address.
70
+ #
71
+ #Required Arguments:
72
+ #
73
+ # :public_ip => String (default : '')
74
+ #
75
+ #Optional Arguments:
76
+ #
77
+ # none
78
+ #
79
+ def release_address( options = {} )
80
+
81
+ options = { :public_ip => '' }.merge(options)
82
+
83
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
84
+
85
+ params = { "PublicIp" => options[:public_ip] }
86
+
87
+ return response_generator(:action => "ReleaseAddress", :params => params)
88
+
89
+ end
90
+
91
+ #Amazon Developer Guide Docs:
92
+ #
93
+ # The AssociateAddress operation associates an elastic IP address with an instance.
94
+ #
95
+ # If the IP address is currently assigned to another instance, the IP address
96
+ # is assigned to the new instance. This is an idempotent operation. If you enter
97
+ # it more than once, Amazon EC2 does not return an error.
98
+ #
99
+ #Required Arguments:
100
+ #
101
+ # :instance_id => String (default : '')
102
+ # :public_ip => String (default : '')
103
+ #
104
+ #Optional Arguments:
105
+ #
106
+ # none
107
+ #
108
+ def associate_address( options = {} )
109
+
110
+ options = { :instance_id => '', :public_ip => '' }.merge(options)
111
+
112
+ raise ArgumentError, "No ':instance_id' provided" if options[:instance_id].nil? || options[:instance_id].empty?
113
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
114
+
115
+ params = {
116
+ "InstanceId" => options[:instance_id],
117
+ "PublicIp" => options[:public_ip]
118
+ }
119
+
120
+ return response_generator(:action => "AssociateAddress", :params => params)
121
+
122
+ end
123
+
124
+ #Amazon Developer Guide Docs:
125
+ #
126
+ # The DisassociateAddress operation disassociates the specified elastic IP
127
+ # address from the instance to which it is assigned. This is an idempotent
128
+ # operation. If you enter it more than once, Amazon EC2 does not return
129
+ # an error.
130
+ #
131
+ #Required Arguments:
132
+ #
133
+ # :public_ip => String (default : '')
134
+ #
135
+ #Optional Arguments:
136
+ #
137
+ # none
138
+ #
139
+ def disassociate_address( options = {} )
140
+
141
+ options = { :public_ip => '' }.merge(options)
142
+
143
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
144
+
145
+ params = { "PublicIp" => options[:public_ip] }
146
+
147
+ return response_generator(:action => "DisassociateAddress", :params => params)
148
+
149
+ end
150
+
151
+ end
152
+
153
+ end
154
+ end
@@ -0,0 +1,168 @@
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
+ module AWS
12
+ module EC2
13
+
14
+ class Base < AWS::Base
15
+
16
+ #Amazon Developer Guide Docs:
17
+ #
18
+ # The ModifyImageAttribute operation modifies an attribute of an AMI. The following attributes may
19
+ # currently be modified:
20
+ #
21
+ # 'launchPermission' : Controls who has permission to launch the AMI. Launch permissions can be
22
+ # granted to specific users by adding userIds. The AMI can be made public by adding the 'all' group.
23
+ #
24
+ # 'productCodes' : Associates product codes with AMIs. This allows a developer to charge a user extra
25
+ # for using the AMIs. productCodes is a write once attribute - once it has been set it can not be
26
+ # changed or removed. Currently only one product code is supported per AMI.
27
+ #
28
+ #Required Arguments:
29
+ #
30
+ # :image_id => String (default : "")
31
+ # :attribute => String ('launchPermission' or 'productCodes', default : "launchPermission")
32
+ # :operation_type => String (default : "")
33
+ #
34
+ #Optional Arguments:
35
+ #
36
+ # :user_id => Array (default : [])
37
+ # :group => Array (default : [])
38
+ # :product_code => Array (default : [])
39
+ #
40
+ def modify_image_attribute( options = {} )
41
+
42
+ # defaults
43
+ options = { :image_id => "",
44
+ :attribute => "launchPermission",
45
+ :operation_type => "",
46
+ :user_id => [],
47
+ :group => [],
48
+ :product_code => [] }.merge(options)
49
+
50
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
51
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
52
+
53
+ # OperationType is not required if modifying a product code.
54
+ unless options[:attribute] == 'productCodes'
55
+ raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
56
+ end
57
+
58
+ params = {
59
+ "ImageId" => options[:image_id],
60
+ "Attribute" => options[:attribute],
61
+ "OperationType" => options[:operation_type]
62
+ }
63
+
64
+ # test options provided and make sure they are valid
65
+ case options[:attribute]
66
+ when "launchPermission"
67
+
68
+ unless options[:operation_type] == "add" || options[:operation_type] == "remove"
69
+ raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be either 'add' or 'remove'"
70
+ end
71
+
72
+ if (options[:user_id].nil? || options[:user_id].empty?) && (options[:group].nil? || options[:group].empty?)
73
+ raise ArgumentError, "Option :attribute=>'launchPermission' requires ':user_id' or ':group' options to also be specified"
74
+ end
75
+ params.merge!(pathlist("UserId", options[:user_id])) unless options[:user_id].nil?
76
+ params.merge!(pathlist("Group", options[:group])) unless options[:group].nil?
77
+ when "productCodes"
78
+ if (options[:product_code].nil? || options[:product_code].empty?)
79
+ raise ArgumentError, "Option :attribute=>'productCodes' requires ':product_code' to be specified"
80
+ end
81
+ params.merge!(pathlist("ProductCode", options[:product_code])) unless options[:product_code].nil?
82
+ else
83
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
84
+ end
85
+
86
+ return response_generator(:action => "ModifyImageAttribute", :params => params)
87
+
88
+ end
89
+
90
+ #Amazon Developer Guide Docs:
91
+ #
92
+ # The DescribeImageAttribute operation returns information about an attribute of an AMI.
93
+ #
94
+ #Required Arguments:
95
+ #
96
+ # :image_id => String (default : "")
97
+ # :attribute => String ("launchPermission" or "productCodes", default : "launchPermission")
98
+ #
99
+ #Optional Arguments:
100
+ #
101
+ # none
102
+ #
103
+ def describe_image_attribute( options = {} )
104
+
105
+ # defaults
106
+ options = {:image_id => "",
107
+ :attribute => "launchPermission"
108
+ }.merge(options)
109
+
110
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
111
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
112
+
113
+ params = { "ImageId" => options[:image_id], "Attribute" => options[:attribute] }
114
+
115
+ # test options provided and make sure they are valid
116
+ case options[:attribute]
117
+ when "launchPermission", "productCodes"
118
+ # these args are ok
119
+ else
120
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
121
+ end
122
+
123
+ return response_generator(:action => "DescribeImageAttribute", :params => params)
124
+
125
+ end
126
+
127
+
128
+ #Amazon Developer Guide Docs:
129
+ #
130
+ # The ResetImageAttribute operation resets an attribute of an AMI to its default value.
131
+ #
132
+ #Required Arguments:
133
+ #
134
+ # :image_id => String (default : "")
135
+ # :attribute => String (default : "launchPermission")
136
+ #
137
+ #Optional Arguments:
138
+ #
139
+ # none
140
+ #
141
+ def reset_image_attribute( options = {} )
142
+
143
+ # defaults
144
+ options = {:image_id => "",
145
+ :attribute => "launchPermission"}.merge(options)
146
+
147
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
148
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
149
+
150
+ params = {"ImageId" => options[:image_id],
151
+ "Attribute" => options[:attribute] }
152
+
153
+ # test options provided and make sure they are valid
154
+ case options[:attribute]
155
+ when "launchPermission"
156
+ # these args are ok
157
+ else
158
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
159
+ end
160
+
161
+ return response_generator(:action => "ResetImageAttribute", :params => params)
162
+
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+ end