mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Updated description and added mock for associateRouteTable.
This commit is contained in:
parent
a1a66231ed
commit
6fc78f63ba
1 changed files with 45 additions and 15 deletions
|
@ -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
|
||||
|
@ -36,6 +30,42 @@ module Fog
|
|||
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue