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,138 @@
|
|
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/has_permissions'
|
16
|
+
require 'aws/ec2/tagged_item'
|
17
|
+
|
18
|
+
module AWS
|
19
|
+
class EC2
|
20
|
+
|
21
|
+
# Represents an Amazon EBS snapshot.
|
22
|
+
#
|
23
|
+
# @example Taking a snapshot from a volume
|
24
|
+
# snapshot = volume.create_snapshot("Database Backup 12/21/2010")
|
25
|
+
# sleep 1 until [:completed, :error].include?(snapshot.status)
|
26
|
+
#
|
27
|
+
# @example Managing snapshot permissions
|
28
|
+
# unless snapshot.public?
|
29
|
+
# snapshot.permissions.add("12345678901")
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# @attr_reader [String] volume_id The ID of the volume this
|
33
|
+
# snapshot was created from.
|
34
|
+
#
|
35
|
+
# @attr_reader [Symbol] status The status of the snapshot.
|
36
|
+
# Possible values:
|
37
|
+
#
|
38
|
+
# * +:pending+
|
39
|
+
# * +:completed+
|
40
|
+
# * +:error+
|
41
|
+
#
|
42
|
+
# @attr_reader [Time] start_time The time at which the snapshot
|
43
|
+
# was initiated.
|
44
|
+
#
|
45
|
+
# @attr_reader [Integer] progress The progress of the snapshot
|
46
|
+
# as a percentage.
|
47
|
+
#
|
48
|
+
# @attr_reader [String] owner_id The AWS account ID of the
|
49
|
+
# snapshot owner.
|
50
|
+
#
|
51
|
+
# @attr_reader [Integer] volume_size The size of the volume from
|
52
|
+
# which the snapshot was created.
|
53
|
+
#
|
54
|
+
# @attr_reader [String] description The description of the
|
55
|
+
# snapshot provided at snapshot initiation.
|
56
|
+
class Snapshot < Resource
|
57
|
+
|
58
|
+
include HasPermissions
|
59
|
+
include TaggedItem
|
60
|
+
alias_method :create_volume_permissions, :permissions
|
61
|
+
|
62
|
+
# The snapshot ID
|
63
|
+
attr_reader :id
|
64
|
+
|
65
|
+
# @private
|
66
|
+
def initialize(id, opts = {})
|
67
|
+
@id = id
|
68
|
+
super(opts)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Deletes the snapshot.
|
72
|
+
def delete
|
73
|
+
client.delete_snapshot(:snapshot_id => id)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Creates a volume from the snapshot.
|
77
|
+
#
|
78
|
+
# @param [AvailabilityZone or String] availability_zone The
|
79
|
+
# Availability Zone in which to create the new volume. See
|
80
|
+
# {EC2#availability_zones} for how to get a list of
|
81
|
+
# availability zones.
|
82
|
+
#
|
83
|
+
# @param [Hash] opts Additional options for creating the volume
|
84
|
+
#
|
85
|
+
# @option opts [Integer] size The desired size (in gigabytes)
|
86
|
+
# for the volume.
|
87
|
+
#
|
88
|
+
# @return [Volume] The newly created volume
|
89
|
+
def create_volume(availability_zone, opts = {})
|
90
|
+
VolumeCollection.new(:config => config).
|
91
|
+
create(opts.merge(:snapshot => self,
|
92
|
+
:availability_zone => availability_zone))
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [Boolean] True if the snapshot exists.
|
96
|
+
def exists?
|
97
|
+
resp =
|
98
|
+
client.describe_snapshots(:filters => [{ :name => 'snapshot-id',
|
99
|
+
:values => [id] }]) and
|
100
|
+
!resp.snapshot_set.empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
describe_call_attribute :volume_id
|
104
|
+
|
105
|
+
# @return [Volume] The volume this snapshot was created from.
|
106
|
+
def volume
|
107
|
+
Volume.new(volume_id, :config => config) if volume_id
|
108
|
+
end
|
109
|
+
|
110
|
+
describe_call_attribute :status, :to_sym => true
|
111
|
+
describe_call_attribute :start_time
|
112
|
+
describe_call_attribute :progress do
|
113
|
+
translate_output { |value| value.to_i if value }
|
114
|
+
end
|
115
|
+
describe_call_attribute :owner_id
|
116
|
+
describe_call_attribute :volume_size
|
117
|
+
describe_call_attribute :owner_alias
|
118
|
+
describe_call_attribute :description
|
119
|
+
|
120
|
+
# @private
|
121
|
+
def __permissions_attribute__
|
122
|
+
"createVolumePermission"
|
123
|
+
end
|
124
|
+
|
125
|
+
populate_from :create_snapshot do |resp|
|
126
|
+
attributes_from_response_object(resp) if
|
127
|
+
resp.snapshot_id == id
|
128
|
+
end
|
129
|
+
|
130
|
+
protected
|
131
|
+
def find_in_response(resp)
|
132
|
+
resp.snapshot_index[id]
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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/snapshot'
|
17
|
+
|
18
|
+
module AWS
|
19
|
+
class EC2
|
20
|
+
|
21
|
+
# Represents a collection of Amazon EBS snapshots. Typically
|
22
|
+
# you should get an instance of this class by calling
|
23
|
+
# {EC2#snapshots}.
|
24
|
+
#
|
25
|
+
# @example Create a snapshot from a volume
|
26
|
+
# ec2.snapshots.create(:volume => ec2.volumes["vol-123"],
|
27
|
+
# :description => "my snapshot")
|
28
|
+
# # or:
|
29
|
+
# ec2.volumes["vol-123"].create_snapshot("my snapshot")
|
30
|
+
#
|
31
|
+
# @example Get a snapshot by ID
|
32
|
+
# snapshot = ec2.snapshots["vol-123"]
|
33
|
+
# snapshot.exists?
|
34
|
+
#
|
35
|
+
# @example Get a map of snapshot IDs to snapshot status
|
36
|
+
# ec2.snapshots.inject({}) { |m, s| m[i.id] = s.status; m }
|
37
|
+
# # => { "snap-12345678" => :pending, "snap-87654321" => :completed }
|
38
|
+
class SnapshotCollection < Collection
|
39
|
+
|
40
|
+
include TaggedCollection
|
41
|
+
|
42
|
+
# @yield [Instance] Yields each volume in the collection.
|
43
|
+
# @return [nil]
|
44
|
+
def each(&block)
|
45
|
+
resp = filtered_request(:describe_snapshots)
|
46
|
+
resp.snapshot_set.each do |v|
|
47
|
+
snapshot = Snapshot.new(v.snapshot_id, :config => config)
|
48
|
+
yield(snapshot)
|
49
|
+
end
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Creates a snapshot of an Amazon EBS volume and stores it in
|
54
|
+
# Amazon S3. You can use snapshots for backups, to make
|
55
|
+
# identical copies of instance devices, and to save data
|
56
|
+
# before shutting down an instance. For more information about
|
57
|
+
# Amazon EBS, go to the {Amazon Elastic Compute Cloud User
|
58
|
+
# Guide}[http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?using-ebs.html].
|
59
|
+
#
|
60
|
+
# @return [Snapshot] An object representing the new snapshot.
|
61
|
+
#
|
62
|
+
# @param [Hash] opts Options for creating the snapshot.
|
63
|
+
# Either +:volume+ or +:volume_id+ is required.
|
64
|
+
#
|
65
|
+
# @param opts [Volume] :volume The Amazon EBS volume of which
|
66
|
+
# to take a snapshot.
|
67
|
+
#
|
68
|
+
# @param opts [String] :volume_id The ID of the Amazon EBS
|
69
|
+
# volume of which to take a snapshot.
|
70
|
+
#
|
71
|
+
# @param opts [String] :description An optional description of
|
72
|
+
# the snapshot. May contain up to 255 characters.
|
73
|
+
def create opts = {}
|
74
|
+
if volume = opts.delete(:volume)
|
75
|
+
opts[:volume_id] = volume.id
|
76
|
+
end
|
77
|
+
resp = client.create_snapshot(opts)
|
78
|
+
Snapshot.new(resp.snapshot_id, :config => config)
|
79
|
+
end
|
80
|
+
|
81
|
+
# @private
|
82
|
+
protected
|
83
|
+
def member_class
|
84
|
+
Snapshot
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
data/lib/aws/ec2/tag.rb
ADDED
@@ -0,0 +1,88 @@
|
|
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/cacheable'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class EC2
|
19
|
+
|
20
|
+
# Represents an EC2 tag.
|
21
|
+
class Tag < Resource
|
22
|
+
|
23
|
+
# @param [String] key The name of the tag
|
24
|
+
# @param [Hash] options
|
25
|
+
# @option options [String] :value ('') The optional value of the tag.
|
26
|
+
def initialize resource, key, options = {}
|
27
|
+
@resource = resource
|
28
|
+
@key = key.to_s
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Object] The EC2 resource this tag belongs to.
|
33
|
+
attr_reader :resource
|
34
|
+
|
35
|
+
# @return [String] The name of this tag.
|
36
|
+
attr_reader :key
|
37
|
+
|
38
|
+
alias_method :name, :key
|
39
|
+
|
40
|
+
# @return [String] The tag value.
|
41
|
+
def value; end
|
42
|
+
describe_call_attribute :value
|
43
|
+
|
44
|
+
# Deletes this tag.
|
45
|
+
# @return [nil]
|
46
|
+
def delete(value = nil)
|
47
|
+
tag_opts = { :key => key }
|
48
|
+
tag_opts[:value] = value if value
|
49
|
+
client.delete_tags(:resources => [resource.id], :tags => [tag_opts])
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# @private
|
54
|
+
def inspect
|
55
|
+
"<#{local_cache_key}>"
|
56
|
+
end
|
57
|
+
|
58
|
+
# @private
|
59
|
+
def local_cache_key
|
60
|
+
"#{self.class}:#{response_index_key}"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def response_index_key
|
65
|
+
type = resource.tagging_resource_type
|
66
|
+
id = resource.send(:__resource_id__)
|
67
|
+
"#{type}:#{id}:#{key}"
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
def find_in_response(resp)
|
72
|
+
resp.tag_index[response_index_key]
|
73
|
+
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
def describe_call
|
77
|
+
client.describe_tags(:filters =>
|
78
|
+
[{ :name => "key",
|
79
|
+
:values => [key] },
|
80
|
+
{ :name => "resource-type",
|
81
|
+
:values => [resource.tagging_resource_type] },
|
82
|
+
{ :name => "resource-id",
|
83
|
+
:values => [resource.send(:__resource_id__)] }])
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,114 @@
|
|
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
|
+
require 'aws/ec2/collection'
|
17
|
+
require 'aws/ec2/tag'
|
18
|
+
require 'aws/ec2/tagged_item'
|
19
|
+
require 'aws/ec2/resource'
|
20
|
+
|
21
|
+
module AWS
|
22
|
+
class EC2
|
23
|
+
|
24
|
+
# Temporary class that will be removed once the rest of the taggable
|
25
|
+
# EC2 resources have been modeled.
|
26
|
+
class ResourceObject < Resource
|
27
|
+
|
28
|
+
def initialize id, options = {}
|
29
|
+
@id = id
|
30
|
+
@resource_type = options[:resource_type]
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :id
|
35
|
+
|
36
|
+
include TaggedItem
|
37
|
+
|
38
|
+
# @private
|
39
|
+
def tagging_resource_type
|
40
|
+
@resource_type
|
41
|
+
end
|
42
|
+
|
43
|
+
# @private
|
44
|
+
# We don't know how to make a describe call for this object yet
|
45
|
+
def cached_tags; nil; end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# Represents all EC2 tags in an account.
|
50
|
+
class TagCollection < Collection
|
51
|
+
|
52
|
+
# Creates a new Tag and assigns it to an EC2 resource.
|
53
|
+
#
|
54
|
+
# @example tagging with names (keys) only
|
55
|
+
#
|
56
|
+
# ec2.tags.create(instance, 'webserver')
|
57
|
+
#
|
58
|
+
# @example tagging with names (keys) and values
|
59
|
+
#
|
60
|
+
# ec2.tags.create(instance, 'stage', 'production')
|
61
|
+
#
|
62
|
+
# @param [Object] resource The item to tag. This should be a taggable
|
63
|
+
# EC2 resource, like an instance, security group, etc.
|
64
|
+
# @param [String] key The tag key (or name).
|
65
|
+
# @param [Hash] options
|
66
|
+
# @option optins [String] :value ('') The optional tag value. When
|
67
|
+
# left blank its assigned the empty string.
|
68
|
+
# @return [Tag]
|
69
|
+
def create resource, key, options = {}
|
70
|
+
value = options[:value].to_s
|
71
|
+
client.create_tags(
|
72
|
+
:resources => [resource.id],
|
73
|
+
:tags => [{ :key => key, :value => value }])
|
74
|
+
Tag.new(resource, key, :value => value, :config => config)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Tag] Returns a reference to a tag with the given name.
|
78
|
+
def [] tag_name
|
79
|
+
super
|
80
|
+
end
|
81
|
+
|
82
|
+
# Yields once for each tag.
|
83
|
+
# @yield [tag]
|
84
|
+
# @yieldparam [Tag] tag
|
85
|
+
# @return [nil]
|
86
|
+
def each &block
|
87
|
+
response = filtered_request(:describe_tags)
|
88
|
+
response.tag_set.each do |tag|
|
89
|
+
|
90
|
+
resource_class_name = Inflection.class_name(tag.resource_type)
|
91
|
+
if EC2.const_defined?(resource_class_name)
|
92
|
+
resource_class = EC2.const_get(resource_class_name)
|
93
|
+
resource = resource_class.new(tag.resource_id, :config => config)
|
94
|
+
else
|
95
|
+
resource = ResourceObject.new(tag.resource_id,
|
96
|
+
:resource_type => tag.resource_type,
|
97
|
+
:config => config)
|
98
|
+
end
|
99
|
+
|
100
|
+
yield(Tag.new(resource, tag.key))
|
101
|
+
|
102
|
+
end
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
# @private
|
107
|
+
protected
|
108
|
+
def member_class
|
109
|
+
Tag
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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
|
+
module AWS
|
15
|
+
class EC2
|
16
|
+
|
17
|
+
# @private
|
18
|
+
module TaggedCollection
|
19
|
+
|
20
|
+
# Filter the collection by one or more tag keys. If you pass multiple
|
21
|
+
# tag keys they will be be treated as OR conditions. If you want to
|
22
|
+
# AND them together call tagged multiple times (chained).
|
23
|
+
#
|
24
|
+
# Filter the collection to items items tagged 'live' OR 'test'
|
25
|
+
#
|
26
|
+
# collection.tagged('live', 'test')
|
27
|
+
#
|
28
|
+
# Filter the collection to items tagged 'live' AND 'webserver'
|
29
|
+
#
|
30
|
+
# collection.tagged('live').tagged('webserver')
|
31
|
+
#
|
32
|
+
def tagged *keys
|
33
|
+
filter('tag-key', *keys)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Filter the collection by one or more tag values. If you pass multiple
|
37
|
+
# tag values they will be be treated as OR conditions. If you want to
|
38
|
+
# AND them together call tagged multiple times (chained).
|
39
|
+
#
|
40
|
+
# collection.tagged('stage').tagged_values('production')
|
41
|
+
#
|
42
|
+
def tagged_values *values
|
43
|
+
filter('tag-value', *values)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|