Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[v2] [octavia] add an ability to filter flavors and flavorprofiles #3199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2024
Merged
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
4 changes: 4 additions & 0 deletions 4 openstack/loadbalancer/v2/flavorprofiles/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type ListOptsBuilder interface {

// ListOpts allows to manage the output of the request.
type ListOpts struct {
// The name of the flavor profile to filter by.
Name string `q:"name"`
// The provider name of the flavor profile to filter by.
ProviderName string `q:"provider_name"`
// The fields that you want the server to return
Fields []string `q:"fields"`
}
Expand Down
6 changes: 6 additions & 0 deletions 6 openstack/loadbalancer/v2/flavors/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ type ListOptsBuilder interface {

// ListOpts allows to manage the output of the request.
type ListOpts struct {
// The name of the flavor to filter by.
Name string `q:"name"`
// The flavor profile id to filter by.
FlavorProfileID string `q:"flavor_profile_id"`
// The enabled status of the flavor to filter by.
Enabled *bool `q:"enabled"`
// The fields that you want the server to return
Fields []string `q:"fields"`
}
Expand Down
47 changes: 47 additions & 0 deletions 47 openstack/loadbalancer/v2/flavors/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package testing

import (
"context"
"fmt"
"net/http"
"testing"

"github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/flavors"
"github.com/gophercloud/gophercloud/v2/pagination"

fake "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/testhelper"
th "github.com/gophercloud/gophercloud/v2/testhelper"
"github.com/gophercloud/gophercloud/v2/testhelper/client"
)

func TestListFlavors(t *testing.T) {
Expand Down Expand Up @@ -41,6 +44,50 @@ func TestListFlavors(t *testing.T) {
}
}

func TestListFlavorsEnabled(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

func() {
testCases := []string{
"true",
"false",
"",
}

cases := 0
th.Mux.HandleFunc("/v2.0/lbaas/flavors", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

w.Header().Add("Content-Type", "application/json")
if err := r.ParseForm(); err != nil {
t.Errorf("Failed to parse request form %v", err)
}
enabled := r.Form.Get("enabled")
if enabled != testCases[cases] {
t.Errorf("Expected enabled=%s got %q", testCases[cases], enabled)
}
cases++
fmt.Fprintf(w, `{"flavorprofiles":[]}`)
})
}()

var nilBool *bool
enabled := true
filters := []*bool{
&enabled,
new(bool),
nilBool,
}
for _, filter := range filters {
allPages, err := flavors.List(fake.ServiceClient(), flavors.ListOpts{Enabled: filter}).AllPages(context.TODO())
th.AssertNoErr(t, err)
_, err = flavors.ExtractFlavors(allPages)
th.AssertNoErr(t, err)
}
}

func TestListAllFlavors(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.