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