1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

more ec2 model implementation and spec work

This commit is contained in:
Wesley Beary 2009-09-27 21:31:15 -07:00
parent 39caa9ff15
commit 830a9907fd
9 changed files with 194 additions and 7 deletions

View file

@ -28,6 +28,8 @@ module Fog
load "fog/aws/models/ec2/address.rb"
load "fog/aws/models/ec2/addresses.rb"
load "fog/aws/models/ec2/key_pair.rb"
load "fog/aws/models/ec2/key_pairs.rb"
load "fog/aws/models/ec2/snapshot.rb"
load "fog/aws/models/ec2/snapshots.rb"
load "fog/aws/models/ec2/volume.rb"

View file

@ -10,10 +10,16 @@ module Fog
attribute :public_ip
def initialize(attributes)
@public_ip ||= []
super
end
def all(public_ip = [])
data = connection.describe_addresses(public_ip).body
addresses = Fog::AWS::EC2::Addresses.new({
:connection => connection
:connection => connection,
:public_ip => public_ip
}.merge!(attributes))
data['addressesSet'].each do |address|
addresses << Fog::AWS::EC2::Address.new({
@ -38,7 +44,7 @@ module Fog
def new
Fog::AWS::EC2::Address.new(
:addresses => self,
:addresses => self,
:connection => connection
)
end

View file

@ -25,7 +25,7 @@ module Fog
def save
data = connection.create_key_pair(@name).body
new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
update_attributes(new_attributes)
merge_attributes(new_attributes)
true
end

View file

@ -10,10 +10,16 @@ module Fog
attribute :key_name
def initialize(attributes)
@key_name ||= []
super
end
def all(key_name = [])
data = connection.describe_key_pairs(key_name).body
key_pairs = Fog::AWS::EC2::KeyPairs.new({
:connection => connection
:connection => connection,
:key_name => key_name
}.merge!(attributes))
data['keySet'].each do |key|
key_pairs << Fog::AWS::EC2::KeyPair.new({

View file

@ -10,10 +10,16 @@ module Fog
attribute :group_name
def initialize(attributes)
@group_name ||= []
super
end
def all(group_name = [])
data = connection.describe_security_groups(group_name)
security_groups = Fog::AWS::EC2::SecurityGroups.new({
:connection => connection
:connection => connection,
:group_name => group_name
}.merge!(attributes))
data['securityGroupInfo'].each do |security_group|
security_groups << Fog::AWS::EC2::SecurityGroup.new({

View file

@ -11,10 +11,16 @@ module Fog
attribute :snapshot_id
attribute :volume_id
def initialize(attributes)
@snapshot_id ||= []
super
end
def all(snapshot_id = [])
data = connection.describe_snapshots(snapshot_id).body
snapshots = Fog::AWS::EC2::Snapshots.new({
:connection => connection
:connection => connection,
:snapshot_id => snapshot_id
}.merge!(attributes))
data['snapshotSet'].each do |snapshot|
snapshots << Fog::AWS::EC2::Snapshot.new({

View file

@ -10,10 +10,16 @@ module Fog
attribute :volume_id
def initialize(attributes)
@volume_id ||= []
super
end
def all(volume_id = [])
data = connection.describe_volumes(volume_id).body
volumes = Fog::AWS::EC2::Volumes.new({
:connection => connection
:connection => connection,
:volume_id => volume_id
}.merge!(attributes))
data['volumeSet'].each do |volume|
volumes << Fog::AWS::EC2::Volume.new({

View file

@ -0,0 +1,84 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::KeyPair' do
describe "#initialize" do
it "should remap attributes from parser" #do
# address = Fog::AWS::EC2::KeyPair.new(
# 'instanceId' => 'i-00000000',
# 'publicIp' => '0.0.0.0'
# )
# address.instance_id.should == 'i-00000000'
# address.public_ip.should == '0.0.0.0'
# end
end
describe "#key_pairs" do
it "should return a Fog::AWS::EC2::KeyPairs" do
ec2.key_pairs.new.key_pairs.should be_a(Fog::AWS::EC2::KeyPairs)
end
it "should be the key_pairs the keypair is related to" do
key_pairs = ec2.key_pairs
key_pairs.new.key_pairs.should == key_pairs
end
end
describe "#destroy" do
it "should return true if the key_pair is deleted" do
address = ec2.key_pairs.create(:name => 'keyname')
address.destroy.should be_true
end
end
describe "#reload" do
before(:each) do
@key_pair = ec2.key_pairs.create(:name => 'keyname')
@reloaded = @key_pair.reload
end
after(:each) do
@key_pair.destroy
end
it "should return a Fog::AWS::EC2::KeyPair" do
@reloaded.should be_a(Fog::AWS::EC2::KeyPair)
end
it "should reset attributes to remote state" do
@key_pair.attributes.should == @reloaded.attributes
end
end
describe "#save" do
before(:each) do
@key_pair = ec2.key_pairs.new(:name => 'keyname')
end
it "should return true when it succeeds" do
@key_pair.save.should be_true
@key_pair.destroy
end
it "should not exist in key_pairs before save" do
@key_pair.key_pairs.get(@key_pair.name).should be_nil
end
it "should exist in buckets after save" do
@key_pair.save
@key_pair.key_pairs.get(@key_pair.name).should_not be_nil
@key_pair.destroy
end
end
end

View file

@ -0,0 +1,71 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::KeyPairs' do
describe "#all" do
it "should return a Fog::AWS::EC2::KeyPairs" do
ec2.key_pairs.all.should be_a(Fog::AWS::EC2::KeyPairs)
end
it "should include persisted key_pairs" do
key_pair = ec2.key_pairs.create(:name => 'keyname')
ec2.key_pairs.get(key_pair.name).should_not be_nil
key_pair.destroy
end
end
describe "#create" do
before(:each) do
@key_pair = ec2.key_pairs.create(:name => 'keyname')
end
after(:each) do
@key_pair.destroy
end
it "should return a Fog::AWS::EC2::KeyPair" do
@key_pair.should be_a(Fog::AWS::EC2::KeyPair)
end
it "should exist on ec2" do
ec2.key_pairs.get(@key_pair.name).should_not be_nil
end
end
describe "#get" do
it "should return a Fog::AWS::EC2::KeyPair if a matching key_pair exists" do
key_pair = ec2.key_pairs.create(:name => 'keyname')
get = ec2.key_pairs.get(key_pair.name)
key_pair.attributes[:fingerprint].should == get.attributes[:fingerprint]
key_pair.attributes[:name].should == get.attributes[:name]
key_pair.destroy
end
it "should return nil if no matching key_pair exists" do
ec2.key_pairs.get('notakeyname').should be_nil
end
end
describe "#new" do
it "should return a Fog::AWS::EC2::KeyPair" do
ec2.key_pairs.new(:name => 'keyname').should be_a(Fog::AWS::EC2::KeyPair)
end
end
describe "#reload" do
it "should return a Fog::AWS::EC2::KeyPairs" do
ec2.key_pairs.all.reload.should be_a(Fog::AWS::EC2::KeyPairs)
end
end
end