Get default sec group
diff --git a/openstack/compute/v2/extensions/defsecrules/fixtures.go b/openstack/compute/v2/extensions/defsecrules/fixtures.go
index c0dc62b..2e02870 100644
--- a/openstack/compute/v2/extensions/defsecrules/fixtures.go
+++ b/openstack/compute/v2/extensions/defsecrules/fixtures.go
@@ -24,7 +24,7 @@
"security_group_default_rules": [
{
"from_port": 80,
- "id": "f9a97fcf-3a97-47b0-b76f-919136afb7ed",
+ "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
"ip_protocol": "TCP",
"ip_range": {
"cidr": "10.10.10.0/24"
@@ -72,3 +72,28 @@
`)
})
}
+
+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)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+{
+ "security_group_default_rule": {
+ "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
+ "from_port": 80,
+ "to_port": 80,
+ "ip_protocol": "TCP",
+ "ip_range": {
+ "cidr": "10.10.12.0/24"
+ }
+ }
+}
+ `)
+ })
+}
diff --git a/openstack/compute/v2/extensions/defsecrules/requests.go b/openstack/compute/v2/extensions/defsecrules/requests.go
index 2973cf0..7d304de 100644
--- a/openstack/compute/v2/extensions/defsecrules/requests.go
+++ b/openstack/compute/v2/extensions/defsecrules/requests.go
@@ -83,3 +83,16 @@
return result
}
+
+// Get will return details for a particular default rule.
+func Get(client *gophercloud.ServiceClient, id string) GetResult {
+ var result GetResult
+
+ _, result.Err = perigee.Request("GET", resourceURL(client, id), perigee.Options{
+ Results: &result.Body,
+ MoreHeaders: client.AuthenticatedHeaders(),
+ OkCodes: []int{200},
+ })
+
+ return result
+}
diff --git a/openstack/compute/v2/extensions/defsecrules/requests_test.go b/openstack/compute/v2/extensions/defsecrules/requests_test.go
index fd3fe17..d220ede 100644
--- a/openstack/compute/v2/extensions/defsecrules/requests_test.go
+++ b/openstack/compute/v2/extensions/defsecrules/requests_test.go
@@ -9,6 +9,8 @@
"github.com/rackspace/gophercloud/testhelper/client"
)
+const ruleID = "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5"
+
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -25,7 +27,7 @@
expected := []DefaultRule{
DefaultRule{
FromPort: 80,
- ID: "f9a97fcf-3a97-47b0-b76f-919136afb7ed",
+ ID: ruleID,
IPProtocol: "TCP",
IPRange: secgroups.IPRange{CIDR: "10.10.10.0/24"},
ToPort: 80,
@@ -58,7 +60,7 @@
th.AssertNoErr(t, err)
expected := &DefaultRule{
- ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
+ ID: ruleID,
FromPort: 80,
ToPort: 80,
IPProtocol: "TCP",
@@ -66,3 +68,23 @@
}
th.AssertDeepEquals(t, expected, group)
}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockGetRuleResponse(t, ruleID)
+
+ group, err := Get(client.ServiceClient(), ruleID).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &DefaultRule{
+ ID: ruleID,
+ FromPort: 80,
+ ToPort: 80,
+ IPProtocol: "TCP",
+ IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"},
+ }
+
+ th.AssertDeepEquals(t, expected, group)
+}