github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/evacuate/requests.go (about) 1 package evacuate 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions" 6 ) 7 8 // EvacuateOptsBuilder allows extensions to add additional parameters to the 9 // the Evacuate request. 10 type EvacuateOptsBuilder interface { 11 ToEvacuateMap() (map[string]interface{}, error) 12 } 13 14 // EvacuateOpts specifies Evacuate action parameters. 15 type EvacuateOpts struct { 16 // The name of the host to which the server is evacuated 17 Host string `json:"host,omitempty"` 18 19 // Indicates whether server is on shared storage 20 OnSharedStorage bool `json:"onSharedStorage"` 21 22 // An administrative password to access the evacuated server 23 AdminPass string `json:"adminPass,omitempty"` 24 } 25 26 // ToServerGroupCreateMap constructs a request body from CreateOpts. 27 func (opts EvacuateOpts) ToEvacuateMap() (map[string]interface{}, error) { 28 return gophercloud.BuildRequestBody(opts, "evacuate") 29 } 30 31 // Evacuate will Evacuate a failed instance to another host. 32 func Evacuate(client *gophercloud.ServiceClient, id string, opts EvacuateOptsBuilder) (r EvacuateResult) { 33 b, err := opts.ToEvacuateMap() 34 if err != nil { 35 r.Err = err 36 return 37 } 38 resp, err := client.Post(extensions.ActionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ 39 OkCodes: []int{200}, 40 }) 41 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 42 return 43 }