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

Add model, collection for instance_options

This commit is contained in:
James Bence 2013-07-08 17:19:20 -07:00
parent 460d2f8f01
commit 11de142ecf
6 changed files with 92 additions and 3 deletions

View file

@ -0,0 +1,21 @@
require 'fog/core/model'
module Fog
module AWS
class RDS
class InstanceOption < Fog::Model
attribute :multi_az_capable, :aliases => 'MultiAZCapable', :type => :boolean
attribute :engine, :aliases => 'Engine'
attribute :license_model, :aliases => 'LicenseModel'
attribute :read_replica_capable, :aliases => 'ReadReplicaCapable', :type => :boolean
attribute :engine_version, :aliases => 'EngineVersion'
attribute :availability_zones, :aliases => 'AvailabilityZones', :type => :array
attribute :db_instance_class, :aliases => 'DBInstanceClass'
attribute :vpc, :aliases => 'Vpc', :type => :boolean
end
end
end
end

View file

@ -0,0 +1,30 @@
require 'fog/core/collection'
require 'fog/aws/models/rds/instance_option'
module Fog
module AWS
class RDS
class InstanceOptions < Fog::PagedCollection
attribute :filters
attribute :engine
model Fog::AWS::RDS::InstanceOption
def initialize(attributes)
self.filters ||= {}
super
end
# This method deliberately returns only a single page of results
def all(filters=filters)
self.filters.merge!(filters)
result = service.describe_orderable_db_instance_options(engine, filters).body['DescribeOrderableDBInstanceOptionsResult']
self.filters[:marker] = result['Marker']
load(result['OrderableDBInstanceOptions'])
end
end
end
end
end

View file

@ -21,7 +21,7 @@ module Fog
def end_element(name)
case name
when 'MultiAZCapable', 'ReadReplicaCapable' then @db_instance_option[name] = to_boolean(value)
when 'MultiAZCapable', 'ReadReplicaCapable', 'Vpc' then @db_instance_option[name] = to_boolean(value)
when 'Engine', 'LicenseModel', 'EngineVersion', 'DBInstanceClass' then @db_instance_option[name] = value
when 'AvailabilityZones' then @db_instance_option[name] = @availability_zones
when 'AvailabilityZone' then @availability_zones << @availability_zone unless @availability_zone.empty?

View file

@ -56,8 +56,10 @@ module Fog
model_path 'fog/aws/models/rds'
model :server
collection :servers
model :snapshot
collection :snapshots
model :parameter_group
collection :parameter_groups
@ -70,6 +72,9 @@ module Fog
model :subnet_group
collection :subnet_groups
model :instance_option
collection :instance_options
class Mock
def self.data

View file

@ -40,9 +40,24 @@ module Fog
class Mock
def describe_orderable_db_instance_options(engine=nil, opts={})
instance_options = []
response = Excon::Response.new
if engine
# set up some mock data here...
(opts[:db_instance_class] || %w(db.m2.xlarge db.m1.large)).each do |size|
instance_options << {'MultiAZCapable' => true,
'Engine' => engine,
'LicenseModel' => opts[:license_model] || 'general-public-license',
'ReadReplicaCapable' => true,
'EngineVersion' => opts[:engine_version] || '5.6.12',
'AvailabilityZones' => [
{'Name' => 'us-east-1b', 'ProvisionedIopsCapable' => true},
{'Name' => 'us-east-1c', 'ProvisionedIopsCapable' => true},
{'Name' => 'us-east-1d', 'ProvisionedIopsCapable' => false},
{'Name' => 'us-east-1e', 'ProvisionedIopsCapable' => true}],
'DBInstanceClass' => size,
'Vpc' => opts[:vpc].nil? ? true : opts[:vpc]}
end
else
raise Fog::AWS::RDS::NotFound.new('An engine must be specified to retrieve orderable instance options')
end
@ -50,7 +65,7 @@ module Fog
response.status = 200
response.body = {
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id },
'DescribeOrderableDBInstanceOptionsResult' => { 'OrderableDBInstanceOptions' => [] }
'DescribeOrderableDBInstanceOptionsResult' => { 'OrderableDBInstanceOptions' => instance_options }
}
response
end

View file

@ -142,4 +142,22 @@ module Fog
end
end
# Base class for collection classes whose 'all' method returns only a single page of results and passes the
# 'Marker' option along as self.filters[:marker]
class PagedCollection < Collection
def each(filters=filters)
if block_given?
begin
page = self.all(filters)
# We need to explicitly use the base 'each' method here on the page, otherwise we get infinite recursion
base_each = Fog::Collection.instance_method(:each)
base_each.bind(page).call { |item| yield item }
end while self.filters[:marker]
end
self
end
end
end