blob: 04b5909372e6340d8c1317e289d3e71d0cd8fcff [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,
17 OkCodes: []int{202},
Jamie Hannaford583e23d2014-11-13 13:22:29 +010018 })
19
20 return res
21}
22
Jamie Hannaford1c015e12014-11-13 13:23:14 +010023// Stop is the operation responsible for stopping a Compute server.
Jamie Hannaford583e23d2014-11-13 13:22:29 +010024func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
25 var res gophercloud.ErrResult
26
Jamie Hannaford3f8c8d82014-11-17 10:55:24 +010027 reqBody := map[string]interface{}{"os-stop": nil}
Jamie Hannaford583e23d2014-11-13 13:22:29 +010028
Ash Wilson59fb6c42015-02-12 16:21:13 -050029 _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
30 JSONBody: reqBody,
31 OkCodes: []int{202},
Jamie Hannaford583e23d2014-11-13 13:22:29 +010032 })
33
34 return res
35}