From 6f54e50830283da91e9df8265d1021c35203e16b Mon Sep 17 00:00:00 2001 From: Matt Heath Date: Tue, 1 Apr 2014 01:41:31 +0100 Subject: [PATCH] Add EC2 AssociateRouteTable --- ec2/responses_test.go | 7 +++++++ ec2/vpc.go | 29 +++++++++++++++++++++++++++++ ec2/vpc_test.go | 15 +++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/ec2/responses_test.go b/ec2/responses_test.go index 08ebba3..cc3cbfb 100644 --- a/ec2/responses_test.go +++ b/ec2/responses_test.go @@ -815,3 +815,10 @@ var DescribeRouteTablesExample = ` ` + +var AssociateRouteTableExample = ` + + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + rtbassoc-f8ad4891 + +` diff --git a/ec2/vpc.go b/ec2/vpc.go index 05aab35..920b17a 100644 --- a/ec2/vpc.go +++ b/ec2/vpc.go @@ -66,3 +66,32 @@ func (ec2 *EC2) DescribeRouteTables(routeTableIds []string, filter *Filter) (res } return } + +// AssociateRouteTableResp represents a response from an AssociateRouteTable call +// +// See http://goo.gl/T4KlYk for more details. +type AssociateRouteTableResp struct { + RequestId string `xml:"requestId"` + AssociationId string `xml:"associationId"` +} + +// AssociateRouteTable associates a subnet with a route table. +// +// The subnet and route table must be in the same VPC. This association causes +// traffic originating from the subnet to be routed according to the routes +// in the route table. The action returns an association ID, which you need in +// order to disassociate the route table from the subnet later. +// A route table can be associated with multiple subnets. +// +// See http://goo.gl/bfnONU for more details. +func (ec2 *EC2) AssociateRouteTable(routeTableId, subnetId string) (resp *AssociateRouteTableResp, err error) { + params := makeParams("AssociateRouteTable") + params["RouteTableId"] = routeTableId + params["SubnetId"] = subnetId + resp = &AssociateRouteTableResp{} + err = ec2.query(params, resp) + if err != nil { + return nil, err + } + return +} diff --git a/ec2/vpc_test.go b/ec2/vpc_test.go index 5082728..ecb0319 100644 --- a/ec2/vpc_test.go +++ b/ec2/vpc_test.go @@ -44,3 +44,18 @@ func (s *S) TestDescribeRouteTables(c *gocheck.C) { {Id: "rtbassoc-faad4893", RouteTableId: "rtb-f9ad4890", SubnetId: "subnet-15ad487c"}, }) } + +func (s *S) TestAssociateRouteTable(c *gocheck.C) { + testServer.Response(200, nil, AssociateRouteTableExample) + + resp, err := s.ec2.AssociateRouteTable("rtb-e4ad488d", "subnet-15ad487c") + + req := testServer.WaitRequest() + c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"AssociateRouteTable"}) + c.Assert(req.Form["RouteTableId"], gocheck.DeepEquals, []string{"rtb-e4ad488d"}) + c.Assert(req.Form["SubnetId"], gocheck.DeepEquals, []string{"subnet-15ad487c"}) + + c.Assert(err, gocheck.IsNil) + c.Assert(resp.RequestId, gocheck.Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE") + c.Assert(resp.AssociationId, gocheck.Equals, "rtbassoc-f8ad4891") +}