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,39 @@
|
|
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/filtered_collection'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class EC2
|
19
|
+
|
20
|
+
# @private
|
21
|
+
class Collection
|
22
|
+
|
23
|
+
include Model
|
24
|
+
include Enumerable
|
25
|
+
include FilteredCollection
|
26
|
+
|
27
|
+
def [] id
|
28
|
+
member_class.new(id.to_s, :config => config)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def member_class
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
|
3
|
+
module AWS
|
4
|
+
class EC2
|
5
|
+
|
6
|
+
# @private
|
7
|
+
class ConfigTransform
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def transform(api_config)
|
12
|
+
["RunInstances",
|
13
|
+
"DetachVolume",
|
14
|
+
"AttachVolume",
|
15
|
+
"CreateSnapshot",
|
16
|
+
"CreateVolume",
|
17
|
+
"DescribeImageAttribute",
|
18
|
+
"DescribeInstanceAttribute"].each do |(op, wrapper)|
|
19
|
+
if op_config = api_config[:operations][op]
|
20
|
+
op_config[:output] = op_config[:output].first.values.first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
api_config[:operations].each do |op, op_config|
|
25
|
+
op_config[:input] =
|
26
|
+
capitalize_input_structure(op_config[:input])
|
27
|
+
end
|
28
|
+
|
29
|
+
api_config
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def capitalize_input_structure(struct)
|
34
|
+
struct.inject({}) do |m, (name, desc)|
|
35
|
+
|
36
|
+
name = name[0,1].upcase + name[1..-1]
|
37
|
+
m[name] = capitalize_input_descriptors(desc)
|
38
|
+
m
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def capitalize_input_descriptors(desc)
|
44
|
+
desc.map do |d|
|
45
|
+
case
|
46
|
+
when d.kind_of?(Hash) && d.key?(:structure)
|
47
|
+
d.merge(:structure =>
|
48
|
+
capitalize_input_structure(d[:structure]))
|
49
|
+
when d.kind_of?(Hash) && d.key?(:list)
|
50
|
+
d.merge(:list =>
|
51
|
+
capitalize_input_descriptors(d[:list]))
|
52
|
+
else
|
53
|
+
d
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,107 @@
|
|
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
|
+
class ElasticIp < Resource
|
19
|
+
|
20
|
+
def initialize public_ip, options = {}
|
21
|
+
@public_ip = public_ip
|
22
|
+
@instance_id = options[:instance_id]
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
# @private
|
27
|
+
def self.describe_call_name; :describe_addresses; end
|
28
|
+
|
29
|
+
# @private
|
30
|
+
def describe_call_name; self.class.describe_call_name; end
|
31
|
+
|
32
|
+
# @return [String] The public IP address.
|
33
|
+
attr_reader :public_ip
|
34
|
+
|
35
|
+
alias_method :ip_address, :public_ip
|
36
|
+
|
37
|
+
# @return [String,nil] Returns the instance id if assigned to an
|
38
|
+
# EC2 instance
|
39
|
+
def instance_id; end
|
40
|
+
describe_call_attribute :instance_id
|
41
|
+
|
42
|
+
# @return [Boolean] Returns true if this IP address is attached to
|
43
|
+
# an EC2 instance.
|
44
|
+
def associated?
|
45
|
+
!!instance_id
|
46
|
+
end
|
47
|
+
alias_method :attached?, :associated?
|
48
|
+
|
49
|
+
# @return [Instance,nil] If associated, returns the {Instance} this
|
50
|
+
# elastic IP address is associated to, nil otherwise.
|
51
|
+
def instance
|
52
|
+
associated? ? Instance.new(instance_id, :config => config) : nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# Releases the elastic IP address.
|
56
|
+
#
|
57
|
+
# (For non-VPC elastic ips) Releasing an IP address automatically
|
58
|
+
# disassociates it from any instance it's associated with.
|
59
|
+
#
|
60
|
+
# @return [true]
|
61
|
+
def delete
|
62
|
+
client.release_address(:public_ip => public_ip)
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
alias_method :release, :delete
|
67
|
+
|
68
|
+
# Disassociates this elastic IP address from an EC2 instance.
|
69
|
+
# Raises an exception if this elastic IP is not currently
|
70
|
+
# associated with an instance.
|
71
|
+
# @return [true]
|
72
|
+
def disassociate
|
73
|
+
client.disassociate_address(:public_ip => public_ip)
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
# @private
|
78
|
+
# @return [String] Returns the public IP address
|
79
|
+
def to_s
|
80
|
+
public_ip.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
# @private
|
84
|
+
protected
|
85
|
+
def resource_id_method
|
86
|
+
:public_ip
|
87
|
+
end
|
88
|
+
|
89
|
+
# @private
|
90
|
+
protected
|
91
|
+
def response_id_method
|
92
|
+
:public_ip
|
93
|
+
end
|
94
|
+
|
95
|
+
# @private
|
96
|
+
protected
|
97
|
+
def find_in_response(resp)
|
98
|
+
resp.address_index[public_ip]
|
99
|
+
end
|
100
|
+
|
101
|
+
# @private
|
102
|
+
protected
|
103
|
+
def __resource_id__; public_ip; end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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/elastic_ip'
|
17
|
+
|
18
|
+
module AWS
|
19
|
+
class EC2
|
20
|
+
class ElasticIpCollection < Collection
|
21
|
+
|
22
|
+
def create
|
23
|
+
response = client.allocate_address
|
24
|
+
ElasticIp.new(response.public_ip, :config => config)
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :allocate, :create
|
28
|
+
|
29
|
+
# @param [String] public_ip The public IP address of an elastic ip.
|
30
|
+
# @return [ElasticIp] The elastic IP with the given address.
|
31
|
+
def [] public_ip
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
# Specify one or more criteria to filter elastic IP addresses by.
|
36
|
+
# A subsequent call to #each will limit the resutls returned
|
37
|
+
# by provided filters.
|
38
|
+
#
|
39
|
+
# * Chain multiple calls of #filter together to AND multiple conditions
|
40
|
+
# together.
|
41
|
+
#
|
42
|
+
# * Supply multiple values to a singler #filter call to OR those
|
43
|
+
# value conditions together.
|
44
|
+
#
|
45
|
+
# * '*' matches one or more characters and '?' matches any one
|
46
|
+
# character.
|
47
|
+
#
|
48
|
+
# === Valid Filters
|
49
|
+
#
|
50
|
+
# * domain - Whether the address is a EC2 address, or a VPC address.
|
51
|
+
# Valid values include 'standard' and 'vpc'
|
52
|
+
# * instance-id - Instance the address is associated with (if any).
|
53
|
+
# * public-ip - The Elastic IP address.
|
54
|
+
# * allocation-id - Allocation ID for the address. For VPC addresses
|
55
|
+
# only.
|
56
|
+
# * association-id - Association ID for the address. For VPC addresses
|
57
|
+
# only.
|
58
|
+
#
|
59
|
+
# @return [ElasticIpCollection] A new collection that represents
|
60
|
+
# a subset of the elastic IP addresses associated with this account.
|
61
|
+
|
62
|
+
# Yields once for each elastic IP address.
|
63
|
+
#
|
64
|
+
# @yield [elastic_ip]
|
65
|
+
# @yieldparam [ElasticIp] elastic_ip
|
66
|
+
def each &block
|
67
|
+
response = filtered_request(:describe_addresses)
|
68
|
+
response.addresses_set.each do |address|
|
69
|
+
|
70
|
+
elastic_ip = ElasticIp.new(address.public_ip,
|
71
|
+
:config => config)
|
72
|
+
|
73
|
+
yield(elastic_ip)
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
def member_class
|
80
|
+
ElasticIp
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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/lazy_error_classes'
|
15
|
+
require 'aws/ec2/client/xml'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class EC2
|
19
|
+
|
20
|
+
# @private
|
21
|
+
module Errors
|
22
|
+
|
23
|
+
BASE_ERROR_GRAMMAR = Client::XML::BaseError
|
24
|
+
|
25
|
+
include LazyErrorClasses
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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 FilteredCollection
|
19
|
+
|
20
|
+
def initialize options = {}
|
21
|
+
@filters = options[:filters] || []
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify one or more criteria to filter elastic IP addresses by.
|
26
|
+
# A subsequent call to #each will limit the results returned
|
27
|
+
# by provided filters.
|
28
|
+
#
|
29
|
+
# * Chain multiple calls of #filter together to AND multiple conditions
|
30
|
+
# together.
|
31
|
+
#
|
32
|
+
# * Supply multiple values to a singler #filter call to OR those
|
33
|
+
# value conditions together.
|
34
|
+
#
|
35
|
+
# * '*' matches one or more characters and '?' matches any one
|
36
|
+
# character.
|
37
|
+
#
|
38
|
+
def filter filter_name, *values
|
39
|
+
filters = @filters.dup
|
40
|
+
filters << { :name => filter_name, :values => values.flatten }
|
41
|
+
collection_with(:filters => filters)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @private
|
45
|
+
def filtered_request client_method, options = {}, &block
|
46
|
+
options[:filters] = @filters unless @filters.empty?
|
47
|
+
client.send(client_method, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @private
|
51
|
+
protected
|
52
|
+
def preserved_options
|
53
|
+
{ :config => config,
|
54
|
+
:filters => @filters }
|
55
|
+
end
|
56
|
+
|
57
|
+
# @private
|
58
|
+
protected
|
59
|
+
def collection_with(options = {})
|
60
|
+
self.class.new(preserved_options.merge(options))
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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/permission_collection'
|
15
|
+
|
16
|
+
module AWS
|
17
|
+
class EC2
|
18
|
+
|
19
|
+
# Helper methods for managing EC2 resource permissions. See
|
20
|
+
# {Image} and {Snapshot} for usage examples.
|
21
|
+
module HasPermissions
|
22
|
+
|
23
|
+
# (see PermissionCollection#public?)
|
24
|
+
def public?
|
25
|
+
permissions.public?
|
26
|
+
end
|
27
|
+
|
28
|
+
# (see PermissionCollection#private?)
|
29
|
+
def private?
|
30
|
+
permissions.private?
|
31
|
+
end
|
32
|
+
|
33
|
+
# (see PermissionCollection#public=)
|
34
|
+
def public=(value)
|
35
|
+
permissions.public = value
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [PermissionCollection] An object to manage the
|
39
|
+
# collection of permissions for this resource.
|
40
|
+
def permissions
|
41
|
+
PermissionCollection.new(self, :config => config)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,245 @@
|
|
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/has_permissions'
|
17
|
+
require 'aws/ec2/instance_collection'
|
18
|
+
|
19
|
+
module AWS
|
20
|
+
class EC2
|
21
|
+
|
22
|
+
# Represents an Amazon Machine Image (AMI).
|
23
|
+
#
|
24
|
+
# @attr [String] description A description of the image.
|
25
|
+
#
|
26
|
+
# @attr_reader [String] location The location of the AMI.
|
27
|
+
#
|
28
|
+
# @attr_reader [Symbol] state Current state of the AMI. If the
|
29
|
+
# state is +:available+, the image is successfully registered
|
30
|
+
# and available for launching. Valid values:
|
31
|
+
#
|
32
|
+
# * +:available+
|
33
|
+
# * +:pending+
|
34
|
+
# * +:failed+
|
35
|
+
#
|
36
|
+
# @attr_reader [String] owner_id AWS account ID of the image
|
37
|
+
# owner.
|
38
|
+
#
|
39
|
+
# @attr_reader [Symbol] architecture The architecture of the
|
40
|
+
# image (e.g. +:i386+).
|
41
|
+
#
|
42
|
+
# @attr_reader [Symbol] type The type of image. Valid values:
|
43
|
+
#
|
44
|
+
# * +:machine+
|
45
|
+
# * +:kernel+
|
46
|
+
# * +:ramdisk+
|
47
|
+
#
|
48
|
+
# @attr_reader [String] kernel_id The kernel ID associated with
|
49
|
+
# the image, if any. Only applicable for machine images.
|
50
|
+
#
|
51
|
+
# @attr_reader [String] ramdisk_id The RAM disk ID associated
|
52
|
+
# with the image, if any. Only applicable for machine images.
|
53
|
+
#
|
54
|
+
# @attr_reader [String] platform Value is +windows+ for Windows
|
55
|
+
# AMIs; otherwise blank.
|
56
|
+
#
|
57
|
+
# @attr_reader [Object] state_reason The reason for the image's
|
58
|
+
# most recent state change. The return value is an object with
|
59
|
+
# the following methods:
|
60
|
+
#
|
61
|
+
# [code] Reason code for the state change.
|
62
|
+
#
|
63
|
+
# [message] A textual description of the state change.
|
64
|
+
#
|
65
|
+
# @attr_reader [String] owner_alias The AWS account alias (e.g.,
|
66
|
+
# +"amazon"+) or AWS account ID that owns the AMI.
|
67
|
+
#
|
68
|
+
# @attr_reader [String] name The name of the AMI that was
|
69
|
+
# provided during image creation.
|
70
|
+
#
|
71
|
+
# @attr [String] description A free-form description of the AMI.
|
72
|
+
# May contain up to 255 characters.
|
73
|
+
#
|
74
|
+
# @attr_reader [Symbol] root_device_type The root device type
|
75
|
+
# used by the AMI. Possible values:
|
76
|
+
#
|
77
|
+
# * +:ebs+
|
78
|
+
# * +:instance_store+
|
79
|
+
#
|
80
|
+
# @attr_reader [String] root_device_name The root device name
|
81
|
+
# (e.g., +"/dev/sda1"+, or +"xvda"+).
|
82
|
+
#
|
83
|
+
# @attr_reader [Hash] block_device_mappings A hash of block
|
84
|
+
# device mappings for the image. In each entry, the key is
|
85
|
+
# the device name (e.g. +"/dev/sda1"+) and the value is an
|
86
|
+
# object with the following methods that return information
|
87
|
+
# about the block device:
|
88
|
+
#
|
89
|
+
# [snapshot_id] The ID of the snapshot that will be used to
|
90
|
+
# create this device (may be nil).
|
91
|
+
#
|
92
|
+
# [volume_size] The size of the volume, in GiBs.
|
93
|
+
#
|
94
|
+
# [delete_on_termination] True if the Amazon EBS volume is
|
95
|
+
# deleted on instance termination.
|
96
|
+
#
|
97
|
+
# @attr_reader [Symbol] virtualization_type The type of
|
98
|
+
# virtualization of the AMI. Possible values:
|
99
|
+
#
|
100
|
+
# * +:paravirtual+
|
101
|
+
# * +:hvm+
|
102
|
+
#
|
103
|
+
# @attr_reader [Symbol] hypervisor The image's hypervisor type.
|
104
|
+
# Possible values:
|
105
|
+
#
|
106
|
+
# * +:ovm+
|
107
|
+
# * +:xen+
|
108
|
+
class Image < Resource
|
109
|
+
|
110
|
+
include TaggedItem
|
111
|
+
include HasPermissions
|
112
|
+
alias_method :launch_permissions, :permissions
|
113
|
+
|
114
|
+
# The ID of the AMI.
|
115
|
+
attr_reader :id
|
116
|
+
|
117
|
+
# @private
|
118
|
+
def initialize(id, opts = {})
|
119
|
+
@id = id
|
120
|
+
super(opts)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Deregisters this AMI. Once deregistered, the AMI cannot be
|
124
|
+
# used to launch new instances.
|
125
|
+
def deregister
|
126
|
+
client.deregister_image(:image_id => id)
|
127
|
+
end
|
128
|
+
alias_method :delete, :deregister
|
129
|
+
|
130
|
+
# Runs a single instance of this image.
|
131
|
+
#
|
132
|
+
# @param [Hash] opts Additional options for running the
|
133
|
+
# instance. See {InstanceCollection#create} for a full list
|
134
|
+
# of supported options.
|
135
|
+
#
|
136
|
+
# @return [Instance] An object representing the new instance.
|
137
|
+
def run_instance(opts = {})
|
138
|
+
InstanceCollection.new(:config => config).
|
139
|
+
create(opts.merge(:image => self))
|
140
|
+
end
|
141
|
+
|
142
|
+
# Runs multiple instances of this image.
|
143
|
+
#
|
144
|
+
# @param count How many instances to request. You can specify
|
145
|
+
# this either as an integer or as a Range, to indicate the
|
146
|
+
# minimum and maximum number of instances to run. Note that
|
147
|
+
# for a new account you can request at most 20 instances at
|
148
|
+
# a time.
|
149
|
+
#
|
150
|
+
# @param [Hash] opts Additional options for running the
|
151
|
+
# instance. See {InstanceCollection#create} for a full list
|
152
|
+
# of supported options.
|
153
|
+
#
|
154
|
+
# @return [Array] An array containing an {Instance} object for
|
155
|
+
# each instance that was run.
|
156
|
+
def run_instances(count, opts = {})
|
157
|
+
InstanceCollection.new(:config => config).
|
158
|
+
create(opts.merge(:image => self,
|
159
|
+
:count => count))
|
160
|
+
end
|
161
|
+
|
162
|
+
# @return [Boolean] +true+ if the AMI exists (is returned by
|
163
|
+
# the DescribeImages action).
|
164
|
+
def exists?
|
165
|
+
resp = client.describe_images(:filters =>
|
166
|
+
[{ :name => "image-id",
|
167
|
+
:values => [id] }]) and
|
168
|
+
!resp.images_set.empty?
|
169
|
+
end
|
170
|
+
|
171
|
+
mutable_attribute :description
|
172
|
+
# use describe_images to get it, so it will work with public images
|
173
|
+
describe_call_attribute :description
|
174
|
+
|
175
|
+
describe_call_attribute :name, :memoize => true
|
176
|
+
describe_call_attribute(:image_location,
|
177
|
+
:getter => :location,
|
178
|
+
:memoize => true)
|
179
|
+
describe_call_attribute :image_state, :getter => :state, :to_sym => true
|
180
|
+
describe_call_attribute(:image_owner_id,
|
181
|
+
:getter => :owner_id,
|
182
|
+
:memoize => true)
|
183
|
+
describe_call_attribute(:image_owner_alias,
|
184
|
+
:getter => :owner_alias,
|
185
|
+
:memoize => true)
|
186
|
+
describe_call_attribute(:architecture,
|
187
|
+
:to_sym => true,
|
188
|
+
:memoize => true)
|
189
|
+
describe_call_attribute(:image_type,
|
190
|
+
:getter => :type,
|
191
|
+
:to_sym => true,
|
192
|
+
:memoize => true)
|
193
|
+
|
194
|
+
describe_call_attribute :kernel_id, :memoize => true
|
195
|
+
|
196
|
+
# @return [Image] The kernel associated with the image, if
|
197
|
+
# any. Only applicable for machine images.
|
198
|
+
def kernel
|
199
|
+
if id = kernel_id
|
200
|
+
Image.new(id, :config => config)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe_call_attribute :ramdisk_id, :memoize => true
|
205
|
+
|
206
|
+
# @return [Image] The RAM disk associated with the image, if
|
207
|
+
# any. Only applicable for machine images.
|
208
|
+
def ramdisk
|
209
|
+
if id = ramdisk_id
|
210
|
+
Image.new(id, :config => config)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe_call_attribute :platform, :memoize => true
|
215
|
+
describe_call_attribute :state_reason
|
216
|
+
describe_call_attribute(:root_device_type,
|
217
|
+
:to_sym => true,
|
218
|
+
:memoize => true)
|
219
|
+
describe_call_attribute :root_device_name
|
220
|
+
describe_call_attribute :virtualization_type, :to_sym => true
|
221
|
+
describe_call_attribute :hypervisor, :to_sym => true
|
222
|
+
describe_call_attribute(:block_device_mapping,
|
223
|
+
:getter => :block_device_mappings) do
|
224
|
+
translate_output do |mappings|
|
225
|
+
(mappings || []).inject({}) do |h, mapping|
|
226
|
+
h[mapping.device_name] = mapping.ebs
|
227
|
+
h
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# @private
|
233
|
+
def __permissions_attribute__
|
234
|
+
"launchPermission"
|
235
|
+
end
|
236
|
+
|
237
|
+
protected
|
238
|
+
def find_in_response(resp)
|
239
|
+
resp.image_index[id]
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
end
|