Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit af49847

Browse files
committed
From Port and To Port should accept values of 0 when the IP Protocol is "ICMP".
Fixing #521
1 parent 680aa02 commit af49847

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

openstack/compute/v2/extensions/defsecrules/requests.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package defsecrules
22

33
import (
44
"errors"
5+
"strings"
56

67
"github.com/rackspace/gophercloud"
78
"github.com/rackspace/gophercloud/pagination"
@@ -42,10 +43,10 @@ type CreateOptsBuilder interface {
4243
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
4344
rule := make(map[string]interface{})
4445

45-
if opts.FromPort == 0 {
46+
if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
4647
return rule, errors.New("A FromPort must be set")
4748
}
48-
if opts.ToPort == 0 {
49+
if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
4950
return rule, errors.New("A ToPort must be set")
5051
}
5152
if opts.IPProtocol == "" {

openstack/compute/v2/extensions/secgroups/requests.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package secgroups
22

33
import (
44
"errors"
5+
"strings"
56

67
"github.com/rackspace/gophercloud"
78
"github.com/rackspace/gophercloud/pagination"
@@ -181,10 +182,10 @@ func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error) {
181182
if opts.ParentGroupID == "" {
182183
return rule, errors.New("A ParentGroupID must be set")
183184
}
184-
if opts.FromPort == 0 {
185+
if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
185186
return rule, errors.New("A FromPort must be set")
186187
}
187-
if opts.ToPort == 0 {
188+
if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
188189
return rule, errors.New("A ToPort must be set")
189190
}
190191
if opts.IPProtocol == "" {

0 commit comments

Comments
 (0)