blob: 89bc248e299f671732b8969dba6fda309545e533 [file] [log] [blame]
Jamie Hannaford583e23d2014-11-13 13:22:29 +01001package startstop
2
Ash Wilson59fb6c42015-02-12 16:21:13 -05003import "github.com/rackspace/gophercloud"
Jamie Hannaford583e23d2014-11-13 13:22:29 +01004
5func actionURL(client *gophercloud.ServiceClient, id string) string {
6 return client.ServiceURL("servers", id, "action")
7}
8
Jamie Hannaford1c015e12014-11-13 13:23:14 +01009// Start is the operation responsible for starting a Compute server.
Jamie Hannaford583e23d2014-11-13 13:22:29 +010010func Start(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
11 var res gophercloud.ErrResult
12
Jamie Hannaford3f8c8d82014-11-17 10:55:24 +010013 reqBody := map[string]interface{}{"os-start": nil}
Jamie Hannaford583e23d2014-11-13 13:22:29 +010014
Ash Wilson59fb6c42015-02-12 16:21:13 -050015 _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
16 JSONBody: reqBody,
Jamie Hannaford583e23d2014-11-13 13:22:29 +010017 })
18
19 return res
20}
21
Jamie Hannaford1c015e12014-11-13 13:23:14 +010022// Stop is the operation responsible for stopping a Compute server.
Jamie Hannaford583e23d2014-11-13 13:22:29 +010023func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
24 var res gophercloud.ErrResult
25
Jamie Hannaford3f8c8d82014-11-17 10:55:24 +010026 reqBody := map[string]interface{}{"os-stop": nil}
Jamie Hannaford583e23d2014-11-13 13:22:29 +010027
Ash Wilson59fb6c42015-02-12 16:21:13 -050028 _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
29 JSONBody: reqBody,
Jamie Hannaford583e23d2014-11-13 13:22:29 +010030 })
31
32 return res
33}