blob: 99c91b054a30fae36c47f206a676397e31fab41a [file] [log] [blame]
Jamie Hannaford583e23d2014-11-13 13:22:29 +01001package startstop
2
3import (
4 "github.com/racker/perigee"
5 "github.com/rackspace/gophercloud"
6)
7
8func actionURL(client *gophercloud.ServiceClient, id string) string {
9 return client.ServiceURL("servers", id, "action")
10}
11
Jamie Hannaford1c015e12014-11-13 13:23:14 +010012// Start is the operation responsible for starting a Compute server.
Jamie Hannaford583e23d2014-11-13 13:22:29 +010013func Start(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
14 var res gophercloud.ErrResult
15
Jamie Hannaford3f8c8d82014-11-17 10:55:24 +010016 reqBody := map[string]interface{}{"os-start": nil}
Jamie Hannaford583e23d2014-11-13 13:22:29 +010017
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 Hannaford1c015e12014-11-13 13:23:14 +010027// Stop is the operation responsible for stopping a Compute server.
Jamie Hannaford583e23d2014-11-13 13:22:29 +010028func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
29 var res gophercloud.ErrResult
30
Jamie Hannaford3f8c8d82014-11-17 10:55:24 +010031 reqBody := map[string]interface{}{"os-stop": nil}
Jamie Hannaford583e23d2014-11-13 13:22:29 +010032
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}