This commit is contained in:
Wesley Beary 2010-01-10 13:22:18 -08:00
Родитель 44dd484fe7
Коммит 56728c6d8f
9 изменённых файлов: 108 добавлений и 8 удалений

Просмотреть файл

@ -7,7 +7,7 @@ require "#{current_directory}/lib/fog"
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.add_dependency('excon', '>=0.0.16')
gem.add_dependency('excon', '>=0.0.17')
gem.add_dependency('mime-types')
gem.add_dependency('nokogiri')
gem.add_dependency('ruby-hmac')

Просмотреть файл

@ -52,6 +52,10 @@ module AWS
connections[:s3].buckets
end
def flavors
connections[:ec2].flavors
end
def servers
connections[:ec2].servers
end

Просмотреть файл

@ -22,6 +22,8 @@ module Fog
def self.reload
load "fog/aws/models/ec2/address.rb"
load "fog/aws/models/ec2/addresses.rb"
load "fog/aws/models/ec2/flavor.rb"
load "fog/aws/models/ec2/flavors.rb"
load "fog/aws/models/ec2/key_pair.rb"
load "fog/aws/models/ec2/key_pairs.rb"
load "fog/aws/models/ec2/security_group.rb"

Просмотреть файл

@ -0,0 +1,20 @@
module Fog
module AWS
class EC2
class Flavor < Fog::Model
identity :id
attribute :bits
attribute :cores
attribute :disk
attribute :id
attribute :name
attribute :ram
end
end
end
end

Просмотреть файл

@ -0,0 +1,43 @@
module Fog
module AWS
class EC2
def flavors
Fog::AWS::EC2::Flavors.new(:connection => self)
end
class Flavors < Fog::Collection
model Fog::AWS::EC2::Flavor
def all
if @loaded
clear
end
@loaded = true
data = [
{ :bits => 32, :cores => 1, :disk => 160, :id => 'm1.small', :name => 'Small Instance', :ram => 1740.8},
{ :bits => 64, :cores => 4, :disk => 850, :id => 'm1.large', :name => 'Large Instance', :ram => 7680},
{ :bits => 64, :cores => 8, :disk => 1690, :id => 'm1.xlarge', :name => 'Extra Large Instance', :ram => 15360},
{ :bits => 32, :cores => 5, :disk => 350, :id => 'c1.medium', :name => 'High-CPU Medium', :ram => 1740.8},
{ :bits => 64, :cores => 20, :disk => 1690, :id => 'c1.xlarge', :name => 'High-CPU Extra Large', :ram => 7168},
{ :bits => 64, :cores => 13, :disk => 850, :id => 'm2.2xlarge', :name => 'High Memory Double Extra Large', :ram => 35020.8},
{ :bits => 64, :cores => 26, :disk => 1690, :id => 'm2.4xlarge', :name => 'High Memory Quadruple Extra Large', :ram => 70041.6},
]
for flavor in data
self << new(flavor)
end
self
end
def get(flavor_id)
all.detect {|flavor| flavor.id = flavor_id}
end
end
end
end
end

Просмотреть файл

@ -12,7 +12,7 @@ module Fog
attribute :group_id, 'groupId'
attribute :image_id, 'imageId'
attribute :state, 'instanceState'
attribute :type, 'instanceType'
attribute :flavor, 'instanceType'
attribute :kernel_id, 'kernelId'
attribute :key_name, 'keyName'
attribute :created_at, 'launchTime'
@ -44,6 +44,14 @@ module Fog
# @group_id = new_security_group.name
# end
def flavor
@flavor || 'm1.small'
end
def flavor=(new_flavor)
@flavor = new_flavor.id
end
def key_pair
requires :key_name
@ -80,16 +88,13 @@ module Fog
def save
requires :image_id
options = {}
options = {'InstanceType' => flavor}
if @availability_zone
options['Placement.AvailabilityZone'] = @availability_zone
end
if @group_id
options['SecurityGroup'] = @group_id
end
if @type
options['InstanceType'] = @type
end
if @kernel_id
options['KernelId'] = @kernel_id
end

Просмотреть файл

@ -23,7 +23,7 @@ unless Fog.mocking?
# * 'Encoding'<~String> - ?
# * 'groupId'<~String> - Name of security group for instances
# * 'InstanceType'<~String> - Type of instance to boot. Valid options
# in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge']
# in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.2xlarge', 'm2.4xlarge']
# default is 'm1.small'
# * 'KernelId'<~String> - Id of kernel with which to launch
# * 'KeyName'<~String> - Name of a keypair to add to booting instances

Просмотреть файл

@ -6,11 +6,37 @@ module Fog
identity :id
attribute :bits
attribute :cores
attribute :disk
attribute :id
attribute :name
attribute :ram
def bits
64
end
def cores
# 2 quad-cores >= 2Ghz = 8 cores
8 * case ram
when 256
1/64.0
when 512
1/32.0
when 1024
1/16.0
when 2048
1/8.0
when 4096
1/4.0
when 8192
1/2.0
when 15872
1
end
end
end
end

Просмотреть файл

@ -39,7 +39,7 @@ describe 'Fog::AWS::EC2::Server' do
server.group_id.should == 'group_id'
server.image_id.should == 'image_id'
server.id.should == 'instance_id'
server.type.should == 'instance_type'
server.flavor.should == 'instance_type'
server.kernel_id.should == 'kernel_id'
server.key_name.should == 'key_name'
server.created_at.should == 'launch_time'