Add/remove servers from secgroups
diff --git a/openstack/compute/v2/extensions/secgroups/requests.go b/openstack/compute/v2/extensions/secgroups/requests.go
index 505439e..c33fcaf 100644
--- a/openstack/compute/v2/extensions/secgroups/requests.go
+++ b/openstack/compute/v2/extensions/secgroups/requests.go
@@ -63,7 +63,7 @@
UpdateOpts `json:"security_group"`
}{opts}
- _, result.Err = perigee.Request("POST", resourceURL(client, id), perigee.Options{
+ _, result.Err = perigee.Request("PUT", resourceURL(client, id), perigee.Options{
Results: &result.Body,
ReqBody: &reqBody,
MoreHeaders: client.AuthenticatedHeaders(),
@@ -169,3 +169,35 @@
return result
}
+
+func actionMap(prefix, groupName string) map[string]map[string]string {
+ return map[string]map[string]string{
+ prefix + "SecurityGroup": map[string]string{"name": groupName},
+ }
+}
+
+func AddServerToGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
+ var result gophercloud.ErrResult
+
+ _, result.Err = perigee.Request("POST", serverActionURL(client, serverID), perigee.Options{
+ Results: &result.Body,
+ ReqBody: actionMap("add", groupName),
+ MoreHeaders: client.AuthenticatedHeaders(),
+ OkCodes: []int{200},
+ })
+
+ return result
+}
+
+func RemoveServerFromGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
+ var result gophercloud.ErrResult
+
+ _, result.Err = perigee.Request("POST", serverActionURL(client, serverID), perigee.Options{
+ Results: &result.Body,
+ ReqBody: actionMap("remove", groupName),
+ MoreHeaders: client.AuthenticatedHeaders(),
+ OkCodes: []int{200},
+ })
+
+ return result
+}