diff --git a/lib/fog/aws/models/rds/instance_option.rb b/lib/fog/aws/models/rds/instance_option.rb new file mode 100644 index 000000000..4db63e75d --- /dev/null +++ b/lib/fog/aws/models/rds/instance_option.rb @@ -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 diff --git a/lib/fog/aws/models/rds/instance_options.rb b/lib/fog/aws/models/rds/instance_options.rb new file mode 100644 index 000000000..363cd4a32 --- /dev/null +++ b/lib/fog/aws/models/rds/instance_options.rb @@ -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 diff --git a/lib/fog/aws/parsers/rds/describe_orderable_db_instance_options.rb b/lib/fog/aws/parsers/rds/describe_orderable_db_instance_options.rb index 13e8e5b97..8535c9330 100644 --- a/lib/fog/aws/parsers/rds/describe_orderable_db_instance_options.rb +++ b/lib/fog/aws/parsers/rds/describe_orderable_db_instance_options.rb @@ -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? diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 77d35f911..1725a7abf 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -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 diff --git a/lib/fog/aws/requests/rds/describe_orderable_db_instance_options.rb b/lib/fog/aws/requests/rds/describe_orderable_db_instance_options.rb index 2263efb42..3b0163fb1 100644 --- a/lib/fog/aws/requests/rds/describe_orderable_db_instance_options.rb +++ b/lib/fog/aws/requests/rds/describe_orderable_db_instance_options.rb @@ -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 diff --git a/lib/fog/core/collection.rb b/lib/fog/core/collection.rb index 993c9a729..b6770a6ed 100644 --- a/lib/fog/core/collection.rb +++ b/lib/fog/core/collection.rb @@ -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