Adding get secgroup
diff --git a/openstack/compute/v2/extensions/secgroups/fixtures.go b/openstack/compute/v2/extensions/secgroups/fixtures.go
index 168bbdd..761d9e5 100644
--- a/openstack/compute/v2/extensions/secgroups/fixtures.go
+++ b/openstack/compute/v2/extensions/secgroups/fixtures.go
@@ -80,3 +80,41 @@
`)
})
}
+
+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)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+{
+ "security_group": {
+ "description": "default",
+ "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
+ "name": "default",
+ "rules": [
+ {
+ "from_port": 80,
+ "group": {
+ "tenant_id": "openstack",
+ "name": "default"
+ },
+ "ip_protocol": "TCP",
+ "to_port": 85,
+ "parent_group_id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
+ "ip_range": {
+ "cidr": "0.0.0.0"
+ },
+ "id": "ebe599e2-6b8c-457c-b1ff-a75e48f10923"
+ }
+ ],
+ "tenant_id": "openstack"
+ }
+}
+ `)
+ })
+}
diff --git a/openstack/compute/v2/extensions/secgroups/requests.go b/openstack/compute/v2/extensions/secgroups/requests.go
index 0c14716..b852883 100644
--- a/openstack/compute/v2/extensions/secgroups/requests.go
+++ b/openstack/compute/v2/extensions/secgroups/requests.go
@@ -49,3 +49,15 @@
return result
}
+
+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/secgroups/requests_test.go b/openstack/compute/v2/extensions/secgroups/requests_test.go
index 311fc4d..0bc843c 100644
--- a/openstack/compute/v2/extensions/secgroups/requests_test.go
+++ b/openstack/compute/v2/extensions/secgroups/requests_test.go
@@ -8,7 +8,10 @@
"github.com/rackspace/gophercloud/testhelper/client"
)
-const serverID = "{serverID}"
+const (
+ serverID = "{serverID}"
+ groupID = "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5"
+)
func TestList(t *testing.T) {
th.SetupHTTP()
@@ -103,3 +106,33 @@
}
th.AssertDeepEquals(t, expected, group)
}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockGetGroupsResponse(t, groupID)
+
+ group, err := Get(client.ServiceClient(), groupID).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &SecurityGroup{
+ ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
+ Description: "default",
+ Name: "default",
+ TenantID: "openstack",
+ Rules: []Rule{
+ Rule{
+ FromPort: 80,
+ ToPort: 85,
+ IPProtocol: "TCP",
+ IPRange: IPRange{CIDR: "0.0.0.0"},
+ Group: Group{TenantID: "openstack", Name: "default"},
+ ParentGroupID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
+ ID: "ebe599e2-6b8c-457c-b1ff-a75e48f10923",
+ },
+ },
+ }
+
+ th.AssertDeepEquals(t, expected, group)
+}
diff --git a/openstack/compute/v2/extensions/secgroups/results.go b/openstack/compute/v2/extensions/secgroups/results.go
index 8f5477e..6418970 100644
--- a/openstack/compute/v2/extensions/secgroups/results.go
+++ b/openstack/compute/v2/extensions/secgroups/results.go
@@ -16,17 +16,24 @@
}
type Rule struct {
- ID string
- FromPort int `mapstructure:"from_port"`
- ToPort int `mapstructure:"to_port"`
- IPProtocol string `mapstructure:"ip_protocol"`
- IPRange IPRange `mapstructure:"ip_range"`
+ ID string
+ FromPort int `mapstructure:"from_port"`
+ ToPort int `mapstructure:"to_port"`
+ IPProtocol string `mapstructure:"ip_protocol"`
+ IPRange IPRange `mapstructure:"ip_range"`
+ ParentGroupID string `mapstructure:"parent_group_id"`
+ Group Group
}
type IPRange struct {
CIDR string
}
+type Group struct {
+ TenantID string `mapstructure:"tenant_id"`
+ Name string
+}
+
// RolePage is a single page of a user Role collection.
type SecurityGroupPage struct {
pagination.SinglePageBase
@@ -60,6 +67,10 @@
commonResult
}
+type GetResult struct {
+ commonResult
+}
+
func (r commonResult) Extract() (*SecurityGroup, error) {
if r.Err != nil {
return nil, r.Err