networking/v2/ports: allow list filter by security group#2728
Merged
pierreprinetti merged 1 commit intogophercloud:masterfrom Aug 25, 2023
Merged
networking/v2/ports: allow list filter by security group#2728pierreprinetti merged 1 commit intogophercloud:masterfrom
pierreprinetti merged 1 commit intogophercloud:masterfrom
Conversation
Contributor
Author
|
neutron v2 ports APIs allow to list ports by security group already: https://docs.openstack.org/api-ref/network/v2/#show-port-details This patch adds the `SecurityGroups` field to `ListOpts`. One way to filter the ports by security group can be done with the following code: ``` listOpts := ports.ListOpts{ SecurityGroups: []string{"2183457b-70cc-4fd0-a2dc-95323fa19e45"} } allPages, err := ports.List(networkClient, listOpts).AllPages() if err != nil { panic(err) } allPorts, err := ports.ExtractPorts(allPages) if err != nil { panic(err) } for _, port := range allPorts { fmt.Printf("%+v\n", port) } ```
Contributor
|
This doesn't seem to be correct to me, listing ports doesn't list |
Contributor
|
Uhm, so docs seems to be missing this, but it does work after I updated my openstackclient: |
Contributor
Author
|
I've tested the code and it worked fine: package main
import (
"fmt"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/utils/openstack/clientconfig"
)
func main() {
client, err := clientconfig.NewServiceClient("network", nil)
if err != nil {
panic(err)
}
listOpts := ports.ListOpts{
SecurityGroups: []string{"21381a6a-6a66-438d-bea3-5cab44441ba8"},
}
allPages, err := ports.List(client, listOpts).AllPages()
if err != nil {
panic(err)
}
allPorts, err := ports.ExtractPorts(allPages)
if err != nil {
panic(err)
}
for _, port := range allPorts {
fmt.Printf("%+v\n", port)
}
}And it returned: |
Contributor
|
Looks like it comes from this extension: https://github.com/openstack/neutron-lib/blob/master/neutron_lib/api/definitions/security_groups_port_filtering.py |
Contributor
|
/lgtm It'll be much better to use this in cloud-provider-openstack. |
Contributor
Author
|
@pierreprinetti for review when time permits. |
kayrus
approved these changes
Aug 23, 2023
Contributor
|
kubernetes/cloud-provider-openstack#2355 - and it's in use already. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
neutron v2 ports APIs allow to list ports by security group already:
https://docs.openstack.org/api-ref/network/v2/#show-port-details
This patch adds the
SecurityGroupsfield toListOpts.One way to filter the ports by security group can be done with the
following code: