From 2c68ac75afd45509152893d591d9e5e90b1be50c Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Sat, 19 Sep 2009 12:31:15 -0700 Subject: [PATCH] fix up collections/reloads --- lib/fog/aws/models/ec2/address.rb | 5 +++++ lib/fog/aws/models/ec2/instance.rb | 19 ++++++++++++------- lib/fog/aws/models/ec2/key_pair.rb | 5 +++++ lib/fog/aws/models/ec2/security_group.rb | 11 ++++++----- lib/fog/aws/models/ec2/snapshot.rb | 12 ++++++------ lib/fog/aws/models/ec2/volume.rb | 12 ++++++------ 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/lib/fog/aws/models/ec2/address.rb b/lib/fog/aws/models/ec2/address.rb index 44191be2c..a5957e7db 100644 --- a/lib/fog/aws/models/ec2/address.rb +++ b/lib/fog/aws/models/ec2/address.rb @@ -16,6 +16,11 @@ module Fog true end + def reload + new_attributes = addresses.all(@public_ip).first.attributes + merge_attributes(new_attributes) + end + def save data = connection.allocate_address @public_ip = data.body['publicIp'] diff --git a/lib/fog/aws/models/ec2/instance.rb b/lib/fog/aws/models/ec2/instance.rb index fb2028156..b669c7232 100644 --- a/lib/fog/aws/models/ec2/instance.rb +++ b/lib/fog/aws/models/ec2/instance.rb @@ -73,13 +73,9 @@ module Fog end end - def volumes - connection.volumes.all.select {|volume| volume.instance_id == @instance_id} - end - - def volume=(new_volume) - new_volume.instance_id = @instance_id - connection.attach_volume(@instance_id, new_volume.volume_id, new_volume.device) + def reload + new_attributes = instances.all(@instance_id).first.attributes + merge_attributes(new_attributes) end def save @@ -113,6 +109,15 @@ module Fog true end + def volumes + connection.volumes.all.select {|volume| volume.instance_id == @instance_id} + end + + def volume=(new_volume) + new_volume.instance_id = @instance_id + connection.attach_volume(@instance_id, new_volume.volume_id, new_volume.device) + end + private def instance_state=(new_instance_state) diff --git a/lib/fog/aws/models/ec2/key_pair.rb b/lib/fog/aws/models/ec2/key_pair.rb index 622cf8f60..ec365b9f7 100644 --- a/lib/fog/aws/models/ec2/key_pair.rb +++ b/lib/fog/aws/models/ec2/key_pair.rb @@ -17,6 +17,11 @@ module Fog @key_pairs end + def reload + new_attributes = key_pairs.all(@name).first.attributes + merge_attributes(new_attributes) + end + def save data = connection.create_key_pair(@name).body new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)} diff --git a/lib/fog/aws/models/ec2/security_group.rb b/lib/fog/aws/models/ec2/security_group.rb index f23a1f2d7..6c6652ee4 100644 --- a/lib/fog/aws/models/ec2/security_group.rb +++ b/lib/fog/aws/models/ec2/security_group.rb @@ -14,17 +14,18 @@ module Fog true end + def reload + new_attributes = security_groups.all(@public_ip).first.attributes + merge_attributes(new_attributes) + end + def save data = connection.create_create_security_group(@group_name, @group_description).body true end def security_groups - @security_groups ||= begin - Fog::AWS::S3::SecurityGroups.new( - :connection => connection - ) - end + @security_groups end private diff --git a/lib/fog/aws/models/ec2/snapshot.rb b/lib/fog/aws/models/ec2/snapshot.rb index 7c684cfeb..69dbbf58b 100644 --- a/lib/fog/aws/models/ec2/snapshot.rb +++ b/lib/fog/aws/models/ec2/snapshot.rb @@ -15,6 +15,11 @@ module Fog true end + def reload + new_attributes = snapshots.all(@snapshot_id).first.attributes + merge_attributes(new_attributes) + end + def save data = connection.create_snapshot(@volume.volume_id).body new_attributes = data.reject {|key,value| key == 'requestId'} @@ -23,12 +28,7 @@ module Fog end def snapshots - @snapshots ||= begin - Fog::AWS::S3::Snapshots.new( - :connection => connection, - :volume => self.volume - ) - end + @snapshots end def volume diff --git a/lib/fog/aws/models/ec2/volume.rb b/lib/fog/aws/models/ec2/volume.rb index d2d806d56..e93ad9f01 100644 --- a/lib/fog/aws/models/ec2/volume.rb +++ b/lib/fog/aws/models/ec2/volume.rb @@ -26,6 +26,11 @@ module Fog true end + def reload + new_attributes = volumes.all(@volume_id).first.attributes + merge_attributes(new_attributes) + end + def save data = connection.create_volume(@availability_zone, @size, @snapshot_id).body new_attributes = data.reject {|key,value| key == 'requestId'} @@ -34,12 +39,7 @@ module Fog end def snapshots - @snapshots ||= begin - Fog::AWS::S3::Snapshots.new( - :connection => connection, - :volume => self - ) - end + connection.snapshots.all.select {|snapshot| snapshot.volume_id == @volume_id} end def volumes