Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,9 @@ func NewWorkflowV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOp
func NewPlacementV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
return initClientOpts(client, eo, "placement", 1)
}

// NewVirtualPrivateCloudV1 creates a ServiceClient that may be used with the v1
// Virtual Private Cloud (Orion) lifecycle management package.
func NewVirtualPrivateCloudV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
return initClientOpts(client, eo, "vpc", 1)
}
2 changes: 2 additions & 0 deletions openstack/networking/v2/extensions/layer3/routers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ListOpts struct {
NotTags string `q:"not-tags"`
NotTagsAny string `q:"not-tags-any"`
RevisionNumber *int `q:"revision_number"`
VpcID string `q:"vpc_id"`
}

// ToRouterListQuery formats a ListOpts into a query string.
Expand Down Expand Up @@ -85,6 +86,7 @@ type CreateOpts struct {
ProjectID string `json:"project_id,omitempty"`
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
AvailabilityZoneHints []string `json:"availability_zone_hints,omitempty"`
VpcID string `json:"vpc_id,omitempty"`
}

// ToRouterCreateMap builds a create request body from CreateOpts.
Expand Down
3 changes: 3 additions & 0 deletions openstack/networking/v2/extensions/layer3/routers/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type Router struct {
// RevisionNumber optionally set via extensions/standard-attr-revisions
RevisionNumber int `json:"revision_number"`

// VpcID is the VPC identifier. 1-to-1 relation with a router.
VpcID string `json:"vpc_id"`

// Timestamp when the router was created
CreatedAt time.Time `json:"-"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,3 +897,98 @@ func TestRemoveExternalGateways(t *testing.T) {
th.AssertEquals(t, n.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c")
th.AssertEquals(t, n.GatewayInfo.NetworkID, "")
}

func TestCreateWithVpcID(t *testing.T) {
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()

fakeServer.Mux.HandleFunc("/v2.0/routers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestHeader(t, r, "Accept", "application/json")
th.TestJSONRequest(t, r, `
{
"router": {
"name": "vpc-router",
"admin_state_up": true,
"vpc_id": "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1"
}
}`)

w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)

fmt.Fprint(w, `
{
"router": {
"status": "ACTIVE",
"external_gateway_info": null,
"name": "vpc-router",
"admin_state_up": true,
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
"distributed": false,
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e",
"vpc_id": "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1"
}
}`)
})

asu := true
options := routers.CreateOpts{
Name: "vpc-router",
AdminStateUp: &asu,
VpcID: "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1",
}
r, err := routers.Create(context.TODO(), fake.ServiceClient(fakeServer), options).Extract()
th.AssertNoErr(t, err)

th.AssertEquals(t, "vpc-router", r.Name)
th.AssertEquals(t, "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1", r.VpcID)
th.AssertEquals(t, "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e", r.ID)
}

func TestListWithVpcID(t *testing.T) {
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()

fakeServer.Mux.HandleFunc("/v2.0/routers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

th.AssertEquals(t, r.URL.Query().Get("vpc_id"), "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1")

w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

fmt.Fprint(w, `
{
"routers": [
{
"status": "ACTIVE",
"external_gateway_info": null,
"name": "vpc-router",
"admin_state_up": true,
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
"distributed": false,
"id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e",
"vpc_id": "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1"
}
]
}`)
})

listOpts := routers.ListOpts{
VpcID: "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1",
}

allPages, err := routers.List(fake.ServiceClient(fakeServer), listOpts).AllPages(context.TODO())
th.AssertNoErr(t, err)

allRouters, err := routers.ExtractRouters(allPages)
th.AssertNoErr(t, err)

th.AssertEquals(t, 1, len(allRouters))
th.AssertEquals(t, "a5c3a4d4-5e0f-4c2a-bb02-e2723de5b8f1", allRouters[0].VpcID)
th.AssertEquals(t, "vpc-router", allRouters[0].Name)
}
8 changes: 8 additions & 0 deletions openstack/networking/v2/extensions/layer3/routetables/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Package routetables provides information and interaction with the route
// tables extension for the OpenStack Networking service.
//
// A route table is associated with a router and contains routes and subnet
// associations. Each router has a default route table that cannot be deleted.
// Additional custom route tables can be created and subnets can be moved
// between them.
package routetables
Loading
Loading