aws-sdk 1.0.4 → 1.1.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.
Files changed (71) hide show
  1. data/lib/aws.rb +10 -9
  2. data/lib/aws/api_config/IAM-2010-07-15.yml +632 -0
  3. data/lib/aws/base_client.rb +1 -1
  4. data/lib/aws/cacheable.rb +34 -46
  5. data/lib/aws/client_logging.rb +19 -14
  6. data/lib/aws/collections.rb +230 -0
  7. data/lib/aws/common.rb +4 -0
  8. data/lib/aws/configuration.rb +7 -0
  9. data/lib/aws/ec2.rb +2 -2
  10. data/lib/aws/ec2/attachment.rb +64 -71
  11. data/lib/aws/ec2/attachment_collection.rb +11 -9
  12. data/lib/aws/ec2/availability_zone.rb +40 -31
  13. data/lib/aws/ec2/availability_zone_collection.rb +2 -3
  14. data/lib/aws/ec2/elastic_ip.rb +25 -22
  15. data/lib/aws/ec2/elastic_ip_collection.rb +5 -2
  16. data/lib/aws/ec2/image.rb +113 -129
  17. data/lib/aws/ec2/image_collection.rb +5 -6
  18. data/lib/aws/ec2/instance.rb +290 -233
  19. data/lib/aws/ec2/instance_collection.rb +72 -67
  20. data/lib/aws/ec2/key_pair.rb +16 -18
  21. data/lib/aws/ec2/region.rb +25 -17
  22. data/lib/aws/ec2/reserved_instances.rb +7 -1
  23. data/lib/aws/ec2/reserved_instances_collection.rb +3 -3
  24. data/lib/aws/ec2/reserved_instances_offering.rb +7 -1
  25. data/lib/aws/ec2/reserved_instances_offering_collection.rb +3 -3
  26. data/lib/aws/ec2/resource.rb +41 -222
  27. data/lib/aws/ec2/security_group.rb +22 -18
  28. data/lib/aws/ec2/security_group_collection.rb +2 -5
  29. data/lib/aws/ec2/snapshot.rb +44 -35
  30. data/lib/aws/ec2/snapshot_collection.rb +43 -1
  31. data/lib/aws/ec2/tag.rb +14 -18
  32. data/lib/aws/ec2/volume.rb +59 -72
  33. data/lib/aws/ec2/volume_collection.rb +16 -12
  34. data/lib/aws/errors.rb +14 -5
  35. data/lib/aws/http/httparty_handler.rb +2 -2
  36. data/lib/aws/iam.rb +306 -0
  37. data/lib/aws/iam/access_key.rb +183 -0
  38. data/lib/aws/iam/access_key_collection.rb +131 -0
  39. data/lib/aws/iam/account_alias_collection.rb +81 -0
  40. data/lib/aws/iam/client.rb +44 -0
  41. data/lib/aws/iam/client/xml.rb +38 -0
  42. data/lib/aws/iam/collection.rb +87 -0
  43. data/lib/aws/iam/errors.rb +29 -0
  44. data/lib/aws/iam/group.rb +117 -0
  45. data/lib/aws/iam/group_collection.rb +135 -0
  46. data/lib/aws/iam/group_policy_collection.rb +49 -0
  47. data/lib/aws/iam/group_user_collection.rb +94 -0
  48. data/lib/aws/iam/login_profile.rb +97 -0
  49. data/lib/aws/iam/mfa_device.rb +52 -0
  50. data/lib/aws/iam/mfa_device_collection.rb +119 -0
  51. data/lib/aws/iam/policy.rb +48 -0
  52. data/lib/aws/iam/policy_collection.rb +191 -0
  53. data/lib/aws/iam/request.rb +27 -0
  54. data/lib/aws/iam/resource.rb +74 -0
  55. data/lib/aws/iam/server_certificate.rb +143 -0
  56. data/lib/aws/iam/server_certificate_collection.rb +174 -0
  57. data/lib/aws/iam/signing_certificate.rb +171 -0
  58. data/lib/aws/iam/signing_certificate_collection.rb +134 -0
  59. data/lib/aws/iam/user.rb +196 -0
  60. data/lib/aws/iam/user_collection.rb +136 -0
  61. data/lib/aws/iam/user_group_collection.rb +101 -0
  62. data/lib/aws/iam/user_policy.rb +90 -0
  63. data/lib/aws/iam/user_policy_collection.rb +48 -0
  64. data/lib/aws/resource.rb +381 -0
  65. data/lib/aws/resource_cache.rb +1 -2
  66. data/lib/aws/response.rb +5 -1
  67. data/lib/aws/response_cache.rb +1 -1
  68. data/lib/aws/s3/client.rb +3 -1
  69. data/lib/aws/s3/presigned_post.rb +1 -1
  70. data/lib/aws/simple_db.rb +1 -1
  71. metadata +113 -50
@@ -167,8 +167,8 @@ module AWS
167
167
  # the string "linux", you can do this:
168
168
  #
169
169
  # ec2.images.with_owner("amazon").
170
- # filtered("platform", "windows").
171
- # filtered("description", "*linux*")
170
+ # filter("platform", "windows").
171
+ # filter("description", "*linux*")
172
172
  #
173
173
  # Similarly, you can tag images, instances, security groups,
174
174
  # snapshots, and volumes with free-form key-value metadata and
@@ -11,8 +11,7 @@
11
11
  # ANY KIND, either express or implied. See the License for the specific
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
- require 'aws/model'
15
- require 'aws/cacheable'
14
+ require 'aws/resource'
16
15
 
17
16
  module AWS
18
17
  class EC2
@@ -31,67 +30,45 @@ module AWS
31
30
  # end
32
31
  # sleep 1 until volume.status == :available
33
32
  # volume.delete
34
- class Attachment
35
-
36
- include Model
37
- include Cacheable
38
-
39
- attr_reader :volume
40
- attr_reader :instance
41
- attr_reader :device
33
+ class Attachment < Resource
42
34
 
43
35
  # @private
44
- def initialize(volume, instance, device, opts = {})
36
+ def initialize volume, instance, device, options = {}
45
37
  @volume = volume
46
38
  @instance = instance
47
39
  @device = device
48
- super(opts)
49
- end
50
-
51
- # (see Volume#detach_from)
52
- def delete(opts = {})
53
- client.detach_volume(opts.merge(:volume_id => volume.id,
54
- :instance_id => instance.id,
55
- :device => device))
40
+ super
56
41
  end
57
42
 
58
- # @return [Symbol] The attachment status. Possible values:
59
- # * +:attaching+
60
- # * +:attached+
61
- # * +:detaching+
62
- # * +:detached+
63
- def status
64
- retrieve_attribute(:status) { describe_call }
65
- end
66
-
67
- # @return [Time] The time at which this attachment was created.
68
- def attach_time
69
- retrieve_attribute(:attach_time) { describe_call }
70
- end
71
-
72
- # @return [Boolean] True if the volume will be deleted on
73
- # instance termination.
74
- def delete_on_termination?
75
- retrieve_attribute(:delete_on_termination?) { describe_call }
76
- end
43
+ # @return [Volume] Returns the volume that is attached.
44
+ attr_reader :volume
77
45
 
78
- # @return [Boolean] True if the attachment exists.
79
- def exists?
80
- !describe_attachment.nil?
81
- end
46
+ # @return [Instance] Returns the EC2 instance the volume is attached to.
47
+ attr_reader :instance
82
48
 
83
- # @return [Boolean] True if the attachments are the same.
84
- #
85
- # @param [Object] other The object to compare with.
86
- def ==(other)
87
- other.kind_of?(Attachment) and
88
- other.volume == volume and
89
- other.instance == instance and
90
- other.device == device
91
- end
92
- alias_method :eql?, :==
49
+ # @return [String] Returns how the device is exposed to the instance
50
+ # (e.g. '/dev/sdh')
51
+ attr_reader :device
93
52
 
94
- populate_from :describe_volumes do |resp|
53
+ # @overload status
54
+ # Returns the attachment status. Possible values are:
55
+ # * +:attaching+
56
+ # * +:attached+
57
+ # * +:detaching+
58
+ # * +:detached+
59
+ # @return [Symbol] Returns the attachment status.
60
+ attribute :status, :to_sym => true
61
+
62
+ # @overload attach_time
63
+ # @return [Time] Returns the time at which this attachment was created.
64
+ attribute :attach_time
65
+
66
+ # @overload delete_on_termination?
67
+ # @return [Boolean] Returns +true+ if the volume will be deleted
68
+ # on instance termination.
69
+ attribute :delete_on_termination?
70
+
71
+ populates_from(:describe_volumes) do |resp|
95
72
  if volume = resp.volume_index[self.volume.id] and
96
73
  attachments = volume.attachment_set and
97
74
  attachment = attachments.find do |att|
@@ -99,31 +76,47 @@ module AWS
99
76
  att.volume_id == self.volume.id &&
100
77
  att.device == self.device
101
78
  end
102
-
103
- attributes_from_response_object(attachment)
79
+ then
80
+ attachment
104
81
  end
105
82
  end
106
83
 
107
- [:attach_volume,
108
- :detach_volume].each do |op|
109
- populate_from op do |resp|
110
- attributes_from_response_object(resp) if
111
- resp.volume_id == volume.id and
112
- resp.instance_id == instance.id and
113
- resp.device == device
84
+ populates_from(:attach_volume, :detach_volume) do |resp|
85
+ if
86
+ resp.volume_id == volume.id and
87
+ resp.instance_id == instance.id and
88
+ resp.device == device
89
+ then
90
+ resp
114
91
  end
115
92
  end
116
93
 
94
+ # @return [Boolean] Returns true if the attachment exists.
95
+ def exists?
96
+ !describe_attachment.nil?
97
+ end
98
+
99
+ # Detaches the volume from its instance.
100
+ # @option options [Boolean] :force Forces detachment if the
101
+ # previous detachment attempt did not occur cleanly (logging
102
+ # into an instance, unmounting the volume, and detaching
103
+ # normally). This option can lead to data loss or a
104
+ # corrupted file system. Use this option only as a last
105
+ # resort to detach a volume from a failed instance. The
106
+ # instance will not have an opportunity to flush file system
107
+ # caches or file system metadata. If you use this option,
108
+ # you must perform file system check and repair procedures.
109
+ def delete options = {}
110
+ client.detach_volume(options.merge(resource_options))
111
+ end
112
+
117
113
  protected
118
- def attributes_from_response_object(attachment)
119
- atts = {}
120
- atts[:status] = (attachment.status.to_sym if
121
- attachment.respond_to?(:status))
122
- atts[:attach_time] = (attachment.attach_time if
123
- attachment.respond_to?(:attach_time))
124
- atts[:delete_on_termination?] = (attachment.delete_on_termination? if
125
- attachment.respond_to?(:delete_on_termination?))
126
- atts
114
+ def resource_identifiers
115
+ [
116
+ [:volume_id, volume.id],
117
+ [:instance_id, instance.id],
118
+ [:device, device],
119
+ ]
127
120
  end
128
121
 
129
122
  protected
@@ -31,22 +31,24 @@ module AWS
31
31
  attr_reader :volume
32
32
 
33
33
  # @private
34
- def initialize(volume, opts = {})
34
+ def initialize volume, options = {}
35
35
  @volume = volume
36
- super(opts)
36
+ super
37
37
  end
38
38
 
39
39
  # @yield [attachment] Each attachment of the volume as an
40
40
  # {Attachment} object.
41
41
  # @return [nil]
42
- def each(&block)
43
- volume.attachment_set.each do |att|
44
- instance = Instance.new(att.instance_id, :config => config)
45
- attachment = Attachment.new(self.volume,
46
- instance,
47
- att.device,
48
- :config => config)
42
+ def each &block
43
+ volume.attachment_set.each do |item|
44
+
45
+ instance = Instance.new(item.instance_id, :config => config)
46
+
47
+ attachment = Attachment.new(self.volume, instance, item.device,
48
+ :config => config)
49
+
49
50
  yield(attachment)
51
+
50
52
  end
51
53
  nil
52
54
  end
@@ -19,59 +19,68 @@ module AWS
19
19
  # Represents an EC2 availability zone. You can use this class
20
20
  # to get information about the state of an availability zone
21
21
  # that is available to your account.
22
+ #
23
+ # @attr_reader [String,nil] region_name Returns the region name
24
+ # of the availability zone.
25
+ #
26
+ # @attr_reader [Symbol] state Returns the state of the availability
27
+ # zone, e.g. +:available+.
28
+ #
29
+ # @attr_reader [Array<String>] messages Returns a list of messages about the
30
+ # Availability Zone.
31
+ #
22
32
  class AvailabilityZone < Resource
23
33
 
34
+ # @param [String] name The name of the availability zone.
35
+ def initialize name, options = {}
36
+ @name = name
37
+ if options[:region]
38
+ options[:region_name] = options[:region].name
39
+
40
+ end
41
+ super
42
+ end
43
+
24
44
  # @return [String] Returns the name of the availability zone,
25
45
  # e.g. "us-east-1a".
26
46
  attr_reader :name
27
47
 
28
48
  alias_method :to_s, :name
49
+
29
50
  alias_method :to_str, :name
30
51
 
31
- # @param [String] name The name of the availability zone.
32
- def initialize(name, opts = {})
33
- @name = name
34
- @region = opts[:region]
35
- super(opts)
36
- end
52
+ attribute :region_name, :static => true
53
+
54
+ attribute :state, :as => :zone_state, :to_sym => true
37
55
 
38
- # @return [Region] The region of this availability zone.
39
- def region; end
40
- describe_call_attribute :region_name, :getter => :region, :memoize => true do
41
- translate_output do |value|
42
- Region.new(value, :config => config) if value
56
+ attribute :messages, :as => :message_set do
57
+ translates_output do |messages|
58
+ messages ? messages.collect{|m| m.message } : []
43
59
  end
44
60
  end
45
61
 
46
- # @return [Symbol] The state of the availability zone,
47
- # e.g. +:available+.
48
- def state; end
49
- describe_call_attribute :zone_state, :getter => :state, :to_sym => true
62
+ populates_from(:describe_availability_zones) do |resp|
63
+ resp.availability_zone_info.find {|az| az.zone_name == name }
64
+ end
50
65
 
51
- # @return [Array] A list of messages about the Availability
52
- # Zone.
53
- def messages; end
54
- describe_call_attribute :message_set, :getter => :messages do
55
- translate_output { |set| set.map { |m| m.message } if set }
66
+ # @return [Region] Returns the region of this availability zone.
67
+ def region
68
+ Region.new(self.region_name, :config => config)
56
69
  end
57
70
 
58
71
  protected
59
- def inflected_name
60
- "zone"
72
+ def describe_call_name
73
+ :describe_availability_zones
61
74
  end
62
75
 
63
76
  protected
64
- def find_in_response(resp)
65
- resp.availability_zone_info.find { |az| az.zone_name == name }
77
+ def inflected_name
78
+ self.class.inflected_name
66
79
  end
67
80
 
68
- # @private
69
- private
70
- def get_attribute(name)
71
- resp = client.describe_availability_zones(:zone_names =>
72
- [self.name])
73
- az = resp.availability_zone_info.first
74
- az.send(name)
81
+ protected
82
+ def self.inflected_name
83
+ "zone"
75
84
  end
76
85
 
77
86
  end
@@ -27,9 +27,8 @@ module AWS
27
27
  resp = filtered_request(:describe_availability_zones)
28
28
  resp.availability_zone_info.each do |az|
29
29
  zone = AvailabilityZone.new(az.zone_name,
30
- :region => Region.new(az.region_name, :config => config),
31
- :config => config
32
- )
30
+ :region_name => az.region_name,
31
+ :config => config)
33
32
  yield(zone)
34
33
  end
35
34
  nil
@@ -15,41 +15,43 @@ require 'aws/ec2/resource'
15
15
 
16
16
  module AWS
17
17
  class EC2
18
+
19
+ #
20
+ # @attr_reader [String,nil] instance_id Returns the instance id if
21
+ # assigned to an EC2 instance, nil otherwise.
22
+ #
18
23
  class ElasticIp < Resource
19
24
 
20
25
  def initialize public_ip, options = {}
21
26
  @public_ip = public_ip
22
- @instance_id = options[:instance_id]
23
27
  super
24
28
  end
25
29
 
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
30
  # @return [String] The public IP address.
33
31
  attr_reader :public_ip
34
32
 
35
33
  alias_method :ip_address, :public_ip
36
34
 
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
35
+ attribute :instance_id
36
+
37
+ populates_from(:describe_addresses) do |resp|
38
+ resp.address_index[public_ip]
39
+ end
41
40
 
42
41
  # @return [Boolean] Returns true if this IP address is attached to
43
42
  # an EC2 instance.
44
43
  def associated?
45
44
  !!instance_id
46
45
  end
46
+
47
47
  alias_method :attached?, :associated?
48
48
 
49
49
  # @return [Instance,nil] If associated, returns the {Instance} this
50
50
  # elastic IP address is associated to, nil otherwise.
51
51
  def instance
52
- associated? ? Instance.new(instance_id, :config => config) : nil
52
+ if instance_id = self.instance_id
53
+ Instance.new(instance_id, :config => config)
54
+ end
53
55
  end
54
56
 
55
57
  # Releases the elastic IP address.
@@ -57,10 +59,10 @@ module AWS
57
59
  # (For non-VPC elastic ips) Releasing an IP address automatically
58
60
  # disassociates it from any instance it's associated with.
59
61
  #
60
- # @return [true]
62
+ # @return [nil]
61
63
  def delete
62
- client.release_address(:public_ip => public_ip)
63
- true
64
+ client.release_address(resource_options)
65
+ nil
64
66
  end
65
67
 
66
68
  alias_method :release, :delete
@@ -68,13 +70,12 @@ module AWS
68
70
  # Disassociates this elastic IP address from an EC2 instance.
69
71
  # Raises an exception if this elastic IP is not currently
70
72
  # associated with an instance.
71
- # @return [true]
73
+ # @return [nil]
72
74
  def disassociate
73
- client.disassociate_address(:public_ip => public_ip)
74
- true
75
+ client.disassociate_address(resource_options)
76
+ nil
75
77
  end
76
78
 
77
- # @private
78
79
  # @return [String] Returns the public IP address
79
80
  def to_s
80
81
  public_ip.to_s
@@ -94,13 +95,15 @@ module AWS
94
95
 
95
96
  # @private
96
97
  protected
97
- def find_in_response(resp)
98
- resp.address_index[public_ip]
98
+ def describe_call_name
99
+ :describe_addresses
99
100
  end
100
101
 
101
102
  # @private
102
103
  protected
103
- def __resource_id__; public_ip; end
104
+ def self.describe_call_name
105
+ :describe_addresses
106
+ end
104
107
 
105
108
  end
106
109
  end
@@ -67,8 +67,11 @@ module AWS
67
67
  response = filtered_request(:describe_addresses)
68
68
  response.addresses_set.each do |address|
69
69
 
70
- elastic_ip = ElasticIp.new(address.public_ip,
71
- :config => config)
70
+ options = {}
71
+ options[:config] = config
72
+ options[:instance_id] = address.instance_id
73
+
74
+ elastic_ip = ElasticIp.new(address.public_ip, options)
72
75
 
73
76
  yield(elastic_ip)
74
77