1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/compute/create_route_table.rb

71 lines
2.4 KiB
Ruby
Raw Normal View History

module Fog
module Compute
class AWS
class Real
require 'fog/aws/parsers/compute/create_route_table'
# Creates a route table for the specified VPC.
#
# ==== Parameters
# * VpcId<~String> - The ID of the VPC.
#
# === Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of the request
# * 'routeTable'<~Array> - Information about the newly created route table
# * 'routeTableId'<~String>
# * 'vpcId'<~String>
# * 'routeSet'<~Array>
# * 'item'<~Array>
# * 'destinationCidrBlock'<~String> - The CIDR address block used for the destination match.
# * 'gatewayId'<~String> - The ID of an Internet gateway attached to your VPC.
# * 'state'<~String> - The state of the route. ['blackhole', 'available']
#
# {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateRouteTable.html]
def create_route_table(vpc_id)
request({
'Action' => 'CreateRouteTable',
'VpcId' => vpc_id,
:parser => Fog::Parsers::Compute::AWS::CreateRouteTable.new
})
end
end
class Mock
def create_route_table(vpc_id)
response = Excon::Response.new
vpc = self.data[:vpcs].find { |vpc| vpc["vpcId"].eql? vpc_id }
unless vpc.nil?
response.status = 200
route_table = {
'routeTableId' => "rtb-#{Fog::Mock.random_hex(8)}",
'vpcId' => vpc["vpcId"],
2013-08-14 14:28:27 -04:00
'routeSet' => [{
"destinationCidrBlock" => vpc["cidrBlock"],
"gatewayId" => "local",
"instanceId"=>nil,
"instanceOwnerId"=>nil,
"networkInterfaceId"=>nil,
"state" => "pending",
"origin" => "CreateRouteTable"
}],
'associationSet' => [],
2013-08-16 10:15:06 -04:00
'tagSet' => {}
}
self.data[:route_tables].push(route_table)
response.body = {
2013-08-16 10:15:06 -04:00
'requestId'=> Fog::AWS::Mock.request_id,
'routeTable' => [route_table]
2013-08-16 10:15:06 -04:00
}
response
else
raise Fog::Compute::AWS::NotFound.new("The vpc ID '#{vpc_id}' does not exist")
end
2013-08-16 10:15:06 -04:00
end
end
end
end
end