Merge pull request #191 from rackspace/stop-start-actions
Add Start, Stop, Pause, Unpause, Suspend, & Resume
diff --git a/interfaces.go b/interfaces.go
index 4c7dbee..d73f11d 100644
--- a/interfaces.go
+++ b/interfaces.go
@@ -244,4 +244,29 @@
// GetSGRule obtains information for a specified security group rule.
// This method only works if the provider supports the os-security-groups-default-rules extension.
GetSGRule(string) (*SGRule, error)
+
+ // Pause stores the state of the server in RAM. A paused instance continues to run in a frozen state.
+ Pause(id string) error
+
+ // Unpause restores normal behavior of a previously paused server.
+ Unpause(id string) error
+
+ // Suspend stores the state of the server on disk or other non-volatile medium.
+ // Administrative users might suspend an infrequently used instance or suspend an instance to perform system maintenance.
+ // Suspending an instance is similar to placing a device in hibernation;
+ // memory and vCPUs become available to create other instances.
+ Suspend(id string) error
+
+ // Resume restores normal behavior of a previously suspended server.
+ Resume(id string) error
+
+ // Start restores a previously stopped server to normal operation.
+ // WARNING: This function depends on a Nova action which remains undocumented on the OpenStack API Reference website,
+ // and may be deprecated in favor of Pause/Unpause, or Suspend/Resume.
+ Start(id string) error
+
+ // Stop stops a server.
+ // WARNING: This function depends on a Nova action which remains undocumented on the OpenStack API Reference website,
+ // and may be deprecated in favor of Pause/Unpause, or Suspend/Resume.
+ Stop(id string) error
}
diff --git a/servers.go b/servers.go
index 1f6a7a4..0861fa2 100644
--- a/servers.go
+++ b/servers.go
@@ -418,6 +418,104 @@
}
// See the CloudServersProvider interface for details.
+func (gsp *genericServersProvider) Pause(id string) error {
+ return gsp.context.WithReauth(gsp.access, func() error {
+ ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
+ return perigee.Post(ep, perigee.Options{
+ ReqBody: &struct {
+ Pause *int `json:"pause"`
+ }{nil},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ OkCodes: []int{202},
+ })
+ })
+}
+
+// See the CloudServersProvider interface for details.
+func (gsp *genericServersProvider) Unpause(id string) error {
+ return gsp.context.WithReauth(gsp.access, func() error {
+ ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
+ return perigee.Post(ep, perigee.Options{
+ ReqBody: &struct {
+ Unpause *int `json:"unpause"`
+ }{nil},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ OkCodes: []int{202},
+ })
+ })
+}
+
+// See the CloudServersProvider interface for details.
+func (gsp *genericServersProvider) Suspend(id string) error {
+ return gsp.context.WithReauth(gsp.access, func() error {
+ ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
+ return perigee.Post(ep, perigee.Options{
+ ReqBody: &struct {
+ Suspend *int `json:"suspend"`
+ }{nil},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ OkCodes: []int{202},
+ })
+ })
+}
+
+// See the CloudServersProvider interface for details.
+func (gsp *genericServersProvider) Resume(id string) error {
+ return gsp.context.WithReauth(gsp.access, func() error {
+ ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
+ return perigee.Post(ep, perigee.Options{
+ ReqBody: &struct {
+ Resume *int `json:"resume"`
+ }{nil},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ OkCodes: []int{202},
+ })
+ })
+}
+
+// WARNING: This function remains undocumented on the OpenStack API reference website, http://developer.openstack.org/api-ref-compute-v2-ext.html .
+// See the CloudServersProvider interface for details.
+func (gsp *genericServersProvider) Start(id string) error {
+ return gsp.context.WithReauth(gsp.access, func() error {
+ ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
+ return perigee.Post(ep, perigee.Options{
+ ReqBody: &struct {
+ Start *int `json:"start"`
+ }{nil},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ OkCodes: []int{202},
+ })
+ })
+}
+
+// WARNING: This function remains undocumented on the OpenStack API reference website, http://developer.openstack.org/api-ref-compute-v2-ext.html .
+// See the CloudServersProvider interface for details.
+func (gsp *genericServersProvider) Stop(id string) error {
+ return gsp.context.WithReauth(gsp.access, func() error {
+ ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
+ return perigee.Post(ep, perigee.Options{
+ ReqBody: &struct {
+ Stop *int `json:"stop"`
+ }{nil},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ OkCodes: []int{202},
+ })
+ })
+}
+
+// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ListSecurityGroups() ([]SecurityGroup, error) {
var sgs []SecurityGroup