blob: 36b8240bb98788f59e555c01b4cd4dd0f5ca0a66 [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
16 reqBody := map[string](*interface{}){"os-start": nil}
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 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
31 reqBody := map[string](*interface{}){"os-stop": nil}
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}