Moving IDs back to strings
diff --git a/openstack/compute/v2/extensions/defsecrules/fixtures.go b/openstack/compute/v2/extensions/defsecrules/fixtures.go
index 9b1480f..c28e492 100644
--- a/openstack/compute/v2/extensions/defsecrules/fixtures.go
+++ b/openstack/compute/v2/extensions/defsecrules/fixtures.go
@@ -3,7 +3,6 @@
import (
"fmt"
"net/http"
- "strconv"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
@@ -25,7 +24,7 @@
"security_group_default_rules": [
{
"from_port": 80,
- "id": 1,
+ "id": "{ruleID}",
"ip_protocol": "TCP",
"ip_range": {
"cidr": "10.10.10.0/24"
@@ -61,7 +60,7 @@
{
"security_group_default_rule": {
"from_port": 80,
- "id": 1,
+ "id": "{ruleID}",
"ip_protocol": "TCP",
"ip_range": {
"cidr": "10.10.12.0/24"
@@ -73,8 +72,8 @@
})
}
-func mockGetRuleResponse(t *testing.T, ruleID int) {
- url := rootPath + "/" + strconv.Itoa(ruleID)
+func mockGetRuleResponse(t *testing.T, ruleID string) {
+ url := rootPath + "/" + ruleID
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -85,7 +84,7 @@
fmt.Fprintf(w, `
{
"security_group_default_rule": {
- "id": 1,
+ "id": "{ruleID}",
"from_port": 80,
"to_port": 80,
"ip_protocol": "TCP",
@@ -98,8 +97,8 @@
})
}
-func mockDeleteRuleResponse(t *testing.T, ruleID int) {
- url := rootPath + "/" + strconv.Itoa(ruleID)
+func mockDeleteRuleResponse(t *testing.T, ruleID string) {
+ url := rootPath + "/" + ruleID
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
diff --git a/openstack/compute/v2/extensions/defsecrules/requests.go b/openstack/compute/v2/extensions/defsecrules/requests.go
index 702a7a7..7d19741 100644
--- a/openstack/compute/v2/extensions/defsecrules/requests.go
+++ b/openstack/compute/v2/extensions/defsecrules/requests.go
@@ -86,7 +86,7 @@
}
// Get will return details for a particular default rule.
-func Get(client *gophercloud.ServiceClient, id int) GetResult {
+func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
_, result.Err = perigee.Request("GET", resourceURL(client, id), perigee.Options{
@@ -99,7 +99,7 @@
}
// Delete will permanently delete a default rule from the project.
-func Delete(client *gophercloud.ServiceClient, id int) gophercloud.ErrResult {
+func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
_, result.Err = perigee.Request("DELETE", resourceURL(client, id), perigee.Options{
diff --git a/openstack/compute/v2/extensions/defsecrules/requests_test.go b/openstack/compute/v2/extensions/defsecrules/requests_test.go
index 5f43b34..d4ebe87 100644
--- a/openstack/compute/v2/extensions/defsecrules/requests_test.go
+++ b/openstack/compute/v2/extensions/defsecrules/requests_test.go
@@ -9,7 +9,7 @@
"github.com/rackspace/gophercloud/testhelper/client"
)
-const ruleID = 1
+const ruleID = "{ruleID}"
func TestList(t *testing.T) {
th.SetupHTTP()
diff --git a/openstack/compute/v2/extensions/defsecrules/urls.go b/openstack/compute/v2/extensions/defsecrules/urls.go
index 07244f7..cc928ab 100644
--- a/openstack/compute/v2/extensions/defsecrules/urls.go
+++ b/openstack/compute/v2/extensions/defsecrules/urls.go
@@ -1,15 +1,11 @@
package defsecrules
-import (
- "strconv"
-
- "github.com/rackspace/gophercloud"
-)
+import "github.com/rackspace/gophercloud"
const rulepath = "os-security-group-default-rules"
-func resourceURL(c *gophercloud.ServiceClient, id int) string {
- return c.ServiceURL(rulepath, strconv.Itoa(id))
+func resourceURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(rulepath, id)
}
func rootURL(c *gophercloud.ServiceClient) string {
diff --git a/openstack/compute/v2/extensions/secgroups/fixtures.go b/openstack/compute/v2/extensions/secgroups/fixtures.go
index d45609c..b205678 100644
--- a/openstack/compute/v2/extensions/secgroups/fixtures.go
+++ b/openstack/compute/v2/extensions/secgroups/fixtures.go
@@ -16,7 +16,7 @@
"security_groups": [
{
"description": "default",
- "id": 1,
+ "id": "{groupID}",
"name": "default",
"rules": [],
"tenant_id": "openstack"
@@ -71,7 +71,7 @@
{
"security_group": {
"description": "something",
- "id": 1,
+ "id": "{groupID}",
"name": "test",
"rules": [],
"tenant_id": "openstack"
@@ -81,8 +81,8 @@
})
}
-func mockUpdateGroupResponse(t *testing.T, groupID int) {
- url := fmt.Sprintf("%s/%d", rootPath, groupID)
+func mockUpdateGroupResponse(t *testing.T, groupID string) {
+ url := fmt.Sprintf("%s/%s", rootPath, groupID)
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -103,7 +103,7 @@
{
"security_group": {
"description": "something",
- "id": 1,
+ "id": "{groupID}",
"name": "new_name",
"rules": [],
"tenant_id": "openstack"
@@ -113,8 +113,8 @@
})
}
-func mockGetGroupsResponse(t *testing.T, groupID int) {
- url := fmt.Sprintf("%s/%d", rootPath, groupID)
+func mockGetGroupsResponse(t *testing.T, groupID string) {
+ url := fmt.Sprintf("%s/%s", rootPath, groupID)
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -126,7 +126,7 @@
{
"security_group": {
"description": "default",
- "id": 1,
+ "id": "{groupID}",
"name": "default",
"rules": [
{
@@ -137,11 +137,11 @@
},
"ip_protocol": "TCP",
"to_port": 85,
- "parent_group_id": 1,
+ "parent_group_id": "{groupID}",
"ip_range": {
"cidr": "0.0.0.0"
},
- "id": 2
+ "id": "{ruleID}"
}
],
"tenant_id": "openstack"
@@ -151,8 +151,8 @@
})
}
-func mockDeleteGroupResponse(t *testing.T, groupID int) {
- url := fmt.Sprintf("%s/%d", rootPath, groupID)
+func mockDeleteGroupResponse(t *testing.T, groupID string) {
+ url := fmt.Sprintf("%s/%s", rootPath, groupID)
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
@@ -172,7 +172,7 @@
"from_port": 22,
"ip_protocol": "TCP",
"to_port": 22,
- "parent_group_id": 1,
+ "parent_group_id": "{groupID}",
"cidr": "0.0.0.0/0"
}
} `)
@@ -187,18 +187,18 @@
"group": {},
"ip_protocol": "TCP",
"to_port": 22,
- "parent_group_id": 1,
+ "parent_group_id": "{groupID}",
"ip_range": {
"cidr": "0.0.0.0/0"
},
- "id": 2
+ "id": "{ruleID}"
}
}`)
})
}
-func mockDeleteRuleResponse(t *testing.T, ruleID int) {
- url := fmt.Sprintf("/os-security-group-rules/%d", ruleID)
+func mockDeleteRuleResponse(t *testing.T, ruleID string) {
+ url := fmt.Sprintf("/os-security-group-rules/%s", ruleID)
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
diff --git a/openstack/compute/v2/extensions/secgroups/requests.go b/openstack/compute/v2/extensions/secgroups/requests.go
index 820146e..0a87068 100644
--- a/openstack/compute/v2/extensions/secgroups/requests.go
+++ b/openstack/compute/v2/extensions/secgroups/requests.go
@@ -119,7 +119,7 @@
// Update will modify the mutable properties of a security group, notably its
// name and description.
-func Update(client *gophercloud.ServiceClient, id int, opts UpdateOptsBuilder) UpdateResult {
+func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult {
var result UpdateResult
reqBody, err := opts.ToSecGroupUpdateMap()
@@ -139,7 +139,7 @@
}
// Get will return details for a particular security group.
-func Get(client *gophercloud.ServiceClient, id int) GetResult {
+func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
_, result.Err = perigee.Request("GET", resourceURL(client, id), perigee.Options{
@@ -152,7 +152,7 @@
}
// Delete will permanently delete a security group from the project.
-func Delete(client *gophercloud.ServiceClient, id int) gophercloud.ErrResult {
+func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
_, result.Err = perigee.Request("DELETE", resourceURL(client, id), perigee.Options{
@@ -167,7 +167,7 @@
// existing security group.
type CreateRuleOpts struct {
// Required - the ID of the group that this rule will be added to.
- ParentGroupID int `json:"parent_group_id"`
+ ParentGroupID string `json:"parent_group_id"`
// Required - the lower bound of the port range that will be opened.
FromPort int `json:"from_port"`
@@ -199,7 +199,7 @@
func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error) {
rule := make(map[string]interface{})
- if opts.ParentGroupID == 0 {
+ if opts.ParentGroupID == "" {
return rule, errors.New("A ParentGroupID must be set")
}
if opts.FromPort == 0 {
@@ -253,7 +253,7 @@
}
// DeleteRule will permanently delete a rule from a security group.
-func DeleteRule(client *gophercloud.ServiceClient, id int) gophercloud.ErrResult {
+func DeleteRule(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
_, result.Err = perigee.Request("DELETE", resourceRuleURL(client, id), perigee.Options{
diff --git a/openstack/compute/v2/extensions/secgroups/requests_test.go b/openstack/compute/v2/extensions/secgroups/requests_test.go
index 667db59..9f62d05 100644
--- a/openstack/compute/v2/extensions/secgroups/requests_test.go
+++ b/openstack/compute/v2/extensions/secgroups/requests_test.go
@@ -10,8 +10,8 @@
const (
serverID = "{serverID}"
- groupID = 1
- ruleID = 2
+ groupID = "{groupID}"
+ ruleID = "{ruleID}"
)
func TestList(t *testing.T) {
diff --git a/openstack/compute/v2/extensions/secgroups/results.go b/openstack/compute/v2/extensions/secgroups/results.go
index e2ac853..2d19fab 100644
--- a/openstack/compute/v2/extensions/secgroups/results.go
+++ b/openstack/compute/v2/extensions/secgroups/results.go
@@ -9,8 +9,10 @@
// SecurityGroup represents a security group.
type SecurityGroup struct {
- // The unique ID of the group.
- ID int
+ // The unique ID of the group. If Neutron is installed, this ID will be
+ // represented as a string UUID; if Neutron is not installed, it will be a
+ // numeric ID. For the sake of consistency, we always cast it to a string.
+ ID string
// The human-readable name of the group, which needs to be unique.
Name string
@@ -28,8 +30,10 @@
// Rule represents a security group rule, a policy which determines how a
// security group operates and what inbound traffic it allows in.
type Rule struct {
- // The unique ID
- ID int
+ // The unique ID. If Neutron is installed, this ID will be
+ // represented as a string UUID; if Neutron is not installed, it will be a
+ // numeric ID. For the sake of consistency, we always cast it to a string.
+ ID string
// The lower bound of the port range which this security group should open up
FromPort int `mapstructure:"from_port"`
@@ -44,7 +48,7 @@
IPRange IPRange `mapstructure:"ip_range"`
// The security group ID to which this rule belongs
- ParentGroupID int `mapstructure:"parent_group_id"`
+ ParentGroupID string `mapstructure:"parent_group_id"`
// Not documented.
Group Group
diff --git a/openstack/compute/v2/extensions/secgroups/urls.go b/openstack/compute/v2/extensions/secgroups/urls.go
index 2363d20..f4760b6 100644
--- a/openstack/compute/v2/extensions/secgroups/urls.go
+++ b/openstack/compute/v2/extensions/secgroups/urls.go
@@ -1,18 +1,14 @@
package secgroups
-import (
- "strconv"
-
- "github.com/rackspace/gophercloud"
-)
+import "github.com/rackspace/gophercloud"
const (
secgrouppath = "os-security-groups"
rulepath = "os-security-group-rules"
)
-func resourceURL(c *gophercloud.ServiceClient, id int) string {
- return c.ServiceURL(secgrouppath, strconv.Itoa(id))
+func resourceURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(secgrouppath, id)
}
func rootURL(c *gophercloud.ServiceClient) string {
@@ -27,8 +23,8 @@
return c.ServiceURL(rulepath)
}
-func resourceRuleURL(c *gophercloud.ServiceClient, id int) string {
- return c.ServiceURL(rulepath, strconv.Itoa(id))
+func resourceRuleURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL(rulepath, id)
}
func serverActionURL(c *gophercloud.ServiceClient, id string) string {