Added gophercloud startstop dependency

This commit is contained in:
Dmytro Aleksandrov 2016-06-15 21:50:21 +03:00 committed by Dmytro Aleksandrov
parent 004cec60b3
commit 20bb0b352a
4 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,5 @@
/*
Package startstop provides functionality to start and stop servers that have
been provisioned by the OpenStack Compute service.
*/
package startstop

View File

@ -0,0 +1,29 @@
// +build fixtures
package startstop
import (
"net/http"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func mockStartServerResponse(t *testing.T, id string) {
th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{"os-start": null}`)
w.WriteHeader(http.StatusAccepted)
})
}
func mockStopServerResponse(t *testing.T, id string) {
th.Mux.HandleFunc("/servers/"+id+"/action", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{"os-stop": null}`)
w.WriteHeader(http.StatusAccepted)
})
}

View File

@ -0,0 +1,23 @@
package startstop
import "github.com/rackspace/gophercloud"
func actionURL(client *gophercloud.ServiceClient, id string) string {
return client.ServiceURL("servers", id, "action")
}
// Start is the operation responsible for starting a Compute server.
func Start(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var res gophercloud.ErrResult
reqBody := map[string]interface{}{"os-start": nil}
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}
// Stop is the operation responsible for stopping a Compute server.
func Stop(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var res gophercloud.ErrResult
reqBody := map[string]interface{}{"os-stop": nil}
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, nil)
return res
}

6
vendor/vendor.json vendored
View File

@ -1184,6 +1184,12 @@
"revision": "d47105ce4ef90cea9a14b85c8dd172b760085828",
"revisionTime": "2016-06-03T22:34:01Z"
},
{
"checksumSHA1": "jqSmOJoNKVtGwDhuoilAF7iftqA=",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/startstop",
"revision": "d47105ce4ef90cea9a14b85c8dd172b760085828",
"revisionTime": "2016-06-03T22:34:01Z"
},
{
"checksumSHA1": "rHEOEAm10HDsfBLU8FqKSUdwqFY=",
"path": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks",