diff --git a/lib/fog/aws/models/ec2/address.rb b/lib/fog/aws/models/ec2/address.rb index c13c60ee2..ba32e3f4c 100644 --- a/lib/fog/aws/models/ec2/address.rb +++ b/lib/fog/aws/models/ec2/address.rb @@ -4,7 +4,8 @@ module Fog class Address < Fog::Model - attr_accessor :instance_id, :public_ip + attr_accessor :instance_id, + :public_ip def initialize(attributes = {}) remap_attributes(attributes, { @@ -16,13 +17,11 @@ module Fog def delete connection.release_address(@public_ip) - true end def save data = connection.allocate_address @public_ip = data.body['publicIp'] - true end end diff --git a/lib/fog/aws/models/ec2/addresses.rb b/lib/fog/aws/models/ec2/addresses.rb index c5be5d136..200493032 100644 --- a/lib/fog/aws/models/ec2/addresses.rb +++ b/lib/fog/aws/models/ec2/addresses.rb @@ -9,9 +9,9 @@ module Fog class Addresses < Fog::Collection def all - data = connection.get_addresses.body + data = connection.describe_addresses.body addresses = [] - body['addressesSet'].each do |address| + data['addressesSet'].each do |address| addresses << Fog::AWS::EC2::Address.new({ :connection => connection }.merge!(address)) diff --git a/lib/fog/aws/models/ec2/key_pair.rb b/lib/fog/aws/models/ec2/key_pair.rb index dedcfd20f..bd3084f9f 100644 --- a/lib/fog/aws/models/ec2/key_pair.rb +++ b/lib/fog/aws/models/ec2/key_pair.rb @@ -4,7 +4,9 @@ module Fog class KeyPair < Fog::Model - attr_accessor :fingerprint, :material, :name + attr_accessor :fingerprint, + :material, + :name def initialize(attributes = {}) remap_attributes(attributes, { @@ -17,14 +19,13 @@ module Fog def delete connection.delete_key_pair(@name) - true end def save - data = connection.create_key_pair(@name) - new_attributes = data['Body'].reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)} + data = connection.create_key_pair(@name).body + new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)} update_attributes(new_attributes) - true + data end end diff --git a/lib/fog/aws/models/ec2/key_pairs.rb b/lib/fog/aws/models/ec2/key_pairs.rb index b3eb04e72..e3b65fed9 100644 --- a/lib/fog/aws/models/ec2/key_pairs.rb +++ b/lib/fog/aws/models/ec2/key_pairs.rb @@ -9,7 +9,7 @@ module Fog class KeyPairs < Fog::Collection def all(key_names = []) - data = connection.describe_key_pairs(key_names) + data = connection.describe_key_pairs(key_names).body key_pairs = [] data['keySet'].each do |key| key_pairs << Fog::AWS::EC2::KeyPair.new({ diff --git a/lib/fog/aws/models/ec2/volume.rb b/lib/fog/aws/models/ec2/volume.rb new file mode 100644 index 000000000..bb4cf5105 --- /dev/null +++ b/lib/fog/aws/models/ec2/volume.rb @@ -0,0 +1,47 @@ +module Fog + module AWS + class EC2 + + class Volume < Fog::Model + + attr_accessor :attachment_time, + :availability_zone, + :device, + :instance_id + :size, + :snapshot_id, + :status, + :volume_id + + def initialize(attributes = {}) + if attributes['attachmentSet'] + attributes.merge!(attributes.delete('attachmentSet')) + end + remap_attributes(attributes, { + 'attachmentTime' => :attachment_time, + 'availabilityZone' => :availability_zone, + 'createTime' => :create_time, + 'instanceId' => :instance_id, + 'snapshotId' => :snapshot_id, + 'status' => :status + 'volumeId' => :volume_id + }) + super + end + + def delete + connection.delete_volume(@volume_id) + end + + def save + data = connection.create_volume(@availability_zone, @size, @snapshot_id).body + new_attributes = data.reject {|key,value| key == 'requestId'} + update_attributes(new_attributes) + data + end + + end + + end + end +end diff --git a/lib/fog/aws/models/ec2/volumes.rb b/lib/fog/aws/models/ec2/volumes.rb new file mode 100644 index 000000000..7febc6585 --- /dev/null +++ b/lib/fog/aws/models/ec2/volumes.rb @@ -0,0 +1,36 @@ +module Fog + module AWS + class EC2 + + def volumes + Fog::AWS::EC2::Volumes.new(:connection => self) + end + + class Volumes < Fog::Collection + + def all(volume_ids = []) + data = connection.describe_volumes(volume_ids) + volumes = [] + data['volumeSet'].each do |volume| + volumes << Fog::AWS::EC2::Volume.new({ + :connection => connection + }.merge!(volume)) + end + volumes + end + + def create(attributes = {}) + volume = new(attributes) + volume.save + volume + end + + def new(attributes = {}) + Fog::AWS::EC2::Volume.new(attributes.merge!(:connection => connection)) + end + + end + + end + end +end diff --git a/lib/fog/aws/models/s3/bucket.rb b/lib/fog/aws/models/s3/bucket.rb index 696c3d826..970db2438 100644 --- a/lib/fog/aws/models/s3/bucket.rb +++ b/lib/fog/aws/models/s3/bucket.rb @@ -4,7 +4,10 @@ module Fog class Bucket < Fog::Model - attr_accessor :creation_date, :location, :name, :owner + attr_accessor :creation_date, + :location, + :name, + :owner def initialize(attributes = {}) remap_attributes(attributes, { @@ -16,7 +19,6 @@ module Fog def delete connection.delete_bucket(name) - true end def location @@ -48,7 +50,6 @@ module Fog options['LocationConstraint'] = @location end connection.put_bucket(name, options) - true end end diff --git a/lib/fog/aws/models/s3/object.rb b/lib/fog/aws/models/s3/object.rb index 24de13991..82796ca16 100644 --- a/lib/fog/aws/models/s3/object.rb +++ b/lib/fog/aws/models/s3/object.rb @@ -4,7 +4,14 @@ module Fog class Object < Fog::Model - attr_accessor :body, :content_length, :etag, :key, :last_modified, :owner, :size, :storage_class + attr_accessor :body, + :content_length, + :etag, + :key, + :last_modified, + :owner, + :size, + :storage_class def initialize(attributes = {}) remap_attributes(attributes, { @@ -42,7 +49,6 @@ module Fog def delete connection.delete_object(bucket, key) - true end def etag @@ -56,7 +62,6 @@ module Fog def save(options = {}) data = connection.put_object(bucket, key, body, options) @etag = data.headers['ETag'] - true end private diff --git a/lib/fog/aws/models/s3/objects.rb b/lib/fog/aws/models/s3/objects.rb index 3a4eac659..5450acafb 100644 --- a/lib/fog/aws/models/s3/objects.rb +++ b/lib/fog/aws/models/s3/objects.rb @@ -4,7 +4,10 @@ module Fog class Objects < Fog::Collection - attr_accessor :is_truncated, :marker, :max_keys, :prefix + attr_accessor :is_truncated, + :marker, + :max_keys, + :prefix def initialize(attributes = {}) remap_attributes(attributes, { diff --git a/lib/fog/aws/models/s3/owner.rb b/lib/fog/aws/models/s3/owner.rb index 9a8c92a03..6483d76a1 100644 --- a/lib/fog/aws/models/s3/owner.rb +++ b/lib/fog/aws/models/s3/owner.rb @@ -4,7 +4,8 @@ module Fog class Owner < Fog::Model - attr_accessor :display_name, :id + attr_accessor :display_name, + :id def initialize(attributes = {}) remap_attributes(attributes, { diff --git a/lib/fog/aws/requests/ec2/create_volume.rb b/lib/fog/aws/requests/ec2/create_volume.rb index 3ff56a84d..a5fcb8734 100644 --- a/lib/fog/aws/requests/ec2/create_volume.rb +++ b/lib/fog/aws/requests/ec2/create_volume.rb @@ -12,12 +12,13 @@ module Fog # ==== Returns # * response<~Fog::AWS::Response>: # * body<~Hash>: - # * 'volumeId'<~String> - Reference to volume - # * 'size'<~Integer> - Size in GiBs for volume - # * 'status's<~String> - State of volume - # * 'createTime'<~Time> - Timestamp for creation # * 'availabilityZone'<~String> - Availability zone for volume + # * 'createTime'<~Time> - Timestamp for creation + # * 'requestId'<~String> - Id of request + # * 'size'<~Integer> - Size in GiBs for volume # * 'snapshotId'<~String> - Snapshot volume was created from, if any + # * 'status'<~String> - State of volume + # * 'volumeId'<~String> - Reference to volume def create_volume(availability_zone, size, snapshot_id = nil) request({ 'Action' => 'CreateVolume',