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

[neutron]: introduce Stateful argument for the security groups #3092

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 1 commit into from
Jul 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestSecurityGroupsCreateUpdateDelete(t *testing.T) {
group, err := CreateSecurityGroup(t, client)
th.AssertNoErr(t, err)
defer DeleteSecurityGroup(t, client, group.ID)
th.AssertEquals(t, group.Stateful, true)

rule, err := CreateSecurityGroupRule(t, client, group.ID)
th.AssertNoErr(t, err)
Expand All @@ -32,6 +33,7 @@ func TestSecurityGroupsCreateUpdateDelete(t *testing.T) {
updateOpts := groups.UpdateOpts{
Name: name,
Description: &description,
Stateful: new(bool),
}

newGroup, err := groups.Update(context.TODO(), client, group.ID, updateOpts).Extract()
Expand All @@ -40,6 +42,7 @@ func TestSecurityGroupsCreateUpdateDelete(t *testing.T) {
tools.PrintResource(t, newGroup)
th.AssertEquals(t, newGroup.Name, name)
th.AssertEquals(t, newGroup.Description, description)
th.AssertEquals(t, newGroup.Stateful, false)

listOpts := groups.ListOpts{}
allPages, err := groups.List(client, listOpts).AllPages(context.TODO())
Expand Down
34 changes: 28 additions & 6 deletions 34 openstack/networking/v2/extensions/security/groups/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/gophercloud/gophercloud/v2/pagination"
)

// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToSecGroupListQuery() (string, error)
}

// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the group attributes you want to see returned. SortKey allows you to
Expand All @@ -16,6 +22,7 @@ type ListOpts struct {
ID string `q:"id"`
Name string `q:"name"`
Description string `q:"description"`
Stateful *bool `q:"stateful"`
TenantID string `q:"tenant_id"`
ProjectID string `q:"project_id"`
Limit int `q:"limit"`
Expand All @@ -28,16 +35,25 @@ type ListOpts struct {
NotTagsAny string `q:"not-tags-any"`
}

// ToPortListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToSecGroupListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}

// List returns a Pager which allows you to iterate over a collection of
// security groups. It accepts a ListOpts struct, which allows you to filter
// and sort the returned collection for greater efficiency.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q, err := gophercloud.BuildQueryString(&opts)
if err != nil {
return pagination.Pager{Err: err}
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := rootURL(c)
if opts != nil {
query, err := opts.ToSecGroupListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
u := rootURL(c) + q.String()
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
return SecGroupPage{pagination.LinkedPageBase{PageResult: r}}
})
}
Expand All @@ -63,6 +79,9 @@ type CreateOpts struct {

// Describes the security group.
Description string `json:"description,omitempty"`

// Stateful indicates if the security group is stateful or stateless.
Stateful *bool `json:"stateful,omitempty"`
}

// ToSecGroupCreateMap builds a request body from CreateOpts.
Expand Down Expand Up @@ -97,6 +116,9 @@ type UpdateOpts struct {

// Describes the security group.
Description *string `json:"description,omitempty"`

// Stateful indicates if the security group is stateful or stateless.
Stateful *bool `json:"stateful,omitempty"`
}

// ToSecGroupUpdateMap builds a request body from UpdateOpts.
Expand Down
3 changes: 3 additions & 0 deletions 3 openstack/networking/v2/extensions/security/groups/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type SecGroup struct {
// traffic entering and leaving the group.
Rules []rules.SecGroupRule `json:"security_group_rules"`

// Indicates if the security group is stateful or stateless.
Stateful bool `json:"stateful"`

// TenantID is the project owner of the security group.
TenantID string `json:"tenant_id"`

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.