Skip to content

Commit

Permalink
EC2-VPC: Add remaining route table methods and types
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheath committed Apr 2, 2014
1 parent b309429 commit ef8cd13
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ec2/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,46 @@ var DescribeRouteTablesExample = `
</DescribeRouteTablesResponse>
`

var CreateRouteTableExample = `
<CreateRouteTableResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>59abcd43-35bd-4eac-99ed-be587EXAMPLE</requestId>
<routeTable>
<routeTableId>rtb-f9ad4890</routeTableId>
<vpcId>vpc-11ad4878</vpcId>
<routeSet>
<item>
<destinationCidrBlock>10.0.0.0/22</destinationCidrBlock>
<gatewayId>local</gatewayId>
<state>active</state>
</item>
</routeSet>
<associationSet/>
<tagSet/>
</routeTable>
</CreateRouteTableResponse>
`

var DeleteRouteTableExample = `
<DeleteRouteTableResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>49dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<return>true</return>
</DeleteRouteTableResponse>
`

var AssociateRouteTableExample = `
<AssociateRouteTableResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<associationId>rtbassoc-f8ad4891</associationId>
</AssociateRouteTableResponse>
`

var DisassociateRouteTableExample = `
<DisassociateRouteTableResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<return>true</return>
</DisassociateRouteTableResponse>
`

var ReplaceRouteTableAssociationExample = `
<ReplaceRouteTableAssociationResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>59dbff89-35bd-4eac-88ed-be587EXAMPLE</requestId>
Expand Down
69 changes: 69 additions & 0 deletions ec2/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ type PropagatingVgw struct {
GatewayId string `xml:"gatewayID"`
}

// CreateRouteTableResp represents a response from a CreateRouteTable request
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateRouteTable.html#query-CreateRouteTable-response-elements
type CreateRouteTableResp struct {
RequestId string `xml:"requestId"`
RouteTable RouteTable `xml:"routeTable"`
}

// CreateRouteTable creates a route table for the specified VPC.
// After you create a route table, you can add routes and associate the table with a subnet.
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateRouteTable.html
func (ec2 *EC2) CreateRouteTable(vpcId string) (resp *CreateRouteTableResp, err error) {
params := makeParams("CreateRouteTable")
params["VpcId"] = vpcId
resp = &CreateRouteTableResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}

// DescribeRouteTablesResp represents a response from a DescribeRouteTables call
//
// See http://goo.gl/T3tVsg for more details.
Expand Down Expand Up @@ -96,6 +119,28 @@ func (ec2 *EC2) AssociateRouteTable(routeTableId, subnetId string) (resp *Associ
return
}

// DisassociateRouteTableResp represents the response from a DisassociateRouteTable request
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DisassociateRouteTable.html#query-DisassociateRouteTable-response-elements
type DisassociateRouteTableResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"` // True if the request succeeds
}

// DisassociateRouteTable disassociates a subnet from a route table.
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DisassociateRouteTable.html
func (ec2 *EC2) DisassociateRouteTable(associationId string) (resp *DisassociateRouteTableResp, err error) {
params := makeParams("DisassociateRouteTable")
params["AssociationId"] = associationId
resp = &DisassociateRouteTableResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}

// ReplaceRouteTableAssociationResp represents a response from a ReplaceRouteTableAssociation call
//
// See for more details.
Expand All @@ -118,3 +163,27 @@ func (ec2 *EC2) ReplaceRouteTableAssociation(associationId, routeTableId string)
}
return
}

// DeleteRouteTableResp represents a response from a DeleteRouteTable request
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteRouteTable.html#query-DeleteRouteTable-response-elements
type DeleteRouteTableResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"` // True if the request succeeds
}

// DeleteRouteTable deletes the specified route table.
// You must disassociate the route table from any subnets before you can delete it.
// You can't delete the main route table.
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteRouteTable.html
func (ec2 *EC2) DeleteRouteTable(routeTableId string) (resp *DeleteRouteTableResp, err error) {
params := makeParams("DeleteRouteTable")
params["RouteTableId"] = routeTableId
resp = &DeleteRouteTableResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
51 changes: 51 additions & 0 deletions ec2/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import (
"github.com/motain/gocheck"
)

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

resp, err := s.ec2.CreateRouteTable("vpc-11ad4878")

req := testServer.WaitRequest()
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"CreateRouteTable"})
c.Assert(req.Form["VpcId"], gocheck.DeepEquals, []string{"vpc-11ad4878"})

c.Assert(err, gocheck.IsNil)
c.Assert(resp.RequestId, gocheck.Equals, "59abcd43-35bd-4eac-99ed-be587EXAMPLE")
c.Assert(resp.RouteTable.Id, gocheck.Equals, "rtb-f9ad4890")
c.Assert(resp.RouteTable.VpcId, gocheck.Equals, "vpc-11ad4878")
c.Assert(resp.RouteTable.Routes, gocheck.HasLen, 1)
c.Assert(resp.RouteTable.Routes[0], gocheck.DeepEquals, ec2.Route{
DestinationCidrBlock: "10.0.0.0/22",
GatewayId: "local",
State: "active",
})
c.Assert(resp.RouteTable.Associations, gocheck.HasLen, 0)
c.Assert(resp.RouteTable.Tags, gocheck.HasLen, 0)
}

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

Expand Down Expand Up @@ -60,6 +83,20 @@ func (s *S) TestAssociateRouteTable(c *gocheck.C) {
c.Assert(resp.AssociationId, gocheck.Equals, "rtbassoc-f8ad4891")
}

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

resp, err := s.ec2.DisassociateRouteTable("rtbassoc-f8ad4891")

req := testServer.WaitRequest()
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"DisassociateRouteTable"})
c.Assert(req.Form["AssociationId"], gocheck.DeepEquals, []string{"rtbassoc-f8ad4891"})

c.Assert(err, gocheck.IsNil)
c.Assert(resp.RequestId, gocheck.Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE")
c.Assert(resp.Return, gocheck.Equals, true)
}

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

Expand All @@ -74,3 +111,17 @@ func (s *S) TestReplaceRouteTableAssociation(c *gocheck.C) {
c.Assert(resp.RequestId, gocheck.Equals, "59dbff89-35bd-4eac-88ed-be587EXAMPLE")
c.Assert(resp.NewAssociationId, gocheck.Equals, "rtbassoc-faad2958")
}

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

resp, err := s.ec2.DeleteRouteTable("rtb-f9ad4890")

req := testServer.WaitRequest()
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"DeleteRouteTable"})
c.Assert(req.Form["RouteTableId"], gocheck.DeepEquals, []string{"rtb-f9ad4890"})

c.Assert(err, gocheck.IsNil)
c.Assert(resp.RequestId, gocheck.Equals, "49dbff89-35bd-4eac-99ed-be587EXAMPLE")
c.Assert(resp.Return, gocheck.Equals, true)
}

0 comments on commit ef8cd13

Please sign in to comment.