grempe-amazon-ec2 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +230 -0
  2. data/License.txt +66 -0
  3. data/Manifest.txt +46 -0
  4. data/README.txt +154 -0
  5. data/Rakefile +4 -0
  6. data/bin/ec2-gem-example.rb +61 -0
  7. data/bin/ec2sh +73 -0
  8. data/bin/setup.rb +19 -0
  9. data/config/hoe.rb +76 -0
  10. data/config/requirements.rb +17 -0
  11. data/lib/EC2.rb +254 -0
  12. data/lib/EC2/console.rb +44 -0
  13. data/lib/EC2/elastic_ips.rb +153 -0
  14. data/lib/EC2/exceptions.rb +136 -0
  15. data/lib/EC2/image_attributes.rb +166 -0
  16. data/lib/EC2/images.rb +134 -0
  17. data/lib/EC2/instances.rb +206 -0
  18. data/lib/EC2/keypairs.rb +94 -0
  19. data/lib/EC2/products.rb +43 -0
  20. data/lib/EC2/responses.rb +175 -0
  21. data/lib/EC2/security_groups.rb +232 -0
  22. data/lib/EC2/version.rb +18 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/script/txt2html +74 -0
  26. data/setup.rb +1585 -0
  27. data/tasks/deployment.rake +27 -0
  28. data/tasks/environment.rake +7 -0
  29. data/tasks/website.rake +17 -0
  30. data/test/test_EC2.rb +52 -0
  31. data/test/test_EC2_console.rb +54 -0
  32. data/test/test_EC2_elastic_ips.rb +144 -0
  33. data/test/test_EC2_image_attributes.rb +238 -0
  34. data/test/test_EC2_images.rb +197 -0
  35. data/test/test_EC2_instances.rb +325 -0
  36. data/test/test_EC2_keypairs.rb +123 -0
  37. data/test/test_EC2_products.rb +48 -0
  38. data/test/test_EC2_responses.rb +102 -0
  39. data/test/test_EC2_security_groups.rb +205 -0
  40. data/test/test_EC2_version.rb +44 -0
  41. data/test/test_helper.rb +20 -0
  42. data/website/index.txt +427 -0
  43. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  44. data/website/stylesheets/screen.css +138 -0
  45. data/website/template.rhtml +55 -0
  46. metadata +174 -0
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
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 GetConsoleOutput operation retrieves console output that has been posted for the specified instance.
18
+ #
19
+ # Instance console output is buffered and posted shortly after instance boot, reboot and once the instance
20
+ # is terminated. Only the most recent 64 KB of posted output is available. Console output is available for
21
+ # at least 1 hour after the most recent post.
22
+ #
23
+ #Required Arguments:
24
+ #
25
+ # :instance_id => String (default : "")
26
+ #
27
+ #Optional Arguments:
28
+ #
29
+ # none
30
+ #
31
+ def get_console_output( options ={} )
32
+
33
+ options = {:instance_id => ""}.merge(options)
34
+
35
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
36
+
37
+ params = { "InstanceId" => options[:instance_id] }
38
+
39
+ return response_generator(:action => "GetConsoleOutput", :params => params)
40
+
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,153 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
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
+
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
@@ -0,0 +1,136 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ module EC2
12
+
13
+ # OUR CUSTOM ERROR CODES
14
+
15
+ # All of our errors are superclassed by Error < RuntimeError
16
+ class Error < RuntimeError #:nodoc:
17
+ end
18
+
19
+ # A client side only argument error
20
+ class ArgumentError < Error #:nodoc:
21
+ end
22
+
23
+
24
+ # AWS EC2 CLIENT ERROR CODES
25
+
26
+ # AWS EC2 can throw error exceptions that contain a '.' in them.
27
+ # since we can't name an exception class with that '.' I compressed
28
+ # each class name into the non-dot version. This allows us to retain
29
+ # the granularity of the exception.
30
+
31
+ # User not authorized.
32
+ class AuthFailure < Error #:nodoc:
33
+ end
34
+
35
+ # Specified AMI has an unparsable manifest.
36
+ class InvalidManifest < Error #:nodoc:
37
+ end
38
+
39
+ # Specified AMI ID is not valid.
40
+ class InvalidAMIIDMalformed < Error #:nodoc:
41
+ end
42
+
43
+ # Specified AMI ID does not exist.
44
+ class InvalidAMIIDNotFound < Error #:nodoc:
45
+ end
46
+
47
+ # Specified AMI ID has been deregistered and is no longer available.
48
+ class InvalidAMIIDUnavailable < Error #:nodoc:
49
+ end
50
+
51
+ # Specified instance ID is not valid.
52
+ class InvalidInstanceIDMalformed < Error #:nodoc:
53
+ end
54
+
55
+ # Specified instance ID does not exist.
56
+ class InvalidInstanceIDNotFound < Error #:nodoc:
57
+ end
58
+
59
+ # Specified keypair name does not exist.
60
+ class InvalidKeyPairNotFound < Error #:nodoc:
61
+ end
62
+
63
+ # Attempt to create a duplicate keypair.
64
+ class InvalidKeyPairDuplicate < Error #:nodoc:
65
+ end
66
+
67
+ # Specified group name does not exist.
68
+ class InvalidGroupNotFound < Error #:nodoc:
69
+ end
70
+
71
+ # Attempt to create a duplicate group.
72
+ class InvalidGroupDuplicate < Error #:nodoc:
73
+ end
74
+
75
+ # Specified group can not be deleted because it is in use.
76
+ class InvalidGroupInUse < Error #:nodoc:
77
+ end
78
+
79
+ # Specified group name is a reserved name.
80
+ class InvalidGroupReserved < Error #:nodoc:
81
+ end
82
+
83
+ # Attempt to authorize a permission that has already been authorized.
84
+ class InvalidPermissionDuplicate < Error #:nodoc:
85
+ end
86
+
87
+ # Specified permission is invalid.
88
+ class InvalidPermissionMalformed < Error #:nodoc:
89
+ end
90
+
91
+ # Specified reservation ID is invalid.
92
+ class InvalidReservationIDMalformed < Error #:nodoc:
93
+ end
94
+
95
+ # Specified reservation ID does not exist.
96
+ class InvalidReservationIDNotFound < Error #:nodoc:
97
+ end
98
+
99
+ # User has reached max allowed concurrent running instances.
100
+ class InstanceLimitExceeded < Error #:nodoc:
101
+ end
102
+
103
+ # An invalid set of parameters were passed as arguments
104
+ # e.g. RunInstances was called with minCount and maxCount set to 0 or minCount > maxCount.
105
+ class InvalidParameterCombination < Error #:nodoc:
106
+ end
107
+
108
+ # An unknown parameter was passed as an argument
109
+ class UnknownParameter < Error #:nodoc:
110
+ end
111
+
112
+ # The user ID is neither in the form of an AWS account ID or one
113
+ # of the special values accepted by the owner or executableBy flags
114
+ # in the DescribeImages call.
115
+ class InvalidUserIDMalformed < Error #:nodoc:
116
+ end
117
+
118
+ # The value of an item added to, or removed from, an image attribute is invalid.
119
+ class InvalidAMIAttributeItemValue < Error #:nodoc:
120
+ end
121
+
122
+ # AWS EC2 SERVER ERROR CODES
123
+
124
+ # Internal AWS EC2 Error.
125
+ class InternalError < Error #:nodoc:
126
+ end
127
+
128
+ # There are not enough available instances to satify your minimum request.
129
+ class InsufficientInstanceCapacity < Error #:nodoc:
130
+ end
131
+
132
+ # The server is overloaded and cannot handle request.
133
+ class Unavailable < Error #:nodoc:
134
+ end
135
+
136
+ end
@@ -0,0 +1,166 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
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 ModifyImageAttribute operation modifies an attribute of an AMI. The following attributes may
18
+ # currently be modified:
19
+ #
20
+ # 'launchPermission' : Controls who has permission to launch the AMI. Launch permissions can be
21
+ # granted to specific users by adding userIds. The AMI can be made public by adding the 'all' group.
22
+ #
23
+ # 'productCodes' : Associates product codes with AMIs. This allows a developer to charge a user extra
24
+ # for using the AMIs. productCodes is a write once attribute - once it has been set it can not be
25
+ # changed or removed. Currently only one product code is supported per AMI.
26
+ #
27
+ #Required Arguments:
28
+ #
29
+ # :image_id => String (default : "")
30
+ # :attribute => String ('launchPermission' or 'productCodes', default : "launchPermission")
31
+ # :operation_type => String (default : "")
32
+ #
33
+ #Optional Arguments:
34
+ #
35
+ # :user_id => Array (default : [])
36
+ # :group => Array (default : [])
37
+ # :product_code => Array (default : [])
38
+ #
39
+ def modify_image_attribute( options = {} )
40
+
41
+ # defaults
42
+ options = { :image_id => "",
43
+ :attribute => "launchPermission",
44
+ :operation_type => "",
45
+ :user_id => [],
46
+ :group => [],
47
+ :product_code => [] }.merge(options)
48
+
49
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
50
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
51
+
52
+ # OperationType is not required if modifying a product code.
53
+ unless options[:attribute] == 'productCodes'
54
+ raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
55
+ end
56
+
57
+ params = {
58
+ "ImageId" => options[:image_id],
59
+ "Attribute" => options[:attribute],
60
+ "OperationType" => options[:operation_type]
61
+ }
62
+
63
+ # test options provided and make sure they are valid
64
+ case options[:attribute]
65
+ when "launchPermission"
66
+
67
+ unless options[:operation_type] == "add" || options[:operation_type] == "remove"
68
+ raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be either 'add' or 'remove'"
69
+ end
70
+
71
+ if (options[:user_id].nil? || options[:user_id].empty?) && (options[:group].nil? || options[:group].empty?)
72
+ raise ArgumentError, "Option :attribute=>'launchPermission' requires ':user_id' or ':group' options to also be specified"
73
+ end
74
+ params.merge!(pathlist("UserId", options[:user_id])) unless options[:user_id].nil?
75
+ params.merge!(pathlist("Group", options[:group])) unless options[:group].nil?
76
+ when "productCodes"
77
+ if (options[:product_code].nil? || options[:product_code].empty?)
78
+ raise ArgumentError, "Option :attribute=>'productCodes' requires ':product_code' to be specified"
79
+ end
80
+ params.merge!(pathlist("ProductCode", options[:product_code])) unless options[:product_code].nil?
81
+ else
82
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
83
+ end
84
+
85
+ return response_generator(:action => "ModifyImageAttribute", :params => params)
86
+
87
+ end
88
+
89
+ #Amazon Developer Guide Docs:
90
+ #
91
+ # The DescribeImageAttribute operation returns information about an attribute of an AMI.
92
+ #
93
+ #Required Arguments:
94
+ #
95
+ # :image_id => String (default : "")
96
+ # :attribute => String ("launchPermission" or "productCodes", default : "launchPermission")
97
+ #
98
+ #Optional Arguments:
99
+ #
100
+ # none
101
+ #
102
+ def describe_image_attribute( options = {} )
103
+
104
+ # defaults
105
+ options = {:image_id => "",
106
+ :attribute => "launchPermission"
107
+ }.merge(options)
108
+
109
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
110
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
111
+
112
+ params = { "ImageId" => options[:image_id], "Attribute" => options[:attribute] }
113
+
114
+ # test options provided and make sure they are valid
115
+ case options[:attribute]
116
+ when "launchPermission", "productCodes"
117
+ # these args are ok
118
+ else
119
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
120
+ end
121
+
122
+ return response_generator(:action => "DescribeImageAttribute", :params => params)
123
+
124
+ end
125
+
126
+
127
+ #Amazon Developer Guide Docs:
128
+ #
129
+ # The ResetImageAttribute operation resets an attribute of an AMI to its default value.
130
+ #
131
+ #Required Arguments:
132
+ #
133
+ # :image_id => String (default : "")
134
+ # :attribute => String (default : "launchPermission")
135
+ #
136
+ #Optional Arguments:
137
+ #
138
+ # none
139
+ #
140
+ def reset_image_attribute( options = {} )
141
+
142
+ # defaults
143
+ options = {:image_id => "",
144
+ :attribute => "launchPermission"}.merge(options)
145
+
146
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
147
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
148
+
149
+ params = {"ImageId" => options[:image_id],
150
+ "Attribute" => options[:attribute] }
151
+
152
+ # test options provided and make sure they are valid
153
+ case options[:attribute]
154
+ when "launchPermission"
155
+ # these args are ok
156
+ else
157
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
158
+ end
159
+
160
+ return response_generator(:action => "ResetImageAttribute", :params => params)
161
+
162
+ end
163
+
164
+ end
165
+
166
+ end