diff --git a/lib/fog/aws/requests/compute/associate_route_table.rb b/lib/fog/aws/requests/compute/associate_route_table.rb index d4279a22e..c1a22dda8 100755 --- a/lib/fog/aws/requests/compute/associate_route_table.rb +++ b/lib/fog/aws/requests/compute/associate_route_table.rb @@ -4,30 +4,24 @@ module Fog class Real require 'fog/aws/parsers/compute/associate_route_table' - - # Attach an Amazon EBS volume with a running instance, exposing as specified device + # Associates a subnet with a route table. # # ==== Parameters - # * instance_id<~String> - Id of instance to associate volume with - # * volume_id<~String> - Id of amazon EBS volume to associate with instance - # * device<~String> - Specifies how the device is exposed to the instance (e.g. "/dev/sdh") + # * RouteTableId<~String> - The ID of the route table + # * SubnetId<~String> - The ID of the subnet # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: - # * 'attachTime'<~Time> - Time of attachment was initiated at - # * 'device'<~String> - Device as it is exposed to the instance - # * 'instanceId'<~String> - Id of instance for volume - # * 'requestId'<~String> - Id of request - # * 'status'<~String> - Status of volume - # * 'volumeId'<~String> - Reference to volume + # * 'requestId'<~String> - The ID of the request + # * 'associationId'<~String> - The route table association ID (needed to disassociate the route table) # - # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AttachVolume.html] - def associate_route_table(route_table_id, subnet_id) + # {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-AssociateRouteTable.html] + def associate_route_table(routeTableId, subnetId) request( 'Action' => 'AssociateRouteTable', - 'RouteTableId' => route_table_id, - 'SubnetId' => subnet_id, + 'RouteTableId' => routeTableId, + 'SubnetId' => subnetId, :parser => Fog::Parsers::Compute::AWS::AssociateRouteTable.new ) end @@ -35,6 +29,42 @@ module Fog end class Mock + + def associate_route_table(routeTableId, subnetId) + response = Excon::Response.new + routetable = self.data[:route_tables].find { |routetable| routetable["routeTableId"].eql? routeTableId } + subnet = self.data[:subnets].find { |subnet| subnet["subnetId"].eql? subnetId } + + if !routetable.nil? && !subnet.nil? + response.status = 200 + routetable["associationSet"].push(add_route_association(routeTableId, subnetId)) + response.body = { + 'requestId' => Fog::AWS::Mock.request_id, + 'associationId' => "rtbassoc-#{Fog::Mock.random_hex(8)}" + } + response + elsif routetable.nil? + raise Fog::Compute::AWS::NotFound.new("The routeTable ID '#{routeTableId}' does not exist") + else + raise Fog::Compute::AWS::NotFound.new("The subnet ID '#{subnetId}' does not exist") + end + + end + + private + + def add_route_association(routeTableId, subnetId, main=nil) + response = { + "routeTableAssociationId" => "rtbassoc-#{Fog::Mock.random_hex(8)}", + "routeTableId" => routeTableId + } + if main + response['main'] = true + else + response['subnetId'] = subnetId + end + response + end end end