aws-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +6 -0
- data/LICENSE.txt +171 -0
- data/NOTICE.txt +2 -0
- data/README.rdoc +189 -0
- data/lib/aws-sdk.rb +14 -0
- data/lib/aws.rb +63 -0
- data/lib/aws/api_config.rb +45 -0
- data/lib/aws/api_config/.document +0 -0
- data/lib/aws/api_config/EC2-2011-02-28.yml +2314 -0
- data/lib/aws/api_config/SNS-2010-03-31.yml +171 -0
- data/lib/aws/api_config/SQS-2009-02-01.yml +161 -0
- data/lib/aws/api_config/SimpleDB-2009-04-15.yml +278 -0
- data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +147 -0
- data/lib/aws/api_config_transform.rb +32 -0
- data/lib/aws/async_handle.rb +90 -0
- data/lib/aws/authorize_v2.rb +37 -0
- data/lib/aws/authorize_v3.rb +37 -0
- data/lib/aws/base_client.rb +524 -0
- data/lib/aws/cacheable.rb +92 -0
- data/lib/aws/common.rb +228 -0
- data/lib/aws/configurable.rb +36 -0
- data/lib/aws/configuration.rb +272 -0
- data/lib/aws/configured_client_methods.rb +81 -0
- data/lib/aws/configured_grammars.rb +65 -0
- data/lib/aws/configured_option_grammars.rb +46 -0
- data/lib/aws/configured_xml_grammars.rb +47 -0
- data/lib/aws/default_signer.rb +38 -0
- data/lib/aws/ec2.rb +321 -0
- data/lib/aws/ec2/attachment.rb +149 -0
- data/lib/aws/ec2/attachment_collection.rb +57 -0
- data/lib/aws/ec2/availability_zone.rb +80 -0
- data/lib/aws/ec2/availability_zone_collection.rb +47 -0
- data/lib/aws/ec2/block_device_mappings.rb +53 -0
- data/lib/aws/ec2/client.rb +54 -0
- data/lib/aws/ec2/client/xml.rb +127 -0
- data/lib/aws/ec2/collection.rb +39 -0
- data/lib/aws/ec2/config_transform.rb +63 -0
- data/lib/aws/ec2/elastic_ip.rb +107 -0
- data/lib/aws/ec2/elastic_ip_collection.rb +85 -0
- data/lib/aws/ec2/errors.rb +29 -0
- data/lib/aws/ec2/filtered_collection.rb +65 -0
- data/lib/aws/ec2/has_permissions.rb +46 -0
- data/lib/aws/ec2/image.rb +245 -0
- data/lib/aws/ec2/image_collection.rb +235 -0
- data/lib/aws/ec2/instance.rb +515 -0
- data/lib/aws/ec2/instance_collection.rb +276 -0
- data/lib/aws/ec2/key_pair.rb +86 -0
- data/lib/aws/ec2/key_pair_collection.rb +102 -0
- data/lib/aws/ec2/permission_collection.rb +177 -0
- data/lib/aws/ec2/region.rb +81 -0
- data/lib/aws/ec2/region_collection.rb +55 -0
- data/lib/aws/ec2/request.rb +27 -0
- data/lib/aws/ec2/reserved_instances.rb +50 -0
- data/lib/aws/ec2/reserved_instances_collection.rb +44 -0
- data/lib/aws/ec2/reserved_instances_offering.rb +55 -0
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +43 -0
- data/lib/aws/ec2/resource.rb +340 -0
- data/lib/aws/ec2/resource_tag_collection.rb +218 -0
- data/lib/aws/ec2/security_group.rb +246 -0
- data/lib/aws/ec2/security_group/ip_permission.rb +70 -0
- data/lib/aws/ec2/security_group/ip_permission_collection.rb +59 -0
- data/lib/aws/ec2/security_group_collection.rb +132 -0
- data/lib/aws/ec2/snapshot.rb +138 -0
- data/lib/aws/ec2/snapshot_collection.rb +90 -0
- data/lib/aws/ec2/tag.rb +88 -0
- data/lib/aws/ec2/tag_collection.rb +114 -0
- data/lib/aws/ec2/tagged_collection.rb +48 -0
- data/lib/aws/ec2/tagged_item.rb +87 -0
- data/lib/aws/ec2/volume.rb +190 -0
- data/lib/aws/ec2/volume_collection.rb +95 -0
- data/lib/aws/errors.rb +129 -0
- data/lib/aws/http/builtin_handler.rb +69 -0
- data/lib/aws/http/curb_handler.rb +123 -0
- data/lib/aws/http/handler.rb +77 -0
- data/lib/aws/http/httparty_handler.rb +61 -0
- data/lib/aws/http/request.rb +136 -0
- data/lib/aws/http/request_param.rb +63 -0
- data/lib/aws/http/response.rb +75 -0
- data/lib/aws/ignore_result_element.rb +38 -0
- data/lib/aws/indifferent_hash.rb +86 -0
- data/lib/aws/inflection.rb +46 -0
- data/lib/aws/lazy_error_classes.rb +64 -0
- data/lib/aws/meta_utils.rb +43 -0
- data/lib/aws/model.rb +57 -0
- data/lib/aws/naming.rb +32 -0
- data/lib/aws/option_grammar.rb +544 -0
- data/lib/aws/policy.rb +912 -0
- data/lib/aws/rails.rb +209 -0
- data/lib/aws/record.rb +79 -0
- data/lib/aws/record/attribute.rb +94 -0
- data/lib/aws/record/attribute_macros.rb +288 -0
- data/lib/aws/record/attributes/boolean.rb +49 -0
- data/lib/aws/record/attributes/datetime.rb +86 -0
- data/lib/aws/record/attributes/float.rb +48 -0
- data/lib/aws/record/attributes/integer.rb +68 -0
- data/lib/aws/record/attributes/sortable_float.rb +60 -0
- data/lib/aws/record/attributes/sortable_integer.rb +95 -0
- data/lib/aws/record/attributes/string.rb +69 -0
- data/lib/aws/record/base.rb +728 -0
- data/lib/aws/record/conversion.rb +38 -0
- data/lib/aws/record/dirty_tracking.rb +286 -0
- data/lib/aws/record/errors.rb +153 -0
- data/lib/aws/record/exceptions.rb +48 -0
- data/lib/aws/record/finder_methods.rb +262 -0
- data/lib/aws/record/naming.rb +31 -0
- data/lib/aws/record/scope.rb +157 -0
- data/lib/aws/record/validations.rb +653 -0
- data/lib/aws/record/validator.rb +237 -0
- data/lib/aws/record/validators/acceptance.rb +51 -0
- data/lib/aws/record/validators/block.rb +38 -0
- data/lib/aws/record/validators/confirmation.rb +43 -0
- data/lib/aws/record/validators/count.rb +108 -0
- data/lib/aws/record/validators/exclusion.rb +43 -0
- data/lib/aws/record/validators/format.rb +57 -0
- data/lib/aws/record/validators/inclusion.rb +56 -0
- data/lib/aws/record/validators/length.rb +107 -0
- data/lib/aws/record/validators/numericality.rb +138 -0
- data/lib/aws/record/validators/presence.rb +45 -0
- data/lib/aws/resource_cache.rb +39 -0
- data/lib/aws/response.rb +113 -0
- data/lib/aws/response_cache.rb +50 -0
- data/lib/aws/s3.rb +109 -0
- data/lib/aws/s3/access_control_list.rb +252 -0
- data/lib/aws/s3/acl_object.rb +266 -0
- data/lib/aws/s3/bucket.rb +320 -0
- data/lib/aws/s3/bucket_collection.rb +122 -0
- data/lib/aws/s3/bucket_version_collection.rb +85 -0
- data/lib/aws/s3/client.rb +999 -0
- data/lib/aws/s3/client/xml.rb +190 -0
- data/lib/aws/s3/data_options.rb +99 -0
- data/lib/aws/s3/errors.rb +43 -0
- data/lib/aws/s3/multipart_upload.rb +318 -0
- data/lib/aws/s3/multipart_upload_collection.rb +78 -0
- data/lib/aws/s3/object_collection.rb +159 -0
- data/lib/aws/s3/object_metadata.rb +67 -0
- data/lib/aws/s3/object_upload_collection.rb +83 -0
- data/lib/aws/s3/object_version.rb +141 -0
- data/lib/aws/s3/object_version_collection.rb +78 -0
- data/lib/aws/s3/paginated_collection.rb +94 -0
- data/lib/aws/s3/policy.rb +76 -0
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +56 -0
- data/lib/aws/s3/prefixed_collection.rb +84 -0
- data/lib/aws/s3/presigned_post.rb +504 -0
- data/lib/aws/s3/request.rb +198 -0
- data/lib/aws/s3/s3_object.rb +794 -0
- data/lib/aws/s3/tree.rb +116 -0
- data/lib/aws/s3/tree/branch_node.rb +71 -0
- data/lib/aws/s3/tree/child_collection.rb +108 -0
- data/lib/aws/s3/tree/leaf_node.rb +99 -0
- data/lib/aws/s3/tree/node.rb +22 -0
- data/lib/aws/s3/tree/parent.rb +90 -0
- data/lib/aws/s3/uploaded_part.rb +82 -0
- data/lib/aws/s3/uploaded_part_collection.rb +86 -0
- data/lib/aws/service_interface.rb +60 -0
- data/lib/aws/simple_db.rb +202 -0
- data/lib/aws/simple_db/attribute.rb +159 -0
- data/lib/aws/simple_db/attribute_collection.rb +227 -0
- data/lib/aws/simple_db/client.rb +52 -0
- data/lib/aws/simple_db/client/options.rb +34 -0
- data/lib/aws/simple_db/client/xml.rb +68 -0
- data/lib/aws/simple_db/consistent_read_option.rb +42 -0
- data/lib/aws/simple_db/delete_attributes.rb +64 -0
- data/lib/aws/simple_db/domain.rb +118 -0
- data/lib/aws/simple_db/domain_collection.rb +116 -0
- data/lib/aws/simple_db/domain_metadata.rb +112 -0
- data/lib/aws/simple_db/errors.rb +46 -0
- data/lib/aws/simple_db/expect_condition_option.rb +45 -0
- data/lib/aws/simple_db/item.rb +84 -0
- data/lib/aws/simple_db/item_collection.rb +594 -0
- data/lib/aws/simple_db/item_data.rb +70 -0
- data/lib/aws/simple_db/put_attributes.rb +62 -0
- data/lib/aws/simple_db/request.rb +27 -0
- data/lib/aws/simple_email_service.rb +373 -0
- data/lib/aws/simple_email_service/client.rb +39 -0
- data/lib/aws/simple_email_service/client/options.rb +24 -0
- data/lib/aws/simple_email_service/client/xml.rb +38 -0
- data/lib/aws/simple_email_service/email_address_collection.rb +66 -0
- data/lib/aws/simple_email_service/errors.rb +29 -0
- data/lib/aws/simple_email_service/quotas.rb +64 -0
- data/lib/aws/simple_email_service/request.rb +27 -0
- data/lib/aws/sns.rb +69 -0
- data/lib/aws/sns/client.rb +37 -0
- data/lib/aws/sns/client/options.rb +24 -0
- data/lib/aws/sns/client/xml.rb +38 -0
- data/lib/aws/sns/errors.rb +29 -0
- data/lib/aws/sns/policy.rb +49 -0
- data/lib/aws/sns/request.rb +27 -0
- data/lib/aws/sns/subscription.rb +100 -0
- data/lib/aws/sns/subscription_collection.rb +84 -0
- data/lib/aws/sns/topic.rb +384 -0
- data/lib/aws/sns/topic_collection.rb +70 -0
- data/lib/aws/sns/topic_subscription_collection.rb +58 -0
- data/lib/aws/sqs.rb +70 -0
- data/lib/aws/sqs/client.rb +38 -0
- data/lib/aws/sqs/client/xml.rb +36 -0
- data/lib/aws/sqs/errors.rb +33 -0
- data/lib/aws/sqs/policy.rb +50 -0
- data/lib/aws/sqs/queue.rb +507 -0
- data/lib/aws/sqs/queue_collection.rb +105 -0
- data/lib/aws/sqs/received_message.rb +184 -0
- data/lib/aws/sqs/received_sns_message.rb +112 -0
- data/lib/aws/sqs/request.rb +44 -0
- data/lib/aws/xml_grammar.rb +923 -0
- data/rails/init.rb +15 -0
- metadata +298 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/model'
|
|
15
|
+
require 'aws/inflection'
|
|
16
|
+
|
|
17
|
+
module AWS
|
|
18
|
+
class EC2
|
|
19
|
+
|
|
20
|
+
# Represents the collection of permissions for an EC2 resource.
|
|
21
|
+
# Each permission is a string containing the AWS account ID of a
|
|
22
|
+
# user who has permission to use the resource in question. The
|
|
23
|
+
# {Image} and {Snapshot} classes are currently the only ones
|
|
24
|
+
# that use this interface.
|
|
25
|
+
class PermissionCollection
|
|
26
|
+
|
|
27
|
+
include Model
|
|
28
|
+
include Enumerable
|
|
29
|
+
|
|
30
|
+
# @private
|
|
31
|
+
def initialize(resource, opts = {})
|
|
32
|
+
@resource = resource
|
|
33
|
+
super(opts)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @yield [user_id] Each user ID that has explicit
|
|
37
|
+
# permissions to launch this AMI.
|
|
38
|
+
def each(&block)
|
|
39
|
+
resp = client.send(describe_call, describe_params)
|
|
40
|
+
resp.send(inflected_permissions_attribute).each do |permission|
|
|
41
|
+
if permission.respond_to?(:user_id)
|
|
42
|
+
user_id = permission.user_id
|
|
43
|
+
yield(user_id)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @return [Integer] The number of users that have explicit
|
|
49
|
+
# permissions to launch this AMI.
|
|
50
|
+
def size
|
|
51
|
+
inject(0) { |sum, i| sum + 1 }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @return [Boolean] True if the collection is empty.
|
|
55
|
+
def empty?
|
|
56
|
+
size == 0
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @return [Boolean] True if the resource is public.
|
|
60
|
+
def public?
|
|
61
|
+
resp = client.send(describe_call, describe_params)
|
|
62
|
+
resp.send(inflected_permissions_attribute).any? do |permission|
|
|
63
|
+
permission.respond_to?(:group) and permission.group == "all"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @return [Boolean] True if the resource is private (i.e. not
|
|
68
|
+
# public).
|
|
69
|
+
def private?
|
|
70
|
+
!public?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Sets whether the resource is public or not. This has no
|
|
74
|
+
# effect on the explicit AWS account IDs that may already have
|
|
75
|
+
# permissions to use the resource.
|
|
76
|
+
#
|
|
77
|
+
# @param [Boolean] value If true, the resource is made public,
|
|
78
|
+
# otherwise the resource is made private.
|
|
79
|
+
# @return [nil]
|
|
80
|
+
def public= value
|
|
81
|
+
params = value ?
|
|
82
|
+
{ :add => [{ :group => "all" }] } :
|
|
83
|
+
{ :remove => [{ :group => "all" }] }
|
|
84
|
+
client.send(modify_call, modify_params(params))
|
|
85
|
+
nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Adds permissions for specific users to launch this AMI.
|
|
89
|
+
#
|
|
90
|
+
# @param [Array of Strings] users The AWS account IDs of the
|
|
91
|
+
# users that should be able to launch this AMI.
|
|
92
|
+
# @return [nil]
|
|
93
|
+
def add(*users)
|
|
94
|
+
modify(:add, *users)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Removes permissions for specific users to launch this AMI.
|
|
98
|
+
# @param [Array of Strings] users The AWS account IDs of the
|
|
99
|
+
# users that should no longer be able to launch this AMI.
|
|
100
|
+
# @return [nil]
|
|
101
|
+
def remove(*users)
|
|
102
|
+
modify(:remove, *users)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Resets the launch permissions to their default state.
|
|
106
|
+
# @return [nil]
|
|
107
|
+
def reset
|
|
108
|
+
client.send(reset_call, reset_params)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @private
|
|
112
|
+
private
|
|
113
|
+
def describe_call
|
|
114
|
+
"describe_#{resource_name}_attribute"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# @private
|
|
118
|
+
private
|
|
119
|
+
def modify_call
|
|
120
|
+
"modify_#{resource_name}_attribute"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# @private
|
|
124
|
+
private
|
|
125
|
+
def reset_call
|
|
126
|
+
"reset_#{resource_name}_attribute"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# @private
|
|
130
|
+
private
|
|
131
|
+
def describe_params
|
|
132
|
+
Hash[[["#{resource_name}_id".to_sym, @resource.send(:__resource_id__)],
|
|
133
|
+
[:attribute, permissions_attribute]]]
|
|
134
|
+
end
|
|
135
|
+
alias_method :reset_params, :describe_params
|
|
136
|
+
|
|
137
|
+
# @private
|
|
138
|
+
private
|
|
139
|
+
def inflected_permissions_attribute
|
|
140
|
+
Inflection.ruby_name(permissions_attribute).to_sym
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @private
|
|
144
|
+
private
|
|
145
|
+
def permissions_attribute
|
|
146
|
+
@resource.__permissions_attribute__
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# @private
|
|
150
|
+
private
|
|
151
|
+
def resource_name
|
|
152
|
+
@resource.send(:inflected_name)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# @private
|
|
156
|
+
private
|
|
157
|
+
def modify(action, *users)
|
|
158
|
+
return if users.empty?
|
|
159
|
+
opts = modify_params(Hash[[[action,
|
|
160
|
+
users.map do |user_id|
|
|
161
|
+
{ :user_id => user_id }
|
|
162
|
+
end]]])
|
|
163
|
+
client.send(modify_call, opts)
|
|
164
|
+
nil
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# @private
|
|
168
|
+
private
|
|
169
|
+
def modify_params(modifications)
|
|
170
|
+
Hash[[["#{resource_name}_id".to_sym, @resource.send(:__resource_id__)],
|
|
171
|
+
[inflected_permissions_attribute, modifications]]]
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/ec2/resource'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
class EC2
|
|
18
|
+
|
|
19
|
+
# Represents an EC2 region. You can use this to find the
|
|
20
|
+
# endpoint for a given region:
|
|
21
|
+
#
|
|
22
|
+
# ec2.regions["us-west-1"].endpoint
|
|
23
|
+
#
|
|
24
|
+
# Region also responds to all of the methods of {EC2} except
|
|
25
|
+
# {EC2#regions}; for example, to list instance IDs by region,
|
|
26
|
+
# you can do:
|
|
27
|
+
#
|
|
28
|
+
# ec2.regions.inject({}) do |h,region|
|
|
29
|
+
# h[region.name] = region.instances.map(&:id)
|
|
30
|
+
# h
|
|
31
|
+
# end
|
|
32
|
+
class Region < Resource
|
|
33
|
+
|
|
34
|
+
# The name of the region (e.g. "us-east-1")
|
|
35
|
+
attr_reader :name
|
|
36
|
+
|
|
37
|
+
def initialize(name, options = {})
|
|
38
|
+
@name = name
|
|
39
|
+
super(options)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @return [String] The endpoint to use for this region.
|
|
43
|
+
def endpoint; end
|
|
44
|
+
describe_call_attribute :region_endpoint, :getter => :endpoint, :memoize => true
|
|
45
|
+
|
|
46
|
+
# @return [Boolean] True if the region is available for this
|
|
47
|
+
# account.
|
|
48
|
+
def exists?
|
|
49
|
+
!client.describe_regions(:filters => [{ :name => "region-name",
|
|
50
|
+
:values => [name] }]).
|
|
51
|
+
region_info.empty?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
PROXIED_METHODS = [:instances,
|
|
55
|
+
:security_groups,
|
|
56
|
+
:key_pairs,
|
|
57
|
+
:elastic_ips,
|
|
58
|
+
:tags,
|
|
59
|
+
:availability_zones,
|
|
60
|
+
:images,
|
|
61
|
+
:volumes,
|
|
62
|
+
:snapshots,
|
|
63
|
+
:reserved_instances,
|
|
64
|
+
:reserved_instances_offerings]
|
|
65
|
+
|
|
66
|
+
PROXIED_METHODS.each do |method|
|
|
67
|
+
define_method(method) do
|
|
68
|
+
EC2.new(:config => config, :ec2_endpoint => endpoint).
|
|
69
|
+
send(method)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
protected
|
|
74
|
+
def find_in_response(resp)
|
|
75
|
+
resp.region_info.find { |r| r.region_name == name }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/model'
|
|
15
|
+
require 'aws/ec2/collection'
|
|
16
|
+
require 'aws/ec2/region'
|
|
17
|
+
|
|
18
|
+
module AWS
|
|
19
|
+
class EC2
|
|
20
|
+
|
|
21
|
+
# Represents all the regions available to your account.
|
|
22
|
+
#
|
|
23
|
+
# @example Getting a map of endpoints by region name
|
|
24
|
+
# ec2.regions.inject({}) { |m, r| m[r.name] = r.endpoint; m }
|
|
25
|
+
class RegionCollection < Collection
|
|
26
|
+
|
|
27
|
+
# @yield [Region] Each region that is available to your account.
|
|
28
|
+
# @return [nil]
|
|
29
|
+
def each
|
|
30
|
+
response = filtered_request(:describe_regions)
|
|
31
|
+
response.region_info.each do |r|
|
|
32
|
+
region = Region.new(r.region_name,
|
|
33
|
+
:endpoint => r.region_endpoint,
|
|
34
|
+
:config => config)
|
|
35
|
+
yield(region)
|
|
36
|
+
end
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return [Region] The region identified by the given name
|
|
41
|
+
# (e.g. "us-east-1").
|
|
42
|
+
def [](name)
|
|
43
|
+
super
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @private
|
|
47
|
+
protected
|
|
48
|
+
def member_class
|
|
49
|
+
Region
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/http/request'
|
|
15
|
+
require 'aws/authorize_v2'
|
|
16
|
+
|
|
17
|
+
module AWS
|
|
18
|
+
class EC2
|
|
19
|
+
|
|
20
|
+
# @private
|
|
21
|
+
class Request < AWS::Http::Request
|
|
22
|
+
|
|
23
|
+
include AuthorizeV2
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/ec2/resource'
|
|
15
|
+
require 'aws/ec2/tagged_item'
|
|
16
|
+
|
|
17
|
+
module AWS
|
|
18
|
+
class EC2
|
|
19
|
+
class ReservedInstances < Resource
|
|
20
|
+
|
|
21
|
+
ATTRIBUTES = [
|
|
22
|
+
:start,
|
|
23
|
+
:instance_count,
|
|
24
|
+
:instance_type,
|
|
25
|
+
:availability_zone,
|
|
26
|
+
:duration,
|
|
27
|
+
:fixed_price,
|
|
28
|
+
:usage_price,
|
|
29
|
+
:product_description,
|
|
30
|
+
:instance_tenancy,
|
|
31
|
+
:currency_code,
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
include TaggedItem
|
|
35
|
+
|
|
36
|
+
def initialize id, options = {}
|
|
37
|
+
@id = id
|
|
38
|
+
super
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [String] The id of this reserved instance.
|
|
42
|
+
attr_reader :id
|
|
43
|
+
|
|
44
|
+
ATTRIBUTES.each do |attr_name|
|
|
45
|
+
describe_call_attribute attr_name, :memoize => true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/ec2/collection'
|
|
15
|
+
require 'aws/ec2/reserved_instances'
|
|
16
|
+
require 'aws/ec2/tagged_collection'
|
|
17
|
+
|
|
18
|
+
module AWS
|
|
19
|
+
class EC2
|
|
20
|
+
class ReservedInstancesCollection < Collection
|
|
21
|
+
|
|
22
|
+
include TaggedCollection
|
|
23
|
+
|
|
24
|
+
def member_class
|
|
25
|
+
ReservedInstances
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def each &block
|
|
29
|
+
|
|
30
|
+
response = filtered_request(:describe_reserved_instances)
|
|
31
|
+
response.reserved_instances_set.each do |item|
|
|
32
|
+
|
|
33
|
+
reserved_instance = ReservedInstances.new(
|
|
34
|
+
item.reserved_instances_id,
|
|
35
|
+
:config => config)
|
|
36
|
+
|
|
37
|
+
yield(reserved_instance)
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'aws/ec2/resource'
|
|
15
|
+
require 'aws/ec2/tagged_item'
|
|
16
|
+
|
|
17
|
+
module AWS
|
|
18
|
+
class EC2
|
|
19
|
+
class ReservedInstancesOffering < Resource
|
|
20
|
+
|
|
21
|
+
ATTRIBUTES = [
|
|
22
|
+
:instance_type,
|
|
23
|
+
:availability_zone,
|
|
24
|
+
:duration,
|
|
25
|
+
:fixed_price,
|
|
26
|
+
:usage_price,
|
|
27
|
+
:product_description,
|
|
28
|
+
:instance_tenancy,
|
|
29
|
+
:currency_code,
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
include TaggedItem
|
|
33
|
+
|
|
34
|
+
def initialize id, options = {}
|
|
35
|
+
@id = id
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @return [String] The id of this reserved instance offering.
|
|
40
|
+
attr_reader :id
|
|
41
|
+
|
|
42
|
+
ATTRIBUTES.each do |attr_name|
|
|
43
|
+
describe_call_attribute attr_name, :memoize => true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def purchase options = {}
|
|
47
|
+
options[:instance_count] = 1 unless options[:instance_count]
|
|
48
|
+
options[:reserved_instances_offering_id] = id
|
|
49
|
+
response = client.purchase_reserved_instances_offering(options)
|
|
50
|
+
ReservedInstances.new(response.reserved_instances_id, :config => config)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|