From f7ca21892347ac1312257db5fd6d45c30a9591e3 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Fri, 25 Sep 2009 09:01:51 -0700 Subject: [PATCH] fill in other collection methods on ec2 models --- lib/fog/aws/models/ec2/instances.rb | 17 ++++++++++++++++- lib/fog/aws/models/ec2/key_pairs.rb | 17 ++++++++++++++++- lib/fog/aws/models/ec2/security_groups.rb | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/fog/aws/models/ec2/instances.rb b/lib/fog/aws/models/ec2/instances.rb index 608aeba70..aaca69520 100644 --- a/lib/fog/aws/models/ec2/instances.rb +++ b/lib/fog/aws/models/ec2/instances.rb @@ -8,9 +8,14 @@ module Fog class Instances < Fog::Collection + attribute :instance_id + def all(instance_id = []) data = connection.describe_instances(instance_id) - instances = Fog::AWS::EC2::Instances.new(:connection => connection) + instances = Fog::AWS::EC2::Instances.new( + :connection => connection, + :instance_id => instance_id + ) data['instancesSet'].each do |instance| instances << Fog::AWS::EC2::Instances.new({ :connection => connection, @@ -26,6 +31,12 @@ module Fog instance end + def get(instance_id) + all(instance_id).first + rescue Fog::Errors::BadRequest + nil + end + def new(attributes = {}) Fog::AWS::EC2::Instance.new( attributes.merge!( @@ -35,6 +46,10 @@ module Fog ) end + def reload + all(instance_id) + end + end end diff --git a/lib/fog/aws/models/ec2/key_pairs.rb b/lib/fog/aws/models/ec2/key_pairs.rb index 531ed3ec2..2bbfb0a1d 100644 --- a/lib/fog/aws/models/ec2/key_pairs.rb +++ b/lib/fog/aws/models/ec2/key_pairs.rb @@ -8,9 +8,14 @@ module Fog class KeyPairs < Fog::Collection + attribute :key_name + def all(key_name = []) data = connection.describe_key_pairs(key_name).body - key_pairs = Fog::AWS::EC2::KeyPairs.new(:connection => connection) + key_pairs = Fog::AWS::EC2::KeyPairs.new( + :connection => connection, + :key_name => key_name + ) data['keySet'].each do |key| key_pairs << Fog::AWS::EC2::KeyPair.new({ :connection => connection, @@ -26,6 +31,12 @@ module Fog bucket end + def get(key_name) + all(key_name).first + rescue Fog::Errors::BadRequest + nil + end + def new(attributes = {}) Fog::AWS::EC2::KeyPair.new( attributes.merge!( @@ -35,6 +46,10 @@ module Fog ) end + def reload + all(key_name) + end + end end diff --git a/lib/fog/aws/models/ec2/security_groups.rb b/lib/fog/aws/models/ec2/security_groups.rb index 4d239885e..8458290bd 100644 --- a/lib/fog/aws/models/ec2/security_groups.rb +++ b/lib/fog/aws/models/ec2/security_groups.rb @@ -8,9 +8,14 @@ module Fog class SecurityGroups < Fog::Collection + attribute :group_name + def all(group_name = []) data = connection.describe_security_groups(group_name) - security_groups = Fog::AWS::EC2::SecurityGroups.new(:connection => connection) + security_groups = Fog::AWS::EC2::SecurityGroups.new( + :connection => connection, + :group_name => group_name + ) data['securityGroupInfo'].each do |security_group| security_groups << Fog::AWS::EC2::SecurityGroup.new({ :connection => connection, @@ -26,6 +31,12 @@ module Fog security_group end + def get(group_name) + all(group_name).first + rescue Fog::Errors::BadRequest + nil + end + def new(attributes = {}) Fog::AWS::EC2::SecurityGroup.new( attributes.merge!( @@ -35,6 +46,10 @@ module Fog ) end + def reload + all(group_name) + end + end end