rsanheim-amazon-ec2 0.3.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
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 EC2
12
+
13
+ class Base
14
+
15
+ #Amazon Developer Guide Docs:
16
+ #
17
+ # The DescribeAvailabilityZones operation describes availability zones that are currently
18
+ # available to the account and their states.
19
+ #
20
+ # An optional list of zone names can be passed.
21
+ #
22
+ #Required Arguments:
23
+ #
24
+ # none
25
+ #
26
+ #Optional Arguments:
27
+ #
28
+ # :zone_name => Array (default : [])
29
+ #
30
+
31
+ def describe_availability_zones( options = {} )
32
+
33
+ options = { :zone_name => [] }.merge(options)
34
+
35
+ params = pathlist("ZoneName", options[:zone_name] )
36
+
37
+ return response_generator(:action => "DescribeAvailabilityZones", :params => params)
38
+
39
+ end
40
+ end
41
+ end
@@ -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: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 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: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 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,147 @@
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 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
+ # Invalid AWS Account
36
+ class InvalidClientTokenId < Error #:nodoc:
37
+ end
38
+
39
+ # Invalid Parameters for Value
40
+ class InvalidParameterValue < Error #:nodoc:
41
+ end
42
+
43
+ # Specified AMI has an unparsable manifest.
44
+ class InvalidManifest < Error #:nodoc:
45
+ end
46
+
47
+ # Specified AMI ID is not valid.
48
+ class InvalidAMIIDMalformed < Error #:nodoc:
49
+ end
50
+
51
+ # Specified AMI ID does not exist.
52
+ class InvalidAMIIDNotFound < Error #:nodoc:
53
+ end
54
+
55
+ # Specified AMI ID has been deregistered and is no longer available.
56
+ class InvalidAMIIDUnavailable < Error #:nodoc:
57
+ end
58
+
59
+ # Specified instance ID is not valid.
60
+ class InvalidInstanceIDMalformed < Error #:nodoc:
61
+ end
62
+
63
+ # Specified instance ID does not exist.
64
+ class InvalidInstanceIDNotFound < Error #:nodoc:
65
+ end
66
+
67
+ # Specified keypair name does not exist.
68
+ class InvalidKeyPairNotFound < Error #:nodoc:
69
+ end
70
+
71
+ # Attempt to create a duplicate keypair.
72
+ class InvalidKeyPairDuplicate < Error #:nodoc:
73
+ end
74
+
75
+ # Specified group name does not exist.
76
+ class InvalidGroupNotFound < Error #:nodoc:
77
+ end
78
+
79
+ # Attempt to create a duplicate group.
80
+ class InvalidGroupDuplicate < Error #:nodoc:
81
+ end
82
+
83
+ # Specified group can not be deleted because it is in use.
84
+ class InvalidGroupInUse < Error #:nodoc:
85
+ end
86
+
87
+ # Specified group name is a reserved name.
88
+ class InvalidGroupReserved < Error #:nodoc:
89
+ end
90
+
91
+ # Attempt to authorize a permission that has already been authorized.
92
+ class InvalidPermissionDuplicate < Error #:nodoc:
93
+ end
94
+
95
+ # Specified permission is invalid.
96
+ class InvalidPermissionMalformed < Error #:nodoc:
97
+ end
98
+
99
+ # Specified reservation ID is invalid.
100
+ class InvalidReservationIDMalformed < Error #:nodoc:
101
+ end
102
+
103
+ # Specified reservation ID does not exist.
104
+ class InvalidReservationIDNotFound < Error #:nodoc:
105
+ end
106
+
107
+ # User has reached max allowed concurrent running instances.
108
+ class InstanceLimitExceeded < Error #:nodoc:
109
+ end
110
+
111
+ # An invalid set of parameters were passed as arguments
112
+ # e.g. RunInstances was called with minCount and maxCount set to 0 or minCount > maxCount.
113
+ class InvalidParameterCombination < Error #:nodoc:
114
+ end
115
+
116
+ # An unknown parameter was passed as an argument
117
+ class UnknownParameter < Error #:nodoc:
118
+ end
119
+
120
+ # The user ID is neither in the form of an AWS account ID or one
121
+ # of the special values accepted by the owner or executableBy flags
122
+ # in the DescribeImages call.
123
+ class InvalidUserIDMalformed < Error #:nodoc:
124
+ end
125
+
126
+ # The value of an item added to, or removed from, an image attribute is invalid.
127
+ class InvalidAMIAttributeItemValue < Error #:nodoc:
128
+ end
129
+
130
+ # AWS EC2 SERVER ERROR CODES
131
+
132
+ # Internal AWS EC2 Error.
133
+ class InternalError < Error #:nodoc:
134
+ end
135
+
136
+ # There are not enough available instances to satify your minimum request.
137
+ class InsufficientInstanceCapacity < Error #:nodoc:
138
+ end
139
+
140
+ # The server is overloaded and cannot handle request.
141
+ class Unavailable < Error #:nodoc:
142
+ end
143
+
144
+ class SignatureDoesNotMatch < Error #:nodoc:
145
+ end
146
+
147
+ 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: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 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