Skip to content

Commit

Permalink
Describe route tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheath committed Apr 2, 2014
1 parent ff3d9a6 commit 4bd3836
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
53 changes: 53 additions & 0 deletions ec2/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,56 @@ var RebootInstancesExample = `
<return>true</return>
</RebootInstancesResponse>
`

var DescribeRouteTablesExample = `
<DescribeRouteTablesResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>6f570b0b-9c18-4b07-bdec-73740dcf861aEXAMPLE</requestId>
<routeTableSet>
<item>
<routeTableId>rtb-13ad487a</routeTableId>
<vpcId>vpc-11ad4878</vpcId>
<routeSet>
<item>
<destinationCidrBlock>10.0.0.0/22</destinationCidrBlock>
<gatewayId>local</gatewayId>
<state>active</state>
<origin>CreateRouteTable</origin>
</item>
</routeSet>
<associationSet>
<item>
<routeTableAssociationId>rtbassoc-12ad487b</routeTableAssociationId>
<routeTableId>rtb-13ad487a</routeTableId>
<main>true</main>
</item>
</associationSet>
<tagSet/>
</item>
<item>
<routeTableId>rtb-f9ad4890</routeTableId>
<vpcId>vpc-11ad4878</vpcId>
<routeSet>
<item>
<destinationCidrBlock>10.0.0.0/22</destinationCidrBlock>
<gatewayId>local</gatewayId>
<state>active</state>
<origin>CreateRouteTable</origin>
</item>
<item>
<destinationCidrBlock>0.0.0.0/0</destinationCidrBlock>
<gatewayId>igw-eaad4883</gatewayId>
<state>active</state>
</item>
</routeSet>
<associationSet>
<item>
<routeTableAssociationId>rtbassoc-faad4893</routeTableAssociationId>
<routeTableId>rtb-f9ad4890</routeTableId>
<subnetId>subnet-15ad487c</subnetId>
</item>
</associationSet>
<tagSet/>
</item>
</routeTableSet>
</DescribeRouteTablesResponse>
`
68 changes: 68 additions & 0 deletions ec2/vpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package ec2

// RouteTable describes a route table which contains a set of rules, called routes
// that are used to determine where network traffic is directed.
//
// See http://goo.gl/bI9hkg for more details.
type RouteTable struct {
Id string `xml:"routeTableId"`
VpcId string `xml:"vpcId"`
Routes []Route `xml:"routeSet>item"`
Associations []RouteTableAssociation `xml:"associationSet>item"`
PropagatingVgws []PropagatingVgw `xml:"propagatingVgwSet>item"`
Tags []Tag `xml:"tagSet>item"`
}

// Route describes a route in a route table.
//
// See http://goo.gl/hE5Kxe for more details.
type Route struct {
DestinationCidrBlock string `xml:"destinationCidrBlock"` // The CIDR block used for the destination match.
GatewayId string `xml:"gatewayId"` // The ID of a gateway attached to your VPC.
InstanceId string `xml:"instanceId"` // The ID of a NAT instance in your VPC.
InstanceOwnerId string `xml:"instanceOwnerId"` // The AWS account ID of the owner of the instance.
NetworkInterfaceId string `xml:"networkInterfaceId"` // The ID of the network interface.
State string `xml:"state"` // The state of the route. Valid values: active | blackhole
Origin string `xml:"origin"` // Describes how the route was created. Valid values: Valid values: CreateRouteTable | CreateRoute | EnableVgwRoutePropagation
VpcPeeringConnectionId string `xml:"vpcPeeringConnectionId"` // The ID of the VPC peering connection.
}

// RouteTableAssociation describes an association between a route table and a subnet.
//
// See http://goo.gl/BZB8o8 for more details.
type RouteTableAssociation struct {
Id string `xml:"routeTableAssociationId"` // The ID of the association between a route table and a subnet.
RouteTableId string `xml:"routeTableId"` // The ID of the route table.
SubnetId string `xml:"subnetId"` // The ID of the subnet.
Main bool `xml:"main"` // Indicates whether this is the main route table.
}

// PropagatingVgw describes a virtual private gateway propagating route.
//
// See http://goo.gl/myGQtG for more details.
type PropagatingVgw struct {
GatewayId string `xml:"gatewayID"`
}

// DescribeRouteTablesResp represents a response from a DescribeRouteTables call
//
// See http://goo.gl/T3tVsg for more details.
type DescribeRouteTablesResp struct {
RequestId string `xml:"requestId"`
RouteTables []RouteTable `xml:"routeTableSet>item"`
}

// DescribeRouteTables describes one or more of your route tables
//
// See http://goo.gl/S0RVos for more details.
func (ec2 *EC2) DescribeRouteTables(routeTableIds []string, filter *Filter) (resp *DescribeRouteTablesResp, err error) {
params := makeParams("DescribeRouteTables")
addParamsList(params, "RouteTableId", routeTableIds)
filter.addParams(params)
resp = &DescribeRouteTablesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
46 changes: 46 additions & 0 deletions ec2/vpc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ec2_test

import (
"github.com/goamz/goamz/ec2"
"github.com/motain/gocheck"
)

func (s *S) TestDescribeRouteTables(c *gocheck.C) {
testServer.Response(200, nil, DescribeRouteTablesExample)

filter := ec2.NewFilter()
filter.Add("key1", "value1")
filter.Add("key2", "value2", "value3")

resp, err := s.ec2.DescribeRouteTables([]string{"rt1", "rt2"}, nil)

req := testServer.WaitRequest()
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"DescribeRouteTables"})
c.Assert(req.Form["RouteTableId.1"], gocheck.DeepEquals, []string{"rt1"})
c.Assert(req.Form["RouteTableId.2"], gocheck.DeepEquals, []string{"rt2"})

c.Assert(err, gocheck.IsNil)
c.Assert(resp.RequestId, gocheck.Equals, "6f570b0b-9c18-4b07-bdec-73740dcf861aEXAMPLE")
c.Assert(resp.RouteTables, gocheck.HasLen, 2)

rt1 := resp.RouteTables[0]
c.Assert(rt1.Id, gocheck.Equals, "rtb-13ad487a")
c.Assert(rt1.VpcId, gocheck.Equals, "vpc-11ad4878")
c.Assert(rt1.Routes, gocheck.DeepEquals, []ec2.Route{
{DestinationCidrBlock: "10.0.0.0/22", GatewayId: "local", State: "active", Origin: "CreateRouteTable"},
})
c.Assert(rt1.Associations, gocheck.DeepEquals, []ec2.RouteTableAssociation{
{Id: "rtbassoc-12ad487b", RouteTableId: "rtb-13ad487a", Main: true},
})

rt2 := resp.RouteTables[1]
c.Assert(rt2.Id, gocheck.Equals, "rtb-f9ad4890")
c.Assert(rt2.VpcId, gocheck.Equals, "vpc-11ad4878")
c.Assert(rt2.Routes, gocheck.DeepEquals, []ec2.Route{
{DestinationCidrBlock: "10.0.0.0/22", GatewayId: "local", State: "active", Origin: "CreateRouteTable"},
{DestinationCidrBlock: "0.0.0.0/0", GatewayId: "igw-eaad4883", State: "active"},
})
c.Assert(rt2.Associations, gocheck.DeepEquals, []ec2.RouteTableAssociation{
{Id: "rtbassoc-faad4893", RouteTableId: "rtb-f9ad4890", SubnetId: "subnet-15ad487c"},
})
}

0 comments on commit 4bd3836

Please sign in to comment.