aws-sdk 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,87 @@
|
|
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_tag_collection'
|
15
|
+
|
16
|
+
module AWS
|
17
|
+
class EC2
|
18
|
+
module TaggedItem
|
19
|
+
|
20
|
+
# Adds a single tag with an optional tag value.
|
21
|
+
#
|
22
|
+
# # adds a tag with the key production
|
23
|
+
# resource.tag('production')
|
24
|
+
#
|
25
|
+
# # adds a tag with the optional value set to production
|
26
|
+
# resource.tag('role', :value => 'webserver')
|
27
|
+
#
|
28
|
+
# @param [String] key The name of the tag to add.
|
29
|
+
# @param [Hash] options
|
30
|
+
# @option options [String] :value An optional tag value.
|
31
|
+
# @return [Tag] The tag that was created.
|
32
|
+
def add_tag key, options = {}
|
33
|
+
client.create_tags({
|
34
|
+
:resources => [id],
|
35
|
+
:tags => [{ :key => key, :value => options[:value].to_s }],
|
36
|
+
})
|
37
|
+
Tag.new(self, key, options.merge(:config => config))
|
38
|
+
end
|
39
|
+
alias_method :tag, :add_tag
|
40
|
+
|
41
|
+
# Deletes all tags associated with this EC2 resource.
|
42
|
+
# @return [nil]
|
43
|
+
def clear_tags
|
44
|
+
client.delete_tags(:resources => [self.id])
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns a collection that represents only tags belonging to
|
49
|
+
# this resource.
|
50
|
+
#
|
51
|
+
# @example Manipulating the tags of an EC2 instance
|
52
|
+
# i = ec2.instances["i-123"]
|
53
|
+
# i.tags.to_h # => { "foo" => "bar", ... }
|
54
|
+
# i.tags.clear
|
55
|
+
# i.tags.stage = "production"
|
56
|
+
# i.tags.stage # => "production"
|
57
|
+
#
|
58
|
+
# @return [ResourceTagCollection] A collection of tags that
|
59
|
+
# belong to this resource.
|
60
|
+
#
|
61
|
+
def tags
|
62
|
+
ResourceTagCollection.new(self, :config => config)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @private
|
66
|
+
def cached_tags
|
67
|
+
if cache = AWS.response_cache
|
68
|
+
cache.select(describe_call_name.to_sym).each do |resp|
|
69
|
+
if obj = find_in_response(resp)
|
70
|
+
return obj.tag_set.inject({}) do |hash, tag|
|
71
|
+
hash[tag.key] = tag.value
|
72
|
+
hash
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
# @private
|
81
|
+
def tagging_resource_type
|
82
|
+
Inflection.ruby_name(self.class.to_s).tr("_","-")
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,190 @@
|
|
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
|
+
require 'aws/ec2/availability_zone'
|
17
|
+
require 'aws/ec2/attachment'
|
18
|
+
require 'aws/ec2/attachment_collection'
|
19
|
+
|
20
|
+
module AWS
|
21
|
+
class EC2
|
22
|
+
|
23
|
+
# Represents an Amazon EBS volume.
|
24
|
+
#
|
25
|
+
# @example Create an empty 15GiB volume and attach it to an instance
|
26
|
+
# volume = ec2.volumes.create(:size => 15,
|
27
|
+
# :availability_zone => "us-east-1a")
|
28
|
+
# attachment = volume.attach_to(ec2.instances["i-123"], "/dev/sdf")
|
29
|
+
# sleep 1 until attachment.status != :attaching
|
30
|
+
#
|
31
|
+
# @example Remove all attachments from a volume and then delete it
|
32
|
+
# volume.attachments.each do |attachment|
|
33
|
+
# attachment.delete(:force => true)
|
34
|
+
# end
|
35
|
+
# sleep 1 until volume.status == :available
|
36
|
+
# volume.delete
|
37
|
+
#
|
38
|
+
# @attr_reader [Symbol] status The status of the volume.
|
39
|
+
# Possible values:
|
40
|
+
#
|
41
|
+
# * +:creating+
|
42
|
+
# * +:available+
|
43
|
+
# * +:in_use+
|
44
|
+
# * +:deleting+
|
45
|
+
# * +:deleted+
|
46
|
+
# * +:error+
|
47
|
+
#
|
48
|
+
# @attr_reader [Integer] size The size of the volume in
|
49
|
+
# gigabytes.
|
50
|
+
#
|
51
|
+
# @attr_reader [AvailabilityZone] availability_zone Availability
|
52
|
+
# Zone in which the volume was created.
|
53
|
+
#
|
54
|
+
# @attr_reader [Time] create_time The time at which the volume
|
55
|
+
# was created.
|
56
|
+
class Volume < Resource
|
57
|
+
|
58
|
+
include TaggedItem
|
59
|
+
|
60
|
+
attr_reader :id
|
61
|
+
|
62
|
+
# @private
|
63
|
+
def initialize(id, opts = {})
|
64
|
+
@id = id
|
65
|
+
super(opts)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Deletes the volume.
|
69
|
+
def delete
|
70
|
+
client.delete_volume(:volume_id => id)
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [Snapshot] A new snapshot created from the volume.
|
74
|
+
#
|
75
|
+
# @param [String] description An optional description of the
|
76
|
+
# snapshot. May be up to 255 characters in length.
|
77
|
+
def create_snapshot(description = nil)
|
78
|
+
opts = { :volume => self }
|
79
|
+
opts[:description] = description if description
|
80
|
+
SnapshotCollection.new(:config => config).
|
81
|
+
create(opts)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Attaches the volume to an instance.
|
85
|
+
#
|
86
|
+
# @param [Instance] instance The instance to which the volume
|
87
|
+
# attaches. The volume and instance must be within the same
|
88
|
+
# Availability Zone and the instance must be running.
|
89
|
+
#
|
90
|
+
# @param [String] device How the device is exposed to the
|
91
|
+
# instance (e.g., /dev/sdh, or xvdh).
|
92
|
+
#
|
93
|
+
# @return [Attachment] An object representing the attachment,
|
94
|
+
# which you can use to query the attachment status.
|
95
|
+
def attach_to(instance, device)
|
96
|
+
resp = client.attach_volume(:volume_id => id,
|
97
|
+
:instance_id => instance.id,
|
98
|
+
:device => device)
|
99
|
+
Attachment.new(self,
|
100
|
+
Instance.new(resp.instance_id),
|
101
|
+
resp.device,
|
102
|
+
:config => config)
|
103
|
+
end
|
104
|
+
alias_method :attach, :attach_to
|
105
|
+
|
106
|
+
# Detaches the volume from an instance.
|
107
|
+
#
|
108
|
+
# @param [Instance] instance The instance to detach from.
|
109
|
+
#
|
110
|
+
# @param [String] device The device name.
|
111
|
+
#
|
112
|
+
# @param [Hash] opts Additional options for detaching the
|
113
|
+
# volume.
|
114
|
+
#
|
115
|
+
# @option opts [Boolean] :force Forces detachment if the
|
116
|
+
# previous detachment attempt did not occur cleanly (logging
|
117
|
+
# into an instance, unmounting the volume, and detaching
|
118
|
+
# normally). This option can lead to data loss or a
|
119
|
+
# corrupted file system. Use this option only as a last
|
120
|
+
# resort to detach a volume from a failed instance. The
|
121
|
+
# instance will not have an opportunity to flush file system
|
122
|
+
# caches or file system metadata. If you use this option,
|
123
|
+
# you must perform file system check and repair procedures.
|
124
|
+
def detach_from(instance, device, opts = {})
|
125
|
+
a = Attachment.new(self,
|
126
|
+
Instance.new(instance.id),
|
127
|
+
device,
|
128
|
+
:config => config)
|
129
|
+
a.delete
|
130
|
+
a
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [AttachmentCollection] The collection of attachments
|
134
|
+
# that involve this volume.
|
135
|
+
def attachments
|
136
|
+
AttachmentCollection.new(self, :config => config)
|
137
|
+
end
|
138
|
+
|
139
|
+
# @return [Boolean] True if the volume exists.
|
140
|
+
def exists?
|
141
|
+
resp =
|
142
|
+
client.describe_volumes(:filters => [{ :name => 'volume-id',
|
143
|
+
:values => [id] }]) and
|
144
|
+
resp.volume_index.key?(id)
|
145
|
+
end
|
146
|
+
|
147
|
+
describe_call_attribute :status, :to_sym => true
|
148
|
+
alias_method :state, :status
|
149
|
+
|
150
|
+
describe_call_attribute :snapshot_id
|
151
|
+
|
152
|
+
# @return [Snapshot] Snapshot from which the volume was created
|
153
|
+
# (may be nil).
|
154
|
+
def snapshot;
|
155
|
+
if snapshot_id = self.snapshot_id
|
156
|
+
Snapshot.new(snapshot_id, :config => config)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe_call_attribute :size do
|
161
|
+
translate_output { |value| value.to_i if value }
|
162
|
+
end
|
163
|
+
|
164
|
+
describe_call_attribute :availability_zone, :getter => :availability_zone_name
|
165
|
+
|
166
|
+
def availability_zone
|
167
|
+
if name = availability_zone_name
|
168
|
+
AvailabilityZone.new(name, :config => config)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe_call_attribute :create_time
|
173
|
+
|
174
|
+
describe_call_attribute :attachment_set
|
175
|
+
|
176
|
+
populate_from :create_volume do |resp|
|
177
|
+
attributes_from_response_object(resp) if
|
178
|
+
resp.volume_id == id
|
179
|
+
end
|
180
|
+
|
181
|
+
# @private
|
182
|
+
protected
|
183
|
+
def find_in_response(resp)
|
184
|
+
resp.volume_index[id]
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,95 @@
|
|
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/tagged_collection'
|
16
|
+
require 'aws/ec2/volume'
|
17
|
+
|
18
|
+
module AWS
|
19
|
+
class EC2
|
20
|
+
|
21
|
+
# Represents a collection of Amazon EBS volumes. Typically you
|
22
|
+
# should get an instance of this class by calling {EC2#volumes}.
|
23
|
+
#
|
24
|
+
# @example Create an empty 15GiB volume
|
25
|
+
# ec2.volumes.create(:size => 15,
|
26
|
+
# :availability_zone => "us-east-1a")
|
27
|
+
#
|
28
|
+
# @example Get a volume by ID
|
29
|
+
# volume = ec2.volumes["vol-123"]
|
30
|
+
# volume.exists?
|
31
|
+
#
|
32
|
+
# @example Get a map of volume IDs to volume status
|
33
|
+
# ec2.volumes.inject({}) { |m, v| m[i.id] = v.status; m }
|
34
|
+
# # => { "vol-12345678" => :available, "vol-87654321" => :in_use }
|
35
|
+
class VolumeCollection < Collection
|
36
|
+
|
37
|
+
include TaggedCollection
|
38
|
+
|
39
|
+
# @yield [Instance] Yields each volume in the collection.
|
40
|
+
# @return [nil]
|
41
|
+
def each(&block)
|
42
|
+
resp = filtered_request(:describe_volumes)
|
43
|
+
resp.volume_set.each do |v|
|
44
|
+
volume = Volume.new(v.volume_id, :config => config)
|
45
|
+
yield(volume)
|
46
|
+
end
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# Creates a new Amazon EBS volume that any Amazon EC2 instance
|
51
|
+
# in the same Availability Zone can attach to. For more
|
52
|
+
# information about Amazon EBS, go to the {Amazon Elastic
|
53
|
+
# Compute Cloud User
|
54
|
+
# Guide}[http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?using-ebs.html].
|
55
|
+
#
|
56
|
+
# @return [Volume] An object representing the new volume.
|
57
|
+
#
|
58
|
+
# @param [Hash] opts Options for creating the volume.
|
59
|
+
# +:availability_zone+ and one of +:size+, +:snapshot+, or
|
60
|
+
# +:snapshot_id+ is required.
|
61
|
+
#
|
62
|
+
# @option opts [Integer] :size The size of the volume, in
|
63
|
+
# GiBs. Valid values: 1 - 1024. If +:snapshot+ or
|
64
|
+
# +:snapshot_id+ is specified, this defaults to the size of
|
65
|
+
# the specified snapshot.
|
66
|
+
#
|
67
|
+
# @option opts [Snapshot] :snapshot The snapshot from which to
|
68
|
+
# create the new volume.
|
69
|
+
#
|
70
|
+
# @option opts [String] :snapshot_id The ID of the snapshot
|
71
|
+
# from which to create the new volume.
|
72
|
+
#
|
73
|
+
# @option opts [String, AvailabilityZone] :availability_zone
|
74
|
+
# The Availability Zone in which to create the new volume.
|
75
|
+
# To get a list of the availability zones you can use, see
|
76
|
+
# {EC2#availability_zones}.
|
77
|
+
# @return [Volume]
|
78
|
+
def create(opts = {})
|
79
|
+
if snapshot = opts.delete(:snapshot)
|
80
|
+
opts[:snapshot_id] = snapshot.id
|
81
|
+
end
|
82
|
+
resp = client.create_volume(opts)
|
83
|
+
Volume.new(resp.volume_id, :config => config)
|
84
|
+
end
|
85
|
+
|
86
|
+
# @private
|
87
|
+
protected
|
88
|
+
def member_class
|
89
|
+
Volume
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
data/lib/aws/errors.rb
ADDED
@@ -0,0 +1,129 @@
|
|
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 'thread'
|
15
|
+
require 'aws/xml_grammar'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
module Errors
|
19
|
+
|
20
|
+
# Base class for the two service error classes:
|
21
|
+
#
|
22
|
+
# * {ClientError}
|
23
|
+
# * {ServerError}
|
24
|
+
#
|
25
|
+
# When interacting with Amazon AWS services, you will sometimes
|
26
|
+
# receive a non-200 level response. These http responses are treated
|
27
|
+
# as errors.
|
28
|
+
#
|
29
|
+
# == Client Errors
|
30
|
+
#
|
31
|
+
# Errors in the three and four hundreds are client errors ({ClientError}).
|
32
|
+
# A client error should not be resent without changes. The body of the
|
33
|
+
# http response (the error #message) should give more information about
|
34
|
+
# the nature of the problem.
|
35
|
+
#
|
36
|
+
# == Server Errors
|
37
|
+
#
|
38
|
+
# A 500 level error typically indicates the service is having an issue.
|
39
|
+
#
|
40
|
+
# Requests that generate service errors are automatically retried with
|
41
|
+
# an exponential backoff. If the service still fails to respond with
|
42
|
+
# a 200 after 3 retries the error is raised.
|
43
|
+
#
|
44
|
+
class Base < StandardError
|
45
|
+
|
46
|
+
# @return [Http::Request] The low level http request that caused the
|
47
|
+
# error to be raised.
|
48
|
+
attr_reader :http_request
|
49
|
+
|
50
|
+
# @return [Http::Response] The low level http response from the service
|
51
|
+
# that wrapped the service error.
|
52
|
+
attr_reader :http_response
|
53
|
+
|
54
|
+
def initialize http_request, http_response, message = http_response.body
|
55
|
+
@http_request = http_request
|
56
|
+
@http_response = http_response
|
57
|
+
super(message)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# @private
|
63
|
+
module ExceptionMixinClassMethods
|
64
|
+
def new(*args)
|
65
|
+
e = Base.new(*args)
|
66
|
+
e.extend(self)
|
67
|
+
e
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Raised when an error occurs as a result of bad client
|
72
|
+
# behavior, most commonly when the parameters passed to a method
|
73
|
+
# are somehow invalid. Other common cases:
|
74
|
+
#
|
75
|
+
# * Throttling errors
|
76
|
+
# * Bad credentials
|
77
|
+
# * No permission to do the requested operation
|
78
|
+
# * Limits exceeded (e.g. too many buckets)
|
79
|
+
#
|
80
|
+
module ClientError
|
81
|
+
extend ExceptionMixinClassMethods
|
82
|
+
end
|
83
|
+
|
84
|
+
# Raised when an AWS service is unable to handle the request. These
|
85
|
+
# are automatically retired. If after 3 retries the request is still
|
86
|
+
# failing, then the error is raised.
|
87
|
+
module ServerError
|
88
|
+
extend ExceptionMixinClassMethods
|
89
|
+
end
|
90
|
+
|
91
|
+
# @private
|
92
|
+
module ModeledError
|
93
|
+
|
94
|
+
# @return [String] The error message given by the AWS service.
|
95
|
+
attr_accessor :message
|
96
|
+
|
97
|
+
# @return [Integer] The HTTP status code returned by the AWS service.
|
98
|
+
attr_reader :code
|
99
|
+
|
100
|
+
def initialize(req, resp)
|
101
|
+
super(req, resp, message)
|
102
|
+
include_error_type
|
103
|
+
parse_body(resp.body)
|
104
|
+
end
|
105
|
+
|
106
|
+
def include_error_type
|
107
|
+
if http_response.status >= 500
|
108
|
+
extend ServerError
|
109
|
+
else
|
110
|
+
extend ClientError
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse_body(body)
|
115
|
+
error_grammar.parse(body, :context => self)
|
116
|
+
end
|
117
|
+
|
118
|
+
def extract_message(body)
|
119
|
+
error_grammar.parse(body).message
|
120
|
+
end
|
121
|
+
|
122
|
+
def error_grammar
|
123
|
+
self.class::BASE_ERROR_GRAMMAR
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|