aws-sdk 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -20,6 +20,14 @@ module AWS
20
20
  class EC2
21
21
 
22
22
  # Represents a security group in EC2.
23
+ #
24
+ # @attr_reader [String] description The short informal description
25
+ # given when the group was created.
26
+ #
27
+ # @attr_reader [String] name The name of the security group.
28
+ #
29
+ # @attr_reader [String] owner_id The security group owner's id.
30
+ #
23
31
  class SecurityGroup < Resource
24
32
 
25
33
  include TaggedItem
@@ -37,28 +45,24 @@ module AWS
37
45
 
38
46
  alias_method :group_id, :id
39
47
 
40
- # @return [Boolean] True if the security group exists.
41
- def exists?
42
- client.describe_security_groups(:filters =>
43
- [{ :name => "group-id",
44
- :values => [id] }]).
45
- security_group_index.key?(id)
46
- end
48
+ attribute :name, :as => :group_name, :static => true
47
49
 
48
- # @return [String] The name of the security group.
49
- def name; end
50
- describe_call_attribute :group_name, :getter => :name, :memoize => true
50
+ attribute :owner_id, :static => true
51
51
 
52
- # @return [String] The id of the owner for this security group.
53
- def owner_id; end
54
- describe_call_attribute :owner_id, :memoize => true
52
+ attribute :description, :as => :group_description, :static => true
55
53
 
56
- # @return [String] The short informal description given when the
57
- # group was created.
58
- def description; end
59
- describe_call_attribute :group_description, :getter => :description, :memoize => true
54
+ attribute :ip_permissions_list, :as => :ip_permissions
60
55
 
61
- describe_call_attribute :ip_permissions, :getter => :ip_permissions_list
56
+ populates_from(:describe_security_groups) do |resp|
57
+ resp.security_group_index[id]
58
+ end
59
+
60
+ # @return [Boolean] True if the security group exists.
61
+ def exists?
62
+ client.describe_security_groups(:filters => [
63
+ { :name => "group-id", :values => [id] }
64
+ ]).security_group_index.key?(id)
65
+ end
62
66
 
63
67
  # @return [SecurityGroup::IpPermissionCollection] Returns a
64
68
  # collection of {IpPermission} objects that represents all of
@@ -110,11 +110,8 @@ module AWS
110
110
  response = filtered_request(:describe_security_groups)
111
111
  response.security_group_info.each do |info|
112
112
 
113
- group = SecurityGroup.new(info.group_id,
114
- :name => info.group_name,
115
- :description => info.group_description,
116
- :owner_id => info.owner_id,
117
- :config => config)
113
+ group = SecurityGroup.new_from(:describe_security_groups, info,
114
+ info.group_id, :config => config)
118
115
 
119
116
  yield(group)
120
117
 
@@ -55,22 +55,51 @@ module AWS
55
55
  # snapshot provided at snapshot initiation.
56
56
  class Snapshot < Resource
57
57
 
58
- include HasPermissions
59
58
  include TaggedItem
60
- alias_method :create_volume_permissions, :permissions
61
-
62
- # The snapshot ID
63
- attr_reader :id
59
+ include HasPermissions
64
60
 
65
61
  # @private
66
- def initialize(id, opts = {})
62
+ def initialize id, options = {}
67
63
  @id = id
68
- super(opts)
64
+ super(options)
65
+ end
66
+
67
+ # @return [String] Returns the snapshot's ID.
68
+ attr_reader :id
69
+
70
+ attribute :status, :to_sym => true
71
+
72
+ attribute :start_time, :static => true
73
+
74
+ attribute :progress do
75
+ translates_output {|value| value.to_i if value }
76
+ end
77
+
78
+ attribute :owner_id, :static => true
79
+
80
+ attribute :volume_size, :static => true
81
+
82
+ attribute :volume_id, :static => true
83
+
84
+ attribute :owner_alias, :static => true
85
+
86
+ attribute :description, :static => true
87
+
88
+ alias_method :create_volume_permissions, :permissions
89
+
90
+ populates_from(:create_snapshot) do |resp|
91
+ resp if resp.snapshot_id == id
92
+ end
93
+
94
+ populates_from(:describe_snapshots) do |resp|
95
+ resp.snapshot_index[id]
69
96
  end
70
97
 
71
98
  # Deletes the snapshot.
99
+ # @return [nil]
72
100
  def delete
73
101
  client.delete_snapshot(:snapshot_id => id)
102
+ nil
74
103
  end
75
104
 
76
105
  # Creates a volume from the snapshot.
@@ -80,16 +109,18 @@ module AWS
80
109
  # {EC2#availability_zones} for how to get a list of
81
110
  # availability zones.
82
111
  #
83
- # @param [Hash] opts Additional options for creating the volume
112
+ # @param [Hash] options Additional options for creating the volume
84
113
  #
85
- # @option opts [Integer] size The desired size (in gigabytes)
114
+ # @option options [Integer] size The desired size (in gigabytes)
86
115
  # for the volume.
87
116
  #
88
117
  # @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))
118
+ def create_volume availability_zone, options = {}
119
+ volumes = VolumeCollection.new(:config => config)
120
+ volumes.create(options.merge(
121
+ :availability_zone => availability_zone,
122
+ :snapshot => self
123
+ ))
93
124
  end
94
125
 
95
126
  # @return [Boolean] True if the snapshot exists.
@@ -100,38 +131,16 @@ module AWS
100
131
  !resp.snapshot_set.empty?
101
132
  end
102
133
 
103
- describe_call_attribute :volume_id
104
-
105
134
  # @return [Volume] The volume this snapshot was created from.
106
135
  def volume
107
136
  Volume.new(volume_id, :config => config) if volume_id
108
137
  end
109
138
 
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
139
  # @private
121
140
  def __permissions_attribute__
122
141
  "createVolumePermission"
123
142
  end
124
143
 
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
144
  end
136
145
 
137
146
  end
@@ -39,10 +39,21 @@ module AWS
39
39
 
40
40
  include TaggedCollection
41
41
 
42
+ # @private
43
+ def initialize(options = {})
44
+ @owners = options[:owners] || []
45
+ @restorable_by = options[:restorable_by] || []
46
+ super(options)
47
+ end
48
+
42
49
  # @yield [Instance] Yields each volume in the collection.
43
50
  # @return [nil]
44
51
  def each(&block)
45
- resp = filtered_request(:describe_snapshots)
52
+ opts = {}
53
+ opts[:owner_ids] = @owners.map { |id| id.to_s } unless @owners.empty?
54
+ opts[:restorable_by_user_ids] = @restorable_by.map { |id| id.to_s } unless
55
+ @restorable_by.empty?
56
+ resp = filtered_request(:describe_snapshots, opts)
46
57
  resp.snapshot_set.each do |v|
47
58
  snapshot = Snapshot.new(v.snapshot_id, :config => config)
48
59
  yield(snapshot)
@@ -50,6 +61,31 @@ module AWS
50
61
  nil
51
62
  end
52
63
 
64
+ # @return [SnapshotCollection] A new collection that only
65
+ # includes snapshots owned by one or more of the specified AWS
66
+ # accounts. The IDs +:amazon+ and +:self+ can be used to
67
+ # include snapshots owned by Amazon or AMIs owned by you,
68
+ # respectively.
69
+ #
70
+ # @param [Array of Strings] owners The AWS account IDs by
71
+ # which the new collection should be filtered.
72
+ def with_owner(*owners)
73
+ collection_with(:owners => @owners + owners)
74
+ end
75
+
76
+ # @return [ImageCollection] A new collection that only includes
77
+ # images for which the specified user ID has explicit launch
78
+ # permissions. The user ID can be an AWS account ID, +:self+
79
+ # to return AMIs for which the sender of the request has
80
+ # explicit launch permissions, or +:all+ to return AMIs with
81
+ # public launch permissions.
82
+ #
83
+ # @param [Array of Strings] users The AWS account IDs by which
84
+ # the new collection should be filtered.
85
+ def restorable_by(*users)
86
+ collection_with(:restorable_by => @restorable_by + users)
87
+ end
88
+
53
89
  # Creates a snapshot of an Amazon EBS volume and stores it in
54
90
  # Amazon S3. You can use snapshots for backups, to make
55
91
  # identical copies of instance devices, and to save data
@@ -84,6 +120,12 @@ module AWS
84
120
  Snapshot
85
121
  end
86
122
 
123
+ # @private
124
+ protected
125
+ def preserved_options
126
+ super.merge(:owners => @owners, :restorable_by => @restorable_by)
127
+ end
128
+
87
129
  end
88
130
 
89
131
  end
@@ -18,6 +18,7 @@ module AWS
18
18
  class EC2
19
19
 
20
20
  # Represents an EC2 tag.
21
+ # @attr [String] value The tag value.
21
22
  class Tag < Resource
22
23
 
23
24
  # @param [String] key The name of the tag
@@ -37,9 +38,11 @@ module AWS
37
38
 
38
39
  alias_method :name, :key
39
40
 
40
- # @return [String] The tag value.
41
- def value; end
42
- describe_call_attribute :value
41
+ attribute :value
42
+
43
+ populates_from(:describe_tags) do |resp|
44
+ resp.tag_index[response_index_key]
45
+ end
43
46
 
44
47
  # Deletes this tag.
45
48
  # @return [nil]
@@ -52,12 +55,12 @@ module AWS
52
55
 
53
56
  # @private
54
57
  def inspect
55
- "<#{local_cache_key}>"
58
+ "<#{self.class}:#{local_cache_key}>"
56
59
  end
57
60
 
58
61
  # @private
59
62
  def local_cache_key
60
- "#{self.class}:#{response_index_key}"
63
+ response_index_key
61
64
  end
62
65
 
63
66
  private
@@ -68,19 +71,12 @@ module AWS
68
71
  end
69
72
 
70
73
  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__)] }])
74
+ def get_resource attr
75
+ client.describe_tags(:filters => [
76
+ { :name => "key", :values => [key] },
77
+ { :name => "resource-type", :values => [resource.tagging_resource_type] },
78
+ { :name => "resource-id", :values => [resource.send(:__resource_id__)] }
79
+ ])
84
80
  end
85
81
 
86
82
  end
@@ -48,8 +48,8 @@ module AWS
48
48
  # @attr_reader [Integer] size The size of the volume in
49
49
  # gigabytes.
50
50
  #
51
- # @attr_reader [AvailabilityZone] availability_zone Availability
52
- # Zone in which the volume was created.
51
+ # @attr_reader [String] availability_zone_name Name of the
52
+ # Availability Zone in which the volume was created.
53
53
  #
54
54
  # @attr_reader [Time] create_time The time at which the volume
55
55
  # was created.
@@ -57,28 +57,54 @@ module AWS
57
57
 
58
58
  include TaggedItem
59
59
 
60
- attr_reader :id
61
-
62
60
  # @private
63
61
  def initialize(id, opts = {})
64
62
  @id = id
65
63
  super(opts)
66
64
  end
67
65
 
66
+ # @return [String] Returns the volume ID.
67
+ attr_reader :id
68
+
69
+ attribute :status, :to_sym => true
70
+
71
+ alias_method :state, :status
72
+
73
+ attribute :snapshot_id, :static => true
74
+
75
+ attribute :size, :static => true do
76
+ translates_output {|value| value.to_i if value }
77
+ end
78
+
79
+ attribute :availability_zone_name, :as => :availability_zone,
80
+ :static => true
81
+
82
+ attribute :create_time, :static => true
83
+
84
+ attribute :attachment_set
85
+
86
+ populates_from(:create_volume) do |resp|
87
+ resp if resp.volume_id == id
88
+ end
89
+
90
+ populates_from(:describe_volumes) do |resp|
91
+ resp.volume_index[id]
92
+ end
93
+
68
94
  # Deletes the volume.
69
95
  def delete
70
96
  client.delete_volume(:volume_id => id)
97
+ nil
71
98
  end
72
99
 
73
100
  # @return [Snapshot] A new snapshot created from the volume.
74
101
  #
75
102
  # @param [String] description An optional description of the
76
103
  # snapshot. May be up to 255 characters in length.
77
- def create_snapshot(description = nil)
104
+ def create_snapshot description = nil
78
105
  opts = { :volume => self }
79
106
  opts[:description] = description if description
80
- SnapshotCollection.new(:config => config).
81
- create(opts)
107
+ SnapshotCollection.new(:config => config).create(opts)
82
108
  end
83
109
 
84
110
  # Attaches the volume to an instance.
@@ -93,95 +119,56 @@ module AWS
93
119
  # @return [Attachment] An object representing the attachment,
94
120
  # which you can use to query the attachment status.
95
121
  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)
122
+ resp = client.attach_volume(
123
+ :volume_id => id,
124
+ :instance_id => instance.id,
125
+ :device => device
126
+ )
127
+ instance = Instance.new(resp.instance_id, :config => config)
128
+ Attachment.new(self, instance, resp.device, :config => config)
103
129
  end
104
130
  alias_method :attach, :attach_to
105
131
 
106
132
  # Detaches the volume from an instance.
107
133
  #
108
134
  # @param [Instance] instance The instance to detach from.
109
- #
110
135
  # @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
136
+ # @param [Hash] options
137
+ # @option (see Attachment#delete)
138
+ # @return [Attachment] Returns the no-longer valid attachment.
139
+ def detach_from(instance, device, options = {})
140
+ instance = Instance.new(instance.id, :config => config),
141
+ a = Attachment.new(self, instance, device, :config => config)
142
+ a.delete(options)
130
143
  a
131
144
  end
132
145
 
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
146
  # @return [Boolean] True if the volume exists.
140
147
  def exists?
141
- resp =
142
- client.describe_volumes(:filters => [{ :name => 'volume-id',
143
- :values => [id] }]) and
144
- resp.volume_index.key?(id)
148
+ resp = client.describe_volumes(:filters => [
149
+ { :name => 'volume-id', :values => [id] }
150
+ ])
151
+ resp.volume_index.key?(id)
145
152
  end
146
153
 
147
- describe_call_attribute :status, :to_sym => true
148
- alias_method :state, :status
149
-
150
- describe_call_attribute :snapshot_id
151
-
152
154
  # @return [Snapshot] Snapshot from which the volume was created
153
155
  # (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 }
156
+ def snapshot
157
+ snapshot_id ? Snapshot.new(snapshot_id, :config => config) : nil
162
158
  end
163
159
 
164
- describe_call_attribute :availability_zone, :getter => :availability_zone_name
165
-
160
+ # @return [AvailabilityZone] Returns the Availability
161
+ # Zone in which the volume was created.
166
162
  def availability_zone
167
163
  if name = availability_zone_name
168
164
  AvailabilityZone.new(name, :config => config)
169
165
  end
170
166
  end
171
167
 
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]
168
+ # @return [AttachmentCollection] The collection of attachments
169
+ # that involve this volume.
170
+ def attachments
171
+ AttachmentCollection.new(self, :config => config)
185
172
  end
186
173
 
187
174
  end