Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 1 | package startstop |
| 2 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 3 | import "github.com/rackspace/gophercloud" |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 4 | |
| 5 | func actionURL(client *gophercloud.ServiceClient, id string) string { |
| 6 | return client.ServiceURL("servers", id, "action") |
| 7 | } |
| 8 | |
Jamie Hannaford | 1c015e1 | 2014-11-13 13:23:14 +0100 | [diff] [blame] | 9 | // Start is the operation responsible for starting a Compute server. |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 10 | func Start(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult { |
| 11 | var res gophercloud.ErrResult |
| 12 | |
Jamie Hannaford | 3f8c8d8 | 2014-11-17 10:55:24 +0100 | [diff] [blame] | 13 | reqBody := map[string]interface{}{"os-start": nil} |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 14 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 15 | _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{ |
| 16 | JSONBody: reqBody, |
| 17 | OkCodes: []int{202}, |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 18 | }) |
| 19 | |
| 20 | return res |
| 21 | } |
| 22 | |
Jamie Hannaford | 1c015e1 | 2014-11-13 13:23:14 +0100 | [diff] [blame] | 23 | // Stop is the operation responsible for stopping a Compute server. |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 24 | func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult { |
| 25 | var res gophercloud.ErrResult |
| 26 | |
Jamie Hannaford | 3f8c8d8 | 2014-11-17 10:55:24 +0100 | [diff] [blame] | 27 | reqBody := map[string]interface{}{"os-stop": nil} |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 28 | |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 29 | _, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{ |
| 30 | JSONBody: reqBody, |
| 31 | OkCodes: []int{202}, |
Jamie Hannaford | 583e23d | 2014-11-13 13:22:29 +0100 | [diff] [blame] | 32 | }) |
| 33 | |
| 34 | return res |
| 35 | } |